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.
69 lines
1.9 KiB
69 lines
1.9 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 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) {
|
|
try {
|
|
callback(event.target.responseText);
|
|
} catch (error) {
|
|
// do nothing
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
xhr.send();
|
|
};
|
|
|
|
var insertTops = function (text) {
|
|
var parent = document.getElementById(PARENT_ID);
|
|
|
|
if (parent) {
|
|
parent.innerHTML = text;
|
|
}
|
|
};
|
|
|
|
var main = function () {
|
|
getTops(getUrl(), insertTops);
|
|
};
|
|
|
|
window.addEventListener("load", main);
|
|
})();
|
|
|