@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.34 kB
JavaScript
!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(l){var c,d,f=l.$,h=function(){return l.$box.hasClass("fr-code-view")};function p(){return d?d.getValue():c.val()}function g(){h()&&(d&&d.setSize(null,l.opts.height||"auto"),l.opts.heightMin||l.opts.height?(l.$box.find(".CodeMirror-scroll, .CodeMirror-gutters").css("min-height",l.opts.heightMin||l.opts.height),c.css("height",l.opts.height)):l.$box.find(".CodeMirror-scroll, .CodeMirror-gutters").css("min-height",""))}var u,m=!1;function b(){h()&&l.events.trigger("blur")}function v(){h()&&m&&l.events.trigger("focus")}function r(e){function t(){return!h()}c||(c=f('<textarea class="fr-code" tabIndex="-1">'),l.$wp.append(c),c.attr("dir",l.opts.direction),l.$box.hasClass("fr-basic")||(u=f('<a data-cmd="html" title="Code View" class="fr-command fr-btn html-switch'.concat(l.helpers.isMobile()?"":" fr-desktop",'" role="button" tabIndex="-1"><i class="fa fa-code"></i></button>')),l.$box.append(u),l.events.bindClick(l.$box,"a.html-switch",function(){l.events.trigger("commands.before",["html"]),w(!1),l.events.trigger("commands.after",["html"])})),l.events.on("buttons.refresh",t),l.events.on("copy",t,!0),l.events.on("cut",t,!0),l.events.on("paste",t,!0),l.events.on("destroy",M,!0),l.events.on("html.set",function(){h()&&w(!0)}),l.events.on("codeView.update",g),l.events.on("codeView.toggle",function(){l.$box.hasClass("fr-code-view")&&w()}),l.events.on("form.submit",function(){h()&&(l.html.set(p()),l.events.trigger("contentChanged",[],!0))},!0),!d&&l.opts.codeMirror?((d=l.opts.codeMirror.fromTextArea(c.get(0),l.opts.codeMirrorOptions)).on("blur",b),d.on("focus",v)):(l.events.$on(c,"keydown keyup change input",function(){l.opts.height?this.removeAttribute("rows"):(this.rows=1,0===this.value.length?this.style.height="auto":this.style.height="".concat(this.scrollHeight,"px"))}),l.events.$on(c,"blur",b),l.events.$on(c,"focus",v))),l.undo.saveStep(),l.html.cleanEmptyTags(),l.html.cleanWhiteTags(!0),l.core.hasFocus()&&!l.core.isEmpty()&&(l.selection.save(),l.$el.find('.fr-marker[data-type="true"]').first().replaceWith('<span class="fr-tmp fr-sm">F</span>'),l.$el.find('.fr-marker[data-type="false"]').last().replaceWith('<span class="fr-tmp fr-em">F</span>'));var r,o,n,s,i=l.html.get(!1,!0),a=(l.$el.find("span.fr-tmp").remove(),l.$box.toggleClass("fr-code-view",!0),!1);l.core.hasFocus()&&(a=!0,l.events.disableBlur(),l.$el.blur()),i=(i=i.replace(/<span class="fr-tmp fr-sm">F<\/span>/,"FROALA-SM")).replace(/<span class="fr-tmp fr-em">F<\/span>/,"FROALA-EM"),l.codeBeautifier&&!i.includes("fr-embedly")&&(i=l.codeBeautifier.run(i,l.opts.codeBeautifierOptions)),d?(o=i.indexOf("FROALA-SM"),(n=i.indexOf("FROALA-EM"))<o?o=n:n-=9,s=(i=i.replace(/FROALA-SM/g,"").replace(/FROALA-EM/g,"")).substring(0,o).length-i.substring(0,o).replace(/\n/g,"").length,r=i.substring(0,n).length-i.substring(0,n).replace(/\n/g,"").length,o=i.substring(0,o).length-i.substring(0,i.substring(0,o).lastIndexOf("\n")+1).length,n=i.substring(0,n).length-i.substring(0,i.substring(0,n).lastIndexOf("\n")+1).length,d.setSize(null,l.opts.height||"auto"),l.opts.heightMin&&l.$box.find(".CodeMirror-scroll").css("min-height",l.opts.heightMin),d.setValue(i),m=!a,d.focus(),m=!0,d.setSelection({line:s,ch:o},{line:r,ch:n}),d.refresh(),d.clearHistory()):(o=i.indexOf("FROALA-SM"),n=i.indexOf("FROALA-EM")-9,l.opts.heightMin&&c.css("min-height",l.opts.heightMin),l.opts.height&&c.css("height",l.opts.height),l.opts.heightMax&&c.css("max-height",l.opts.height||l.opts.heightMax),c.val(i.replace(/FROALA-SM/g,"").replace(/FROALA-EM/g,"")).trigger("change"),s=f(l.o_doc).scrollTop(),m=!a,c.focus(),m=!0,c.get(0).setSelectionRange(o,n),f(l.o_doc).scrollTop(s)),l.$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 l.opts.codeViewKeepActiveButtons.indexOf(f(this).data("cmd"))<0}).addClass("fr-disabled").attr("aria-disabled",!0),e.addClass("fr-active").attr("aria-pressed",!0),!l.helpers.isMobile()&&l.opts.toolbarInline&&l.toolbar.hide()}function w(e){void 0===e&&(e=!h());var t=l.$tb.find('.fr-command[data-cmd="html"]');e?(l.popups.hideAll(),r(t)):(l.$box.toggleClass("fr-code-view",!1),e=t,t=p(),l.html.set(t),l.$el.blur(),l.$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).removeClass("fr-disabled").attr("aria-disabled",!1),e.removeClass("fr-active").attr("aria-pressed",!1),l.selection.setAtStart(l.el),l.selection.restore(),l.placeholder.refresh(),l.undo.saveStep(),l.events.trigger("codeView.update"))}function M(){h()&&w(!1),d&&d.toTextArea(),c.val("").removeData().remove(),c=null,u&&(u.remove(),u=null)}return{_init:function(){if(l.events.on("focus",function(){var e;l.opts.toolbarContainer&&(e=l.$tb.find('.fr-command[data-cmd="html"]'),(h()?(l.$tb.find(".fr-btn-grp > .fr-command, .fr-more-toolbar > .fr-command").not(e).filter(function(){return l.opts.codeViewKeepActiveButtons.indexOf(f(this).data("cmd"))<0}).addClass("fr-disabled").attr("aria-disabled",!1),e.addClass("fr-active")):(l.$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))}),!l.$wp)return!1},toggle:w,isActive:h,get:p}},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.js.map