window="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},document=window.document||{},function(e,a){"function"==typeof require&&"object"==typeof exports&&"object"==typeof module?e(require("jquery")):"function"==typeof define&&define.amd?define(["jquery"],e):e(a.jQuery)}(function(x){"use strict";var e=0,l={},s={},C=window.emojione,n=[];function t(e){C?e():n.push(e)}var z,T,i,A="data:image/gif;base64,R0lGODlhAQABAJH/AP///wAAAMDAwAAAACH5BAEAAAIALAAAAAABAAEAAAICVAEAOw==",_=[].slice,q="emojionearea",S=0,P="​";function E(o,e,n){var t=!0,a=1;if(e){e=e.toLowerCase();do{var i=1==a?"@"+e:e;l[o.id][i]&&l[o.id][i].length&&x.each(l[o.id][i],function(e,a){return t=!1!==a.apply(o,n||[])})}while(t&&a--)}return t}function R(o,n,t,i){i=i||function(e,a){return x(a.currentTarget)},x.each(t,function(e,a){e=x.isArray(t)?a:e,(s[o.id][a]||(s[o.id][a]=[])).push([n,e,i])})}function r(e,a,o){var n=C.imageType,t="svg"==n?C.imagePathSVG:C.imagePathPNG,i="",r=(o&&(i=o.substr(1,o.length-2).replace(/_/g," ").replace(/\w\S*/g,function(e){return e.charAt(0).toUpperCase()+e.substr(1).toLowerCase()})),"");return a.uc_base&&4/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/`/g,"`").replace(/(?:\r\n|\r|\n)/g,"\n").replace(/(\n+)/g,"
$1
").replace(/\n/g,"
").replace(/<\/div>/g,""),u(e=a.shortnames?C.shortnameToUnicode(e):e,a.emojiTemplate).replace(/\t/g,"    ").replace(/ /g,"  ")}function N(e,a){switch(e=e.replace(/ /g,"\n").replace(/ /g,"\t").replace(/]*alt="([^"]+)"[^>]*>/gi,"$1").replace(/\n|\r/g,"").replace(/]*>/gi,"\n").replace(/(?:<(?:div|p|ol|ul|li|pre|code|object)[^>]*>)+/gi,"
").replace(/(?:<\/(?:div|p|ol|ul|li|pre|code|object)>)+/gi,"
").replace(/\n
<\/div>/gi,"\n").replace(/
<\/div>\n/gi,"\n").replace(/(?:
)+<\/div>/gi,"\n").replace(/([^\n])<\/div>
/gi,"$1\n").replace(/(?:<\/div>)+/gi,"
").replace(/([^\n])<\/div>([^\n])/gi,"$1\n$2").replace(/<\/div>/gi,"").replace(/([^\n])
/gi,"$1\n").replace(/\n
/gi,"\n").replace(/
\n/gi,"\n\n").replace(/<(?:[^>]+)?>/g,"").replace(new RegExp(P,"g"),"").replace(/ /g," ").replace(/</g,"<").replace(/>/g,">").replace(/"/g,'"').replace(/'/g,"'").replace(/`/g,"`").replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&"),a.saveEmojisAs){case"image":e=u(e,a.emojiTemplate);break;case"shortname":e=C.toShort(e)}return e}function L(){var e=this,a=e.editor[0].offsetWidth-e.editor[0].clientWidth,o=parseInt(e.button.css("marginRight"));o!==a&&(e.button.css({marginRight:a}),e.floatingPicker)&&e.picker.css({right:parseInt(e.picker.css("right"))-o+a})}function U(){var o,n,e=this;!e.sprite&&e.lasyEmoji[0]&&e.lasyEmoji.eq(0).is(".lazy-emoji")&&(o=e.picker.offset().top,n=o+e.picker.height()+20,e.lasyEmoji.each(function(){var e=x(this),a=e.offset().top;if(o",D(e)?e:{class:$(e,!0)});return x.each(_.call(arguments).slice(1),function(e,a){(a=x.isFunction(a)?a.call(o):a)&&x(a).appendTo(o)}),o}function G(){return localStorage.getItem("recent_emojis")||""}function M(e,a){var o,n,t,i=G();e.recent&&e.recent===i&&!a||(i.length?((t=e.scrollArea.is(".skinnable"))||(o=e.scrollArea.scrollTop(),a&&e.recentCategory.show(),n=e.recentCategory.is(":visible")?e.recentCategory.height():0),a=F(i,e.emojiBtnTemplate,!0).split("|").join(""),e.recentCategory.children(".emojibtn").remove(),x(a).insertAfter(e.recentCategory.children(".emojionearea-category-title")),e.recentCategory.children(".emojibtn").on("click",function(){e.trigger("emojibtn.click",x(this))}),e.recentFilter.show(),t||(e.recentCategory.show(),n!==(t=e.recentCategory.height())&&e.scrollArea.scrollTop(o+t-n))):(e.recentFilter.hasClass("active")&&e.recentFilter.removeClass("active").next().addClass("active"),e.recentCategory.hide(),e.recentFilter.hide()),e.recent=i)}window.getSelection&&document.createRange?(z=function(e){var a=window.getSelection&&window.getSelection();if(a&&0",{rel:"stylesheet",href:e}).appendTo("head"));n.length;)n.shift().call();d.isLoading=!1}})):(o=m(C),S=g(o),d.base=4]*>.*?|]*>.*?|<(?:object|embed|svg|img|div|span|p|a)[^>]*>|("+C.unicodeRegexp+")","gi")})}function a(y,v){var j=this;p(v),l[j.id=++e]={},s[j.id]={},t(function(){var l,a,i,e,t,o,r,s,_,n,c,m,g,u,d,p,f,h,b,w,k;a=y,i=v,(l=j).options=i=O(i),l.sprite=i.sprite&&S<3,l.inline=null===i.inline?a.is("INPUT"):i.inline,l.shortnames=i.shortnames,l.saveEmojisAs=i.saveEmojisAs,l.standalone=i.standalone,l.emojiTemplate='{alt}':'emoji" src="{img}"/>'),l.emojiTemplateAlt=l.sprite?'':'',l.emojiBtnTemplate=''+l.emojiTemplateAlt+"",l.recentEmojis=i.recentEmojis&&function(){var e="test";try{return localStorage.setItem(e,e),localStorage.removeItem(e),!0}catch(e){return!1}}(),e=i.pickerPosition,l.floatingPicker="top"===e||"bottom"===e,((l.source=a).is(":disabled")||a.is(".disabled"))&&l.disable(),d=a.is("TEXTAREA")||a.is("INPUT")?"val":"text",p=V("tones",i.tones?function(){this.addClass($("tones-"+i.tonesStyle,!0));for(var e=0;e<=5;e++)this.append(x("",{class:"btn-tone btn-tone-"+e+(e?"":" active"),"data-skin":e,role:"button"}))}:null),f=V({class:q+(l.standalone?" "+q+"-standalone ":" ")+(a.attr("class")||""),role:"application"},t=l.editor=V("editor").attr({contenteditable:!l.standalone,placeholder:i.placeholder||a.data("placeholder")||a.attr("placeholder")||"",tabindex:0}),o=l.button=V("button",V("button-open"),V("button-close")).attr("title",i.buttonTitle),r=l.picker=V("picker",V("wrapper",s=V("filters"),i.search?n=V("search-panel",V("search",i.search?function(){l.search=x("",{placeholder:i.searchPlaceholder||"",type:"text",class:"search"}),this.append(l.search)}:null),p):null,u=V("scroll-area",i.tones&&!i.search?V("tones-panel",p):null,c=V("emojis-list")))).addClass($("picker-position-"+i.pickerPosition,!0)).addClass($("filters-position-"+i.filtersPosition,!0)).addClass($("search-position-"+i.searchPosition,!0)).addClass("hidden")),i.search&&n.addClass($("with-search",!0)),l.searchSel=null,t.data(a.data()),x.each(i.attributes,function(e,a){t.attr(e,a)}),h=V("category-block").attr({"data-tone":0}).prependTo(c),x.each(i.filters,function(e,a){var o=0;if("recent"!==e||l.recentEmojis){if("tones"!==e)x("",{class:$("filter",!0)+" "+$("filter-"+e,!0),"data-filter":e,title:a.title}).wrapInner(F(a.icon,l.emojiTemplateAlt)).appendTo(s);else{if(!i.tones)return;o=5}do{var n=a.emoji.replace(/[\s,;]+/g,"|"),t=0===o?V("category").attr({name:e,"data-tone":o}).appendTo(h):V("category-block").attr({name:e,"data-tone":o}).appendTo(c)}while(0':'',!0).split("|").join(""),t.html(n),x('
').text(a.title).prependTo(t),0<--o)}}),i.filters=null,l.sprite||(l.lasyEmoji=c.find(".lazy-emoji")),(_=s.find($("filter"))).eq(0).addClass("active"),g=c.find($("category-block")),m=c.find($("category")),l.recentFilter=_.filter('[data-filter="recent"]'),l.recentCategory=m.filter("[name=recent]"),l.scrollArea=u,i.container?x(i.container).wrapInner(f):f.insertAfter(a),i.hideSource&&a.hide(),l.setText(a[d]()),a[d](l.getText()),L.apply(l),l.standalone&&!l.getText().length&&(w=x(a).data("emoji-placeholder")||i.emojiPlaceholder,l.setText(w),t.addClass("has-placeholder")),R(l,c.find(".emojibtn"),{click:"emojibtn.click"}),R(l,window,{resize:"!resize"}),R(l,p.children(),{click:"tone.click"}),R(l,[r,o],{mousedown:"!mousedown"},t),R(l,o,{click:"button.click"}),R(l,t,{paste:"!paste"},t),R(l,t,["focus","blur"],function(){return!l.stayFocused&&t}),R(l,r,{mousedown:"picker.mousedown",mouseup:"picker.mouseup",click:"picker.click",keyup:"picker.keyup",keydown:"picker.keydown",keypress:"picker.keypress"}),R(l,t,["mousedown","mouseup","click","keyup","keydown","keypress"]),R(l,r.find(".emojionearea-filter"),{click:"filter.click"}),R(l,a,{change:"source.change"}),i.search&&R(l,l.search,{keyup:"search.keypress",focus:"search.focus",blur:"search.blur"}),k=!1,u.on("scroll",function(){var o,n,e;!k&&(U.call(l),u.is(":not(.skinnable)"))&&(o=m.eq(0),n=u.offset().top,m.each(function(e,a){return!(10<=x(a).offset().top-n)&&void(o=x(a))}),(e=_.filter('[data-filter="'+o.attr("name")+'"]'))[0]&&!e.is(".active")&&(_.removeClass("active"),e.addClass("active")))}),l.on("@filter.click",function(e){var a=e.is(".active");if(u.is(".skinnable")){if(a)return;p.children().eq(0).click()}k=!0,a||(_.filter(".active").removeClass("active"),e.addClass("active"));var o=m.filter('[name="'+e.data("filter")+'"]').offset().top,a=u.scrollTop(),e=u.offset().top;u.stop().animate({scrollTop:o+a-e-2},200,"swing",function(){U.call(l),k=!1})}).on("@picker.show",function(){l.recentEmojis&&M(l),U.call(l)}).on("@tone.click",function(e){p.children().removeClass("active"),(e=e.addClass("active").data("skin"))?(u.addClass("skinnable"),g.hide().filter("[data-tone="+e+"]").show(),_.removeClass("active")):(u.removeClass("skinnable"),g.hide().filter("[data-tone=0]").show(),_.eq(0).click()),U.call(l),i.search&&l.trigger("search.keypress")}).on("@button.click",function(e){e.is(".active")?l.hidePicker():(l.showPicker(),l.searchSel=null)}).on("@!paste",function(i,e){function a(e){var a="caret-"+(new Date).getTime(),o=I(e,l),n=(B(o),B(''),i.scrollTop(r),x("#"+a)),t=n.offset().top-i.offset().top;((a=i.height())<=r+t||t"+P+"");var o=z(i[0]),r=i.scrollTop(),n=x("
",{contenteditable:!0}).css({position:"fixed",left:"-999px",width:"1px",height:"1px",top:"20px",overflow:"hidden"}).appendTo(x("BODY")).focus();window.setTimeout(function(){i.focus(),T(i[0],o);var e=N(n.html().replace(/\r\n|\n|\r/g,"
"),l);n.remove(),a(e)},200)}).on("@emojibtn.click",function(e){var a,o,n;t.removeClass("has-placeholder"),null!==l.searchSel&&(t.focus(),T(t[0],l.searchSel),l.searchSel=null),l.standalone?(t.html(F(e.data("name"),l.emojiTemplate)),l.trigger("blur")):(z(t[0]),B(F(e.data("name"),l.emojiTemplate))),l.recentEmojis&&(a=l,o=e.data("name"),-1!==(e=(n=G().split("|")).indexOf(o))&&n.splice(e,1),n.unshift(o),9]*>/gi,"");e.length&&!/^]*>$/i.test(e)||l.editor.html(l.content=""),a[d](l.getText())}).on("@source.change",function(){l.setText(a[d]()),E("change")}).on("@focus",function(){f.addClass("focused")}).on("@blur",function(){f.removeClass("focused"),i.hidePickerOnBlur&&l.hidePicker();var e=l.editor.html();l.content!==e?(l.content=e,E(l,"change",[l.editor]),a.trigger("blur").trigger("change")):a.trigger("blur"),i.search&&(l.search.val(""),l.trigger("search.keypress",!0))}),i.search&&l.on("@search.focus",function(){l.stayFocused=!0,l.search.addClass("focused")}).on("@search.keypress",function(e){var n=r.find(".emojionearea-filter"),o=i.tones?p.find("i.active").data("skin"):0,t=l.search.val().replace(/ /g,"_").replace(/"/g,'\\"');t&&t.length?(l.recentFilter.hasClass("active")&&l.recentFilter.removeClass("active").next().addClass("active"),l.recentCategory.hide(),l.recentFilter.hide(),g.each(function(){function e(e,a){var o=e.find('.emojibtn[data-name*="'+t+'"]');0===o.length?(e.data("tone")===a&&e.hide(),n.filter('[data-filter="'+e.attr("name")+'"]').hide()):(e.find('.emojibtn:not([data-name*="'+t+'"])').hide(),o.show(),e.data("tone")===a&&e.show(),n.filter('[data-filter="'+e.attr("name")+'"]').show())}var a=x(this);0===a.data("tone")?m.filter(':not([name="recent"])').each(function(){e(x(this),0)}):e(a,o)}),k?U.call(l):u.trigger("scroll")):(M(l,!0),g.filter('[data-tone="'+p.find("i.active").data("skin")+'"]:not([name="recent"])').show(),x(".emojibtn",g).show(),n.show(),U.call(l))}).on("@search.blur",function(){l.stayFocused=!1,l.search.removeClass("focused"),l.trigger("blur")}),i.shortcuts&&l.on("@keydown",function(e,a){a.ctrlKey||(9==a.which?(a.preventDefault(),o.click()):27==a.which&&(a.preventDefault(),o.is(".active"))&&l.hidePicker())}),D(i.events)&&!x.isEmptyObject(i.events)&&x.each(i.events,function(e,a){l.on(e.replace(/_/g,"."),a)}),i.autocomplete&&(b=function(){var e={maxCount:i.textcomplete.maxCount,placement:i.textcomplete.placement},o=(i.shortcuts&&(e.onKeydown=function(e,a){if(!e.ctrlKey&&13==e.which)return a.KEY_ENTER}),x.map(C.emojioneList,function(e,a){return!i.autocompleteTones&&/_tone[12345]/.test(a)?null:a}));o.sort(),t.textcomplete([{id:q,match:/\B(:[\-+\w]*)$/,search:function(a,e){e(x.map(o,function(e){return 0===e.indexOf(a)?e:null}))},template:function(e){return F(e,l.emojiTemplate)+" "+e.replace(/:/g,"")},replace:function(e){return F(e,l.emojiTemplate)},cache:!0,index:1}],e),i.textcomplete.placement&&"static"==x(t.data("textComplete").option.appendTo).css("position")&&x(t.data("textComplete").option.appendTo).css("position","relative")},w=function(){var e;l.disabled?l.on("enabled",e=function(){l.off("enabled",e),b()}):b()},x.fn.textcomplete?w():x.ajax({url:"https://cdn.rawgit.com/yuku-t/jquery-textcomplete/v1.3.4/dist/jquery.textcomplete.js",dataType:"script",cache:!0,success:w})),l.inline&&(f.addClass($("inline",!0)),l.on("@keydown",function(e,a){13==a.which&&a.preventDefault()})),/firefox/i.test(navigator.userAgent)&&document.execCommand("enableObjectResizing",!1,!1),l.isReady=!0,l.trigger("onLoad",t),l.trigger("ready",t)})}a.prototype.on=function(e,i){var r;return e&&x.isFunction(i)&&(r=this,x.each(e.toLowerCase().split(" "),function(e,a){var n,t,o;n=r,t=(t=a).replace(/^@/,""),o=n.id,s[o][t]&&(x.each(s[o][t],function(e,o){x.each(x.isArray(o[0])?o[0]:[o[0]],function(e,a){x(a).on(o[1],function(){var e=_.call(arguments),a=x.isFunction(o[2])?o[2].apply(n,[t].concat(e)):o[2];a&&E(n,t,[a].concat(e))})})}),s[o][t]=null),(l[r.id][a]||(l[r.id][a]=[])).push(i)})),this},a.prototype.off=function(e,n){var t;return e&&(t=this.id,x.each(e.toLowerCase().replace(/_/g,".").split(" "),function(e,o){l[t][o]&&!/^@/.test(o)&&(n?x.each(l[t][o],function(e,a){a===n&&(l[t][o]=l[t][o].splice(e,1))}):l[t][o]=[])})),this},a.prototype.trigger=function(){var e=_.call(arguments),a=[this].concat(e.slice(0,1));return a.push(e.slice(1)),E.apply(this,a)},a.prototype.setFocus=function(){var e=this;return t(function(){e.editor.focus()}),e},a.prototype.setText=function(e){var a=this;return t(function(){a.editor.html(I(e,a)),a.content=a.editor.html(),E(a,"change",[a.editor]),L.apply(a)}),a},a.prototype.getText=function(){return N(this.editor.html(),this)},a.prototype.showPicker=function(){var e=this;return e._sh_timer&&window.clearTimeout(e._sh_timer),e.picker.removeClass("hidden"),e._sh_timer=window.setTimeout(function(){e.button.addClass("active")},50),E(e,"picker.show",[e.picker]),e},a.prototype.hidePicker=function(){var e=this;return e._sh_timer&&window.clearTimeout(e._sh_timer),e.button.removeClass("active"),e._sh_timer=window.setTimeout(function(){e.picker.addClass("hidden")},500),E(e,"picker.hide",[e.picker]),e},a.prototype.enable=function(){function e(){a.disabled=!1,a.editor.prop("contenteditable",!0),a.button.show();var e=a[a.standalone?"button":"editor"];e.parent().removeClass("emojionearea-disable"),E(a,"enabled",[e])}var a=this;return a.isReady?e():a.on("ready",e),a},a.prototype.disable=function(){var a=this;function e(){a.editor.prop("contenteditable",!1),a.hidePicker(),a.button.hide();var e=a[a.standalone?"button":"editor"];e.parent().addClass("emojionearea-disable"),E(a,"disabled",[e])}return a.disabled=!0,a.isReady?e():a.on("ready",e),a},x.fn.emojioneArea=function(e){return this.each(function(){return this.emojioneArea||(x.data(this,"emojioneArea",this.emojioneArea=new a(x(this),e)),this.emojioneArea)})},x.fn.emojioneArea.defaults=o(),x.fn.emojioneAreaText=function(e){e=O(e);var a=this,o={shortnames:!e||void 0===e.shortnames||e.shortnames,emojiTemplate:'{alt}'};return p(e),t(function(){a.each(function(){var e=x(this);return e.hasClass("emojionearea-text")||e.addClass("emojionearea-text").html(I(e.is("TEXTAREA")||e.is("INPUT")?e.val():e.text(),o)),e})}),this}},window); //# sourceMappingURL=emojionearea.min.js.map