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) • 8.82 kB
JavaScript
/*!
* 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,o){"object"==typeof exports&&"undefined"!=typeof module?o(require("jquery")):"function"==typeof define&&define.amd?define(["jquery"],o):o(e.jQuery)}(this,function(e){"use strict";var b=(e=e&&e.hasOwnProperty("default")?e["default"]:e).FE;Object.assign(b.POPUP_TEMPLATES,{emoticons:"[_BUTTONS_][_EMOTICONS_]"}),Object.assign(b.DEFAULTS,{emoticonsStep:8,emoticonsSet:[{code:"1f600",desc:"Grinning face"},{code:"1f601",desc:"Grinning face with smiling eyes"},{code:"1f602",desc:"Face with tears of joy"},{code:"1f603",desc:"Smiling face with open mouth"},{code:"1f604",desc:"Smiling face with open mouth and smiling eyes"},{code:"1f605",desc:"Smiling face with open mouth and cold sweat"},{code:"1f606",desc:"Smiling face with open mouth and tightly-closed eyes"},{code:"1f607",desc:"Smiling face with halo"},{code:"1f608",desc:"Smiling face with horns"},{code:"1f609",desc:"Winking face"},{code:"1f60a",desc:"Smiling face with smiling eyes"},{code:"1f60b",desc:"Face savoring delicious food"},{code:"1f60c",desc:"Relieved face"},{code:"1f60d",desc:"Smiling face with heart-shaped eyes"},{code:"1f60e",desc:"Smiling face with sunglasses"},{code:"1f60f",desc:"Smirking face"},{code:"1f610",desc:"Neutral face"},{code:"1f611",desc:"Expressionless face"},{code:"1f612",desc:"Unamused face"},{code:"1f613",desc:"Face with cold sweat"},{code:"1f614",desc:"Pensive face"},{code:"1f615",desc:"Confused face"},{code:"1f616",desc:"Confounded face"},{code:"1f617",desc:"Kissing face"},{code:"1f618",desc:"Face throwing a kiss"},{code:"1f619",desc:"Kissing face with smiling eyes"},{code:"1f61a",desc:"Kissing face with closed eyes"},{code:"1f61b",desc:"Face with stuck out tongue"},{code:"1f61c",desc:"Face with stuck out tongue and winking eye"},{code:"1f61d",desc:"Face with stuck out tongue and tightly-closed eyes"},{code:"1f61e",desc:"Disappointed face"},{code:"1f61f",desc:"Worried face"},{code:"1f620",desc:"Angry face"},{code:"1f621",desc:"Pouting face"},{code:"1f622",desc:"Crying face"},{code:"1f623",desc:"Persevering face"},{code:"1f624",desc:"Face with look of triumph"},{code:"1f625",desc:"Disappointed but relieved face"},{code:"1f626",desc:"Frowning face with open mouth"},{code:"1f627",desc:"Anguished face"},{code:"1f628",desc:"Fearful face"},{code:"1f629",desc:"Weary face"},{code:"1f62a",desc:"Sleepy face"},{code:"1f62b",desc:"Tired face"},{code:"1f62c",desc:"Grimacing face"},{code:"1f62d",desc:"Loudly crying face"},{code:"1f62e",desc:"Face with open mouth"},{code:"1f62f",desc:"Hushed face"},{code:"1f630",desc:"Face with open mouth and cold sweat"},{code:"1f631",desc:"Face screaming in fear"},{code:"1f632",desc:"Astonished face"},{code:"1f633",desc:"Flushed face"},{code:"1f634",desc:"Sleeping face"},{code:"1f635",desc:"Dizzy face"},{code:"1f636",desc:"Face without mouth"},{code:"1f637",desc:"Face with medical mask"}],emoticonsButtons:["emoticonsBack","|"],emoticonsUseImage:!0}),b.PLUGINS.emoticons=function(g){var E=g.$;function c(){if(!g.selection.isCollapsed())return!1;var e=g.selection.element(),o=g.selection.endElement();if(e&&g.node.hasClass(e,"fr-emoticon"))return e;if(o&&g.node.hasClass(o,"fr-emoticon"))return o;var t=g.selection.ranges(0),s=t.startContainer;if(s.nodeType==Node.ELEMENT_NODE&&0<s.childNodes.length&&0<t.startOffset){var c=s.childNodes[t.startOffset-1];if(g.node.hasClass(c,"fr-emoticon"))return c}return!1}return{_init:function(){var e=function(){for(var e=g.el.querySelectorAll(".fr-emoticon:not(.fr-deletable)"),o=0;o<e.length;o++)e[o].className+=" fr-deletable"};e(),g.events.on("html.set",e),g.events.on("keydown",function(e){if(g.keys.isCharacter(e.which)&&g.selection.inEditor()){var o=g.selection.ranges(0),t=c();g.node.hasClass(t,"fr-emoticon-img")&&t&&(0===o.startOffset&&g.selection.element()===t?E(t).before(b.MARKERS+b.INVISIBLE_SPACE):E(t).after(b.INVISIBLE_SPACE+b.MARKERS),g.selection.restore())}}),g.events.on("keyup",function(e){for(var o=g.el.querySelectorAll(".fr-emoticon"),t=0;t<o.length;t++)"undefined"!=typeof o[t].textContent&&0===o[t].textContent.replace(/\u200B/gi,"").length&&E(o[t]).remove();if(!(e.which>=b.KEYCODE.ARROW_LEFT&&e.which<=b.KEYCODE.ARROW_DOWN)){var s=c();g.node.hasClass(s,"fr-emoticon-img")&&(E(s).append(b.MARKERS),g.selection.restore())}})},insert:function(e,o){var t=c(),s=g.selection.ranges(0);t?(0===s.startOffset&&g.selection.element()===t?E(t).before(b.MARKERS+b.INVISIBLE_SPACE):0<s.startOffset&&g.selection.element()===t&&s.commonAncestorContainer.parentNode.classList.contains("fr-emoticon")&&E(t).after(b.INVISIBLE_SPACE+b.MARKERS),g.selection.restore(),g.html.insert('<span class="fr-emoticon fr-deletable'+(o?" fr-emoticon-img":"")+'"'+(o?' style="background: url('+o+');"':"")+">"+(o?" ":e)+"</span> "+b.MARKERS,!0)):g.html.insert('<span class="fr-emoticon fr-deletable'+(o?" fr-emoticon-img":"")+'"'+(o?' style="background: url('+o+');"':"")+">"+(o?" ":e)+"</span> ",!0)},showEmoticonsPopup:function(){var e=g.$tb.find('.fr-command[data-cmd="emoticons"]'),o=g.popups.get("emoticons");if(o||(o=function(){var e="";g.opts.toolbarInline&&0<g.opts.emoticonsButtons.length&&(e='<div class="fr-buttons fr-emoticons-buttons">'+g.button.buildList(g.opts.emoticonsButtons)+"</div>");var h,o={buttons:e,emoticons:function(){for(var e='<div style="text-align: center">',o=0;o<g.opts.emoticonsSet.length;o++)0!==o&&o%g.opts.emoticonsStep==0&&(e+="<br>"),e+='<span class="fr-command fr-emoticon" tabIndex="-1" data-cmd="insertEmoticon" title="'+g.language.translate(g.opts.emoticonsSet[o].desc)+'" role="button" data-param1="'+g.opts.emoticonsSet[o].code+'">'+(g.opts.emoticonsUseImage?'<img src="https://cdnjs.cloudflare.com/ajax/libs/emojione/2.0.1/assets/svg/'+g.opts.emoticonsSet[o].code+'.svg"/>':"&#x"+g.opts.emoticonsSet[o].code+";")+'<span class="fr-sr-only">'+g.language.translate(g.opts.emoticonsSet[o].desc)+" </span></span>";return g.opts.emoticonsUseImage&&(e+='<p style="font-size: 12px; text-align: center; padding: 0 5px;">Emoji free by <a class="fr-link" tabIndex="-1" href="http://emojione.com/" target="_blank" rel="nofollow" role="link" aria-label="Open Emoji One website.">Emoji One</a></p>'),e+="</div>"}()},t=g.popups.create("emoticons",o);return g.tooltip.bind(t,".fr-emoticon"),h=t,g.events.on("popup.tab",function(e){var o=E(e.currentTarget);if(!g.popups.isVisible("emoticons")||!o.is("span, a"))return!0;var t,s,c,n=e.which;if(b.KEYCODE.TAB==n){if(o.is("span.fr-emoticon")&&e.shiftKey||o.is("a")&&!e.shiftKey){var i=h.find(".fr-buttons");t=!g.accessibility.focusToolbar(i,!!e.shiftKey)}if(!1!==t){var a=h.find("span.fr-emoticon:focus:first, span.fr-emoticon:visible:first, a");o.is("span.fr-emoticon")&&(a=a.not("span.fr-emoticon:not(:focus)")),s=a.index(o),s=e.shiftKey?((s-1)%a.length+a.length)%a.length:(s+1)%a.length,c=a.get(s),g.events.disableBlur(),c.focus(),t=!1}}else if(b.KEYCODE.ARROW_UP==n||b.KEYCODE.ARROW_DOWN==n||b.KEYCODE.ARROW_LEFT==n||b.KEYCODE.ARROW_RIGHT==n){if(o.is("span.fr-emoticon")){var f=o.parent().find("span.fr-emoticon");s=f.index(o);var d=g.opts.emoticonsStep,r=Math.floor(f.length/d),l=s%d,m=Math.floor(s/d),p=m*d+l,u=r*d;b.KEYCODE.ARROW_UP==n?p=((p-d)%u+u)%u:b.KEYCODE.ARROW_DOWN==n?p=(p+d)%u:b.KEYCODE.ARROW_LEFT==n?p=((p-1)%u+u)%u:b.KEYCODE.ARROW_RIGHT==n&&(p=(p+1)%u),c=E(f.get(p)),g.events.disableBlur(),c.focus(),t=!1}}else b.KEYCODE.ENTER==n&&(o.is("a")?o[0].click():g.button.exec(o),t=!1);return!1===t&&(e.preventDefault(),e.stopPropagation()),t},!0),t}()),!o.hasClass("fr-active")){g.popups.refresh("emoticons"),g.popups.setContainer("emoticons",g.$tb);var t=e.offset().left+e.outerWidth()/2,s=e.offset().top+(g.opts.toolbarBottom?10:e.outerHeight()-10);g.popups.show("emoticons",t,s,e.outerHeight())}},hideEmoticonsPopup:function(){g.popups.hide("emoticons")},back:function(){g.popups.hide("emoticons"),g.toolbar.showInline()}}},b.DefineIcon("emoticons",{NAME:"smile-o",FA5NAME:"smile"}),b.RegisterCommand("emoticons",{title:"Emoticons",undo:!1,focus:!0,refreshOnCallback:!1,popup:!0,callback:function(){this.popups.isVisible("emoticons")?(this.$el.find(".fr-marker").length&&(this.events.disableBlur(),this.selection.restore()),this.popups.hide("emoticons")):this.emoticons.showEmoticonsPopup()},plugin:"emoticons"}),b.RegisterCommand("insertEmoticon",{callback:function(e,o){this.emoticons.insert("&#x"+o+";",this.opts.emoticonsUseImage?"https://cdnjs.cloudflare.com/ajax/libs/emojione/2.0.1/assets/svg/"+o+".svg":null),this.emoticons.hideEmoticonsPopup()}}),b.DefineIcon("emoticonsBack",{NAME:"arrow-left"}),b.RegisterCommand("emoticonsBack",{title:"Back",undo:!1,focus:!1,back:!0,refreshAfterCallback:!1,callback:function(){this.emoticons.back()}})});