(function(){const e=40;const t=38;const i=27;const n=13;const o=8;var l=[e,t,i,n];var r=["123"];if(typeof wpzinc_autocomplete!=="undefined"){wpzinc_autocomplete.forEach(function(o,s){o.triggers.forEach(function(o,s){if("url"in o){return}tinymce.create("tinymce.plugins."+o.tinyMCEName,{init:function(s){var c=false,a=createAutoComplete();function createAutoComplete(){var e=document.createElement("ul");e.setAttribute("class","wpzinc-tinymce-autocomplete");o.values.forEach(function(t,i){var n=document.createElement("li");n.classList.add("displayed");e.appendChild(n);n.innerHTML=n.innerHTML+t.value});document.body.appendChild(e);return e}function showAutoComplete(e,t){var i=getCaretPosition(e);positionAutoComplete(t,i.top,i.left);t.classList.remove("displayed");t.classList.add("displayed");c=true}function getCaretPosition(e){var t=e.getContainer()?e.getContainer():document.getElementById(e.id);var i={top:t.getBoundingClientRect().top+window.scrollY,left:t.getBoundingClientRect().left+window.scrollX};var n={top:0,left:0};if(e.selection.getRng().getClientRects().length>0){n={top:e.selection.getRng().getClientRects()[0].top+20,left:e.selection.getRng().getClientRects()[0].left}}else{n={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:i.top+o.getBoundingClientRect().height+n.top,left:i.left+n.left}}return n}function positionAutoComplete(e,t,i){e.style.marginTop=t+"px";e.style.marginLeft=i+"px"}function getSearchWord(e){var t=e.selection.getSel().focusNode==null?"":e.selection.getSel().focusNode.nodeValue,i=e.selection.getSel().focusOffset,n=0;if(t==null||t.length==0){return""}for(var o=i;o>=0;o--){if(r.indexOf(t.charCodeAt(o).toString())!=-1){n=o;break}}var l=t.substr(n,i-n);return{search:l,start:n,end:i}}function filterAutoComplete(e,t,i){var n=i.getElementsByTagName("li"),o=true,l=n.length;for(var r=0;r<l-1;r++){n.item(r).classList.remove("highlight");if(n.item(r).innerText.indexOf(e.search)==-1){n.item(r).classList.remove("displayed")}else{n.item(r).classList.add("displayed");if(o){n.item(r).classList.add("highlight");o=false}}}}function changeAutoCompleteItemHighlighted(e,t,i){var n=i.querySelectorAll("li.displayed"),o=n.length;for(var l=0;l<o-1;l++){if(!n[l].classList.contains("highlight")){continue}if(e=="previous"){if(l==0){break}n[l].classList.remove("highlight");n[l-1].classList.add("highlight");break}if(e=="next"){if(l==n.length-1){break}n[l].classList.remove("highlight");n[l+1].classList.add("highlight");break}}}function insertAutoCompleteItemHighlighted(e,t){var i=t.querySelectorAll("li.highlight")[0].innerText;insertAutoCompleteItemByText(i,e,t)}function insertAutoCompleteItemByText(e,t){var i=getSearchWord(t),n=t.selection.getSel().focusNode,o=t.selection.getRng();o.setStart(n,i.start);o.setEnd(n,i.end);t.selection.setRng(o);t.selection.setContent(e)}function hideAutoComplete(e,t){t.classList.remove("displayed");c=false}function keyDownEvent(l,r){if(o.triggerKeyCode==r.keyCode&&!c){if(o.triggerKeyShiftRequired){if(r.shiftKey){showAutoComplete(l,a);return}}else{showAutoComplete(l,a);return}}if(i==r.keyCode&&c){hideAutoComplete(l,a);return}if(c&&(t==r.keyCode||e==r.keyCode)){var s=t==r.keyCode?"previous":"next";changeAutoCompleteItemHighlighted(s,l,a)}if(c&&n==r.keyCode){tinymce.dom.Event.cancel(r);insertAutoCompleteItemHighlighted(l,a);hideAutoComplete(l,a);return}}function keyUpEvent(e,t){if(l.indexOf(t.keyCode)==-1&&c){showAutoComplete(e,a);var i=getSearchWord(e);filterAutoComplete(i,e,a)}}function clickEventInEditor(e,t){hideAutoComplete(e,a)}function clickEvent(e){if(!e.target.matches("li.displayed")){hideAutoComplete(s,a);return}insertAutoCompleteItemByText(e.target.innerText,s);hideAutoComplete(s,a)}s.onKeyDown.add(keyUpEvent);s.onKeyDown.add(keyDownEvent);s.onClick.add(clickEventInEditor);document.addEventListener("click",clickEvent)},getInfo:function(){return{longname:"Autocomplete",author:"WP Zinc",authorurl:"https://www.wpzinc.com/",infourl:"https://www.wpzinc.com/",version:tinymce.majorVersion+"."+tinymce.minorVersion}}});tinymce.PluginManager.add(o.tinyMCEName,tinymce.plugins[o.tinyMCEName])})})}})();