UNPKG

@firestitch/froala

Version:

The next generation Javascript WYSIWYG HTML rich text editor made by devs for devs. High performance and modern design make it easy to use for developers and loved by users.

3 lines (2 loc) 7.28 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(require("froala-editor")):"function"==typeof define&&define.amd?define(["froala-editor"],t):t(e.FroalaEditor)}(this,function(p){"use strict";p=p&&p.hasOwnProperty("default")?p.default:p,Object.assign(p.DEFAULTS,{quickInsertButtons:["image","video","embedly","table","ul","ol","hr"],quickInsertTags:["p","div","h1","h2","h3","h4","h5","h6","pre","blockquote"],quickInsertEnabled:!0}),p.QUICK_INSERT_BUTTONS={},p.DefineIcon("quickInsert",{SVG_KEY:"add",template:"svg"}),p.RegisterQuickInsertButton=function(e,t){p.QUICK_INSERT_BUTTONS[e]=Object.assign({undo:!0},t)},p.RegisterQuickInsertButton("image",{icon:"insertImage",requiredPlugin:"image",title:"Insert Image",undo:!1,callback:function(){var e=this,t=e.$;e.shared.$qi_image_input||(e.shared.$qi_image_input=t(document.createElement("input")).attr("accept","image/"+e.opts.imageAllowedTypes.join(", image/").toLowerCase()).attr("name","quickInsertImage".concat(this.id)).attr("style","display: none;").attr("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)[0].click()}}),p.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)}}),p.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)}}),p.RegisterQuickInsertButton("table",{icon:"insertTable",requiredPlugin:"table",title:"Insert Table",callback:function(){this.table.insert(2,2)}}),p.RegisterQuickInsertButton("ol",{icon:"formatOL",requiredPlugin:"lists",title:"Ordered List",callback:function(){this.lists.format("OL")}}),p.RegisterQuickInsertButton("ul",{icon:"formatUL",requiredPlugin:"lists",title:"Unordered List",callback:function(){this.lists.format("UL")}}),p.RegisterQuickInsertButton("hr",{icon:"insertHR",title:"Insert Horizontal Line",callback:function(){this.commands.insertHR()}}),p.PLUGINS.quickInsert=function(a){var r,l,c=a.$,u=!1;function t(e){var t,n,i=e.offset().top-a.$box.offset().top,s=(a.$iframe&&a.$iframe.offset().left||0)+e.offset().left-e.position().left-4<r.outerWidth()?e.offset().left+r.outerWidth():0-r.outerWidth();a.opts.enter!=p.ENTER_BR?t=(r.outerHeight()-e.outerHeight())/2:(c(document.createElement("span")).html(p.INVISIBLE_SPACE).insertAfter(e),t=(r.outerHeight()-e.next().outerHeight())/2,e.next().remove()),a.opts.iframe&&(n=a.helpers.getPX(a.$wp.find(".fr-iframe").css("padding-top")),i+=a.$iframe.offset().top+n),r.hasClass("fr-on")&&0<=i&&l.css("top",i-t),0<=i&&i-Math.abs(t)<=a.$box.outerHeight()-e.outerHeight()?(r.hasClass("fr-hidden")&&(r.hasClass("fr-on")&&o(),r.removeClass("fr-hidden")),r.css("top",i-t)):r.hasClass("fr-visible")&&!a.opts.toolbarInline&&(r.addClass("fr-hidden"),d()),r.css("left",s)}function n(e){if(!a.markdown||!a.markdown.isEnabled()){if(!r)a.shared.$quick_insert||(a.shared.$quick_insert=c(document.createElement("div")).attr("class","fr-quick-insert").html('<a class="fr-floating-btn" role="button" tabIndex="-1" title="'.concat(a.language.translate("Quick Insert"),'">').concat(a.icon.create("quickInsert"),"</a>"))),r=a.shared.$quick_insert,a.tooltip.bind(a.$box,".fr-quick-insert > a.fr-floating-btn"),a.events.on("destroy",function(){c("body").first().append(r.removeClass("fr-on")),l&&(d(),c("body").first().append(l.css("left",-9999).css("top",-9999)))},!0),a.events.on("shared.destroy",function(){r.html("").removeData().remove(),r=null,l&&(l.html("").removeData().remove(),l=null)},!0),a.events.on("commands.before",s),a.events.on("commands.after",function(){a.popups.areVisible()||i()}),a.events.bindClick(a.$box,".fr-quick-insert > a",o),a.events.bindClick(a.$box,".fr-qi-helper > a.fr-btn",function(e){var t=c(e.currentTarget).data("cmd");if(!1===a.events.trigger("quickInsert.commands.before",[t]))return!1;p.QUICK_INSERT_BUTTONS[t].callback.apply(a,[e.currentTarget]),p.QUICK_INSERT_BUTTONS[t].undo&&a.undo.saveStep(),a.events.trigger("quickInsert.commands.after",[t]),a.quickInsert.hide()}),a.events.$on(a.$wp,"scroll",f),a.events.$on(a.$tb,"transitionend",".fr-more-toolbar",f);r.hasClass("fr-on")&&d(),a.$box.append(r),t(e),r.data("tag",e),r.addClass("fr-visible")}}function i(){var e,t;a.core.hasFocus()&&(e=a.selection.element(),a.opts.enter==p.ENTER_BR||a.node.isBlock(e)||(e=a.node.blockParent(e)),a.opts.enter!=p.ENTER_BR||a.node.isBlock(e)||(t=a.node.deepestParent(e))&&(e=t),e&&(a.opts.enter!=p.ENTER_BR&&a.node.isEmpty(e)&&0<=a.opts.quickInsertTags.indexOf(e.tagName.toLowerCase())||a.opts.enter==p.ENTER_BR&&("BR"==e.tagName&&(!e.previousSibling||"BR"==e.previousSibling.tagName||a.node.isBlock(e.previousSibling))||a.node.isEmpty(e)&&(!e.previousSibling||"BR"==e.previousSibling.tagName||a.node.isBlock(e.previousSibling))&&(!e.nextSibling||"BR"==e.nextSibling.tagName||a.node.isBlock(e.nextSibling))))?r&&r.data("tag").is(c(e))&&r.hasClass("fr-on")?d():a.selection.isCollapsed()&&n(c(e)):s())}function s(){r&&!u&&(r.hasClass("fr-on")&&d(),r.removeClass("fr-visible fr-on"),r.css("left",-9999).css("top",-9999))}function o(e){if(e&&e.preventDefault(),r.hasClass("fr-on")&&!r.hasClass("fr-hidden"))d();else{if(!a.shared.$qi_helper){for(var t=a.opts.quickInsertButtons,n='<div class="fr-qi-helper">',i=0,s=0;s<t.length;s++){var o=p.QUICK_INSERT_BUTTONS[t[s]];o&&(!o.requiredPlugin||p.PLUGINS[o.requiredPlugin]&&0<=a.opts.pluginsEnabled.indexOf(o.requiredPlugin))&&(n+='<a class="fr-btn fr-floating-btn" role="button" title="'.concat(a.language.translate(o.title),'" tabIndex="-1" data-cmd="').concat(t[s],'" style="transition-delay: ').concat(.025*i++,'s;">').concat(a.icon.create(o.icon),"</a>"))}a.shared.$qi_helper=c(n+="</div>"),a.tooltip.bind(a.shared.$qi_helper,"a.fr-btn"),a.events.$on(a.shared.$qi_helper,"mousedown",function(e){e.preventDefault()},!0)}l=a.shared.$qi_helper,a.$box.append(l),u=!0,setTimeout(function(){u=!1,l.css("top",parseFloat(r.css("top"))),l.css("left",parseFloat(r.css("left"))+r.outerWidth()),l.find("a").addClass("fr-size-1"),r.addClass("fr-on")},10)}}function d(){var t=a.$box.find(".fr-qi-helper");if(t.length){for(var n=t.find("a"),e=0;e<n.length;e++)!function(e){setTimeout(function(){t.children().eq(n.length-1-e).removeClass("fr-size-1")},25*e)}(e);setTimeout(function(){t.css("left",-9999),r&&!r.hasClass("fr-hidden")&&r.removeClass("fr-on")},25*e)}}function f(){r.hasClass("fr-visible")&&t(r.data("tag"))}return{_init:function(){if(!a.$wp||!a.opts.quickInsertEnabled)return!1;a.popups.onShow("image.edit",s),a.events.on("mouseup",i),a.helpers.isMobile()&&a.events.$on(c(a.o_doc),"selectionchange",i),a.events.on("blur",s),a.events.on("keyup",i),a.events.on("keydown",function(){setTimeout(function(){i()},0)})},hide:s}}}); //# sourceMappingURL=quick_insert.min.js.map