function updateSegments(data) { for (var name in data) { if (data.hasOwnProperty(name)) { $("#" + name).html(data[name]); } } } function setBusy(elem, left, top) { removeBusy(); if (typeof left == "undefined") left = "center"; if (typeof top == "undefined") top = "center"; elem.prepend('
'); } function removeBusy() { $("div#busy").remove(); } $(document).ready(function() { /* Submenu */ $(".has-submenu").hover(function(e) { if ($(this).find(".submenu").is(":hidden")) { $(this).find(".submenu").show(); $(this).addClass('triangel'); $(this).children("a").eq(0).attr("aria-expanded", "true"); } }, function(e) { $(this).find(".submenu").hide(); $(this).removeClass('triangel'); $(this).children("a").eq(0).attr("aria-expanded", "false"); }).keydown(function(e) { var keycode = e.keyCode ? e.keyCode : e.which; if (keycode === 40 || keycode === 32) { e.preventDefault(); if ($(this).find(".submenu").is(":hidden")){ $(this).find(".submenu").show(); $(this).addClass('triangel'); $(this).children("a").eq(0).attr("aria-expanded", "true"); } } else if (keycode === 27) { e.preventDefault(); $(this).find(".submenu").hide(); $(this).removeClass('triangel'); $(this).children("a").eq(0).attr("aria-expanded", "false"); } }); /* Mobile menu */ $(".header-navig-open-menu").click(function() { $("#mobile-navig").show(); $(".header-navig-open-menu").hide(); $(".header-navig-close-menu").show(); }); $(".header-navig-close-menu").click(function() { $("#mobile-navig").hide(); $(".header-navig-open-menu").show(); $(".header-navig-close-menu").hide(); }); /* Mobile submenu */ $(".open-submenu").click(function(e) { e.preventDefault(); $(".submenu").toggle(); }); $(".submenu .links ul li").on("mouseenter mouseleave focus", "a", function(e) { $(".submenu .menu-top .links li a").removeClass("active").attr("aria-expanded", "false"); $(".submenu .menu-top .content:visible").hide(); var contentId = $(this).data("content-id"); $(this).addClass("active").attr("aria-expanded", "true"); $("#content-" + contentId).show(); }) .on("click keydown", "a img", function(e) { if (e.type !== "keydown" || e.which !== 13) { return; } e.preventDefault(); var contentId = $(this).parent("a").data("content-id"); $("#content-" + contentId + " a:first").focus(); }); $(".submenu .menu-top .content").on("blur", "a:last", function(e) { var linkId = $(this).closest("div.content").data("link-id"); $("#link-" + linkId).parent("li").next().find("a:first").focus(); }); $("body").click(function(e) { var elem = $(e.target); if (elem.hasClass("open-submenu") || elem.hasClass("submenu") || elem.closest(".open-submenu").length !== 0 || elem.closest(".submenu").length !== 0) { return; } $(".submenu:visible").hide(); }); $("#anketa").on("click", ".answers a", function(e) { e.preventDefault(); var _this = $(this); setBusy(_this.closest("#anketa")); $.ajax({ method: "GET", url: _this.attr("href") }).done(function(data) { updateSegments(data["segments"]); }).always(function() { removeBusy(); }); }); $(".back-button").on("click", function(e) { e.preventDefault(); window.history.back(); }); /* Scroll to Top */ $(window).scroll(function() { if ($(this).scrollTop() >= 50) { $('#return-to-top').fadeIn(200); } else { $('#return-to-top').fadeOut(200); } }); $('#return-to-top').click(function() { $('body,html').animate({ scrollTop: 0 }, 500); }); $("#suvisiace-odkazy > div").each(function() { if ($.trim($(this).text()).match(/^\s*$/)) { $(this).closest("#suvisiace-odkazy").hide(); } }); $("#carousel-pause").click(function() { var _this = $(this); var target = _this.data("target"); var pause = _this.data("pause"); var resume = _this.data("resume"); var html = _this.html(); if (html === pause) { _this.html(resume); $(target).carousel("pause"); } else { _this.html(pause); $(target).carousel("cycle"); } }); $('.carousel-pause').click(function(e) { e.preventDefault(); var _this = $(this); var icon = _this.find('.fa'); var car = _this.closest('.carousel'); if (icon.hasClass('fa-pause')) { car.carousel('pause'); icon.removeClass('fa-pause').addClass('fa-play'); } else if (icon.hasClass('fa-play')) { car.carousel('cycle'); icon.removeClass('fa-play').addClass('fa-pause'); } }); $(".carousel-caption h2, .carousel-caption p").dotdotdot({watch: true}); /* if (window.sessionStorage) { var wst = window.sessionStorage; var name = "panelOpen" + $("html").attr("lang"); var po = wst.getItem(name); $("#accordion .panel-default .panel-collapse").on("show.bs.collapse", function() { if (!po) { po = 0; } else { po = parseInt(po); } var nr = $(this).attr("id").match(/(\d+)$/); if (nr) { var pow = Math.pow(2, parseInt(nr[1])); if (!(po & pow)) { po += pow; wst.setItem(name, po); } } }).on("hide.bs.collapse", function() { if (!po) { return; } else { po = parseInt(po); } var nr = $(this).attr("id").match(/(\d+)$/); if (nr) { var pow = Math.pow(2, parseInt(nr[1])); if (po & pow) { po -= pow; wst.setItem(name, po); } } }); if (po) { var l = $("#accordion .panel-default").length; for (var i = 1; i <= l; i++) { if (po & Math.pow(2, i)) { $("#accordion #collapse" + i).collapse('show'); } } } } */ });