gosora/public/jquery-emojiarea/jquery.emojiarea.min.js

1 line
7.3 KiB
JavaScript
Raw Permalink Normal View History

(function(e,t,n){var r=1;var i=3;var s=["p","div","pre","form"];var o=27;var u=9;e.emojiarea={path:"",icons:{},defaults:{button:null,buttonLabel:"Emojis",buttonPosition:"after"}};e.fn.emojiarea=function(t){t=e.extend({},e.emojiarea.defaults,t);return this.each(function(){var r=e(this);if("contentEditable"in n.body&&t.wysiwyg!==false){new c(r,t)}else{new l(r,t)}})};var a={};a.restoreSelection=function(){if(t.getSelection){return function(e){var n=t.getSelection();n.removeAllRanges();for(var r=0,i=e.length;r<i;++r){n.addRange(e[r])}}}else if(n.selection&&n.selection.createRange){return function(e){if(e){e.select()}}}}();a.saveSelection=function(){if(t.getSelection){return function(){var e=t.getSelection(),n=[];if(e.rangeCount){for(var r=0,i=e.rangeCount;r<i;++r){n.push(e.getRangeAt(r))}}return n}}else if(n.selection&&n.selection.createRange){return function(){var e=n.selection;return e.type.toLowerCase()!=="none"?e.createRange():null}}}();a.replaceSelection=function(){if(t.getSelection){return function(e){var r,i=t.getSelection();var s=typeof e==="string"?n.createTextNode(e):e;if(i.getRangeAt&&i.rangeCount){r=i.getRangeAt(0);r.deleteContents();r.insertNode(n.createTextNode(" "));r.insertNode(s);r.setStart(s,0);t.setTimeout(function(){r=n.createRange();r.setStartAfter(s);r.collapse(true);i.removeAllRanges();i.addRange(r)},0)}}}else if(n.selection&&n.selection.createRange){return function(e){var t=n.selection.createRange();if(typeof e==="string"){t.text=e}else{t.pasteHTML(e.outerHTML)}}}}();a.insertAtCursor=function(e,t){e=" "+e;var r=t.value,i,s,o;if(typeof t.selectionStart!="undefined"&&typeof t.selectionEnd!="undefined"){s=t.selectionStart;i=t.selectionEnd;t.value=r.substring(0,s)+e+r.substring(t.selectionEnd);t.selectionStart=t.selectionEnd=s+e.length}else if(typeof n.selection!="undefined"&&typeof n.selection.createRange!="undefined"){t.focus();o=n.selection.createRange();o.text=e;o.select()}};a.extend=function(e,t){if(typeof e==="undefined"||!e){e={}}if(typeof t==="object"){for(var n in t){if(t.hasOwnProperty(n)){e[n]=t[n]}}}return e};a.escapeRegex=function(e){return(e+"").replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")};a.htmlEntities=function(e){return String(e).replace(/&/g,"&").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")};var f=function(){};f.prototype.setup=function(){var e=this;this.$editor.on("focus",function(){e.hasFocus=true});this.$editor.on("blur",function(){e.hasFocus=false});this.setupButton()};f.prototype.setupButton=function(){var t=this;var n;if(this.options.button){n=e(this.options.button)}else if(this.options.button!==false){n=e('<a href="javascript:void(0)">');n.html(this.options.buttonLabel);n.addClass("emoji-button");n.attr({title:this.options.buttonLabel});this.$editor[this.options.buttonPosition](n)}else{n=e("")}n.on("click",function(e){h.show(t);e.stopPropagation()});this.$button=n};f.createIcon=function(t,n){var r=e.emojiarea.icons[t]["icons"][n];var i=e.emojiarea.path||"";if(i.length&&i.charAt(i.length-1)!=="/"){i+="/"}return'<img src="'+i+r+'" alt="'+a.htmlEntities(n)+'">'};var l=function(e,t){this.options=t;this.$textarea=e;this.$editor=e;this.setup()};l.prototype.insert=function(t,n){if(!e.emojiarea.icons[t]["icons"].hasOwnProperty(n))return;a.insertAtCursor(n,this.$textarea[0]);this.$textarea.trigger("change")};l.prototype.val=function(){return this.$textarea.val()};a.extend(l.prototype,f.prototype);var c=function(t,r){var i=this;this.options=r;this.$textarea=t;this.$editor=e("<div>").addClass("emoji-wysiwyg-editor");this.$editor.text(t.val());this.$editor.attr({contenteditable:"true"});this.$editor.on("blur keyup paste",function(){return i.onChange.apply(i,arguments)});this.$editor.on("mousedown focus",function(){n.execCommand("enableObjectResizing",false,false)});this.$editor.on("blur",function(){n.execCommand("enableObjectResizing",true,true)});var s=this.$editor.text();var o=e.emojiarea.icons;for(var u in o){for(var l in o[u]["icons"]){if(o[u]["icons"].hasOwnProperty(l)){s=s.replace(new RegExp(a.escapeRegex(l),"g"),f.createIcon(u,l))}}}this.$editor.html(s);t.hide().after