| 1 |
!function(){"use strict";var t={response:null,getEndpointURL:function(t){var e,s="undefined"!=typeof wp&&wp.customize&&wp.customize.settings&&wp.customize.settings.url&&wp.customize.settings.url.self;s?(e=document.createElement("a")).href=wp.customize.settings.url.self:e=document.location,"string"==typeof t&&t.match(/^https?:\/\//)&&((e=document.createElement("a")).href=t);var a="relatedposts=1",r=document.querySelector("#jp-relatedposts");if(!r)return!1;r.hasAttribute("data-exclude")&&(a+="&relatedposts_exclude="+r.getAttribute("data-exclude")),s&&(a+="&jetpackrpcustomize=1");var o=e.pathname;return"/"!==o[0]&&(o="/"+o),""===e.search?o+"?"+a:o+e.search+"&"+a},getAnchor:function(t,e){var s=t.title,a=document.createElement("a");return a.setAttribute("class",e),a.setAttribute("href",t.url),a.setAttribute("title",s),a.setAttribute("data-origin",t.url_meta.origin),a.setAttribute("data-position",t.url_meta.position),""!==t.rel&&a.setAttribute("rel",t.rel),a},cleanHtml:function(t){var e=document.createElement("div");return e.innerHTML=t,e.textContent||e.innerText||""},generateMinimalDiv:function(t,e){var s=this,a=document.createElement("div");return a.setAttribute("class","jp-relatedposts-items jp-relatedposts-items-minimal jp-relatedposts-"+e.layout),t.forEach(function(t,r){var o="jp-relatedposts-post jp-relatedposts-post"+r;t.classes.length>0&&(o+=" "+t.classes.join(" "));var n=document.createElement("p");n.setAttribute("class",o),n.setAttribute("data-post-id",t.id),n.setAttribute("data-post-format",t.format),a.appendChild(n);var i=document.createElement("span");i.setAttribute("class","jp-relatedposts-post-title"),n.appendChild(i);var p=s.getAnchor(t,"jp-relatedposts-post-a");if(i.appendChild(p),p.textContent=s.cleanHtml(t.title),e.showDate){var l=document.createElement("time");l.setAttribute("class","jp-relatedposts-post-date"),l.setAttribute("datetime",t.date),l.textContent=t.date,n.appendChild(l)}if(e.showContext){var c=document.createElement("span");c.setAttribute("class","jp-relatedposts-post-context"),c.textContent=s.cleanHtml(t.context),n.appendChild(c)}}),a},generateVisualDiv:function(t,e){var s=this,a=document.createElement("div");return a.setAttribute("class","jp-relatedposts-items jp-relatedposts-items-visual jp-relatedposts-"+e.layout),t.forEach(function(t,r){var o="jp-relatedposts-post jp-relatedposts-post"+r;t.classes.length>0&&(o+=" "+t.classes.join(" ")),t.img.src?o+=" jp-relatedposts-post-thumbs":o+=" jp-relatedposts-post-nothumbs";var n=document.createElement("div");if(n.setAttribute("class",o),n.setAttribute("data-post-id",t.id),n.setAttribute("data-post-format",t.format),a.appendChild(n),t.img.src){var i=s.getAnchor(t,"jp-relatedposts-post-a");n.appendChild(i);var p=document.createElement("img");p.setAttribute("class","jp-relatedposts-post-img"),p.setAttribute("loading","lazy"),p.setAttribute("src",t.img.src),p.setAttribute("width",t.img.width),p.setAttribute("height",t.img.height),t.img.srcset&&p.setAttribute("srcset",t.img.srcset),t.img.sizes&&p.setAttribute("sizes",t.img.sizes),p.setAttribute("alt",t.img.alt_text),i.appendChild(p)}else{var l=s.getAnchor(t,"jp-relatedposts-post-a jp-relatedposts-post-aoverlay");n.appendChild(l)}var c=document.createElement(related_posts_js_options.post_heading);c.setAttribute("class","jp-relatedposts-post-title"),n.appendChild(c);var d=s.getAnchor(t,"jp-relatedposts-post-a");d.textContent=s.cleanHtml(t.title),c.appendChild(d);var u=document.createElement("p");if(u.setAttribute("class","jp-relatedposts-post-excerpt"),u.textContent=s.cleanHtml(t.excerpt),n.appendChild(u),e.showDate){var m=document.createElement("time");m.setAttribute("class","jp-relatedposts-post-date"),m.setAttribute("datetime",t.date),m.textContent=t.date,n.appendChild(m)}if(e.showContext){var h=document.createElement("p");h.setAttribute("class","jp-relatedposts-post-context"),h.textContent=s.cleanHtml(t.context),n.appendChild(h)}}),a},setVisualExcerptHeights:function(){var t=document.querySelectorAll("#jp-relatedposts .jp-relatedposts-post-nothumbs .jp-relatedposts-post-excerpt");if(t.length)for(var e=getComputedStyle(t[0]),s=parseInt(e.fontSize,10),a=parseInt(e.lineHeight,10),r=0;r<t.length;r++)t[r].style.maxHeight=5*a/s+"em"},getTrackedUrl:function(t){var e="relatedposts_hit=1";e+="&relatedposts_origin="+t.getAttribute("data-origin"),e+="&relatedposts_position="+t.getAttribute("data-position");var s=t.pathname;return"/"!==s[0]&&(s="/"+s),""===t.search?s+"?"+e:s+t.search+"&"+e},cleanupTrackedUrl:function(){if("function"==typeof history.replaceState){var t=document.location.search.replace(/\brelatedposts_[a-z]+=[0-9]*&?\b/gi,"");"?"===t&&(t=""),document.location.search!==t&&history.replaceState({},document.title,document.location.pathname+t)}}};function e(){t.setVisualExcerptHeights();var e=document.querySelectorAll("#jp-relatedposts a.jp-relatedposts-post-a");Array.prototype.forEach.call(e,function(e){document.addEventListener("click",function(){e.href=t.getTrackedUrl(e)})})}function s(){t.cleanupTrackedUrl();var s=t.getEndpointURL();if(s)if(document.querySelectorAll("#jp-relatedposts .jp-relatedposts-post").length)e();else{var a=document.querySelector("#jp-relatedposts"),r=new XMLHttpRequest;r.open("GET",s,!0),r.setRequestHeader("x-requested-with","XMLHttpRequest"),r.onreadystatechange=function(){if(this.readyState===XMLHttpRequest.DONE&&200===this.status)try{var s=JSON.parse(r.responseText);if(0===s.items.length||0===a.length)return;t.response=s;var o,n={};"undefined"!=typeof wp&&wp.customize?(o=wp.customize.instance("jetpack_relatedposts[show_thumbnails]").get(),n.showDate=wp.customize.instance("jetpack_relatedposts[show_date]").get(),n.showContext=wp.customize.instance("jetpack_relatedposts[show_context]").get(),n.layout=wp.customize.instance("jetpack_relatedposts[layout]").get()):(o=s.show_thumbnails,n.showDate=s.show_date,n.showContext=s.show_context,n.layout=s.layout);var i=o?t.generateVisualDiv(s.items,n):t.generateMinimalDiv(s.items,n);if(a.appendChild(i),n.showDate){var p=a.querySelectorAll(".jp-relatedposts-post-date");Array.prototype.forEach.call(p,function(t){t.style.display="block"})}a.style.display="block",e()}catch{}},r.send()}}function a(){"undefined"!=typeof wp&&wp.customize?(wp.customize.selectiveRefresh&&wp.customize.selectiveRefresh.bind("partial-content-rendered",function(t){"jetpack_relatedposts"===t.partial.id&&s()}),wp.customize.bind("preview-ready",s)):s()}"loading"!==document.readyState?a():document.addEventListener("DOMContentLoaded",a)}(); |