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.
 
 
 
 
 
 

95 lines
3.0 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) {
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 removeDublicates = function () {
$('div#' + PARENT_ID + ' ul li.cl-item').each(function(index, el) {
$('div.page-body ul.cat-list li.cl-item[data-slug=\'' + $(el).data('slug') + '\']').not(el).remove();
});
}
var insertTops = function (text) {
var parent = document.getElementById(PARENT_ID);
if (parent) {
parent.innerHTML = text;
$(document).ready(function () {
removeDublicates();
});
}
};
var main = function () {
getTops(getUrl(), insertTops);
};
// main();
// window.addEventListener("load", main);
// document.addEventListener("DOMContentLoaded", main);
main();
})();