Notice: Undefined offset: 1 in /home/plusensd/steelhammer.com.ua/route.php on line 89
var bannerRotationThread = undefined;
$(function() {
var bannerCount = $(".banner").length;
var bannerIndex = bannerCount - 1;
var update = function() {
$(".banner:eq(" + bannerIndex + ")").show().siblings(".banner").hide();
}
update();
$("#main-banner").on("dropbox", function() {
var images = $(this).data("dropbox");
var loadedCount = 0;
images.ForEach(function() {
post({ add_banner: this }, function() {
loadedCount++;
});
});
(function() {
while (loadedCount < images.length) { setTimeout(arguments.callee, 100); return; }
location.reload();
})();
});
$(".banner").click(function(e) {
if ($("body").hasClass("admin")) {
var bannerId = $(this).attr("bannerid");
var url = $(this).attr("href");
var newUrl = prompt("Введите ссылку для этого баннера:", url);
if (newUrl && newUrl != url) {
post({ banner_id: bannerId, url: newUrl }, function() {
location.reload();
});
e.preventDefault();
} else if (newUrl === "" && confirm("Удалить баннер?")) {
post({ remove_banner_id: bannerId }, function() {
location.reload();
});
e.preventDefault();
}
}
});
var nextBanner = function() {
bannerIndex = (bannerIndex + 1) % bannerCount;
update();
}
$("#main-banner .next").click(function(e) {
nextBanner();
clearInterval(bannerRotationThread);
bannerRotationThread = undefined;
e.preventDefault();
}).dblclick(function(e) {
if ($("body").hasClass("admin")) {
var oldInterval = Number($("#main-banner").attr("rotation-interval"));
var newInterval = prompt("Введите кол-во секунд ротации каждого баннера:", oldInterval);
if (newInterval && newInterval != oldInterval) {
post({ banner_rotation_interval: Number(newInterval) }, function() {
location.reload();
});
}
}
e.stopPropagation();
});
$("#main-banner .prev").click(function(e) {
bannerIndex = (bannerIndex - 1 + bannerCount) % bannerCount;
update();
clearInterval(bannerRotationThread);
bannerRotationThread = undefined;
e.preventDefault();
}).dblclick(function(e) { e.stopPropagation(); });
if (!bannerRotationThread && bannerCount > 1) {
bannerRotationThread = setInterval(function() {
nextBanner();
}, Number($("#main-banner").attr("rotation-interval")) * 1000);
}
$("#pre-footer .article>p").on("savechanges", function() {
post({ description: $(this).text() });
});
});