2026-10-05 GLOBAL

This commit is contained in:
Dekart Deploy Bot 2026-10-06 15:03:57 +00:00
parent c9ad49c820
commit 0697bebe03

View File

@ -3770,7 +3770,8 @@ function dekart_deferred_loader_script($blocks, int $timeout = 3000): string
if (! $blocks) {
return '';
}
$json = wp_json_encode($blocks, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
// JSON_HEX_TAG: '</script>' в сниппете иначе рвёт тег загрузчика → JS виден текстом
$json = wp_json_encode($blocks, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_HEX_TAG);
return '<script>(function(){var B=' . $json . ';var done=false;function inject(){if(done){return;}done=true;B.forEach(function(html){var t=document.createElement("template");t.innerHTML=html;Array.prototype.slice.call(t.content.childNodes).forEach(function(n){var node;if(n.nodeName==="SCRIPT"){node=document.createElement("script");for(var i=0;i<n.attributes.length;i++){node.setAttribute(n.attributes[i].name,n.attributes[i].value);}node.text=n.textContent||"";}else{node=n.cloneNode(true);}(document.head||document.documentElement).appendChild(node);});});}var ev=["scroll","click","keydown","mousemove","touchstart","pointerdown"];function go(){ev.forEach(function(e){window.removeEventListener(e,go);});inject();}ev.forEach(function(e){window.addEventListener(e,go,{passive:true,once:true});});if(window.requestIdleCallback){requestIdleCallback(inject,{timeout:' . (int) $timeout . '});}else{setTimeout(inject,' . (int) $timeout . ');}})();</script>';
}