| Current Path : /home/ereika83/www/wp-content/plugins/squirrly-seo/view/assets/js/assistant/ |
| Current File : /home/ereika83/www/wp-content/plugins/squirrly-seo/view/assets/js/assistant/sq_briefcase.min.js |
(function($){"use strict";if($.isFunction($.fn.sq_briefcase)){return}$.fn.sq_briefcase=function(options){var $this=this;var $last_action=false;var settings=$.extend({briefcase_keywords:[],optimizations:[],getapi:false,gettimeout:false,loaded:false,tmpk:false},options);$.sq_fields=$.extend({sq_briefcase:$.sq_config.div.find("#sq_briefcase"),sq_briefcase_help:$.sq_config.div.find("#sq_briefcase_help"),sq_keywords_briefcase:$this.find("#sq_keywords_briefcase"),sq_briefcase_content:$this.find("#sq_briefcase_content"),sq_briefcase_keyword:$this.find("#sq_briefcase_keyword"),sq_briefcase_close:$this.find("#sq_briefcase_close")},$.sq_fields);$this.init=function(){settings.loaded=true;$this.show();$.sq_fields.sq_briefcase_keyword.val("");$this.get()};$this.get=function(search,circles){$.sq_fields.sq_briefcase_content.find(".sq_briefcase_item_notused").sq_loading();var labels=[];if(typeof circles!=="undefined"){circles.each(function(){labels.push($(this).data("id"))})}settings.getapi=$.post($.sq_config.ajaxurl,{action:"sla_briefcase_get",sq_nonce:$.sq_config.sq_nonce,post_id:$.sq_config.postID,search:search,label:labels.length>0?labels.join(","):"",return:"html",output:"json"}).done(function(response){if(typeof response.error!=="undefined"){}else if(typeof response.data.briefcase!=="undefined"){$this.loadList(response.data.briefcase)}else{if(typeof search==="undefined"||search===""){$.sq_fields.sq_briefcase_content.html($.sq_config.__no_briefcase).addClass("sq_error")}}if(typeof search!=="undefined"&&search!==""){$.sq_fields.sq_briefcase_keyword.focus()}$.sq_fields.sq_briefcase_content.find(".sq_briefcase_item_notused").sq_doneloading();$this.trigger("briefcase.after_get")}).fail(function(){$.sq_fields.sq_errorloading.show();$.sq_fields.sq_preloading_keyword.hide();$.sq_fields.sq_briefcase_content.find(".sq_briefcase_item_notused").sq_doneloading()})};$this.optimize=function(keyword){$.post($.sq_config.ajaxurl,{action:"sla_briefcase_add",sq_nonce:$.sq_config.sq_nonce,post_id:$.sq_config.postID,keyword:keyword,output:"json"}).done(function(response){$this.get($.sq_fields.sq_briefcase_keyword.val(),$.sq_fields.sq_briefcase_content.find(".sq_briefcase_circle.sq_active"));$this.trigger("briefcase.after_optimize")}).fail(function(){$.sq_fields.sq_briefcase_content.html("Lost connection with the server. Please make sure you whitelisted the IP from https://api.squirrly.co").addClass("sq_error")})};$this.blink=function($obj,$times){if(typeof $times==="undefined")$times=0;if($times>3)return;$obj.animate({opacity:0},150,"linear",function(){$(this).animate({opacity:1},150,"linear",function(){$this.blink($obj,$times+1)})})};$this.delete=function(id){$.post($.sq_config.ajaxurl,{action:"sla_briefcase_delete",sq_nonce:$.sq_config.sq_nonce,id:id,output:"json"}).done(function(response){$this.get($.sq_fields.sq_briefcase_keyword.val(),$.sq_fields.sq_briefcase_content.find(".sq_briefcase_circle.sq_active"));$this.trigger("briefcase.after_delete")}).fail(function(){$.sq_fields.sq_briefcase_content.html("Lost connection with the server. Please make sure you whitelisted the IP from https://api.squirrly.co").addClass("sq_error")})};$this.loadList=function(briefcase){$.sq_fields.sq_briefcase_content.before($.sq_fields.sq_briefcase_keyword);$.sq_fields.sq_briefcase_content.html(briefcase).removeClass("sq_error");$.sq_fields.sq_briefcase_content.find("ul.sq_briefcase_item_used").after($.sq_fields.sq_briefcase_keyword);if(typeof $.sq_config.lsi!=="undefined"){$.each($.sq_config.lsi,function(key,value){if(value.main){$.sq_fields.sq_keyword.val(value.keyword)}})}$.sq_fields.sq_briefcase_keyword.show();$.sq_fields.sq_briefcase_content.find(".sq_briefcase_item_circles").show();var $briefcase_empty=$.sq_fields.sq_briefcase_content.find("ul.sq_briefcase_item_notused").find(".sq_briefcase_empty");if($briefcase_empty.length>0){$.sq_fields.sq_briefcase_content.find(".sq_briefcase_item_circles").hide()}if($.sq_fields.sq_briefcase_keyword.val()!==""||$.sq_fields.sq_briefcase_content.find(".sq_briefcase_circle.sq_active").length>0){if($.sq_fields.sq_briefcase_keyword.val()!==$.sq_config.keyword){$.sq_fields.sq_briefcase_content.append('<div class="sq_briefcase_add_keyword"><i class="fa-solid fa-plus-circle" ></i> add this keyword</div>');$.sq_fields.sq_briefcase_content.find(".sq_briefcase_add_keyword").on("click",function(){$this.optimize($.sq_fields.sq_briefcase_keyword.val())})}}$this.setEvents();$this.setMainKeyword($.sq_fields.sq_keyword.val())};$this.setMainKeyword=function(keyword){if(typeof $.sq_fields.sq_briefcase_content!=="undefined"){if($.sq_fields.sq_briefcase_content.find("li.sq_briefcase_item_used").length>0){$.sq_fields.sq_briefcase_content.find("li.sq_briefcase_item_used").removeClass("sq_main_keyword");$.sq_fields.sq_briefcase_content.find("li.sq_briefcase_item_used").each(function(){if(keyword===""||$.sq_strEqual(keyword,$(this).find(".sq_briefcase_value").text())){$(this).addClass("sq_main_keyword");$.sq_fields.sq_keyword_nokeyword.hide();$.sq_fields.sq_keyword_div.show();$.sq_fields.sq_keyword.val($(this).find(".sq_briefcase_value").text());$.sq_fields.sq_keyword_score.html($(this).find(".sq_briefcase_item_percent").text());return false}});$.sq_fields.sq_keyword_nokeyword.hide();$.sq_fields.sq_keyword_div.show()}}$.sq_fields.sq_selectit.trigger("click")};$this.getColor=function(value){var hue=value.toString();return["hsl(",hue,",71%,43%)"].join("")};$this.setColor=function(obj,value){return;obj.css("color",$this.getColor(value));obj.css("font-weight","bold")};$this.setEvents=function(){$.sq_fields.sq_briefcase_content.find(".sq_briefcase_item_delete").on("click",function(){$(this).parent("li").sq_loading();$this.delete($(this).data("id"))});$.sq_fields.sq_briefcase_content.find(".sq_briefcase_item_used").find(".sq_briefcase_value").on("click",function(){$this.setMainKeyword($(this).text())});$.sq_fields.sq_briefcase_content.find(".sq_briefcase_circle").on("click",function(){if($(this).hasClass("sq_active")){$(this).removeClass("sq_active")}else{$(this).addClass("sq_active")}$this.get($.sq_fields.sq_briefcase_keyword.val(),$.sq_fields.sq_briefcase_content.find(".sq_briefcase_circle.sq_active"))});$this.find(".sq_briefcase_optimize").on("click",function(){$(this).parent("li").sq_loading();$this.optimize($(this).data("value"))});$this.checkKeywords()};$this.setOptimizations=function(){$.sq_config.silent=true;$.sq_config.briefcase=true;settings.show_addtobriefcasebutton=true;settings.tmpk=$.sq_config.keyword;settings.optimizations=[];if($.sq_fields.sq_briefcase_content.find("li.sq_briefcase_item_used").length>0){$.sq_fields.sq_briefcase_content.find("li.sq_briefcase_item_used").each(function(){$.sq_config.keyword=$(this).find(".sq_briefcase_value").text();if($.sq_strEqual($.sq_fields.sq_keyword.val(),$(this).find(".sq_briefcase_value").text())){settings.show_addtobriefcasebutton=false}$.sq_fields.div_blockseo=$.sq_fields.div_blockseo.clone();$.sq_fields.div_blockseo.find("li").removeClass("checked");$.sq_fields.div_blockseo.find("input").remove();$.sq_blockseo.checkSEO();var completed=$.sq_blockseo.getPercentCompleted();if(completed){$(this).find(".sq_briefcase_item_percent").html(parseInt(completed)+"%");$this.setColor($(this).find(".sq_briefcase_value"),parseInt(completed));if($.sq_strEqual($.sq_fields.sq_keyword.val(),$(this).find(".sq_briefcase_value").text())){$.sq_fields.sq_keyword_score.html(parseInt(completed)+"%")}}$(this).attr("data-position",parseInt(completed));settings.optimizations.push({keyword:$(this).find(".sq_briefcase_value").html(),score:parseInt(completed),main:$(this).hasClass("sq_main_keyword")});$.sq_fields.div_blockseo.remove();$.sq_fields.div_blockseo=$.sq_config.div.find("#sq_blockseo")})}else{settings.show_addtobriefcasebutton=true}$.sq_config.keyword=settings.tmpk;return settings.optimizations};$this.checkKeywords=function(){$this.setOptimizations();$.sq_fields.sq_briefcase_content.find(".sq_briefcase_item_used").find(".sq_briefcase_separator").attr("data-position",-2);$.sq_fields.sq_briefcase_content.find("ul.sq_briefcase_item_used li").sort($this.sortList).appendTo($.sq_fields.sq_briefcase_content.find("ul.sq_briefcase_item_used"));if(settings.show_addtobriefcasebutton){if($.sq_fields.wp_publish.find("#sq_publish_alert").length==0){$("#sq_publish_alert_briefcase").find("#sq_addtobriefcase").show()}}};$this.sortList=function(a,b){return $(b).data("position")<$(a).data("position")?-1:1};$this.sendOptimization=function(){$this.setOptimizations();$.sq_fields.div_blockseo.find("input[name=sq_optimizations]").remove();$.sq_fields.div_blockseo.append('<input name="sq_optimizations" type="hidden" value="'+JSON.stringify($.sq_blockbriefcase.setOptimizations()).replace(/\"/g,""")+'" />');if(settings.optimizations.length){$.post($.sq_config.ajaxurl,{action:"sla_briefcase_save",sq_nonce:$.sq_config.sq_nonce,post_id:$.sq_config.postID,optimizations:JSON.stringify(settings.optimizations)}).done(function(response){}).fail(function(){})}};$this.listen=function(){$.sq_fields.sq_briefcase_keyword.on("keypress",function(event){if(event.keyCode===$.ui.keyCode.ENTER){clearTimeout(settings.gettimeout);settings.getapi.abort();$this.get($.sq_fields.sq_briefcase_keyword.val(),$.sq_fields.sq_briefcase_content.find(".sq_briefcase_circle.sq_active"));return false}});$.sq_fields.sq_briefcase_keyword.on("keyup",function(event){if(event.keyCode!==$.ui.keyCode.ENTER){clearTimeout(settings.gettimeout);settings.getapi.abort();settings.gettimeout=setTimeout(function(){$this.get($.sq_fields.sq_briefcase_keyword.val(),$.sq_fields.sq_briefcase_content.find(".sq_briefcase_circle.sq_active"))},1e3)}});$this.on("briefcase.save",function(){$this.sendOptimization()})};$this.one("seo.loaded",function(){$.sq_config.debug&&console.log("sq_briefcase seo.loaded");if(!$.sq_config.subscription_active){return}$this.listen();$.sq_blockseo.on("seo.task_loaded",function(){$this.get()});$.sq_blockseo.on("seo.callback",function(){$this.checkKeywords()});setInterval(function(){$this.trigger("briefcase.save")},3e4);$this.on("briefcase.refresh",function(){$.sq_config.debug&&console.log("sq_briefcase refresh");$this.init(false)});$this.trigger("briefcase.refresh");$this.on("briefcase.after_delete",function(){$this.on("briefcase.after_get",function(){if($.sq_fields.sq_briefcase_content.find("ul.sq_briefcase_item_used").length>0){var $briefcase_empty=$.sq_fields.sq_briefcase_content.find("ul.sq_briefcase_item_used").find(".sq_briefcase_empty");if($briefcase_empty.length>0){$.sq_blocksearch.reset()}}})})});return $this}})(jQuery);