define(['jquery','mage/translate'],function($){$.widget('bss.seo_toolbar',{dataToolbar:{url:'',canonicalTag:'',title:'',metaTitle:'',metaDescription:'',metaKeyword:'',headings:{h1Elements:'',h2Elements:'',h3Elements:'',h4Elements:'',h5Elements:''},imageObject:[],openGraph:{ogTitle:'',ogImage:'',ogDescription:'',ogUrl:'',ogType:''},twitterCard:{twitterSite:'',twitterTitle:'',twitterDescription:'',twitterImage:''}},statusHide:false,urlEdit:'',_create:function(){let self=this;$(document).ready(function(){let urlVars=self.getUrlVars();let cookieName='bss_seo_toolbar_token';if(typeof urlVars.token!=="undefined"){let token=urlVars.token;self.createCookie(cookieName,token,30);} let cookieValue=self.getCookie(cookieName);let hideCookieName='bss_seo_toolbar_hide';let statusHideValue=self.getCookie(hideCookieName);self.statusHide=statusHideValue!==''&&statusHideValue!==null&&Number(statusHideValue)===1;self.handleToolbarStatus();self.handleClickToolbar();if(cookieValue!==''&&cookieValue!==null){self.setData();self.handleAjaxCheckAdmin(cookieValue);}});},handleAjaxCheckAdmin:function(token){let ajaxUrl=this.options.ajaxUrl;let self=this;$.ajax({showLoader:false,url:ajaxUrl,data:{token:token,entity_id:self.options.entityId,entity_type:self.options.entityType},type:"POST",dataType:'json',complete:function(response){let result=response.responseText;result=JSON.parse(result);if(result.status){self.urlEdit=result.data.backend_url;let DOMToolbar=self.getDOMToolbar();self.renderToolbar(DOMToolbar);}}});},getDOMToolbar:function(){let headerToolbar=this.getHeaderToolbar();let bodyToolbar=this.getBodyToolbar();return headerToolbar+bodyToolbar;},getHeaderToolbar:function(){return'
Logo

'+$.mage.__("SEO Toolbar")+'

';},getBodyToolbar:function(){let firstBodyToolbar='';if(this.statusHide){firstBodyToolbar='
';}else{firstBodyToolbar='
';} let lastBodyToolbar='
';let urlDOM=this.getItemToolbar($.mage.__("URL:"),this.dataToolbar.url,"success",this.toolTipObject.url);let statusCanonicalTag="success";if(this.dataToolbar.canonicalTag===''||this.dataToolbar.canonicalTag===null){statusCanonicalTag="false";} let canonicalTagDOM=this.getItemToolbar($.mage.__("Canonical Tag:"),this.dataToolbar.canonicalTag,statusCanonicalTag,this.toolTipObject.canonicalTag);let statusMetaTitle="false";if(this.dataToolbar.title===''||this.dataToolbar.title===null){statusMetaTitle="false";}else{if(this.dataToolbar.title.length>=50&&this.dataToolbar.title.length<=70){statusMetaTitle="success";} if(this.dataToolbar.title.length>70){statusMetaTitle="false"} if(this.dataToolbar.title.length<50){statusMetaTitle="warming";}} let titleDOM=this.getItemToolbar($.mage.__("Title:"),this.dataToolbar.title,statusMetaTitle,this.toolTipObject.title);let statusMetaDescription="false";if(this.dataToolbar.metaDescription===''||this.dataToolbar.metaDescription===null){statusMetaDescription="false";}else{if(this.dataToolbar.metaDescription.length>=200&&this.dataToolbar.metaDescription.length<=255){statusMetaDescription="success";} if(this.dataToolbar.metaDescription.length>255){statusMetaDescription="false"} if(this.dataToolbar.metaDescription.length>=100&&this.dataToolbar.metaDescription.length<200){statusMetaDescription="warming";}} let metaDescriptionDOM=this.getItemToolbar($.mage.__("Meta Description:"),this.dataToolbar.metaDescription,statusMetaDescription,this.toolTipObject.description);let statusMetaKeywords="success";if(this.dataToolbar.metaKeyword===''||this.dataToolbar.metaKeyword===null){statusMetaKeywords="warming";} let metaKeywordDOM=this.getItemToolbar($.mage.__("Meta Keywords:"),this.dataToolbar.metaKeyword,statusMetaKeywords,this.toolTipObject.metaKeyword);let headingText='H1 ['+this.dataToolbar.headings.h1Elements+'] - H2 ['+this.dataToolbar.headings.h2Elements+'] - H3 ['+this.dataToolbar.headings.h3Elements+'] - H4 ['+this.dataToolbar.headings.h4Elements+'] - H5 ['+this.dataToolbar.headings.h5Elements+']';let statusHeading="false";if(this.dataToolbar.headings.h1Elements===1&&this.dataToolbar.headings.h2Elements>0){statusHeading="success";} if(this.dataToolbar.headings.h1Elements===1&&this.dataToolbar.headings.h2Elements===0){statusHeading="warming";} let headingsDOM=this.getItemToolbar($.mage.__("Headings:"),headingText,statusHeading,this.toolTipObject.headings);let lostAltNumbmer=0;this.dataToolbar.imageObject.each(function(){let alt=$(this).attr('alt');if(typeof alt==='undefined'||alt===null||alt===''){lostAltNumbmer++;}});let imageAltDOM='';let statusImages="false";if(lostAltNumbmer===0){statusImages="success";imageAltDOM=this.getItemToolbar($.mage.__("All images have ALT attribute."),'',statusImages,statusHeading,this.toolTipObject.images);}else{let textImageAltDOM='';if(lostAltNumbmer===1){textImageAltDOM=lostAltNumbmer+$.mage.__(" image without ALT.");}else{textImageAltDOM=lostAltNumbmer+$.mage.__(" images without ALT.");} imageAltDOM=this.getItemToolbar(textImageAltDOM,'',statusImages,this.toolTipObject.images);} let countOpenGraph=0;if(typeof this.dataToolbar.openGraph.ogTitle!=="undefined"&&this.dataToolbar.openGraph.ogTitle!==''&&this.dataToolbar.openGraph.ogTitle!==null){countOpenGraph++;} if(typeof this.dataToolbar.openGraph.ogDescription!=="undefined"&&this.dataToolbar.openGraph.ogDescription!==''&&this.dataToolbar.openGraph.ogDescription!==null){countOpenGraph++;} if(typeof this.dataToolbar.openGraph.ogImage!=="undefined"&&this.dataToolbar.openGraph.ogImage!==''&&this.dataToolbar.openGraph.ogImage!==null){countOpenGraph++;} if(typeof this.dataToolbar.openGraph.ogUrl!=="undefined"&&this.dataToolbar.openGraph.ogUrl!==''&&this.dataToolbar.openGraph.ogUrl!==null){countOpenGraph++;} if(typeof this.dataToolbar.openGraph.ogType!=="undefined"&&this.dataToolbar.openGraph.ogType!==''&&this.dataToolbar.openGraph.ogType!==null){countOpenGraph++;} let textOpenGraph='';let statusOpenGraphRender="false";if(countOpenGraph>0){textOpenGraph=$.mage.__("Great! We have found several Open Graph objects.");statusOpenGraphRender="success";}else{textOpenGraph=$.mage.__("Your page does not have any Open Graph objects.");} let openGraphDOM=this.getItemToolbar($.mage.__("Open Graph:"),textOpenGraph,statusOpenGraphRender,this.toolTipObject.openGraph);let countTwitterCard=0;if(typeof this.dataToolbar.twitterCard.twitterSite!=="undefined"&&this.dataToolbar.twitterCard.twitterSite!==''&&this.dataToolbar.twitterCard.twitterSite!==null){countTwitterCard++;} if(typeof this.dataToolbar.twitterCard.twitterTitle!=="undefined"&&this.dataToolbar.twitterCard.twitterTitle!==''&&this.dataToolbar.twitterCard.twitterTitle!==null){countTwitterCard++;} if(typeof this.dataToolbar.twitterCard.twitterDescription!=="undefined"&&this.dataToolbar.twitterCard.twitterDescription!==''&&this.dataToolbar.twitterCard.twitterDescription!==null){countTwitterCard++;} if(typeof this.dataToolbar.twitterCard.twitterImage!=="undefined"&&this.dataToolbar.twitterCard.twitterImage!==''&&this.dataToolbar.twitterCard.twitterImage!==null){countTwitterCard++;} let textTwitterCard='';let statusTwitterCardRender="false";if(countTwitterCard>0){textTwitterCard=$.mage.__("Nice! We have found Twitter Cards on your page.");statusTwitterCardRender="success";}else{textTwitterCard=$.mage.__("Your page does not have any Twitter Cards.");} let twitterCardDOM=this.getItemToolbar($.mage.__("Twitter Card:"),textTwitterCard,statusTwitterCardRender,this.toolTipObject.twitterCard);let editLink=this.urlEdit;let editBody='';if(editLink){editBody='
Edit In Backend
';} return firstBodyToolbar+urlDOM+canonicalTagDOM+titleDOM+metaDescriptionDOM+metaKeywordDOM+headingsDOM+imageAltDOM+openGraphDOM+twitterCardDOM+editBody+lastBodyToolbar;},handleToolbarStatus:function(){let bssSeoToolbarDOM=$("#bss_seo_toolbar");bssSeoToolbarDOM.removeClass("toolbar_hide");if(this.statusHide){bssSeoToolbarDOM.addClass("toolbar_hide");}},handleClickToolbar:function(){let self=this;$(document).on('click',"#bss_seo_toolbar .bss_toolbar_header svg",function(){let valueCookieHide='0';if(!self.statusHide){valueCookieHide='1';self.statusHide=true;}else{self.statusHide=false;} let hideCookieName='bss_seo_toolbar_hide';self.createCookie(hideCookieName,valueCookieHide,30);self.handleToolbarStatus();let DOMToolbar=self.getDOMToolbar();self.renderToolbar(DOMToolbar);});},getItemToolbar:function(title,value,status,toolTip){let icon='';let self=this;switch(status){case'success':icon=self.iconToolbar.success;break;case'false':icon=self.iconToolbar.false;break;case'warming':icon=self.iconToolbar.warming;break;} return'
'+icon+'
'+title+' '+value+'
'+toolTip+'
';},renderToolbar:function(DOMToolbar){$("#bss_seo_toolbar").show();$("#bss_seo_toolbar").html(DOMToolbar);},setData:function(){this.dataToolbar.url=window.location.href;let canonicalTag=$('link[rel=canonical]').attr("href");if(typeof canonicalTag!=="undefined"){this.dataToolbar.canonicalTag=canonicalTag;} let title=$(document).attr('title');if(typeof title!=="undefined"){this.dataToolbar.title=title;} let metaTitle=$('meta[name=title]').attr("content");if(typeof metaTitle!=="undefined"){this.dataToolbar.metaTitle=metaTitle;} let metaDescription=$('meta[name=description]').attr("content");if(typeof metaDescription!=="undefined"){this.dataToolbar.metaDescription=metaDescription;} let metaKeyword=$('meta[name=keywords]').attr("content");if(typeof metaKeyword!=="undefined"){this.dataToolbar.metaKeyword=metaKeyword;} this.dataToolbar.headings.h1Elements=$("h1").length;this.dataToolbar.headings.h2Elements=$("h2").length;this.dataToolbar.headings.h3Elements=$("h3").length;this.dataToolbar.headings.h4Elements=$("h4").length;this.dataToolbar.headings.h5Elements=$("h5").length;this.dataToolbar.imageObject=$("img");this.dataToolbar.openGraph.ogTitle=$('meta[property="og:title"]').attr("content");this.dataToolbar.openGraph.ogImage=$('meta[property="og:image"]').attr("content");this.dataToolbar.openGraph.ogDescription=$('meta[property="og:description"]').attr("content");this.dataToolbar.openGraph.ogUrl=$('meta[property="og:url"]').attr("content");this.dataToolbar.openGraph.ogType=$('meta[property="og:type"]').attr("content");this.dataToolbar.twitterCard.twitterSite=$('meta[name="twitter:site"]').attr("content");this.dataToolbar.twitterCard.twitterTitle=$('meta[name="twitter:title"]').attr("content");this.dataToolbar.twitterCard.twitterDescription=$('meta[name="twitter:description"]').attr("content");this.dataToolbar.twitterCard.twitterImage=$('meta[name="twitter:image"]').attr("content");},getUrlVars:function(){let vars=[],hash;let hashes=window.location.href.slice(window.location.href.indexOf('?')+1).split('&');for(let i=0;i0){let c_start=document.cookie.indexOf(cookie_name+"=");if(c_start!==-1){c_start=c_start+cookie_name.length+1;let c_end=document.cookie.indexOf(";",c_start);if(c_end===-1){c_end=document.cookie.length;} cookie_value=unescape(document.cookie.substring(c_start,c_end));}} return cookie_value;},iconToolbar:{success:'',false:' ',warming:' '},toolTipObject:{url:'A SEO-friendly URL should be easy-to-read, definitive, and keyword-rich so that Google can easily index your website.',headings:'You only use one <H1> heading for each page to strengthen your SEO.
This <H1> heading should contain your main keyword.',images:'You should add ALT text to your images to help search engines easily index them.
The reason is search engines don\'t physically see images like the way people do. Hence, ALT text plays a role in describing the image so that they show up in Googleâ„¢ and other search engine\'s image results.
Make sure your website images have their own specific ALT text.',openGraph:'Open Graph is a technology introduced by Facebook that integrates between Facebook and its user data and a website. When integrating Open Graph meta tags into your page, you can identify which elements of your page you desire to display when your page is shared.',twitterCard:'By using Twitter Cards, you can easily attach photo, videos, and media experience to Tweets to increase traffic to your site.',canonicalTag:'A canonical tag is used to prevent issues caused by duplicated content appearing on multiple URLs. On the other hand, the canonical tag lets search engines which version of URL will be included in search results.',title:'A perfect length of a title should be about 50-70 characters, including spaces. You need to make your title concise and contain the main keyword.',description:'Meta description determines how your pages are displayed in the search results. Hence, you should keep it 200-255 characters long for the best effectiveness. Also, don\'t forget to include your main keyword in the meta description and make it attractive to encourage customers to click.',metaKeyword:'Meta keywords are words or phrases that pertain to your site\'s content. In the past, people have tried to take advantage of this tag so now it doesn\'t affect your search rankings the way that it used to.'}});return $.bss.seo_toolbar;});