Browse Source

executer les éventuels scripts inline contenus dans les z_apl

pull/1/head
placido@roxing.net 4 years ago
parent
commit
251552ffb4
  1. 109
      javascript/zapl.scripts.js
  2. 2
      paquet.xml

109
javascript/zapl.scripts.js

@ -1,61 +1,68 @@
// equivalent de $.get en pur js
var getAjax = function(url, success) {
var r = new XMLHttpRequest();
r.open('GET', url);
r.onreadystatechange = function() {
if (r.readyState > 3 && r.status == 200) success(r.responseText);
};
r.send();
return r;
var r = new XMLHttpRequest();
r.open('GET', url);
r.onreadystatechange = function() {
if (r.readyState > 3 && r.status == 200) success(r.responseText);
};
r.send();
return r;
};
// peupler le zbloc et dire qu'il est prêt
function getZapl(bloc) {
var myurl = window.location + "";
myurl = myurl.split('#');
myurl = myurl[0] + ((myurl[0].indexOf("?") > 0) ? "&" : "?") + "var_zajax=" + bloc;
getAjax(myurl, function(data) {
var el = document.querySelector("#zapl-" + bloc);
var newEl = document.createElement('div');
newEl.innerHTML = data;
el.parentNode.replaceChild(newEl, el);
// un array qui liste les zblocs traités
if (!window.zapl_list) {
window.zapl_list = [];
}
window.zapl_list.push(bloc);
});
var zapl = document.querySelector("#zapl-" + bloc);
if (zapl) {
var myurl = window.location + "";
myurl = myurl.split('#');
myurl = myurl[0] + ((myurl[0].indexOf("?") > 0) ? "&" : "?") + "var_zajax=" + bloc;
getAjax(myurl, function(data) {
var newEl = document.createElement('div');
newEl.innerHTML = data;
zapl.parentNode.replaceChild(newEl, zapl);
// un array qui liste les zblocs traités
window.zapl_list.push(bloc);
});
}
};
// attendre jQuery et les zblocs pour renclencher AjaxLoad
window.zapl_loop_index = 0;
zapl_loop_index = 0;
zapl_list = [];
zapl_loop = setInterval(function() {
//console.log("loop index : " + window.zapl_loop_index + " - jQuery chargé ? : " + (typeof jQuery.spip.triggerAjaxLoad !== 'undefined') + " - Nb zapl traités:" + window.zapl_list.length );
if ( (typeof jQuery.spip === 'object') &&
(typeof jQuery.spip.triggerAjaxLoad === 'function') &&
(typeof window.zapl_list !== 'undefined') &&
!(document.querySelectorAll("[id^='zapl-']").length) ) {
clearInterval(zapl_loop);
var h = window.location.hash;
if (h) {
// $b correspond à la selection jQuery des zblocs
var $b = $();
window.zapl_list.forEach(function(e) {
$b = $b.add(e);
});
if ($b.find(h)[0]) {
jQuery(h).positionner(true);
}
}
jQuery.spip.triggerAjaxLoad(document);
return;
}
// Au dela de 20 sec ...
else if (window.zapl_loop_index < 200) {
window.zapl_loop_index++;
}
// ... auto-débraillage
else {
clearInterval(zapl_loop);
}
//console.log("loop index : " + window.zapl_loop_index + " - jQuery chargé ? : " + (typeof jQuery.spip.triggerAjaxLoad !== 'undefined') + " - Nb zapl traités:" + window.zapl_list.length );
if (
typeof jQuery.spip === 'object' &&
typeof jQuery.spip.triggerAjaxLoad === 'function' &&
window.zapl_list.length &&
!document.querySelectorAll("[id^='zapl-']").length
) {
clearInterval(window.zapl_loop);
// $b = collection jQuery des zblocs
var $b = jQuery();
window.zapl_list.forEach(function(e) {
$b = $b.add("#" + e);
});
//executer les scripts inline inclus
var $s = $b.find("script");
if ($s.length) {
$s.each(function(i, e) {
jQuery.globalEval($(e).html());
});
}
// positionner ancre
var h = window.location.hash;
if (h && $b.find(h)[0]) {
jQuery(h).positionner(true);
}
jQuery.spip.triggerAjaxLoad(document);
return;
}
// Au dela de 20 sec ...
else if (window.zapl_loop_index < 200) {
window.zapl_loop_index++;
}
// ... auto-débraillage
else {
clearInterval(zapl_loop);
}
}, 100);

2
paquet.xml

@ -1,7 +1,7 @@
<paquet
prefix="Zcore"
categorie="outil"
version="2.6.6"
version="2.6.7"
etat="stable"
compatibilite="[3.0.0;3.2.*]"
logo="prive/themes/spip/images/z-core-32.png"

Loading…
Cancel
Save