!function(){var e=[40,38,27,13],t=["123"];"undefined"!=typeof wpzinc_autocomplete&&wpzinc_autocomplete.forEach((function(n,i){n.triggers.forEach((function(n,i){"url"in n||(tinymce.create("tinymce.plugins."+n.tinyMCEName,{init:function(i){var o,l=!1,s=((o=document.createElement("ul")).setAttribute("class","wpzinc-tinymce-autocomplete"),n.values.forEach((function(e,t){var n=document.createElement("li");n.classList.add("displayed"),o.appendChild(n),n.innerHTML=n.innerHTML+e.value})),document.body.appendChild(o),o);function c(e,t){var n=function(e){var t=e.getContainer()?e.getContainer():document.getElementById(e.id),n={top:t.getBoundingClientRect().top+window.scrollY,left:t.getBoundingClientRect().left+window.scrollX},i={top:0,left:0};i=e.selection.getRng().getClientRects().length>0?{top:e.selection.getRng().getClientRects()[0].top+20,left:e.selection.getRng().getClientRects()[0].left}:{top:e.selection.getNode().getClientRects()[0].top+20,left:e.selection.getNode().getClientRects()[0].left};var o=t.getElementsByClassName("mce-toolbar-grp")[0];if(o)return{top:n.top+o.getBoundingClientRect().height+i.top,left:n.left+i.left};return i}(e);!function(e,t,n){e.style.marginTop=t+"px",e.style.marginLeft=n+"px"}(t,n.top,n.left),t.classList.remove("displayed"),t.classList.add("displayed"),l=!0}function r(e){var n=null==e.selection.getSel().focusNode?"":e.selection.getSel().focusNode.nodeValue,i=e.selection.getSel().focusOffset,o=0;if(null==n||0==n.length)return"";for(var l=i;l>=0;l--)if(-1!=t.indexOf(n.charCodeAt(l).toString())){o=l;break}return{search:n.substr(o,i-o),start:o,end:i}}function a(e,t){var n=r(t),i=t.selection.getSel().focusNode,o=t.selection.getRng();o.setStart(i,n.start),o.setEnd(i,n.end),t.selection.setRng(o),t.selection.setContent(e)}function d(e,t){t.classList.remove("displayed"),l=!1}i.onKeyDown.add((function(t,n){-1==e.indexOf(n.keyCode)&&l&&(c(t,s),function(e,t,n){for(var i=n.getElementsByTagName("li"),o=!0,l=i.length,s=0;s<l-1;s++)i.item(s).classList.remove("highlight"),-1==i.item(s).innerText.indexOf(e.search)?i.item(s).classList.remove("displayed"):(i.item(s).classList.add("displayed"),o&&(i.item(s).classList.add("highlight"),o=!1))}(r(t),0,s))})),i.onKeyDown.add((function(e,t){if(n.triggerKeyCode==t.keyCode&&!l){if(!n.triggerKeyShiftRequired)return void c(e,s);if(t.shiftKey)return void c(e,s)}if(27!=t.keyCode||!l){if(l&&(38==t.keyCode||40==t.keyCode))!function(e,t,n){for(var i=n.querySelectorAll("li.displayed"),o=i.length,l=0;l<o-1;l++)if(i[l].classList.contains("highlight")){if("previous"==e){if(0==l)break;i[l].classList.remove("highlight"),i[l-1].classList.add("highlight");break}if("next"==e){if(l==i.length-1)break;i[l].classList.remove("highlight"),i[l+1].classList.add("highlight");break}}}(38==t.keyCode?"previous":"next",0,s);return l&&13==t.keyCode?(tinymce.dom.Event.cancel(t),function(e,t){a(t.querySelectorAll("li.highlight")[0].innerText,e)}(e,s),void d(0,s)):void 0}d(0,s)})),i.onClick.add((function(e,t){d(0,s)})),document.addEventListener("click",(function(e){e.target.matches("li.displayed")?(a(e.target.innerText,i),d(0,s)):d(0,s)}))},getInfo:function(){return{longname:"Autocomplete",author:"WP Zinc",version:tinymce.majorVersion+"."+tinymce.minorVersion}}}),tinymce.PluginManager.add(n.tinyMCEName,tinymce.plugins[n.tinyMCEName]))}))}))}();