UNPKG

froala-editor

Version:

A beautiful jQuery WYSIWYG HTML rich text editor. High performance and modern design make it easy to use for developers and loved by users.

7 lines (6 loc) 5.06 kB
/*! * froala_editor v2.3.4 (https://www.froala.com/wysiwyg-editor) * License https://froala.com/wysiwyg-editor/terms/ * Copyright 2014-2016 Froala Labs */ !function(a){"function"==typeof define&&define.amd?define(["jquery"],a):"object"==typeof module&&module.exports?module.exports=function(b,c){return void 0===c&&(c="undefined"!=typeof window?require("jquery"):require("jquery")(b)),a(c),c}:a(jQuery)}(function(a){"use strict";a.extend(a.FE.DEFAULTS,{quickInsertButtons:["image","table","ul","ol","hr"],quickInsertTags:["p","div","h1","h2","h3","h4","h5","h6","pre","blockquote"]}),a.FE.QUICK_INSERT_BUTTONS={image:{icon:"insertImage",callback:function(){var b=this;b.shared.$qi_image_input||(b.shared.$qi_image_input=a('<input accept="image/*" name="quickInsertImage'+this.id+'" style="display: none;" type="file">'),a("body").append(b.shared.$qi_image_input),b.events.$on(b.shared.$qi_image_input,"change",function(){var b=a(this).data("inst");this.files&&(b.quickInsert.hide(),b.image.upload(this.files)),a(this).val("")},!0)),b.$qi_image_input=b.shared.$qi_image_input,b.helpers.isMobile()&&b.selection.save(),b.$qi_image_input.data("inst",b).trigger("click")},requiredPlugin:"image",title:"Insert Image"},table:{icon:"insertTable",callback:function(){this.quickInsert.hide(),this.table.insert(2,2),this.undo.saveStep()},requiredPlugin:"table",title:"Insert Table"},ol:{icon:"formatOL",callback:function(){this.quickInsert.hide(),this.lists.format("OL"),this.undo.saveStep()},requiredPlugin:"lists",title:"Ordered List"},ul:{icon:"formatUL",callback:function(){this.quickInsert.hide(),this.lists.format("UL"),this.undo.saveStep()},requiredPlugin:"lists",title:"Unordered List"},hr:{icon:"insertHR",callback:function(){this.quickInsert.hide(),this.commands.insertHR(),this.undo.saveStep()},title:"Insert Horizontal Line"}},a.FE.RegisterQuickInsertCommand=function(b,c){a.FE.QUICK_INSERT_BUTTONS[b]=c},a.FE.PLUGINS.quickInsert=function(b){function c(c){j||h(),b.$box.append(j);var d,e;d=c.offset().top-b.$box.offset().top-(j.outerHeight()-c.outerHeight())/2,e=0-j.outerWidth(),b.opts.iframe&&(d+=b.$iframe.offset().top-a(b.o_win).scrollTop()),j.css("top",d),j.css("left",e),j.data("tag",c),j.addClass("fr-visible")}function d(){var d=b.selection.element();b.node.isBlock(d)||(d=b.node.blockParent(d)),d&&b.node.isEmpty(d)&&b.node.isElement(d.parentNode)?d&&b.selection.isCollapsed()&&c(a(d)):e()}function e(){j&&(b.html.checkIfEmpty(),j.hasClass("fr-on")&&g(),j.removeClass("fr-visible fr-on"),j.css("left",-9999).css("top",-9999))}function f(c){if(c.preventDefault(),j.hasClass("fr-on"))g();else{if(!b.shared.$qi_helper){for(var d=b.opts.quickInsertButtons,e='<div class="fr-qi-helper">',f=0,h=0;h<d.length;h++){var i=a.FE.QUICK_INSERT_BUTTONS[d[h]];i&&(!i.requiredPlugin||a.FE.PLUGINS[i.requiredPlugin]&&b.opts.pluginsEnabled.indexOf(i.requiredPlugin)>=0)&&(e+='<a class="fr-btn fr-floating-btn" role="button" title="'+b.language.translate(i.title)+'" tabindex="-1" data-cmd="'+d[h]+'" style="transition-delay: '+.025*f++ +'s;">'+b.icon.create(i.icon)+"</a>")}e+="</div>",b.shared.$qi_helper=a(e),b.tooltip.bind(b.shared.$qi_helper,".fr-qi-helper > a.fr-btn")}k=b.shared.$qi_helper,k.appendTo(b.$box),setTimeout(function(){k.css("top",parseFloat(j.css("top"))),k.css("left",parseFloat(j.css("left"))+j.outerWidth()),k.find("a").addClass("fr-size-1"),j.addClass("fr-on")},10)}}function g(){var a=b.$box.find(".fr-qi-helper");a.length&&(a.find("a").removeClass("fr-size-1"),a.css("left",-9999),j.removeClass("fr-on"))}function h(){b.shared.$quick_insert||(b.shared.$quick_insert=a('<div class="fr-quick-insert"><a class="fr-floating-btn" role="button" tabindex="-1" title="'+b.language.translate("Quick Insert")+'"><svg viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg"><path d="M22,16.75 L16.75,16.75 L16.75,22 L15.25,22.000 L15.25,16.75 L10,16.75 L10,15.25 L15.25,15.25 L15.25,10 L16.75,10 L16.75,15.25 L22,15.25 L22,16.75 Z"/></svg></a></div>')),j=b.shared.$quick_insert,b.tooltip.bind(b.$box,".fr-quick-insert > a.fr-floating-btn"),b.events.on("destroy",function(){j.removeClass("fr-on").appendTo(a("body")).css("left",-9999).css("top",-9999),k&&(g(),k.appendTo(a("body")))},!0),b.events.on("shared.destroy",function(){j.html("").removeData().remove(),j=null,k&&(k.html("").removeData().remove(),k=null)},!0),b.events.on("commands.before",e),b.events.on("commands.after",function(){b.popups.areVisible()||d()}),b.events.bindClick(b.$box,".fr-quick-insert > a",f),b.events.bindClick(b.$box,".fr-qi-helper > a.fr-btn",function(c){var d=a(c.currentTarget).data("cmd");a.FE.QUICK_INSERT_BUTTONS[d].callback.apply(b,[c.currentTarget])})}function i(){return b.$wp?(b.opts.iframe&&b.$el.parent("html").find("head").append('<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.min.css">'),b.popups.onShow("image.edit",e),b.events.on("mouseup",d),b.helpers.isMobile()&&b.events.$on(a(b.o_doc),"selectionchange",d),b.events.on("blur",e),void b.events.on("keyup",d)):!1}var j,k;return{_init:i,hide:e}}});