UNPKG

froala-editor

Version:

A beautiful Javascript 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) 7.06 kB
/*! * froala_editor v2.8.3 (https://www.froala.com/wysiwyg-editor) * License https://froala.com/wysiwyg-editor/terms/ * Copyright 2014-2018 Froala Labs */ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(require("jquery")):"function"==typeof define&&define.amd?define(["jquery"],t):t(e.jQuery)}(this,function(t){"use strict";var c=(t=t&&t.hasOwnProperty("default")?t["default"]:t).FE;Object.assign(c.DEFAULTS,{quickInsertButtons:["image","video","embedly","table","ul","ol","hr"],quickInsertTags:["p","div","h1","h2","h3","h4","h5","h6","pre","blockquote"]}),c.QUICK_INSERT_BUTTONS={},c.DefineIcon("quickInsert",{PATH:'<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"/>',template:"svg"}),c.RegisterQuickInsertButton=function(e,t){c.QUICK_INSERT_BUTTONS[e]=Object.assign({undo:!0},t)},c.RegisterQuickInsertButton("image",{icon:"insertImage",requiredPlugin:"image",title:"Insert Image",undo:!1,callback:function(){var e=this;e.shared.$qi_image_input||(e.shared.$qi_image_input=t('<input accept="image/*" name="quickInsertImage'+this.id+'" style="display: none;" type="file">'),t("body").first().append(e.shared.$qi_image_input),e.events.$on(e.shared.$qi_image_input,"change",function(){var e=t(this).data("inst");this.files&&(e.quickInsert.hide(),e.image.upload(this.files)),t(this).val("")},!0)),e.$qi_image_input=e.shared.$qi_image_input,e.helpers.isMobile()&&e.selection.save(),e.events.disableBlur(),e.$qi_image_input.data("inst",e).trigger("click")}}),c.RegisterQuickInsertButton("video",{icon:"insertVideo",requiredPlugin:"video",title:"Insert Video",undo:!1,callback:function(){var e=prompt(this.language.translate("Paste the URL of the video you want to insert."));e&&this.video.insertByURL(e)}}),c.RegisterQuickInsertButton("embedly",{icon:"embedly",requiredPlugin:"embedly",title:"Embed URL",undo:!1,callback:function(){var e=prompt(this.language.translate("Paste the URL of any web content you want to insert."));e&&this.embedly.add(e)}}),c.RegisterQuickInsertButton("table",{icon:"insertTable",requiredPlugin:"table",title:"Insert Table",callback:function(){this.table.insert(2,2)}}),c.RegisterQuickInsertButton("ol",{icon:"formatOL",requiredPlugin:"lists",title:"Ordered List",callback:function(){this.lists.format("OL")}}),c.RegisterQuickInsertButton("ul",{icon:"formatUL",requiredPlugin:"lists",title:"Unordered List",callback:function(){this.lists.format("UL")}}),c.RegisterQuickInsertButton("hr",{icon:"insertHR",title:"Insert Horizontal Line",callback:function(){this.commands.insertHR()}}),c.PLUGINS.quickInsert=function(o){var a,l,u=o.$;function t(e){var t,i,n;t=e.offset().top-o.$box.offset().top,i=0-a.outerWidth(),o.opts.enter!=c.ENTER_BR?n=(a.outerHeight()-e.outerHeight())/2:(u("<span>"+c.INVISIBLE_SPACE+"</span>").insertAfter(e),n=(a.outerHeight()-e.next().outerHeight())/2,e.next().remove()),o.opts.iframe&&(t+=o.$iframe.offset().top-o.helpers.scrollTop()),a.hasClass("fr-on")&&0<=t&&l.css("top",t-n),0<=t&&t-n<=o.$box.outerHeight()-e.outerHeight()?(a.hasClass("fr-hidden")&&(a.hasClass("fr-on")&&r(),a.removeClass("fr-hidden")),a.css("top",t-n)):a.hasClass("fr-visible")&&(a.addClass("fr-hidden"),d()),a.css("left",i)}function i(e){a||function(){o.shared.$quick_insert||(o.shared.$quick_insert=u('<div class="fr-quick-insert"><a class="fr-floating-btn" role="button" tabIndex="-1" title="'+o.language.translate("Quick Insert")+'">'+o.icon.create("quickInsert")+"</a></div>"));a=o.shared.$quick_insert,o.tooltip.bind(o.$box,".fr-quick-insert > a.fr-floating-btn"),o.events.on("destroy",function(){u("body").first().append(a.removeClass("fr-on").css("left",-9999).css("top",-9999)),l&&(d(),u("body").first().append($helpper))},!0),o.events.on("shared.destroy",function(){a.html("").removeData().remove(),a=null,l&&(l.html("").removeData().remove(),l=null)},!0),o.events.on("commands.before",s),o.events.on("commands.after",function(){o.popups.areVisible()||n()}),o.events.bindClick(o.$box,".fr-quick-insert > a",r),o.events.bindClick(o.$box,".fr-qi-helper > a.fr-btn",function(e){var t=u(e.currentTarget).data("cmd");if(!1===o.events.trigger("quickInsert.commands.before",[t]))return!1;c.QUICK_INSERT_BUTTONS[t].callback.apply(o,[e.currentTarget]),c.QUICK_INSERT_BUTTONS[t].undo&&o.undo.saveStep(),o.events.trigger("quickInsert.commands.after",[t]),o.quickInsert.hide()}),o.events.$on(o.$wp,"scroll",function(){a.hasClass("fr-visible")&&t(a.data("tag"))})}(),a.hasClass("fr-on")&&d(),o.$box.append(a),t(e),a.data("tag",e),a.addClass("fr-visible")}function n(){if(o.core.hasFocus()){var e=o.selection.element();if(o.opts.enter==c.ENTER_BR||o.node.isBlock(e)||(e=o.node.blockParent(e)),o.opts.enter==c.ENTER_BR&&!o.node.isBlock(e)){var t=o.node.deepestParent(e);t&&(e=t)}e&&(o.opts.enter!=c.ENTER_BR&&o.node.isEmpty(e)&&o.node.isElement(e.parentNode)&&0<=o.opts.quickInsertTags.indexOf(e.tagName.toLowerCase())||o.opts.enter==c.ENTER_BR&&("BR"==e.tagName&&(!e.previousSibling||"BR"==e.previousSibling.tagName||o.node.isBlock(e.previousSibling))||o.node.isEmpty(e)&&(!e.previousSibling||"BR"==e.previousSibling.tagName||o.node.isBlock(e.previousSibling))&&(!e.nextSibling||"BR"==e.nextSibling.tagName||o.node.isBlock(e.nextSibling))))?a&&a.data("tag").is(u(e))&&a.hasClass("fr-on")?d():o.selection.isCollapsed()&&i(u(e)):s()}}function s(){a&&(a.hasClass("fr-on")&&d(),a.removeClass("fr-visible fr-on"),a.css("left",-9999).css("top",-9999))}function r(e){if(e&&e.preventDefault(),a.hasClass("fr-on")&&!a.hasClass("fr-hidden"))d();else{if(!o.shared.$qi_helper){for(var t=o.opts.quickInsertButtons,i='<div class="fr-qi-helper">',n=0,s=0;s<t.length;s++){var r=c.QUICK_INSERT_BUTTONS[t[s]];r&&(!r.requiredPlugin||c.PLUGINS[r.requiredPlugin]&&0<=o.opts.pluginsEnabled.indexOf(r.requiredPlugin))&&(i+='<a class="fr-btn fr-floating-btn" role="button" title="'+o.language.translate(r.title)+'" tabIndex="-1" data-cmd="'+t[s]+'" style="transition-delay: '+.025*n+++'s;">'+o.icon.create(r.icon)+"</a>")}i+="</div>",o.shared.$qi_helper=u(i),o.tooltip.bind(o.shared.$qi_helper,"> a.fr-btn"),o.events.$on(o.shared.$qi_helper,"mousedown",function(e){e.preventDefault()},!0)}l=o.shared.$qi_helper,o.$box.append(l),setTimeout(function(){l.css("top",parseFloat(a.css("top"))),l.css("left",parseFloat(a.css("left"))+a.outerWidth()),l.find("a").addClass("fr-size-1"),a.addClass("fr-on")},10)}}function d(){var e=o.$box.find(".fr-qi-helper");e.length&&(e.find("a").removeClass("fr-size-1"),e.css("left",-9999),a.hasClass("fr-hidden")||a.removeClass("fr-on"))}return{_init:function(){if(!o.$wp)return!1;o.opts.iframe&&o.$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">'),o.popups.onShow("image.edit",s),o.events.on("mouseup",n),o.helpers.isMobile()&&o.events.$on(u(o.o_doc),"selectionchange",n),o.events.on("blur",s),o.events.on("keyup",n),o.events.on("keydown",function(){setTimeout(function(){n()},0)})},hide:s}}});