| 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_blockseo.min.js |
(function($){"use strict";if($.isFunction($.fn.sq_blockseo)){return}$.fn.sq_blockseo=function(options){var $this=this;var settings=$.extend({check:[],single_tag:[],double_tag:[],custom_tag:[],custom_tag_id:[],clicked:[]},options);$.sq_fields=$.extend({sq_wp_title_info:$('<span id="sq_wp_title_info" style="display: block; float: right;" />')},$.sq_fields);var seo={title:"",content:""};$this.setContent=function(content){seo.content=content};$this.load=function(){$.sq_fields.div_blockseo.find(".sq_tasks > ul > li").not(".sq_tasks_category").removeClass("checked");if($.sq_config.timeout_seo){clearTimeout($.sq_config.timeout_seo)}$.sq_config.timeout_seo=setTimeout(function(){$this.callback()},100)};$this.callback=function(){$.sq_config.manual=true;$.sq_config.silent=false;$.sq_config.briefcase=false;if(typeof $.sq_config.keyword==="undefined"||$.sq_config.keyword==="")return;if($.sq_config.editor_type==="tinymce"){if($.sq_isGutenberg()){ed=$.sq_editor.getBlockEditor("select");if(ed)seo.content=ed.getEditedPostContent()}else if($.sq_config.active_editor&&typeof $.sq_config.active_editor.html=="function"){seo.content=$.sq_config.active_editor.html()}else{ed=$.sq_editor.getIframeEditor();seo.content=ed.html()}}else{if($.sq_isGutenberg()){var ed=$.sq_editor.getBlockEditor("select");if(ed){seo.content=ed.getEditedPostContent();if($.sq_clearText(seo.content)===""){ed=$.sq_editor.getIframeEditor();seo.content=ed.html()}}}else if($.sq_isFrontend()){var ed=$.sq_editor.getFrontendEditor();if(ed)seo.content=ed.getPageContent()}else if($.sq_config.active_editor&&typeof $.sq_config.active_editor.val=="function"){seo.content=$.sq_fields.wp_content.val()}else if($.sq_fields.wp_content.length){seo.content=$.sq_fields.wp_content.val()}}if(!$.sq_fields.wp_input_title.length){if($(".editor-post-title").find("textarea").length>0){$.sq_fields.wp_input_title=$(".editor-post-title").find("textarea")}else if($("h1.wp-block-post-title").length>0){var $wp_input_title=$("h1.wp-block-post-title");$.sq_fields.wp_input_title=$('<textarea id="title" style="display: none">'+$wp_input_title.html()+"</textarea>");$wp_input_title.after($.sq_fields.wp_input_title);$wp_input_title.on("DOMSubtreeModified",function(){$.sq_fields.wp_input_title.val($wp_input_title.html())})}else if($(".block-editor-iframe__container").find("iframe").contents().find("h1.wp-block-post-title")){var $wp_input_title=$(".block-editor-iframe__container").find("iframe").contents().find("h1.wp-block-post-title");$.sq_fields.wp_input_title=$('<textarea id="title" style="display: none">'+$wp_input_title.html()+"</textarea>");$wp_input_title.after($.sq_fields.wp_input_title);$wp_input_title.on("DOMSubtreeModified",function(){$.sq_fields.wp_input_title.val($wp_input_title.html())})}}$this.trigger("seo.content");$this.checkSEO();$this.trigger("seo.callback")};$this.checkSEO=function(){if(typeof seo.content!=="undefined"&&$.sq_clearText(seo.content)!==""){$.sq_config.debug&&console.log("check keywords in body and tags");$this.checkTitle();$this.checkBody();$this.checkSingleTags();$this.checkCustomTags();$this.checkKPinguinUrl();$this.checkKeyword();if($.sq_fields.wp_thumbnail.length>0){$this.sq_eventsseo.listenMediaLibrary()}else if($("#postimagediv").length>0){$this.checkImage($("#postimagediv"))}else if($.sq_isFrontend()){var ed=$.sq_editor.getFrontendEditor();if(ed)$.sq_blockseo.checkImage($("<div>"+ed.getPageImages()+"</div>"))}if($(".editor-post-featured-image").length>0){$this.checkImage($(".editor-post-featured-image"))}if($("#visual_composer_content").length>0){$this.sq_eventsseo.listenVComposer()}if($("#fusion_builder_container").length>0){$this.sq_eventsseo.listenFusion()}}};$this.close=function(){$.sq_fields.div_blockseo.hide()};$this.checkKPinguinUrl=function(){if($.sq_config.keyword!==""){if($("#custom_permalinks_home_url").length>0&&$("#custom_permalink").length>0){var slug=$("#custom_permalinks_home_url").val()+" "+$("#custom_permalink").val();$this.setChecked($this.urlMatch(slug,$.sq_config.keyword),"pinguin_url")}else if($("#editable-post-name-full").length>0){var root="";if($("#sample-permalink").length>0){var sample_permalink=$("#sample-permalink").find("a").clone();sample_permalink.find("span").remove();root=sample_permalink.text()}var slug=root+" "+$("#editable-post-name-full").html();$this.setChecked($this.urlMatch(slug,$.sq_config.keyword),"pinguin_url")}else if($("#new-post-slug").length>0){var slug=$("#new-post-slug").val();$this.setChecked($this.urlMatch(slug,$.sq_config.keyword),"pinguin_url")}else if($("#sample-permalink").length>0){var slug=$("#sample-permalink").html().replace(/<\/?[^>]+>/gi," ");$this.setChecked($this.urlMatch(slug,$.sq_config.keyword),"pinguin_url")}else if($.sq_isGutenberg()){var ed=$.sq_editor.getBlockEditor("select");if(ed){var slug=decodeURIComponent(ed.getPermalink()).replace(/<\/?[^>]+>/gi," ");$this.setChecked($this.urlMatch(slug,$.sq_config.keyword),"pinguin_url")}}}};$this.checkKeyword=function(){$this.setChecked($this.checkWordsLength($.sq_config.keyword,2,0),"longtail_keyword")};$this.checkPinguin=function(){var domain=$.sq_getDomain(document.domain,[8])!==""?$.sq_getDomain(document.domain,[8]):document.domain;$this.setChecked(!$this.keywordMatch($.sq_fields.wp_input_title.val(),domain,true),"pinguin_title")};$this.checkTitle=function(){$.sq_config.debug&&console.log("check keywords in title: "+$.sq_fields.wp_input_title.val());if(typeof $.sq_config.keyword==="undefined"||$.sq_config.keyword==="")return;if($.sq_fields.wp_input_title.length&&$.sq_clearText($.sq_fields.wp_input_title.val()).length>1){$this.setChecked($this.checkLength($.sq_fields.wp_input_title.val(),$.sq_params.min_length_title,$.sq_params.max_length_title),"title_length");$this.setChecked($this.keywordMatch($.sq_fields.wp_input_title.val(),$.sq_config.keyword),"title");$this.checkPinguin();var id="density_title";if($this.checkWordsLength($.sq_config.keyword,1,100)){if($.sq_strEqual($.sq_fields.wp_input_title.val(),$.sq_config.keyword)){$this.setChecked(true,id)}else{$this.keywordDensity($.sq_fields.wp_input_title.val(),$.sq_params.low_density_title,$.sq_params.high_density_title,"density_title")}}else{$("#sq_"+id+"_val").html($("#sq_"+id+"_longtail").html());$this.setChecked(false,id)}}};$this.checkImage=function(_this){$.sq_config.silent=true;var pattern=null;pattern=new RegExp("<img([^>]*)>","gi");if(_this.html()!==""&&$this.checkPattern(pattern)){$this.setChecked(true,"img",true)}else if(_this.html()!==""){$.sq_config.debug&&console.log("Check image in object");if($this.checkPattern(pattern,_this.html())){$this.setChecked($this.checkPattern(pattern,_this.html()).length>0,"img",true)}else{pattern=new RegExp("\\[gallery[^\\]]*ids=[^\\]]*\\]","gi");if($this.checkPattern(pattern)){$this.setChecked($this.checkPattern(pattern).length>0,"img")}else{$this.setChecked(0,"img")}}}pattern=new RegExp('alt="([^"]+)"',"gi");if(!$this.keywordMatch($this.checkPattern(pattern),$.sq_config.keyword)){$.sq_config.debug&&console.log("There is no alt image in content");$this.setChecked($this.keywordMatch($this.checkPattern(pattern,_this.html()),$.sq_config.keyword),"alt")}};$this.hideOptions=function(){$("#sq_wp_title_suggestion").remove();$this.checkTitle()};$this.checkBody=function(){var $str=$("<div></div>").html(seo.content);$str.find("form").remove();$.sq_highlight($str,$.sq_config.keyword,{counter:0,done:function(count,positions){$.sq_config.debug&&console.log($str.text(),$.sq_config.keyword,count,positions);$this.processBody($str.text(),count,positions)}})};$this.processBody=function(cleanContent,count,positions){var checked=false,id=false,words=[],density,i=0;if($.sq_config.editor_type==="tinymce"){var iframe_tinymce=$.sq_editor.getIframeEditor()}$this.setChecked(count>0,"body");if($.sq_fields.wp_input_title.length&&$.sq_fields.wp_input_title.val()!==""){$this.keywordDensity($.sq_fields.wp_input_title.val()+" "+cleanContent,$.sq_params.low_density,$.sq_params.high_density,"density")}else{$this.keywordDensity(cleanContent,$.sq_params.low_density,$.sq_params.high_density,"density")}checked=true;id="over_density";if($this.checkWordsLength(cleanContent,$.sq_params.min_length_body,$.sq_params.max_length_body)===false){$.sq_fields.div_blockseo.find("#sq_request_"+id+"").remove();$.sq_fields.div_blockseo.find("#sq_"+id+"").append('<span id="sq_request_'+id+'">: '+"("+$.sq_config.__addminimumwords.replace(/%s/g,$this.getWords2Min(cleanContent,$.sq_params.min_length_body))+")</span>");checked=false;$.sq_fields.div_blockseo.find("#sq_"+id+"_val").parent("li").removeClass("sq_"+id+"_high")}else{$.sq_fields.div_blockseo.find("#sq_request_"+id+"").remove();$.sq_fields.div_blockseo.find("#sq_"+id+"_val").html($.sq_fields.div_blockseo.find("#sq_"+id+"_done").html());words=$.sq_clearText($.sq_config.keyword).split(" ");density=$this.getDensity(cleanContent,$.sq_config.keyword);if(density.val>0){var ignore=["and","und","or","the","yet","for","also","then","like","too","but","i","you","he","she","we","they"];var wordslen=words.length;for(i=0;i<wordslen;i++){if(words[i].length>2&&ignore.indexOf(words[i])===-1){var word=words[i];density=$this.getDensity(cleanContent,word);if(density.val>=$.sq_params.max_word_density){var need=density.keywords-$.sq_params.max_word_density*density.words/100+1;need=Math.round(need)<=0?1:need.toFixed();$.sq_fields.div_blockseo.find("#sq_request_"+id+"").remove();$.sq_fields.div_blockseo.find("#sq_"+id+"").append('<span id="sq_request_'+id+'">: '+'<span id="sq_request_'+id+'_highlight" style="color:yellow; text-decoration:underline; cursor: pointer;">'+word+"</span> "+$.sq_config.__toomanytimes.replace(/%s/g,need)+' <span id="sq_request_synonyms_oo"></span></span>');$this.getSynonyms(word,"sq_request_synonyms_oo");settings.clicked[id]=false;$.sq_fields.div_blockseo.find("#sq_request_"+id+"_highlight").parents("li#sq_"+id+":last").on("click",function(e){e.stopPropagation();settings.clicked[id]=true;$("body").on("mouseup",function(){$.sq_removeHighlight($.sq_getBuilderEditorContainer())})}).on("mouseenter",function(e){e.stopPropagation();$(this).css("cursor","pointer");$.sq_highlight($.sq_getBuilderEditorContainer(),word)}).on("mouseleave",function(){$.sq_removeHighlight($.sq_getBuilderEditorContainer())});$.sq_fields.div_blockseo.find("#sq_"+id+"_val").parent("li").attr("class","sq_"+id+"_high");$.sq_fields.div_blockseo.find("#sq_"+id+"_val").html("");checked=false;break}}}}else{checked=false}$this.setChecked(checked,id)}checked=true;id="human_friendly";$.sq_fields.div_blockseo.find("#sq_"+id+"_val").html("");if($this.checkWordsLength(cleanContent,$.sq_params.min_length_body,$.sq_params.max_length_body)===false){$.sq_fields.div_blockseo.find("#sq_request_"+id+"").remove();$.sq_fields.div_blockseo.find("#sq_"+id+"").append('<span id="sq_request_'+id+'">: '+"("+$.sq_config.__writemorewords.replace(/%s/g,$this.getWords2Min(cleanContent,$.sq_params.min_length_body))+")</span>");checked=false;$.sq_fields.div_blockseo.find("#sq_"+id+"_val").html("")}else{$.sq_fields.div_blockseo.find("#sq_request_"+id+"").remove();if(count>=2){for(i=2;i<=count;i++){$.sq_config.debug&&console.log(positions[i]-positions[i-1],$.sq_params.begin_last_max_chars);if(positions[i]-positions[i-1]<$.sq_params.begin_last_max_chars){$.sq_fields.div_blockseo.find("#sq_request_"+id+"").remove();var ndt=i===2?"st":i===3?"nd":i===4?"rd":"th";$.sq_fields.div_blockseo.find("#sq_"+id+"").append('<span id="sq_request_'+id+'">: '+"("+$.sq_config.__morewordsafter.replace(/%s/g,'<span id="sq_request_'+id+'_highlight_key" style="color:lightcoral; text-decoration:underline; cursor: pointer;">'+(i-1)+ndt+"</span>")+' <span id="sq_request_synonyms"></span>)</span>');$this.getSynonyms($.sq_config.keyword,"sq_request_synonyms");settings.clicked[id]=false;$.sq_fields.div_blockseo.find("#sq_request_"+id+"_highlight_key").parents("li#sq_"+id+":last").off().on("click",function(e){e.stopPropagation();settings.clicked[id]=true;$("body").on("mouseup",function(){$.sq_removeHighlight($.sq_getBuilderEditorContainer())})}).on("mouseenter",function(e){e.stopPropagation();$(this).css("cursor","pointer");$.sq_highlight($.sq_getBuilderEditorContainer(),$.sq_config.keyword)}).on("mouseleave",function(){$.sq_removeHighlight($.sq_getBuilderEditorContainer())});checked=false;$.sq_fields.div_blockseo.find("#sq_"+id+"_val").html("");break}}}}$this.setChecked(checked,id)};$this.getSynonyms=function(word,span){var ignore=["and","und","or","the","yet","for","also","then","like","too","but","i","you","he","she","we","they"];var words=$.sq_stripChars(word).split(" ");$this.find("#"+span).html(" "+$.sq_config.__orusesynonyms);var wordslen=words.length;for(var w=0;w<wordslen;w++)if(words[w].length>2&&ignore.indexOf(words[w])===-1){$this.find("#"+span).append(" "+(w===0?"for":"or for")+' <span class="'+span+"_"+words[w]+" "+span+'" style="text-decoration:underline; cursor: pointer;" title="">'+words[w]+"</span>");var synonyms_all=$.sq_getCache("synonyms_"+words[w]);if(synonyms_all!==""){if(synonyms_all.length>0)$this.find("."+span+"_"+words[w]).attr("title",synonyms_all.join("\n"))}else{$.post($.sq_config.ajaxurl,{action:"sla_customcall",sq_nonce:$.sq_config.sq_nonce,url:"https://thesaurus.altervista.org/thesaurus/v1",word:words[w],language:$.sq_config.language.replace("-","_"),key:"TDm3SO7N3XEfRWuXYFb9",output:"json"}).done(function(word){return function(data){var response=data.response;var synonyms=[];var synonyms_all=[];if(typeof response!=="undefined"&&response.length>0){var responselen=response.length;for(var j=0;j<responselen;j++){if(typeof response[j].list.synonyms!=="undefined"){synonyms=response[j].list.synonyms.split("|");var synonymslen=synonyms.length;for(var k=0;k<synonymslen;k++){if(typeof synonyms[k]!=="undefined"&&synonyms[k]!==""&&synonyms[k].indexOf("antonym")===-1){synonyms_all.push(synonyms[k]);if(synonyms_all.length>10)break}}}}if(synonyms_all.length>0){$this.find("."+span+"_"+word).attr("title",synonyms_all.join("\n"))}}$.sq_setCache("synonyms_"+word,synonyms_all)}}(words[w])).error(function(word){var synonyms_all=[];synonyms_all.push("no synonyms found");$this.find("."+span+"_"+word).attr("title",synonyms_all.join("\n"));$.sq_setCache("synonyms_"+word,synonyms_all)}(words[w]))}}};$this.checkTags=function(){var id;var striptag="[\\],\\[]";striptag=new RegExp(striptag,"g");for(var i in settings.double_tag){id="";try{if(typeof settings.double_tag[i]==="string"||settings.double_tag[i]instanceof String){id=settings.double_tag[i];id=id.replace(striptag,"");if(id!=="")$this.setChecked($this.keywordMatch($this.checkTag(["<"+settings.double_tag[i]+">","</"+settings.double_tag[i]+">"])),id)}}catch(e){}}};$this.checkCustomTags=function(){var pattern;for(var i in settings.custom_tag){pattern="";try{if(typeof settings.custom_tag[i]==="string"||settings.custom_tag[i]instanceof String){pattern=new RegExp(settings.custom_tag[i],"gi");if(pattern!==""){$this.setChecked($this.keywordMatch($this.checkPattern(pattern),$.sq_config.keyword),settings.custom_tag_id[i])}}}catch(e){}}return false};$this.checkSingleTags=function(){var id;var striptag="[\\],\\[]";striptag=$.sq_regex(striptag);for(var i in settings.single_tag){id="";try{if(typeof settings.single_tag[i]==="string"||settings.single_tag[i]instanceof String){id=settings.single_tag[i].replace(striptag,"");if(id!==""){$this.setChecked($this.checkTag(["<"+settings.single_tag[i],">"]).length>0,id)}}}catch(e){}}};$this.checkTag=function(tag,content){var pattern="";if($.sq_isArray(tag)){if(tag[0]!==""&&tag[1]!==""){pattern=tag[0].replace("/","\\/")+"([^>]*)"+tag[1].replace("/","\\/");pattern=$.sq_regex(pattern)}}else{return false}$.sq_config.debug&&console.log("checkTag pattern: "+pattern);return $this.checkPattern(pattern,content)};$this.checkPattern=function(pattern,content){if(typeof content==="undefined")var content=seo.content;content=content.replace(/<img([^>]*)(mceItemMedia|mce-object)([^>]*)>/gi," ");var matches="";if(pattern!==""){matches=content.toLowerCase().match(pattern);$.sq_config.debug&&console.log((matches!==null)+" for "+pattern+" in content");if(matches!==null&&$.sq_isArray(matches)){return matches.join(", ")}}return false};$this.getPercentCompleted=function(){var all=$.sq_fields.div_blockseo.find(".sq_tasks > ul > li").not(".sq_tasks_category").length;var checked=$.sq_fields.div_blockseo.find(".sq_tasks > ul > li.checked").not(".sq_tasks_category").length;return checked*100/all};$this.checkCompleted=function(){if($.sq_config.silent){return}var cached=null;var ky=$.sq_config.keyword.replace(/[^a-zA-Z0-9]/g,"");var timeout=3e3;if(!$.sq_config.manual){timeout=1e3}cached=$.sq_getCache("complete_"+ky);if(cached!=="1"){if($.sq_fields.div_blockseo.find(".sq_tasks > ul > li").length>10){if($.sq_fields.div_blockseo.find(".sq_tasks > ul > li").not(".sq_tasks_category").not(".checked").length==0){$("body").prepend($("<ul/>").html("<li>"+$.sq_config.__fulloptimized+"</li>").addClass("sq_complete"));if($("#wpadminbar").css("display")=="none"){$(".sq_complete").css("top","0")}else{$(".sq_complete").css("top","28px")}setTimeout(function(){$("ul.sq_complete").remove()},timeout);$.sq_setCache("complete_"+ky,"1")}}}$(".sq_blockseo_progress").val(parseInt($this.getPercentCompleted()));$.sq_fields.sq_keyword_score.html(parseInt($this.getPercentCompleted())+"%")};$this.setChecked=function(cond,id,hidden){var cached=null;var ky=$.sq_config.keyword.replace(/[^a-zA-Z0-9]/g,"");if($.sq_getCookie("sq_sla")==="off"){hidden=true}if(cond){$.sq_fields.div_blockseo.find("#sq_"+id).attr("class","checked");if($.sq_fields.div_blockseo.find("#sq_"+id).find(".sq_request_highlight_key").length>0){$.sq_fields.div_blockseo.find("#sq_"+id).find(".sq_request_highlight_key").hide();$this.sq_eventsseo.listenHighlight(false)}$.sq_config.debug&&console.log("sq_setCache true: ",id);$.sq_setCache("task_"+ky+id,"1");$.sq_fields.div_blockseo.find("#sq_input_"+id+"").remove();$.sq_fields.div_blockseo.find("#sq_"+id).append('<input id="sq_input_'+id+'" type="hidden" name="sq_seo[]" value="'+id+'" />')}else{$.sq_setCache("task_"+ky+id,"0");if(id!=="img"&&id!=="alt"){$.sq_config.debug&&console.log("sq_setCache false: ",id);$.sq_setCache("complete_"+ky,"0")}$.sq_fields.div_blockseo.find("#sq_"+id).removeClass("checked");if($.sq_fields.div_blockseo.find("#sq_"+id).find(".sq_request_highlight_key").length>0){$.sq_fields.div_blockseo.find("#sq_"+id).find(".sq_request_highlight_key").show();$this.sq_eventsseo.listenHighlight(true)}$.sq_fields.div_blockseo.find("#sq_input_"+id).remove()}$this.checkCompleted();if(!$.sq_config.briefcase){$this.trigger("seo.after_checked",[id])}return Boolean(cond)};$this.checkLength=function(str,min,max){str=$.sq_clearText(str);if(min>0&&str.length>=min&&(max===0||str.length<=max)){return true}return false};$this.checkWordsLength=function(str,min,max){if(min>0&&$this.wordCount(str)>=min&&(max===0||$this.wordCount(str)<=max)){return true}return false};$this.getWords2Min=function(str,min){if(min>0&&$this.wordCount(str)<min){return(min-$this.wordCount(str)+1).toFixed()}return 0};$this.urlMatch=function(str,keyword){if(str===false)return;if(typeof keyword==="undefined")return;var original=keyword;str=$.sq_clearText(str);str=$.sq_stripChars(str);keyword=$.sq_umlautsText(keyword);keyword=$.sq_clearText(keyword);keyword=$.sq_stripChars(keyword);$.sq_config.debug&&console.log("keywordMatch: "+keyword+"=>"+str);if(str!==""&&keyword!==""){var matches=0;$.sq_highlight($("<div>"+str+"</div>"),keyword,{counter:1,done:function(count){matches=count}});if(!matches){keyword=keyword.replace(/\s/g,"");$.sq_highlight($("<div>"+str+"</div>"),keyword,{counter:1,done:function(count){matches=count}})}if(!matches&&original.indexOf("ü")){keyword=original.replace("ü","ue");keyword=$.sq_clearText(keyword);keyword=$.sq_stripChars(keyword);$.sq_highlight($("<div>"+str+"</div>"),keyword,{counter:1,done:function(count){matches=count}})}$.sq_config.debug&&console.log("matches="+matches);return matches>0}};$this.keywordMatch=function(str,keyword,exact_match){var matches=0;if(str===false)return matches;if(typeof keyword==="undefined")return matches;if(typeof exact_match==="undefined")exact_match=false;str=$.sq_clearText(str);keyword=$.sq_clearText(keyword);keyword=keyword.replace(/[\"]/g,"");keyword=keyword.trim();if(typeof str!=="undefined"&&str!==""&&keyword!==""){matches=$.sq_strEqual(str,keyword);if(!exact_match){if(!matches){$.sq_highlight($("<div>"+str+"</div>"),keyword,{counter:0,done:function(count){matches=count}});if(!matches){$.sq_highlight($("<div>"+str+"</div>"),keyword+"s",{counter:0,done:function(count){matches=count}})}$.sq_config.debug&&console.log("string="+str);$.sq_config.debug&&console.log("matches="+matches)}}}return matches};$this.keywordDensity=function(str,low,high,id){var density=$this.getDensity(str,$.sq_config.keyword);var cached=null;var ky=$.sq_config.keyword.replace(/[^a-zA-Z0-9]/g,"");if(density.words<$this.checkWordsLength($.sq_config.keyword)){$.sq_config.debug&&console.log("keywordDensity: TOO FEW WORDS ",density.words);$.sq_fields.div_blockseo.find("#sq_"+id+"_val").html("");$this.setChecked(false,id);return}if(density.val<=low&&density.keywords<$.sq_params.max_keywords){$.sq_config.debug&&console.log("keywordDensity: TOO LOW ",density.val,low,density.keywords,$.sq_params.max_keywords);var need=density.words-100*density.keywords/low;need=Math.round(need)<=0?1:Math.round(need);var kr_need=Math.min(low*density.words/100-density.keywords+.5,$.sq_params.max_keywords-density.keywords);kr_need=Math.round(kr_need)<=0?1:kr_need.toFixed();$.sq_fields.div_blockseo.find("#sq_"+id+"_val").html($.sq_fields.div_blockseo.find("#sq_"+id+"_low").html());$.sq_fields.div_blockseo.find("#sq_"+id+"_val").parent("li").attr("class","sq_"+id+"_low");cached=$.sq_getCache("task_"+ky+id);if(cached==="1"){if($.sq_config.manual){$this.find("#sqt_"+id).addClass("sq_"+id+"_low")}}$.sq_setCache("task_"+ky+id,"2");$.sq_fields.div_blockseo.find("#sq_"+id+"_val").html($.sq_fields.div_blockseo.find("#sq_"+id+"_low").html()+" ("+$.sq_config.__addmorekeywords.replace(/%s/g,kr_need)+(need<density.words?" "+$.sq_config.__removewords.replace(/%s/g,Math.min(need,density.words)):"")+")");$.sq_fields.div_blockseo.find("#sq_input_"+id).remove()}else{if(density.val>=high){$.sq_config.debug&&console.log("keywordDensity: TOO HIGH ",density.val);var need=100*density.keywords/high-density.words+.5;need=Math.round(need)<=0?1:Math.round(need);var kr_need=density.keywords-high*density.words/100+.5;kr_need=Math.round(kr_need)<=0?1:kr_need.toFixed();$.sq_fields.div_blockseo.find("#sq_"+id+"_val").html($.sq_fields.div_blockseo.find("#sq_"+id+"_high").html());$.sq_fields.div_blockseo.find("#sq_"+id+"_val").parent("li").attr("class","sq_"+id+"_high");cached=$.sq_getCache("task_"+ky+id);if(cached==="1"){if($.sq_config.manual){$this.find("#sqt_"+id).addClass("sq_"+id+"_high")}}$.sq_setCache("task_"+ky+id,"3");if($this.checkWordsLength(str,$.sq_params.min_length_body,$.sq_params.max_length_body)!==false)kr_need="remove "+kr_need+" keyword(s) or ";else kr_need="";$.sq_fields.div_blockseo.find("#sq_"+id+"_val").html($.sq_fields.div_blockseo.find("#sq_"+id+"_high").html()+" ("+kr_need+$.sq_config.__addmorewords.replace(/%s/g,need)+")");$.sq_fields.div_blockseo.find("#sq_input_"+id).remove()}else{$.sq_config.debug&&console.log("keywordDensity: "+((density.val>low||density.keywords>=$.sq_params.max_keywords)&&density.val<high),density.val,low,density.keywords,$.sq_params.max_keywords);$.sq_fields.div_blockseo.find("#sq_"+id+"_val").html($.sq_fields.div_blockseo.find("#sq_"+id+"_done").html());$this.setChecked((density.val>low||density.keywords>=$.sq_params.max_keywords)&&density.val<high,id)}}};$this.getDensity=function(str,keyword){var density={};keyword=$.sq_clearText(keyword);str=$.sq_clearText(str);density.keywords=$this.phraseCount(str,keyword);density.words=$this.wordCount(str);density.words=density.words-density.keywords*($this.keywordWords(keyword)-1);if(density.words>0){density.val=density.keywords*100/density.words}else if(density.keywords>=1){density.val=100}else{density.val=0}return density};$this.keywordWords=function(keyword){var pattern=new RegExp("[㐀-龿 -〿-ゟ゠-ヿ-゚一-龯㐀-䶿]|\\S+","gi");var words=keyword.match(pattern);if(words&&words.length>0)return words.length+1;else return 1};$this.phraseCount=function(str,keyword){var words=0;$.sq_highlight($("<div>"+str+"</div>"),keyword,{counter:1,done:function(count){words=count}});return words};$this.wordCount=function(str){str=$.sq_clearText(str);var matches=str.match(/[\u3400-\u9FBF\u3000-\u303f\u3040-\u309f\u30a0-\u30ff\uff00-\uff9f\u4e00-\u9faf\u3400-\u4dbf]|\S+/g);if(matches)return matches.length;return 0};$this.sq_eventsseo={listen:function(){$.post($.sq_config.ajaxurl,{action:"sla_tasks",sq_nonce:$.sq_config.sq_nonce,output:"json"}).done(function(response){$this.sq_doneloading("sq_minloading").removeClass("sq_error");if(typeof response.data!=="undefined"&&typeof response.data.tasks!=="undefined"&&$this.find(".sq_tasks").length>0){settings.custom_tag.push("<(strong|b)[^>]*>(.*?)</(strong|b)>");settings.custom_tag_id.push("strong");settings.custom_tag.push("<h[1-6][^>]*>(.*?)</h[1-6]>");settings.custom_tag_id.push("h2_6");settings.single_tag.push("img");settings.custom_tag.push('alt=["]([^"]+)["]');settings.custom_tag_id.push("alt");$this.find(".sq_tasks").append(response.data.tasks);$this.find(".sq_tasks").find("li").show();$this.sq_eventsseo.listenHighlight(true);$this.on("seo.refresh",function(){$.sq_config.div.find(".sq_seo_refresh").addClass("sq_minloading");setTimeout(function(){$.sq_config.div.find(".sq_seo_refresh").removeClass("sq_minloading");$this.load()},1e3)});$.sq_config.div.find(".sq_seo_refresh").on("lateclick",function(){$this.trigger("seo.refresh");$this.trigger("seo.refresh_lateclick")});$.sq_config.div.find(".sq_seo_refresh").on("click",function(){$this.trigger("seo.refresh");$this.trigger("seo.refresh_click")});$this.trigger("seo.refresh");$this.trigger("seo.task_loaded")}else{$this.sq_doneloading("sq_minloading").removeClass("sq_error");$this.find(".sq_tasks").html('<div class="sq_message" style="width: 100% !important;">'+$.sq_config.__ajaxerror+"</div>")}});$this.sq_eventsseo.listenTitle();$this.sq_eventsseo.listenSlug();$.sq_fields.content_tmce.on("click",function(){$.sq_config.editor_type="tinymce"});$.sq_fields.content_html.on("click",function(){$.sq_config.editor_type="html"});$.sq_fields.wp_input_title.off("click").on("click",function(){if($this.find(".sq_overlay").length>0)if($.sq_fields.sq_keyword.val()!==""){$.sq_config.showInspiration=false;$.sq_fields.sq_selectit.trigger("click")}});if(typeof ET_PageBuilder!=="undefined"&&typeof ET_PageBuilder.Events!=="undefined"){ET_PageBuilder.Events.on("et-pb-loading:ended",function(){$(".et-pb-remove").on("click",function(){$.sq_config.debug&&console.log("Divi Save Pressed");$.sq_config.div.find(".sq_seo_refresh").trigger("lateclick")})});ET_PageBuilder.Events.on("et-modal-settings:save",function(){ET_PageBuilder.Events.on("et-modal-view-removed",function(){$.sq_config.debug&&console.log("Divi Save Pressed");$.sq_config.div.find(".sq_seo_refresh").trigger("lateclick");$(".et-pb-remove").on("click",function(){$.sq_config.debug&&console.log("Divi Save Pressed");$.sq_config.div.find(".sq_seo_refresh").trigger("lateclick")})})})}if($("#visual_composer_content").length>0){if($("div#vc_ui-panel-edit-element").length>0){$("div#vc_ui-panel-edit-element").find("span[data-vc-ui-element=button-save]").on("click",function(){$.sq_config.debug&&console.log("Visual Composer Save");$.sq_config.div.find(".sq_seo_refresh").trigger("lateclick");if($("#visual_composer_content").find(".vc-c-icon-delete_empty").length>0){$("#visual_composer_content").find(".vc-c-icon-delete_empty").on("click",function(){$.sq_config.debug&&console.log("Visual Composer Delete");$.sq_config.div.find(".sq_seo_refresh").trigger("lateclick")})}})}if($("#visual_composer_content").find(".vc-c-icon-delete_empty").length>0){$("#visual_composer_content").find(".vc-c-icon-delete_empty").on("click",function(){$.sq_config.debug&&console.log("Visual Composer Delete");$.sq_config.div.find(".sq_seo_refresh").trigger("lateclick")})}}},listenTinymce:function(){$.sq_config.debug&&console.log("listenTinymce");$.sq_config.editor_type="tinymce";if($.sq_config.interval_seo){clearInterval($.sq_config.interval_seo)}$.sq_config.interval_seo=setInterval(function(){var iframe_tinymce=$.sq_editor.getIframeEditor();if(iframe_tinymce!==false){$.sq_editor.insertHandler=function(e){$.sq_config.active_editor=$(this);if(e.target.nodeName==="IMG"){$.sq_config.debug&&console.log("DOMNodeInserted ",e);$.sq_editor.listen(e);$this.callback()}};$(iframe_tinymce).off("DOMNodeInserted",$.sq_editor.insertHandler).on("DOMNodeInserted",$.sq_editor.insertHandler);$.sq_editor.removeHandler=function(e){$.sq_config.active_editor=$(this);if(e.target.nodeName==="IMG"){$.sq_config.debug&&console.log("DOMNodeRemoved "+e.target.nodeName);$.sq_editor.lastimage="";$this.callback()}};$(iframe_tinymce).off("DOMNodeRemoved",$.sq_editor.removeHandler).on("DOMNodeRemoved",$.sq_editor.removeHandler);$.sq_editor.changeHandler=function(e){$.sq_config.active_editor=$(this);$.sq_config.debug&&console.log(" keyup mouseup ",e.type);if(e.type==="mouseup"){$.sq_removeHighlight($.sq_getBuilderEditorContainer())}if($.sq_config.timeout_seo){clearTimeout($.sq_config.timeout_seo)}$.sq_config.timeout_seo=setTimeout(function(){if($this.find(".sq_overlay").length>0)if($.sq_fields.sq_keyword.val()!==""){$.sq_config.showInspiration=false;$.sq_fields.sq_selectit.trigger("click")}$this.callback()},$.sq_config.delay_seo)};$(iframe_tinymce).off("keyup mouseup",$.sq_editor.changeHandler).on("keyup mouseup",$.sq_editor.changeHandler);$this.callback();clearInterval($.sq_config.interval_seo);$.sq_removeHighlight($.sq_getBuilderEditorContainer())}if(typeof $.sq_config.frontend_css!=="undefined"){if($.sq_editor.getIframeEditor("head link[href='"+$.sq_config.frontend_css+"']")===false){var iframe_head=$.sq_editor.getIframeEditor("head");if(iframe_head!==false){iframe_head.append($("<link/>",{rel:"stylesheet",href:$.sq_config.frontend_css,type:"text/css"}))}}}$this.sq_eventsseo.listenFeatureImage()},3e4)},stopListenTinymce:function(){$.sq_config.debug&&console.log("stop listen Tinymce");if($.sq_config.interval_seo){clearInterval($.sq_config.interval_seo)}var iframe_tinymce=$.sq_editor.getIframeEditor();if(iframe_tinymce!==false)$(iframe_tinymce).off("keyup mouseup")},listenHtml:function(){$.sq_config.editor_type="html";$.sq_fields.wp_content.on("click keyup",function(){$.sq_config.active_editor=$(this);if($.sq_config.editor_type==="html"){if($this.timeout_html){clearTimeout($this.timeout_html)}$this.timeout_html=setTimeout(function(){$this.callback()},$.sq_config.delay_seo)}});$.sq_fields.wp_content.on("dragover",false).on("dragenter",false).on("drop",function(e){if($.sq_config.editor_type==="html"){e.preventDefault();$.sq_editor.listenHtml(e)}});$this.sq_eventsseo.listenFeatureImage();$this.sq_eventsseo.listenMediaLibrary()},listenFeatureImage:function(){$("#postimagediv").on("DOMNodeInserted DOMNodeRemoved",function(){$this.checkImage($(this))});$(".editor-post-featured-image").on("DOMNodeInserted DOMNodeRemoved",function(){$this.checkImage($(this))})},listenMediaLibrary:function(){if($.sq_fields.wp_thumbnail_alt.length>0){$.sq_fields.wp_thumbnail_alt.on("keyup",function(){$this.setChecked($this.keywordMatch($.sq_fields.wp_thumbnail_alt.val(),$.sq_config.keyword),"alt")});$this.checkImage($.sq_fields.wp_thumbnail);$this.setChecked($this.keywordMatch($.sq_fields.wp_thumbnail_alt.val(),$.sq_config.keyword),"alt")}},listenVComposer:function(){if($("#visual_composer_content").length>0){var composer=$("#visual_composer_content");if(composer.find("img.attachment-thumbnail").length>0){$.sq_config.debug&&console.log("Visual Composer Image");$this.checkImage($("#visual_composer_content").find("img.attachment-thumbnail").parents(".wpb_content_element:last"))}if(composer.find("ul.attachment-thumbnails").length>0){$.sq_config.debug&&console.log("Visual Composer Galerry");$this.checkImage($("#visual_composer_content").find("ul.attachment-thumbnails"))}if(composer.find(".wpb_vc_custom_heading .admin_label_text").length>0){composer.find(".wpb_vc_custom_heading .admin_label_text").each(function(){if($this.keywordMatch($(this).text(),$.sq_config.keyword)){$.sq_config.debug&&console.log("Visual Composer Headline");return $this.setChecked($this.keywordMatch($(this).text(),$.sq_config.keyword),"h2_6")}})}}},listenFusion:function(){if($(".fusion_module_block_preview").find("img").length>0){$.sq_config.debug&&console.log("Fusion Image Preview");$this.checkImage($(".fusion_module_block_preview").find("img").parents("div:last"))}else if($("img.fusion-child-element-image").length>0){$.sq_config.debug&&console.log("Fusion Image Element");$this.checkImage($("img.fusion-child-element-image").parents("div:last"))}if($(".fusion_module_block_preview").find(".title_text").length>0){$(".fusion_module_block_preview").find(".title_text").each(function(){if($this.keywordMatch($(this).text(),$.sq_config.keyword)){$.sq_config.debug&&console.log("Fusion Headline");return $this.setChecked($this.keywordMatch($(this).text(),$.sq_config.keyword),"h2_6")}})}},stopListenHtml:function(){$.sq_config.debug&&console.log("stop listen HTML");$.sq_fields.wp_content.off("keyup");$.sq_fields.wp_content.off("drop")},listenTitle:function(){$.sq_config.debug&&console.log("listen title");$.sq_fields.wp_input_title.off("keyup change").on("keyup change",function(){$(this).trackLength("wp_title");$.sq_config.manual=true;$.sq_config.silent=false;$.sq_config.briefcase=false;$this.checkTitle()});if($("#sq_wp_title_info").length==0){$.sq_fields.wp_input_title.after($.sq_fields.sq_wp_title_info)}},listenSlug:function(){var timeout_post_slug=setInterval(function(){if($("#new-post-slug").length>0){clearInterval(timeout_post_slug);$("#new-post-slug").off("keyup").on("keyup",function(){$this.checkKPinguinUrl()});$("#edit-slug-buttons").find("a").on("click",function(){$this.sq_eventsseo.listenSlug()})}},3e4);var timeout_sample_permalink=setInterval(function(){if($("#sample-permalink").length>0){clearInterval(timeout_sample_permalink);if(typeof $.sq_loadFrontMenu!=="undefined"){$.sq_config.debug&&console.log("Reload the Squirrly Snippet");$.sq_loadFrontMenu()}}},3e4)},listenHighlight:function(on){if(on){settings.clicked["highlight"]=false;$this.find(".sq_request_highlight_key").parents("li:last").on("click",function(e){e.stopPropagation();settings.clicked["highlight"]=true}).on("mouseenter",function(e){e.stopPropagation();$(this).css("cursor","pointer");$.sq_highlight($.sq_getBuilderEditorContainer(),$.sq_config.keyword)}).on("mouseleave",function(){$.sq_removeHighlight($.sq_getBuilderEditorContainer())})}else{$this.find(".sq_request_highlight_key").parents("li:last").off()}}};$this.one("seo.loaded",function(){$.sq_config.debug&&console.log("sq_blockseo seo.loaded");if(!$.sq_config.subscription_active){return}if(!$.sq_isGutenberg()&&!$.sq_isFrontend()){if($.sq_fields.wp_content_wrap.length>0&&$.sq_fields.wp_content_wrap.attr("class").indexOf("html-active")!==-1){$.sq_config.debug&&console.log("seo.loaded listenHTML");$this.sq_eventsseo.listenHtml();$.sq_config.active_editor=$.sq_fields.wp_content}else{$.sq_config.debug&&console.log("seo.loaded listenTinymce");$this.sq_eventsseo.listenTinymce();$.sq_config.active_editor=$.sq_editor.getIframeEditor()}$("#save-post,#publish,#post-preview,.editor-post-publish-button").click(function(){$.sq_removeHighlight($.sq_getBuilderEditorContainer());if($.sq_floating){if($.sq_config.timeout_save){clearTimeout($.sq_config.timeout_save)}$.sq_floating.trigger("seo.floating.page_saved")}})}else if($.sq_isGutenberg()){wp.data.subscribe(function(){var ed=$.sq_editor.getBlockEditor("select");if(ed&&ed.isTyping){if($.sq_config.timeout_seo){clearTimeout($.sq_config.timeout_seo)}$.sq_config.timeout_seo=setTimeout(function(){$this.callback()},$.sq_config.delay_seo)}if(ed&&ed.isSavingPost()&&!ed.isAutosavingPost()){$.sq_removeHighlight($.sq_getBuilderEditorContainer());if($.sq_floating){if($.sq_config.timeout_save){clearTimeout($.sq_config.timeout_save)}$.sq_floating.trigger("seo.floating.page_saved")}}})}$this.sq_loading();$this.one("seo.keyword_loaded",function(){$this.sq_eventsseo.listen()})});return $this};$.fn.trackLength=function(type){var $this=this;var min=0;var max=0;var color="green";if(typeof $this==="undefined")return;if(type==="title"||type==="wp_title"){min=$.sq_params.min_length_title;max=$.sq_params.max_length_title}else if(type==="description"){min=$.sq_params.min_length_description;max=$.sq_params.max_length_description}if(min>0&&min>$this.val().length){color="red"}else if(max>0&&max<$this.val().length){color="red"}else{color="green"}if(max>0){$("#sq_"+type+"_info").html($this.val().length+"/"+max);$("#sq_"+type+"_info").css("color",color)}}})(jQuery);