File: //proc/1526/root/var/www/zaklada/html/lib/js/core/app.js
(function ($) {
$(document).ready(function () {
//#region Expandable Content
const expandContent = function (e) {
let clickedElem = e.target;
let linkedContent = clickedElem.nextElementSibling;
$(".expandable__content").remove("show");
$(".expandable__content").slideUp(200);
if (linkedContent.classList.contains("show")) {
// toggle off
linkedContent.classList.remove("show");
$(linkedContent).slideUp(200);
} else {
// toggle on
$(".expandable__content").removeClass("show");
linkedContent.classList.add("show");
$(linkedContent).slideDown(200);
}
};
if (document.getElementsByClassName("expandable__btn")) {
const expandBtns = document.getElementsByClassName("expandable__btn");
for (let i = 0; i < expandBtns.length; i++) {
expandBtns[i].addEventListener("click", expandContent);
}
}
//#endregion
//#region tabs on donation pay
const showTab = function (e) {
let targetId = e.target.getAttribute("data-tab");
$(".payment-type__btn").removeClass("active");
$(e.target).addClass("active");
$(".payment-type__content").removeClass("show");
$(`#${targetId}`).addClass("show");
};
if (document.querySelector(".payment-type")) {
const tabBtns = document.getElementsByClassName("payment-type__btn");
for (let i = 0; i < tabBtns.length; i++) {
tabBtns[i].addEventListener("click", showTab);
}
}
//#endregion
$("#modal-trigger").click(function (e) {
e.preventDefault();
$(".modal-window").addClass("visible");
});
$("#js-close-modal").click(function () {
$(".modal-window").removeClass("visible");
});
});
$(".program-list__item").click(function () {
let itemContent = $(this).next();
if ($(itemContent).hasClass("open")) {
$(this).find(".program-list__img").removeClass("open");
$(itemContent).removeClass("open");
$(itemContent).slideUp();
} else {
$(this).find(".program-list__img").addClass("open");
$(itemContent).addClass("open");
$(itemContent).slideDown();
}
});
$(".accordion").click(function () {
$(this).toggleClass("active");
$(this).find(".accordion__content").slideToggle();
});
// font controls
if ($(".font-controls").length >= 1) {
const main = document.querySelector("main");
const pList = main.getElementsByTagName("p");
const liList = main.getElementsByTagName("li");
const headingList = main.getElementsByTagName("h2");
const timeList = main.getElementsByTagName("time");
const newsListPage = document.querySelector("section.news");
$(".font-controls__increment").click(function () {
for (let i = 0; i < pList.length; i++) {
const item = pList[i];
var style = window.getComputedStyle(item, null).getPropertyValue("font-size");
var fontSize = parseFloat(style);
item.style.fontSize = fontSize + 1 + "px";
}
for (let i = 0; i < liList.length; i++) {
const item = liList[i];
var style = window.getComputedStyle(item, null).getPropertyValue("font-size");
var fontSize = parseFloat(style);
item.style.fontSize = fontSize + 1 + "px";
}
for (let i = 0; i < headingList.length; i++) {
const item = headingList[i];
var style = window.getComputedStyle(item, null).getPropertyValue("font-size");
var fontSize = parseFloat(style);
item.style.fontSize = fontSize + 1 + "px";
}
if (newsListPage) {
for (let i = 0; i < timeList.length; i++) {
const item = timeList[i];
var style = window.getComputedStyle(item, null).getPropertyValue("font-size");
var fontSize = parseFloat(style);
item.style.fontSize = fontSize + 1 + "px";
}
}
});
$(".font-controls__decrement").click(function () {
for (let i = 0; i < pList.length; i++) {
const item = pList[i];
var style = window.getComputedStyle(item, null).getPropertyValue("font-size");
var fontSize = parseFloat(style);
item.style.fontSize = fontSize - 1 + "px";
}
for (let i = 0; i < liList.length; i++) {
const item = liList[i];
var style = window.getComputedStyle(item, null).getPropertyValue("font-size");
var fontSize = parseFloat(style);
item.style.fontSize = fontSize - 1 + "px";
}
for (let i = 0; i < headingList.length; i++) {
const item = headingList[i];
var style = window.getComputedStyle(item, null).getPropertyValue("font-size");
var fontSize = parseFloat(style);
item.style.fontSize = fontSize - 1 + "px";
}
if (newsListPage) {
for (let i = 0; i < timeList.length; i++) {
const item = timeList[i];
var style = window.getComputedStyle(item, null).getPropertyValue("font-size");
var fontSize = parseFloat(style);
item.style.fontSize = fontSize - 1 + "px";
}
}
});
}
$(".js-open-video").modalVideo({
controls: 1,
// allowFullScreen: false,
});
//#region youtube carousel
$(".video-carousel").owlCarousel({
loop: true,
margin: 10,
nav: true,
dots: false,
responsive: {
0: {
items: 3,
},
600: {
items: 3,
},
992: {
items: 3,
},
},
onChanged: function (e) {
var itemIndex = e.item.index;
$(".video-carousel .owl-item.middle").removeClass("middle");
$(".video-carousel .owl-item")
.eq(itemIndex + 1)
.addClass("middle");
},
});
//#endregion
//#region instagram carousel
$(".instagram-carousel").owlCarousel({
loop: true,
margin: 0,
nav: true,
dots: false,
responsive: {
0: {
items: 1.8,
// items: 3.3,
},
768: {
items: 6.3,
},
},
});
//#endregion
//#region cookies
let acceptAllCookiesBtn = document.querySelector(".acceptAllCookies");
let acceptCookiesBtn = document.querySelector(".acceptNecessaryCookies");
let cookiesContainer = document.querySelector(".cookie");
var cookies = {
createCookie: function (name, value, days) {
if (days) {
var date = new Date();
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
var expires = "; expires=" + date.toUTCString();
} else var expires = "";
document.cookie = name + "=" + value + expires + "; path=/";
},
readCookie: function (name) {
var nameEQ = name + "=";
var ca = document.cookie.split(";");
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == " ") c = c.substring(1, c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
}
return null;
},
eraseCookie: function (name) {
createCookie(name, "", -1);
},
};
var cookiesCleared = cookies.readCookie("cookiesCleared");
if (!cookiesCleared) {
cookiesContainer.style.display = "block";
}
function closeCookiesContainer() {
cookiesContainer.style.display = "none";
}
function acceptAllCookies() {
cookies.createCookie("cookiesCleared", "true", "365");
cookies.createCookie("marketingCookies", "true", "365");
closeCookiesContainer();
}
function acceptCookies() {
cookies.createCookie("cookiesCleared", "true", "365");
cookies.createCookie("marketingCookies", "false", "365");
closeCookiesContainer();
}
acceptAllCookiesBtn.addEventListener("click", acceptAllCookies);
acceptCookiesBtn.addEventListener("click", acceptCookies);
//#endregion
//#region social media sharing
// news single
function facebookShare(isNewsBox, elem) {
if (isNewsBox) {
const newsUrlElem = $(elem).closest(".news-box__cta").children();
const newsUrl = newsUrlElem[0].href;
window.open("http://www.facebook.com/share.php?u=" + newsUrl, "", "menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600");
return false;
} else {
window.open("http://www.facebook.com/share.php?u=" + window.location.href, "", "menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600");
return false;
}
}
function twitterShare(isNewsBox, elem) {
if (isNewsBox) {
const newsUrlElem = $(elem).closest(".news-box__cta").children();
const newsUrl = newsUrlElem[0].href;
window.open("http://twitter.com/share?url=" + newsUrl, "", "menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600");
return false;
} else {
window.open("http://twitter.com/share?url=" + window.location.href, "", "menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600");
return false;
}
}
function linkedinShare(isNewsBox, elem) {
if (isNewsBox) {
const newsUrlElem = $(elem).closest(".news-box__cta").children();
const newsUrl = newsUrlElem[0].href;
window.open(
"http://www.linkedin.com/sharing/share-offsite/?url=" + newsUrl,
"",
"menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600"
);
return false;
} else {
window.open(
"http://www.linkedin.com/sharing/share-offsite/?url=" + window.location.href,
"",
"menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600"
);
return false;
}
}
$(".js-facebook-share").click(function () {
facebookShare();
});
$(".js-twitter-share").click(function () {
twitterShare();
});
$(".js-linkedin-share").click(function () {
linkedinShare();
});
// news box
$(".js-share-box").click(function () {
$(this).toggleClass("open");
$(this).next().toggleClass("open");
});
$(".js-share-box-facebook").click(function () {
facebookShare(true, $(this));
});
$(".js-share-box-twitter").click(function () {
twitterShare(true, $(this));
});
$(".js-share-box-linkedin").click(function () {
linkedinShare(true, $(this));
});
//#endregion
$("table").wrap('<div class="table-responsive"></div>');
let maxTextHeight = 0;
$(".news-box-home__text-wrap").each(function () {
if ($(this).height() > maxTextHeight) {
maxTextHeight = $(this).height();
}
});
$(".news-box-home__text-wrap").height(maxTextHeight);
$('.toggle-info__trigger').on('click', function() {
$(this).toggleClass('toggle-info__trigger--active');
$(this).siblings('.toggle-info__content').slideToggle('fast');
})
// Modal for Newsletter
if (!localStorage.getItem('modalNewsletterClosed')){
setTimeout(function () {
$('.js-modal-newsletter')
.css("display", "flex")
.hide()
.fadeIn();
}, 1000);
}
function closeModalNewsletter() {
$('.js-modal-newsletter').fadeOut('fast');
localStorage.setItem('modalNewsletterClosed',true);
}
$('.js-modal-newsletter-close').on('click', function(e) {
e.preventDefault();
closeModalNewsletter();
});
$('.js-modal-newsletter-apply').on('click', function(e) {
closeModalNewsletter();
});
$('[data-open-newsletter-modal]').on('click', function(e){
$('.js-modal-newsletter').css("display", "flex").fadeIn();
})
})(jQuery);