You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

102 lines
3.3 KiB

(function () {
"use strict";
var API_URL_ROOT = "/expo-b/get-tops/";
var PARENT_ID = "expo_top_events";
var getUrl = function () {
var search = [];
var parts = /^\/([^\/]+)(?:\/|$)/i.exec(location.pathname);
if (parts) {
search.push("catalog=" + encodeURIComponent(parts[1]));
} else {
search.push("catalog=");
}
var data = window.sendData;
if (data instanceof Object) {
for (var key in data) {
if (data.hasOwnProperty(key)) {
var value = data[key];
if (value instanceof Array) {
for (var i = 0, l = value.length; i < l; i++) {
search.push(encodeURIComponent(key) + "=" + encodeURIComponent(value[i]));
}
} else {
search.push(encodeURIComponent(key) + "=" + encodeURIComponent(value));
}
}
}
}
return API_URL_ROOT + "?" + search.join("&");
};
var runCallback = function (callback, arg) {
try {
callback(arg);
} catch (error) {
// do nothing
}
console.info('callback Done');
};
var getTops = function (url, callback) {
var xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.onreadystatechange = function (event) {
if (event.target.readyState === 4) {
if (event.target.status === 200) {
console.info(document.readyState);
if (document.readyState === "loading" && !window.marker_DOMtopjsElementInserted) {
// console.info('setting DOMContentLoaded event listener');
console.info('setting DOMtopjsElementInserted event listener');
// document.addEventListener("DOMContentLoaded", function() {
document.addEventListener("DOMtopjsElementInserted", function() {
runCallback(callback, event.target.responseText);
});
} else {
runCallback(callback, event.target.responseText);
}
}
}
};
xhr.send();
};
var insertTops = function (text) {
var parent = document.getElementById(PARENT_ID);
if (parent) {
parent.innerHTML = text;
}
};
var main = function () {
getTops(getUrl(), insertTops);
};
// main();
// window.addEventListener("load", main);
// document.addEventListener("DOMContentLoaded", main);
var DOMtopjsElementInserted = new Event('DOMtopjsElementInserted');
window.marker_DOMtopjsElementInserted = window.marker_DOMtopjsElementInserted || false;
document.addEventListener("DOMtopjsElementInserted", function() {
console.info("DOMtopjsElementInserted fired");
window.marker_DOMtopjsElementInserted = true
});
// Listen for the event.
main();
// function ready() {
// console.info( 'DOM готов' );
// // alert( "Размеры картинки: " + img.offsetWidth + "x" + img.offsetHeight );
// }
// document.addEventListener("DOMContentLoaded", ready);
})();