(function () {
"use strict";
var API_URL_ROOT = "/expo-b/get-banners/";
var getUrl = function (top_load) {
var search = [];
var parts = /^\/([^\/]+)(?:\/|$)/i.exec(location.pathname);
if (parts) {
search.push("catalog=" + encodeURIComponent(parts[1]));
} else {
search.push("catalog=");
}
if (!top_load) {
var elements = $("[id^=\"expo_b_\"]").not("[id=\"expo_b_under_search\"]");
for (var j = 0; j < elements.length; j++) {
search.push("places=" + encodeURIComponent($(elements[j]).attr("id")));
}
} else {
search.push("places=" + encodeURIComponent('expo_b_under_search'));
}
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(JSON.parse(arg));
} catch (error) {
// do nothing
}
// console.info('callback Done');
};
var getBanners = function (url, callback, top_load) {
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" && top_load && !window.marker_DOMbannersjsElementInserted) {
document.addEventListener("DOMbannersjsElementInserted", function() {
runCallback(callback, event.target.responseText);
});
} else {
runCallback(callback, event.target.responseText);
}
}
}
};
xhr.send();
};
var addBanner = function (banner) {
var parent = document.getElementById(banner.id);
if (parent) {
if (banner.is_popup) {
window.is_popup_banner = true;
// маркируем для попапа подписки о том что есть попап банер
// /templates/client/popups/announce_subscription.html
if (banner.is_img) {
parent.innerHTML =
"