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) 6.33 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(e){"use strict";e=e&&e.hasOwnProperty("default")?e.default:e,Object.assign(e.DEFAULTS,{codeMirror:window.CodeMirror,codeMirrorOptions:{lineNumbers:!0,tabMode:"indent",indentWithTabs:!0,lineWrapping:!0,mode:"text/html",tabSize:2},codeBeautifierOptions:{end_with_newline:!0,indent_inner_html:!0,extra_liners:["p","h1","h2","h3","h4","h5","h6","blockquote","pre","ul","ol","table","dl"],brace_style:"expand",indent_char:"\t",indent_size:1,wrap_line_length:0},codeViewKeepActiveButtons:["fullscreen"]}),e.PLUGINS.codeView=function(d){var c,f,h=d.$,p=function(){return d.$box.hasClass("fr-code-view")};function g(){return f?f.getValue():c.val()}function u(){p()&&(f&&f.setSize(null,d.opts.height||"auto"),d.opts.heightMin||d.opts.height?(d.$box.find(".CodeMirror-scroll, .CodeMirror-gutters").css("min-height",d.opts.heightMin||d.opts.height),c.css("height",d.opts.height)):d.$box.find(".CodeMirror-scroll, .CodeMirror-gutters").css("min-height",""))}var m,b=!1;function v(){p()&&d.events.trigger("blur")}function w(){p()&&b&&d.events.trigger("focus")}function M(e){void 0===e&&(e=!p());var t,r,o,n,s,i,a=d.$tb.find('.fr-command[data-cmd="html"]');function l(){return!p()}e?(d.popups.hideAll(),e=a,c||(c=h('<textarea class="fr-code" tabIndex="-1">'),d.$wp.append(c),c.attr("dir",d.opts.direction),d.$box.hasClass("fr-basic")||(m=h('<a data-cmd="html" title="Code View" class="fr-command fr-btn html-switch'.concat(d.helpers.isMobile()?"":" fr-desktop",'" role="button" tabIndex="-1"><i class="fa fa-code"></i></button>')),d.$box.append(m),d.events.bindClick(d.$box,"a.html-switch",function(){d.events.trigger("commands.before",["html"]),M(!1),d.events.trigger("commands.after",["html"])})),d.events.on("buttons.refresh",l),d.events.on("copy",l,!0),d.events.on("cut",l,!0),d.events.on("paste",l,!0),d.events.on("destroy",x,!0),d.events.on("html.set",function(){p()&&M(!0)}),d.events.on("codeView.update",u),d.events.on("codeView.toggle",function(){d.$box.hasClass("fr-code-view")&&M()}),d.events.on("form.submit",function(){p()&&(d.html.set(g()),d.events.trigger("contentChanged",[],!0))},!0),!f&&d.opts.codeMirror?((f=d.opts.codeMirror.fromTextArea(c.get(0),d.opts.codeMirrorOptions)).on("blur",v),f.on("focus",w)):(d.events.$on(c,"keydown keyup change input",function(){d.opts.height?this.removeAttribute("rows"):(this.rows=1,0===this.value.length?this.style.height="auto":this.style.height="".concat(this.scrollHeight,"px"))}),d.events.$on(c,"blur",v),d.events.$on(c,"focus",w))),d.undo.saveStep(),d.html.cleanEmptyTags(),d.html.cleanWhiteTags(!0),d.core.hasFocus()&&!d.core.isEmpty()&&(d.selection.save(),d.$el.find('.fr-marker[data-type="true"]').first().replaceWith('<span class="fr-tmp fr-sm">F</span>'),d.$el.find('.fr-marker[data-type="false"]').last().replaceWith('<span class="fr-tmp fr-em">F</span>')),t=d.html.get(!1,!0),d.$el.find("span.fr-tmp").remove(),d.$box.toggleClass("fr-code-view",!0),i=!1,d.core.hasFocus()&&(i=!0,d.events.disableBlur(),d.$el.blur()),t=(t=t.replace(/<span class="fr-tmp fr-sm">F<\/span>/,"FROALA-SM")).replace(/<span class="fr-tmp fr-em">F<\/span>/,"FROALA-EM"),d.codeBeautifier&&!t.includes("fr-embedly")&&(t=d.codeBeautifier.run(t,d.opts.codeBeautifierOptions)),f?(o=t.indexOf("FROALA-SM"),(n=t.indexOf("FROALA-EM"))<o?o=n:n-=9,s=(t=t.replace(/FROALA-SM/g,"").replace(/FROALA-EM/g,"")).substring(0,o).length-t.substring(0,o).replace(/\n/g,"").length,r=t.substring(0,n).length-t.substring(0,n).replace(/\n/g,"").length,o=t.substring(0,o).length-t.substring(0,t.substring(0,o).lastIndexOf("\n")+1).length,n=t.substring(0,n).length-t.substring(0,t.substring(0,n).lastIndexOf("\n")+1).length,f.setSize(null,d.opts.height||"auto"),d.opts.heightMin&&d.$box.find(".CodeMirror-scroll").css("min-height",d.opts.heightMin),f.setValue(t),b=!i,f.focus(),b=!0,f.setSelection({line:s,ch:o},{line:r,ch:n}),f.refresh(),f.clearHistory()):(o=t.indexOf("FROALA-SM"),n=t.indexOf("FROALA-EM")-9,d.opts.heightMin&&c.css("min-height",d.opts.heightMin),d.opts.height&&c.css("height",d.opts.height),d.opts.heightMax&&c.css("max-height",d.opts.height||d.opts.heightMax),c.val(t.replace(/FROALA-SM/g,"").replace(/FROALA-EM/g,"")).trigger("change"),s=h(d.o_doc).scrollTop(),b=!i,c.focus(),b=!0,c.get(0).setSelectionRange(o,n),h(d.o_doc).scrollTop(s)),d.$tb.find(".fr-btn-grp > .fr-command, .fr-more-toolbar > .fr-command, .fr-btn-grp > .fr-btn-wrap > .fr-command, .fr-more-toolbar > .fr-btn-wrap > .fr-command").not(e).filter(function(){return d.opts.codeViewKeepActiveButtons.indexOf(h(this).data("cmd"))<0}).addClass("fr-disabled").attr("aria-disabled",!0),e.addClass("fr-active").attr("aria-pressed",!0),!d.helpers.isMobile()&&d.opts.toolbarInline&&d.toolbar.hide()):(d.$box.toggleClass("fr-code-view",!1),r=a,t=g(),d.html.set(t),d.$el.blur(),d.$tb.find(".fr-btn-grp > .fr-command, .fr-more-toolbar > .fr-command, .fr-btn-grp > .fr-btn-wrap > .fr-command, .fr-more-toolbar > .fr-btn-wrap > .fr-command").not(r).removeClass("fr-disabled").attr("aria-disabled",!1),r.removeClass("fr-active").attr("aria-pressed",!1),d.selection.setAtStart(d.el),d.selection.restore(),d.placeholder.refresh(),d.undo.saveStep(),d.events.trigger("codeView.update"))}function x(){p()&&M(!1),f&&f.toTextArea(),c.val("").removeData().remove(),c=null,m&&(m.remove(),m=null)}return{_init:function(){if(d.events.on("focus",function(){var e;d.opts.toolbarContainer&&(e=d.$tb.find('.fr-command[data-cmd="html"]'),(p()?(d.$tb.find(".fr-btn-grp > .fr-command, .fr-more-toolbar > .fr-command").not(e).filter(function(){return d.opts.codeViewKeepActiveButtons.indexOf(h(this).data("cmd"))<0}).addClass("fr-disabled").attr("aria-disabled",!1),e.addClass("fr-active")):(d.$tb.find(".fr-btn-grp > .fr-command, .fr-more-toolbar > .fr-command").not(e).removeClass("fr-disabled").attr("aria-disabled",!1),e.removeClass("fr-active"))).attr("aria-pressed",!1))}),!d.$wp)return!1},toggle:M,isActive:p,get:g}},e.RegisterCommand("html",{title:"Code View",undo:!1,focus:!1,forcedRefresh:!0,toggle:!0,callback:function(){this.codeView.toggle()},plugin:"codeView"}),e.DefineIcon("html",{NAME:"code",SVG_KEY:"codeView"})}); //# sourceMappingURL=code_view.min.min.js.map