/* Copyright (C) 2018 AdSimple (https://www.adsimple.at). All rights reserved. @license GPLv2 or later; See http://www.gnu.org/licenses/gpl-2.0.html @author Alexander Khmelnitskiy (hi@alexander.khmelnitskiy.ua) @support support@adsimple.at */ tinymce.create("tinymce.plugins.adsimplevote_plugin",{init:function(e,t){e.addButton("adsimplevote",{title:"Insert AdSimple Vote",image:t+"/../images/icon.svg",onclick:function(){e.windowManager.open({title:"Insert Vote",width:500,height:400,body:[{type:"container",html:'

Your shortcode is: [adsimplevote id=""]

Select one of the existing votes.

'}],buttons:[{text:"Insert Vote",classes:"btn primary",id:"insert-vote-btn",onclick:function(t){var s=e.selection.getContent(),i=jQuery("#insert-adsimplevote .shortcode").text(),l="";l=s?s+i:i,e.execCommand("mceInsertContent",0,l),e.windowManager.close()}},{text:"Close",id:"close-vote-btn",onclick:"close"}],onOpen:function(e){jQuery("#adsimplevote-search-results").addClass("loader"),jQuery.ajax({url:adsimple_data.rest_url+"wp/v2/adsimplevote/?filter[posts_per_page]=42",dataType:"json"}).done(function(e){jQuery("#adsimplevote-search-results ul").empty(),jQuery.each(e,function(e,t){jQuery("#adsimplevote-search-results ul").append('
  • '+t.title.rendered+''+new Date(t.date).toLocaleDateString()+"
  • ")})}).fail(function(e){console.log("error!"),console.log(e)}).always(function(){jQuery("#adsimplevote-search-results").removeClass("loader")}),jQuery("#adsimplevote-search").on("keyup paste",function(){var e=jQuery(this).val().toLowerCase();e.length>1?jQuery("#adsimplevote-search-results ul li").each(function(t){~jQuery(this).find(".item-title").text().toLowerCase().indexOf(e)?jQuery(this).show():jQuery(this).hide()}):jQuery("#adsimplevote-search-results ul li").show()}),jQuery("body").on("click","#adsimplevote-search-results ul li",function(){jQuery("#adsimplevote-search-results ul li").removeClass("selected"),jQuery(this).addClass("selected"),jQuery("#insert-adsimplevote .shortcode").html('[adsimplevote id="'+jQuery(this).find(".item-vote").val()+'"]')})}})}})},createControl:function(e,t){return null},getInfo:function(){return{longname:"AdSimple Vote",author:"www.AdSimple.at",version:"1.0.0"}}}),tinymce.PluginManager.add("adsimplevote_plugin",tinymce.plugins.adsimplevote_plugin);