/* * SiteSEO * https://siteseo.io/ * (c) SiteSEO Team <support@siteseo.io> */ /* Copyright 2016 - 2024 - Benjamin Denis (email : contact@seopress.org) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. 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. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ function pixelTitle(e){return inputText=e,font="20px Arial",(context=(canvas=document.createElement("canvas")).getContext("2d")).font=font,formattedWidth=Math.ceil(width=context.measureText(inputText).width)}function pixelDesc(e){return inputText=e,font="14px Arial",(context=(canvas=document.createElement("canvas")).getContext("2d")).font=font,formattedWidth=Math.ceil(width=context.measureText(inputText).width)}function siteseo_is_valid_url(e){return null!==e.match(/(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/g)}function siteseo_social_img(e){let t=jQuery,s=t("#siteseo_social_"+e+"_img_meta");if(s.lenght<1)return;let a=s.val();if(a.length<1||!siteseo_is_valid_url(a)){siteseo_show_metabox_input_error(!0,s,"Image has invalid URL"),s.val("");return}t.get(a).done((i,o,n)=>{let l=n.getResponseHeader("Content-Length"),r=n.getResponseHeader("Content-Type");if(r&&-1==["image/jpeg","image/jpg","image/gif","image/png","image/webp"].indexOf(r)){siteseo_show_metabox_input_error(!0,s,"Please upload image of the supported image types only"),s.val("");return}if(!l){siteseo_show_metabox_input_error(!0,s,"Could not retrive the size of the image"),s.val("");return}let d=5;if("fb"==e&&(d=8),l/1024>1024*d){siteseo_show_metabox_input_error(!0,s,"Selected image has size "+content_lenght/1024+"which is larer than 5MB"),s.val("");return}let c=new Image;c.src=a,t(c).one("load",function(){if(img_width=parseInt(c.width),img_height=parseInt(c.height),!img_width||!img_height){siteseo_show_metabox_input_error(!0,s,"Selected image does not have any width or height"),s.val("");return}if("fb"==e)var i=200,o=200;else var i=144,o=144;if(img_width<i||img_height<o){siteseo_show_metabox_input_error(!0,s,"Width or height of this image ("+img_width+"x"+img_height+") is smaller than the minimum requirment"),s.val("");return}if((img_width/img_height).toFixed(2),c=null,siteseo_show_metabox_input_error(!1,s),"twitter"==e){t(".siteseo-metabox-x-preview img").attr("src",a);return}t(".siteseo-metabox-"+e+"-preview img").attr("src",a)})}).fail((e,t,a)=>{siteseo_show_metabox_input_error(!0,s,a),s.val("")})}function siteseo_show_metabox_input_error(e,t,s=""){let a=t.prev("span");if(a.length){if(e){a.show(),a.text(s);return}a.hide()}}function siteseo_ca_toggle(){let e=jQuery;var t=!1;e(document).off("click",".siteseo-analysis-block-title").on("click",".siteseo-analysis-block-title",function(s){t&&(s.stopImmediatePropagation(),s.preventDefault(),t=!1),e(this).toggleClass("open"),e(this).attr("aria-expanded","false"==e(this).attr("aria-expanded")),e(this).next(".siteseo-analysis-block-content").toggle(),e(this).next(".siteseo-analysis-block-content").attr("aria-hidden","true"!=e(this).parent().parent().next(".siteseo-analysis-block-content").attr("aria-hidden"))}),e(document).on("click","#expand-all",function(t){t.preventDefault(),e(".siteseo-analysis-block-content").show(),e(".siteseo-analysis-block-title button").attr("aria-expanded",!0),e(".siteseo-analysis-block-content").attr("aria-hidden",!1)}),e(document).on("click","#close-all",function(t){t.preventDefault(),e(".siteseo-analysis-block-content").hide(),e(".siteseo-analysis-block-title button").attr("aria-expanded",!1),e(".siteseo-analysis-block-content").attr("aria-hidden",!0)})}jQuery(document).ready(function(){jQuery("#siteseo-ca-tabs .wrap-ca-list").length&&(jQuery("#siteseo-ca-tabs .hidden").removeClass("hidden"),jQuery("#siteseo-ca-tabs").tabs())});var input=document.querySelector('input[name="siteseo_analysis_target_kw"]'),siteseo_metabox_tag=new Tagify(input,{originalInputValueFormat:e=>e.map(e=>e.value).join(",")});function siteseo_google_suggest(e){let t=jQuery;var s,a=String(e).split(",");for(s=0;s<a.length;s++)null!=a[s]&&void 0!=a[s]&&""!=a[s]&&"[object Object]"!=a[s]&&(document.getElementById("siteseo_suggestions").innerHTML+='<li><a href="#" class="siteseo-suggest-btn components-button is-secondary">'+a[s]+"</a></li>");t(".siteseo-suggest-btn").click(function(e){e.preventDefault(),siteseo_metabox_tag.addTags(t(this).text())})}function siteseo_analysis_init(e){var t=function(){if(void 0!==jQuery(".siteseo-metabox-tabs").attr("data_id"))var t=jQuery(".siteseo-metabox-tabs").attr("data_id");else if(void 0!==jQuery("#siteseo_content_analysis .wrap-siteseo-analysis").attr("data_id"))var t=jQuery("#siteseo_content_analysis .wrap-siteseo-analysis").attr("data_id");if(t){if(void 0!==jQuery("#siteseo-tabs").attr("data_tax"))var s=jQuery("#siteseo-tabs").attr("data_tax");else if(void 0!==jQuery("#siteseo_content_analysis .wrap-siteseo-analysis").attr("data_tax"))var s=jQuery("#siteseo_content_analysis .wrap-siteseo-analysis").attr("data_tax");if(void 0!==jQuery(".siteseo-metabox-tabs").attr("data_origin"))var a=jQuery(".siteseo-metabox-tabs").attr("data_origin");else if(void 0!==jQuery("#siteseo_content_analysis .wrap-siteseo-analysis").attr("data_origin"))var a=jQuery("#siteseo_content_analysis .wrap-siteseo-analysis").attr("data_origin");jQuery.ajax({method:"GET",url:siteseoAjaxRealPreview.siteseo_real_preview,data:{action:"siteseo_do_real_preview",post_id:t,tax_name:s,origin:a,post_type:jQuery("#siteseo_launch_analysis").attr("data_post_type"),siteseo_analysis_target_kw:jQuery("#siteseo_analysis_target_kw_meta").val(),_ajax_nonce:siteseoAjaxRealPreview.siteseo_nonce},beforeSend:function(){e(".siteseo-analysis-summary-pill").fadeIn().text(""),e(".siteseo-analysis-summary-pill").addClass("siteseo-stripes")},success:function(e){og_title=void 0===e.data.og_title?"":e.data.og_title.values,og_desc=void 0===e.data.og_desc?"":e.data.og_desc.values,og_img=void 0===e.data.og_img?"":e.data.og_img.values,og_url=void 0===e.data.og_url?"":e.data.og_url.host,og_site_name=void 0===e.data.og_site_name?"":e.data.og_site_name.values,tw_title=void 0===e.data.tw_title?"":e.data.tw_title.values,tw_desc=void 0===e.data.tw_desc?"":e.data.tw_desc.values,tw_img=void 0===e.data.tw_img?"":e.data.tw_img.values,meta_robots=void 0===e.data.meta_robots?"":e.data.meta_robots[0];var t={og_title:og_title,og_desc:og_desc,og_img:og_img,og_url:og_url,og_site_name:og_site_name,tw_title:tw_title,tw_desc:tw_desc,tw_img:tw_img};for(var s in t)t.length&&(s=t[s].length>1?t[s].slice(-1)[0]:t[s][0]);meta_robots=meta_robots.toString(),jQuery("#siteseo-advanced-alert").empty(),/noindex/.test(meta_robots)&&jQuery("#siteseo-advanced-alert").append('<span class="impact high" aria-hidden="true"></span>'),title="",e.data.title&&(title=e.data.title.substr(0,60)+"..."),jQuery(".siteseo-search-preview-desktop h3").html(title),jQuery(".siteseo_titles_title_meta").attr("placeholder",title),meta_desc="",e.data.meta_desc&&(meta_desc=e.data.meta_desc.substr(0,160)+"..."),jQuery(".siteseo-search-preview-desktop .siteseo-search-preview-description").html(meta_desc),jQuery(".siteseo_titles_desc_meta").attr("placeholder",meta_desc),t.og_title&&(jQuery("#siteseo_social_fb_title_meta").attr("placeholder",t.og_title[0]),jQuery(".siteseo-metabox-fb-preview .siteseo-metabox-fb-title").html(t.og_title[0])),t.og_desc&&(jQuery("#siteseo_social_fb_desc_meta").attr("placeholder",t.og_desc[0]),jQuery(".siteseo-metabox-fb-preview .siteseo-metabox-fb-desc").html(t.og_desc[0])),t.og_img&&(jQuery("#siteseo_social_fb_img_meta").attr("placeholder",t.og_img[0]),jQuery(".siteseo-metabox-fb-preview .siteseo-metabox-fb-image img").attr("src",t.og_img[0])),jQuery(".siteseo-metabox-fb-preview .siteseo-metabox-fb-host").html(t.og_url),t.tw_title&&(jQuery("#siteseo_social_twitter_title_meta").attr("placeholder",t.tw_title[0]),jQuery(".siteseo-metabox-x-preview .siteseo-metabox-x-title").html(t.tw_title[0])),t.tw_desc&&jQuery("#siteseo_social_twitter_desc_meta").attr("placeholder",t.tw_desc[0]),t.tw_img&&(jQuery("#siteseo_social_twitter_img_meta").attr("placeholder",t.tw_img[0]),jQuery(".siteseo-metabox-x-preview .siteseo-metabox-x-image img").attr("src",t.tw_img[0])),jQuery("#siteseo_cpt .twitter-snippet-preview .snippet-twitter-url").html(t.og_url),jQuery("#siteseo_robots_canonical_meta").attr("placeholder",e.data.canonical),jQuery("#siteseo-analysis-tabs").load(" #siteseo-analysis-tabs-1","",siteseo_ca_toggle),jQuery("#siteseo-metabox-wrapper #siteseo-analysis-tabs").load(" #siteseo-analysis-tabs-1","",siteseo_ca_toggle),jQuery("#siteseo-wrap-notice-target-kw").load(" #siteseo-notice-target-kw","")}})}};e(document).off("click","#siteseo_launch_analysis",t),e(document).on("click","#siteseo_launch_analysis",t),siteseo_ca_toggle(),e("#siteseo_inspect_url").on("click",function(){if(e(this).attr("disabled","disabled"),e(".spinner").css("visibility","visible"),e(".spinner").css("float","none"),void 0!==jQuery("#siteseo-tabs").attr("data_id"))var t=jQuery("#siteseo-tabs").attr("data_id");else if(void 0!==jQuery("#siteseo_content_analysis .wrap-siteseo-analysis").attr("data_id"))var t=jQuery("#siteseo_content_analysis .wrap-siteseo-analysis").attr("data_id");jQuery.ajax({method:"POST",url:siteseoAjaxInspectUrl.siteseo_inspect_url,data:{action:"siteseo_inspect_url",post_id:t,_ajax_nonce:siteseoAjaxInspectUrl.siteseo_nonce},success:function(){e(".spinner").css("visibility","hidden"),e("#siteseo_inspect_url").removeAttr("disabled"),e("#siteseo-ca-tabs-1").load(" #siteseo-ca-tabs-1")}})})}siteseo_metabox_tag.on("change",function(){siteseo_sync_kw_tags(siteseo_metabox_tag,siteseo_sidebar_tag)}),jQuery(document).ready(function(e){siteseo_analysis_init(e)});