egroupware_official/api/js/tinymce/plugins/emoticons/plugin.min.js

1 line
6.7 KiB
JavaScript

!function(){"use strict";var n,t,e,r,o,i=tinymce.util.Tools.resolve("tinymce.PluginManager"),u=function(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t]},c=function(n){return function(){return n}},a=function(n){return n},l=c(!1),f=c(!0),s=l,d=f,m=function(){return g},g=(r={fold:function(n,t){return n()},is:s,isSome:s,isNone:d,getOr:e=function(n){return n},getOrThunk:t=function(n){return n()},getOrDie:function(n){throw new Error(n||"error: getOrDie called on none.")},getOrNull:function(){return null},getOrUndefined:function(){return undefined},or:e,orThunk:t,map:m,ap:m,each:function(){},bind:m,flatten:m,exists:s,forall:d,filter:m,equals:n=function(n){return n.isNone()},equals_:n,toArray:function(){return[]},toString:c("none()")},Object.freeze&&Object.freeze(r),r),y=function(e){var n=function(){return e},t=function(){return o},r=function(n){return n(e)},o={fold:function(n,t){return t(e)},is:function(n){return e===n},isSome:d,isNone:s,getOr:n,getOrThunk:n,getOrDie:n,getOrNull:n,getOrUndefined:n,or:t,orThunk:t,map:function(n){return y(n(e))},ap:function(n){return n.fold(m,function(n){return y(n(e))})},each:function(n){n(e)},bind:r,flatten:n,exists:r,forall:r,filter:function(n){return n(e)?o:g},equals:function(n){return n.is(e)},equals_:function(n,t){return n.fold(s,function(n){return t(e,n)})},toArray:function(){return[e]},toString:function(){return"some("+e+")"}};return o},p={some:y,none:m,from:function(n){return null===n||n===undefined?g:y(n)}},h=(o="function",function(n){return function(n){if(null===n)return"null";var t=typeof n;return"object"===t&&Array.prototype.isPrototypeOf(n)?"array":"object"===t&&String.prototype.isPrototypeOf(n)?"string":t}(n)===o}),v=function(n,t){for(var e=0,r=n.length;e<r;e++)if(t(n[e],e,n))return p.some(e);return p.none()},O=(Array.prototype.slice,h(Array.from)&&Array.from,function(n,t,e){for(var r,o=[],i=e.fold(function(){return l},function(t){return function(n){return t<=n}}),u=0;u<n.length&&(!(0===t.length||-1<n[u].title.indexOf(t)||(r=n[u].keywords,v(r,function(n){return-1<n.indexOf(t)}).isSome()))||(o.push({value:n[u]["char"],text:n[u].title,icon:n[u]["char"]}),!i(o.length)));u++);return o}),b=function(n){var t=n,e=function(){return t};return{get:e,set:function(n){t=n},clone:function(){return b(e())}}},w="undefined"!=typeof window?window:Function("return this;")(),A=Object.keys,k=Object.hasOwnProperty,T=function(e){return{is:function(n){return e===n},isValue:f,isError:l,getOr:c(e),getOrThunk:c(e),getOrDie:c(e),or:function(n){return T(e)},orThunk:function(n){return T(e)},fold:function(n,t){return t(e)},map:function(n){return T(n(e))},each:function(n){n(e)},bind:function(n){return n(e)},exists:function(n){return n(e)},forall:function(n){return n(e)},toOption:function(){return p.some(e)}}},j=function(e){return{is:l,isValue:l,isError:f,getOr:a,getOrThunk:function(n){return n()},getOrDie:function(){return n=String(e),function(){throw new Error(n)}();var n},or:function(n){return n},orThunk:function(n){return n()},fold:function(n,t){return n(e)},map:function(n){return j(e)},each:u,bind:function(n){return j(e)},exists:l,forall:f,toOption:p.none}},C={value:T,error:j},S=tinymce.util.Tools.resolve("tinymce.dom.ScriptLoader"),_=tinymce.util.Tools.resolve("tinymce.util.Promise"),x="All",D=b(p.none()),L=b(p.none()),E={symbols:"Symbols",people:"People",animals_and_nature:"Animals and Nature",food_and_drink:"Food and Drink",activity:"Activity",travel_and_places:"Travel and Places",objects:"Objects",flags:"Flags"},P="mce_emoticons_plugin_database",F=function(n){return t=E,e=n,k.call(t,e)?E[n]:n;var t,e},N=function(n,u){n.on("init",function(){S.ScriptLoader.loadScript(u,function(){var o={},i=[];(function(n){if(w[P]){var t=C.value(w[P]);return delete w[P],t}return C.error("Url "+n+" did not contain the expected format for emoticons")})(u).fold(function(n){console.log(n),D.set(p.some({})),L.set(p.some([]))},function(n){!function(n,t){for(var e=A(n),r=0,o=e.length;r<o;r++){var i=e[r];t(n[i],i,n)}}(n,function(n,t){var e={title:t,keywords:n.keywords,"char":n["char"],category:F(n.category)},r=o[e.category]!==undefined?o[e.category]:[];o[e.category]=r.concat([e]),i.push(e)}),D.set(p.some(o)),L.set(p.some(i))})},function(){})});var e=function(){return L.get().getOr([])},o=function(){return D.get().isSome()&&L.get().isSome()};return{listCategories:function(){return[x].concat(A(D.get().getOr({})))},hasLoaded:o,waitForLoad:function(){return o()?_.resolve(!0):new _(function(n,t){var e=3,r=setInterval(function(){o()?(clearInterval(r),n(!0)):--e<0&&(console.log("Could not load emojis from url: "+u),clearInterval(r),t(!1))},500)})},listAll:e,listCategory:function(t){return t===x?e():D.get().bind(function(n){return p.from(n[t])}).getOr([])}}},q="pattern",I=function(o,c){var e,r,i,u=(e=function(n){var t,e,r,o,i,u=a.get();e=u,r=(t=n).getData(),o=c.listCategory(e),i=O(o,r[q].toLowerCase(),e===x?p.some(50):p.none()),t.setData({results:i})},r=200,i=null,{cancel:function(){null!==i&&(clearTimeout(i),i=null)},throttle:function(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];null!==i&&clearTimeout(i),i=setTimeout(function(){e.apply(null,n),i=null},r)}}),a=b(x),t={label:"Search",type:"input",name:q},l={type:"collection",name:"results",columns:"auto"},f=o.windowManager.open({title:"Emoticons",size:"normal",body:{type:"tabpanel",tabs:function(n,t){for(var e=n.length,r=new Array(e),o=0;o<e;o++){var i=n[o];r[o]=t(i,o,n)}return r}(c.listCategories(),function(n){return{title:n,items:[t,l]}})},initialData:{pattern:"",results:O(c.listAll(),"",p.some(50))},onTabChange:function(n,t){a.set(t),u.throttle(n)},onChange:u.throttle,onAction:function(n,t){var e,r;"results"===t.name&&(e=o,r=t.value,e.insertContent(r),n.close())},buttons:[{type:"cancel",text:"Cancel"}]});f.focus(q),c.hasLoaded()||(f.block("Loading emoticons..."),c.waitForLoad().then(function(){u.throttle(f),f.focus(q),f.unblock()})["catch"](function(n){f.redial({title:"Emoticons",body:{type:"panel",items:[{type:"alertbanner",level:"error",icon:"",text:"<p>Could not load emoticons</p>"}]},buttons:[{type:"cancel",text:"Cancel"}],initialData:{}}),f.focus(q),f.unblock()}))},z=function(n,t){var e=function(){return I(n,t)};n.ui.registry.addButton("emoticons",{type:"button",tooltip:"Emoticons",icon:"emoji",onAction:e}),n.ui.registry.addMenuItem("emoticons",{text:"Emoticons",icon:"emoji",onAction:e})},M=function(n,t){return n.getParam("emoticons_database_url",t+"/json/emojis.js")};i.add("emoticons",function(n,t){var r,o,e=M(n,t),i=N(n,e);z(n,i),o=i,(r=n).ui.registry.addAutocompleter("emoticons",{ch:":",columns:"auto",fetch:function(t,e){return o.waitForLoad().then(function(){var n=o.listAll();return O(n,t.toLowerCase(),p.some(e))})},onAction:function(n,t,e){r.selection.setRng(t),r.insertContent(e),n.hide()}})}),function U(){}}();