(function(){ try{ template = document.createElement('div'); template.innerHTML = ''; document.head.appendChild(template); //var anchor = '#article-popular'; var anchor = '#article-related'; var related_template = 'queryly_related_template'; queryly.related.batchSize = 6; queryly.related.decay = 5; queryly.extendedDataFields = "creator,section"; queryly.callback.relatedClicked = function (link) { var section = link.getAttribute("section"); var label = link.getAttribute("data-label"); window.dataLayer = window.dataLayer || []; window.dataLayer.push({ "event" : "eventTracker", "eventAction" : section, "eventLabel" : label, "eventCategory" : "Navigation", "contentPlacementCD" : 'related articles' }); } queryly.QuerylyRelatedCallback = function (related) { if (related == null || related.items == null) { return; } if (document.location.href.indexOf('/education/') >=0 || document.location.href.indexOf('/recommends/') >=0){ return; } var templatename = 'queryly_related_template'; var existingarticles = []; var relateditemhtml = ''; var counter = 0; for (var relateditemcount = 0; relateditemcount < related.items.length; relateditemcount++) { try { queryly.relateddata = related.items[relateditemcount]; //queryly.relateddata.title = queryly.relateddata.title.replace(/(([^\s]+\s\s*){18})(.*)/, "$1..."); if (existingarticles.indexOf(queryly.relateddata.title) >= 0){continue;} existingarticles.push(queryly.relateddata.title); var recommendsArticle = queryly.relateddata.link.match(/recommends/g); if (recommendsArticle) { queryly.relateddata.pubdate = ''; } else { queryly.relateddata.pubdate = (new Date(queryly.relateddata.pubdate)).toLocaleDateString('en-US',{ year: 'numeric', month: 'long', day: 'numeric' }); } if (queryly.relateddata.image.indexOf('resize=1200,600') > 0){ //queryly.relateddata.image = queryly.relateddata.image.replace('resize=1200,600','resize=130,86'); } else if (queryly.relateddata.image.indexOf('?') < 0){ //queryly.relateddata.image = queryly.relateddata.image + '?resize=130,86'; } else{ //queryly.relateddata.image = queryly.relateddata.image + '&resize=130,86'; } queryly.relateddata.image = queryly.relateddata.image.replace('?w=2048','?w=1024'); var creators = queryly.relateddata.creator.split(','); var creatorhtml = ''; for (var i=0;i < creators.length; i++){ if (creators[i].trim() == "The Associated Press"){ creators[i] ="Associated Press"; } if (creators[i] == '') {continue;} creatorhtml = creatorhtml + '' + creators[i] + ''; if (i == 0){ if (creators.length ==2){ creatorhtml = creatorhtml + " and "; } else if (creators.length > 2){ creatorhtml = creatorhtml + ", "; } } else if (i == 1 && creators.length > 2){ creatorhtml = creatorhtml + " and Others"; break; } } queryly.relateddata.creatorhtml = creatorhtml; if (document.querySelector(anchor) != null){ relateditemhtml = relateditemhtml + queryly.util.tmpl(related_template, queryly.relateddata); } else{ relateditemhtml = relateditemhtml + queryly.util.tmpl('queryly_related_template_bottom', queryly.relateddata); } counter = counter + 1; } catch (e) {} } if (relateditemhtml != '') { if (document.querySelector(anchor) != null){ htmlcontent ="
Related Articles
"; document.querySelector(anchor).innerHTML = htmlcontent; queryly.related.hookRelatedEvent('#article-related a'); } else{ htmlcontent ="
"; //document.querySelector('#article-content').innerHTML = htmlcontent; var newNode=document.createElement("div"); newNode.setAttribute('class','latest-popular-module'); newNode.setAttribute('id','article-related'); newNode.innerHTML = htmlcontent; //document.querySelector('#article-content').parentNode.insertBefore(newNode, document.querySelector('#article-content').nextSibling); document.querySelector('#article-content').parentNode.appendChild(newNode); queryly.related.hookRelatedEvent('#article-related a'); } } else { setTimeout(queryly.QuerylyRelatedCallback(related), 1000); } }; var relatedurl = '//related.queryly.com/json.aspx?queryly_key=' + queryly.QuerylyKey + '&callback=queryly.QuerylyRelatedCallback' + '&pageurl=' + encodeURIComponent('https://www.fortune.com/') + '&batchsize=' + queryly.related.batchSize + '&decay=' + queryly.related.decay + "&extendedDataFields=" + encodeURIComponent(queryly.extendedDataFields); if (typeof queryly.related.title != 'undefined' && queryly.related.title != ''){ var relatedurl = '//related.queryly.com/json.aspx?queryly_key=' + queryly.QuerylyKey + '&callback=queryly.QuerylyRelatedCallback' + '&batchsize=' + queryly.related.batchSize + '&decay=' + queryly.related.decay + "&extendedDataFields=" + encodeURIComponent(queryly.extendedDataFields) + '&title=' + encodeURIComponent(queryly.related.title); if (typeof queryly.related.text != 'undefined' && queryly.related.text != ''){ if (queryly.related.text.length < 512){ relatedurl = relatedurl + '&text=' + encodeURIComponent(queryly.related.text); } else{ relatedurl = relatedurl + '&text=' + encodeURIComponent(queryly.related.text.substring(0,512)); } } } if (queryly.related.feednames != ''){ relatedurl = relatedurl + '&feednames=' + encodeURIComponent(queryly.related.feednames) } if (typeof queryly.related.facetedkey != 'undefined' && typeof queryly.related.facetedvalue != 'undefined'){ relatedurl = relatedurl + '&facetedkey=' + encodeURIComponent(queryly.related.facetedkey) + "&facetedvalue=" + encodeURIComponent(queryly.related.facetedvalue); } queryly.util.loadScript(relatedurl, function () { }); } catch(e){} })();