/*
Agoda Affiliate Partners Text Link Generator WordPress plugin, Copyright © 2017 Agoda Company Pte. Ltd. (Agoda.com)
Agoda Affiliate Partners Text Link Generator is distributed under the terms of the GNU GPL
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
http://www.gnu.org/licenses/gpl-2.0.html
You should have received a copy of the GNU General Public License along with this program; see also above URL; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
function agdtlwpTextLinkObject(){this.map=[]}!function(){var e="agdtlwp-textlink-container";tinymce.PluginManager.add("agdtlwp_text_link_button",function(t,r){t.addButton("agdtlwp_text_link_button",{image:r+"/image/agoda-icon.png",text:"Agoda Text Link",title:"Agoda Text Link",id:"agdtlwp-agoda-text-link",onclick:function(){function r(t){clearTimeout(Q),Q=setTimeout(function(){i(p,jQuery(t.target).val(),f),l(jQuery("#"+e+" #search-input").val())},400)}function i(e,t,r){r.append(e,t)}function a(t){jQuery(t.target).val().length?jQuery("#"+e+" #clear-search").show():jQuery("#"+e+" #clear-search").hide(),clearTimeout(j),j=setTimeout(function(){l(jQuery(t.target).val())},400)}function n(e){clearTimeout(v),j=setTimeout(function(){i(g,jQuery(e.target).val(),f)},400)}function l(t){if(void 0!=t&&t.length){jQuery("#"+e+" #search-result #search-result-instruction").removeClass("no-result"),jQuery("#"+e+" #search-result #search-result-instruction").text("Loding results..."),jQuery("#"+e+" #search-result ul li").remove();var r="";null!=f.get(p)&&(r=f.get(p)),agdtlwpTextlinkSearch(r,f.get(y),t,c)}else jQuery("#"+e+" #search-result ul li").remove(),jQuery("#"+e+" #search-result #search-result-instruction").removeClass("no-result"),jQuery("#"+e+" #search-result #search-result-instruction").text("No search term specified.")}function c(t){var t=JSON.parse(t),r=[],a=jQuery([]);switch(f.get(y)){case"TextlinkCityArea":null!=t.suggestions.All&&(r=t.suggestions.All);break;case"TextlinkHotel":null!=t.suggestions.Hotel&&(r=t.suggestions.Hotel)}jQuery(r).each(function(e,t){return a=a.add(jQuery('
'+t.displayText+"")),e<4}),jQuery("#"+e+" #search-result ul").append(a),jQuery("#"+e+" #search-result ul li").length?jQuery("#"+e+" #search-result #search-result-instruction").text("Search or use up and down arrow keys to select an item."):(jQuery("#"+e+" #search-result #search-result-instruction").addClass("no-result"),jQuery("#"+e+" #search-result #search-result-instruction").text("No results found.")),jQuery("#"+e+" #search-result ul li").on("click",function(t){jQuery("#"+e+" #search-result ul li.selected").removeClass("selected"),jQuery(this).addClass("selected"),i(m,jQuery(this).data("url"),f)})}function u(t){var r="";switch(t){case"city-button":r=b,i(y,"TextlinkCityArea",f);break;case"hotel-button":r=k,i(y,"TextlinkHotel",f)}jQuery("#"+e+" #search-criteria .mce-criteria-item.mce-criteria-active").removeClass("mce-criteria-active"),jQuery("#"+e+" #"+t).addClass("mce-criteria-active"),jQuery("#"+e+" #search-input").attr("placeholder",r),l(jQuery("#"+e+" #search-input").val())}function s(t){t&&t.length?o(t[0].cid):(jQuery("#"+e+" #cid-input").prop("placeholder","Please insert your CID"),jQuery("#"+e+" #cid-input-l,#"+e+" #cid-input").removeClass("mce-disabled"),jQuery("#"+e+" #cid-input").removeProp("disabled"))}function o(t){jQuery("#"+e+" #cid-input").val(t),i(p,t,f),l(jQuery("#"+e+" #search-input").val()),jQuery("#"+e+" #cid-input").prop("placeholder","Please insert your CID"),jQuery("#"+e+" #cid-input-l,#"+e+" #cid-input").removeClass("mce-disabled"),jQuery("#"+e+" #cid-input").removeProp("disabled")}function d(e){for(var t=e+"=",r=decodeURIComponent(document.cookie).split(";"),i=0;iSearch Type'},{type:"container",name:"search-criteria",id:"search-criteria",html:'City/Area
Property
'},{type:"textbox",name:"search-input",id:"search-input",label:"Search"},{type:"container",id:"search-result-container",html:'No search term specified.
'}],buttons:[{text:"Add Link",id:"add-link-button",subtype:"primary",onclick:"submit"},{text:"Cancel",id:"cancel-button",onclick:"close"}],onsubmit:function(r){var i;i=null!=f.get(g)?f.get(g):null!=f.get(m)?f.get(m):"",jQuery("#"+e+" #remember-checkbox").hasClass("mce-checked")&&null!=f.get(p)&&""!=f.get(p)&&f.get(p)!=h&&agdtlwpTextlinkSave(f.get(p));var a="";jQuery("#"+e+" #newtab-checkbox").hasClass("mce-checked")&&(a="_blank");var n="";if(null!=f.get(p)&&(n=f.get(p)),""!=i){var l="";l=null!=f.get(m)?f.get(m):"https://www.agoda.com?cid="+n+"&pcs=5",t.insertContent(''+i+"")}agdtlwpTrackEvent(n)}}),jQuery("#"+e+" #cid-input").on("input",function(e){r(e)}),jQuery("#"+e+" #link-text-input").on("input",function(e){n(e)}),jQuery("#"+e+" #search-input").on("input",function(e){a(e)}),function(){jQuery("#"+e+" #cid-input").prop("placeholder","Loading your existing CID...");var t="";""!=(t=d("agoda_textlink_cid_cookie"))?(o(t),jQuery("#"+e+" #cid-input-l,#"+e+"#cid-input").removeClass("mce-disabled"),jQuery("#"+e+" #cid-input").removeProp("disabled")):agdtlwpTextlinkLoad(s),h=jQuery("#"+e+" #cid-input").val()}(),function(){var r=t.selection.getContent({format:"text"});null!=r&&""!=r&&(jQuery("#"+e+" #link-text-input").val(r),i(g,r,f))}(),function(){var t="";jQuery("#"+e+" #search-criteria .mce-criteria-item").each(function(){if(jQuery(this).hasClass("mce-criteria-active"))switch(jQuery(this).attr("id")){case"city-button":t=b;break;case"hotel-button":t=k}}),jQuery("#"+e+" #search-input").attr("placeholder",t)}(),jQuery("#"+e+" #city-button,#"+e+" #hotel-button,#"+e+" #area-button").on("click",function(e){u(jQuery(e.target).attr("id"))}),jQuery(document).on("keydown",function(t){if(40===t.keyCode)t.preventDefault(),jQuery("#"+e+" #search-result ul li").length&&((r=jQuery("#"+e+" #search-result ul li.selected")).length?r.is(":last-child")||(a=jQuery(r.next()),r.removeClass("selected"),a.addClass("selected"),i(m,a.data("url"),f)):(jQuery("#"+e+" #search-result ul li:first-child").addClass("selected"),i(m,jQuery("#"+e+" #search-result ul li:first-child").data("url"),f)));else if(38===t.keyCode&&(t.preventDefault(),jQuery("#"+e+" #search-result ul li").length)){var r=jQuery("#"+e+" #search-result ul li.selected");if(r.length){if(!r.is(":first-child")){var a=jQuery(r.prev());r.removeClass("selected"),a.addClass("selected"),i(m,a.data("url"),f)}}else jQuery("#"+e+" #search-result ul li:first-child").addClass("selected"),i(m,jQuery("#"+e+" #search-result ul li:first-child").data("url"),f)}}),jQuery("#"+e+" #search-input").parent().append('
'),jQuery("#"+e+" #clear-search").on("click",function(){jQuery("#"+e+" #search-input").focus(),jQuery("#"+e+" #search-input").val(""),jQuery("#"+e+" #clear-search").hide(),l("")})}})})}(jQuery),agdtlwpTextLinkObject.prototype.get=function(e){return this.map[e]},agdtlwpTextLinkObject.prototype.append=function(e,t){this.map[e]=t},agdtlwpTextLinkObject.prototype.delete=function(e){this.map.hasOwnProperty(e)&&delete this.map[e]};