File "scripts.js"

Full Path: /home/ozbarhaber/public_html/19052025___siteeee/wp-content/themes/anka/scripts/scripts.js
File size: 34.98 KB
MIME-type: text/html
Charset: utf-8

jQuery(function($) {

// Arrangements

	$(".safirWidget").each(function() {
		if($(this).find(".mainHeading").length) {
			$(this).addClass("withHeading");
		} else {
			$(this).addClass("noHeading");
		}
	});

// Currency

	$("#currency .items").clone().addClass("clone").appendTo($("#currency"))

	var currencyInterval;
	var currencyCount;
	var currencyActive = 0;
	if($('#currency .items .item').length > 1 ) {
		currencyInterval = setInterval(changeCurrency, 2500);
		currencyCount = $('#currency .items.clone .item').length;
	}

	function changeCurrency(next = 1) {
		currencyActive = (currencyActive + next) % currencyCount;
		if(currencyActive < 0) currencyActive = currencyCount - 1;
		$("#currency .items.clone .item").fadeOut().promise().done(function() {
			$("#currency .items.clone .item").eq(currencyActive).fadeIn().css("display", "inline-flex");
		});
	}

// Search

	$("#topsearch input, .mobileSearch input").focus(function() {
		$(".searchTerms").fadeIn();
	});

	$(document).mouseup(function(e) {
		var container = $("#topsearch");
		if (!container.is(e.target) && container.has(e.target).length === 0) {
			$("#topsearch .searchTerms").fadeOut(100);
			var input = $("#topsearch .searchTerms").prev().find("input[type=text]");
			if( input.val() == '') {
				input.val(input.attr("value"));
			}
		}
	});

	$(".searchTerms span").click(function() {
		$(".searchTerms").fadeOut(100);
		$(".searchTerms").prev().find("input[type=text]").val($(this).html());
		$(".searchTerms").prev().submit();
	});

	$("#logo .mobileButtons .searchButton").click(function() {
		$("#logo .mobileSearch").fadeIn(100);
	});

	$("#logo .mobileSearch .close").click(function() {
		$("#logo .mobileSearch").fadeOut(100);
	});



// Lazy

	!function(t){t.fn.unveil=function(i,e){var n,r=t(window),o=i||0,u=window.devicePixelRatio>1?"data-src-retina":"data-src",s=this;function l(){var i=s.filter(function(){var i=t(this);if(!i.is(":hidden")){var e=r.scrollTop(),n=e+r.height(),u=i.offset().top;return u+i.height()>=e-o&&u<=n+o}});n=i.trigger("unveil"),s=s.not(n)}return this.one("unveil",function(){var t=this.getAttribute(u);(t=t||this.getAttribute("data-src"))&&(this.setAttribute("src",t),"function"==typeof e&&e.call(this))}),r.on("scroll.unveil resize.unveil lookup.unveil",l),l(),this}}(window.jQuery||window.Zepto);

	$('img.lazy').unveil(0, function() {
		$(this).load(function() {
			this.style.opacity = 1;
		});
	});

// Owl

	const owlNavText = [themeIcon("chewleft"), themeIcon("chewright")];
	

// advancedPostsWidget4

	$(".advancedPostsWidget4 .slider .owl-carousel").owlCarousel({
		mouseDrag: false,
		loop:false,
		navText:owlNavText,
		autoplay:true,
		autoplayTimeout:6000,
		autoplayHoverPause:true,
		rewind:true,
		rewindNav:true,
		dots: true,
		items: 1,
		onInitialized: makePagesAdv3,
		onResized: makePagesAdv3,
		onChanged: owlLazyLoad,
	});

	$( ".advancedPostsWidget4 .slider .owl-dot" ).hover(function() {
		order = $(this).index();
		$(this).closest(".owl-carousel").trigger("to.owl.carousel", [order, 500, true]);
	});

	function makePagesAdv3() {
		counter = 1;
		$(".advancedPostsWidget4 .slider .post").each( function(i) {
			text = $(this).closest(".owl-item").index() + 1;
			linkUrl = $(".advancedPostsWidget4 .slider .post").eq(counter-1).find('a').attr('href');
			$('.advancedPostsWidget4 .slider .owl-dot').eq(counter-1)
			.html("<a href='"+linkUrl+"'>"+text+"</a>")
			counter++;
		});
	}

	$('.advancedPostsWidget4 .slider .owl-carousel .owl-dot a').click(function() {
		window.location = $(this).attr("href");
	});


// Breaking

	var breakingInterval;
	var breakingCount;
	var breakingActive = 0;
	if($('#breaking .post').length > 1 ) {
		breakingInterval = setInterval(changeBreaking, 5e3);
		breakingCount = $('#breaking .post').length;
	}

	function changeBreaking(next = 1) {
		breakingActive = (breakingActive + next) % breakingCount;
		if(breakingActive < 0) breakingActive = breakingCount - 1;
		$("#breaking .items .post").fadeOut().promise().done(function() {
			$("#breaking .items .post").eq(breakingActive).fadeIn();
		});
	}

	$('#breaking').hover(function () {
		clearInterval(breakingInterval);
	}, function () {
		if ($('#breaking .post').length > 1 ) breakingInterval = setInterval(changeBreaking, 5e3);
	});

	$("#breaking .arrows span").click(function() {
		if ($(this).hasClass("up")) {
			changeBreaking(-1);
		} else {
			changeBreaking();
		}
	});





// Gallery

	$(".safirHover").each(function() {
		var icon = $(this).data("hovericon");
		$(this).find(".postthumb a").append('<div class="hover safiricon icon"><svg class="safiricon-'+icon+'"><use href="#safiricon-'+icon+'"></use></svg></div>');
	});


	$('#main.attachment .skipAd').click(function(e) {
		e.preventDefault();
		$('#main.attachment .inner.ads').hide();
		$('#galleryContent').fadeIn();
	});

	$("body").on("keydown", function(e) {
		var $url;
		if(e.key == "ArrowLeft") {
			$url = $('#gallery-nav').attr('data-prev');
		}
		else if(e.key == "ArrowRight") {
			$url = $('#gallery-nav').attr('data-next');
		}
		if($url != null) {
			window.location = $url;
		}
	});



// Gallery Hover

	$(document).on("mouseenter", "#singleContent .wp-block-gallery figure a, #singleContent div.gallery .gallery-item a", function () {
		$(this).find(".icon").remove();
		$(this).append('<div class="icon"></div>');
		$(this).find(".icon").stop().hide().fadeIn();
	});
	$(document).on("mouseleave", "#singleContent .wp-block-gallery figure a, #singleContent div.gallery .gallery-item a", function () {
		$(this).find(".icon").stop().fadeOut(100);
	});



// Font Sizes

	readingFontSize = localStorage.getItem("readingFontSize");
	if (readingFontSize != null) {
		$("<style id='readingFontSize'>#singleContent{font-size:"+readingFontSize+"px}</style>").appendTo("body");
	}

	$(document).on("click", ".metaBox .sizing", function() {
		parent = $(this).closest(".haberSingle");
		currentSize = parseInt(parent.find('#singleContent').css('font-size'));
		if($(this).hasClass('fontplus')) {
			if (currentSize <= 22) {
				currentSize++;
			}
		} else if($(this).hasClass('fontminus')) {
			if (currentSize >= 11) {
				currentSize--;
			}
		}
		localStorage.setItem("readingFontSize", currentSize);
		$("style#readingFontSize").html("#singleContent{font-size:"+currentSize+"px}");
	});



// Scores Widget

	$(".scoresWidget").on("click", ".showAll", function() {
		$(this).hide();
		$(".scoresWidget tr.hidden").fadeIn();
	});

// Opt Widgets

	$(".optWidget .hamburger").on("click", function() {
		$(this).toggleClass("active");
		$(this).closest(".optWidget").find(".options").slideToggle();
	});

	$(".optWidget .options span").click(function () {
		if($(this).closest(".optWidget").hasClass("weatherWidget")) {
			changeWeatherAjax($(this).attr("data-city"));
		} else {
			parent = $(this).closest(".optWidget");
			file =  parent.attr("data-file")
			ajaxVar = $(this).attr('data-city');
			parent.find(".loading").fadeIn();
			parent.find(".options").fadeOut();
			parent.find(".hamburger").fadeOut();
			parent.find(".data").fadeOut(function() {
				$(this).html("");
				nonce = $("body").attr("data-nonce");
				$.ajax({
					type: "post",
					dataType: "json",
					url: safirAjax.ajaxurl,
					data: {
						action: "safirAjaxRequest",
						filename: file,
						ajaxVar: ajaxVar,
						nonce: nonce,
					},
					success: function (response) {
						parent.find(".loading").fadeOut();
						parent.find(".data").html(response.data).fadeIn();
						parent.find(".hamburger").removeClass("active").fadeIn();
						if(parent.hasClass("scoresWidget")) {
							parent.find(".mainHeading .title").hide().html(parent.find(".hiddenTitle").html()).fadeIn();
						}
					},
				});
			});
		}

	});

// Ajax Hits

	let numberWithDots = function(x) {
		return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ".");
	}

	let safirUpdateHit = function(element) {
		jQuery(element).each(function () {
			var item = jQuery(this)
			var id = item.data("id")

			jQuery.ajax({
				type: "post",
				dataType: "json",
				url: safirAjax.ajaxurl,
				data: {
					action: "safirHits",
					id: id,
					nonce: jQuery("body").attr("data-nonce"),
				},
				success: function (response) {
					item.closest(".haberSingle").find('.metaBox .hit .count').html(numberWithDots(response.data)).animate({ "opacity": "1" }, 200)
					item.removeClass("active").addClass("passive")
				},
				error: function (xhr, ajaxOptions, thrownError) {
					console.log(xhr.responseText);
				}
			});

		});
	}
	safirUpdateHit(".safirHit.active")

	let safirGetHits = function(ids) {
		jQuery.ajax({
			type: "post",
			dataType: "json",
			url: safirAjax.ajaxurl,
			data: {
				action: "safirGetHits",
				ids: ids,
				nonce: jQuery("body").attr("data-nonce"),
			},
			success: function (response) {
				for (const [key, value] of Object.entries(response.data)) {
					let count = numberWithDots(Number(value))
					jQuery(".meta.hit[data-id="+key+"] .count").html(count).hide().css("opacity", "1").fadeIn()
				}
			},
			error: function (xhr, ajaxOptions, thrownError) {
				console.log(xhr.responseText);
			}
		});
	}

// Widgets
	widgetHitPostIDs = []
	jQuery(".meta.hit").each(function () {
		let id = jQuery(this).data("id")
		if(widgetHitPostIDs.indexOf(id) === -1) widgetHitPostIDs.push(id)
	})
	if(widgetHitPostIDs.length) safirGetHits(widgetHitPostIDs)

// AuthorsWidget

	var authorsWidgetCount = $(".authorsWidget").length;

	$('.authorsWidget .author-name a').each(function(index, element) {
	    var yazaradi = $(element), word_array, last_word, first_part;
	    word_array = yazaradi.html().split(/\s+/);
	    last_word = word_array.pop();
	    first_part = word_array.join(' ');
	    yazaradi.html([first_part, ' <span>', last_word, '</span>'].join(''));
	});


	$(".authorsWidget").each(function() {
		parent = $(this);
		order = parent.data("order");
		if(parent.hasClass("nosort")) order = "";
		switch (order) {

			case 'rand':
				parent.find(".items>div").html(parent.find(".post-container").sort(function(){
					return Math.random() - 0.5;
				}));
			break;

			case 'lastpost':
			case 'mostpost':
				parent.find('.post-container').sort(function (a, b) {
					return $(b).attr('data-order') - $(a).attr('data-order');
				}).appendTo(parent.find(".items>div"));
			break;

			case 'manual':
				parent.find('.post-container').sort(function (a, b) {
					return $(a).attr('data-order') - $(b).attr('data-order');
				}).appendTo(parent.find(".items>div"));
			break;

		}

		parent.find(".listing").css("display","flex");

		if(parent.hasClass("wideWidget")) itemCount = 4;
		if(parent.hasClass("homeWidget")) itemCount = 3;
		if(parent.hasClass("sidebarWidget")) itemCount = 1;
		parent.find(".owl-carousel").owlCarousel({
			mouseDrag: false,
			loop:false,
			navText:owlNavText,
			autoplay:true,
			autoplayTimeout:6000,
			autoplayHoverPause:true,
			rewind:true,
			rewindNav:true,
			lazyLoad: true,
			nav:true,
			autoplay:true,
			autoplayTimeout:5000,
			autoplayHoverPause:true,
			responsive:{
				0:{
					items:1,
					margin: 10,
				},
				401:{
					items:2,
					margin: 10,
				},
				601:{
					items:3,
					margin: 20,
				},
				801:{
					items:4,
					margin: 20,
				},
				1025:{
					items:itemCount,
					margin: 30
				},
			},
			onChanged: owlLazyLoad
		});

	});

	$('#allAuthorsPage img.lazy').unveil(0, function() {
		$(this).load(function() {
			this.style.opacity = 1;
		});
	});

// Tabbed Widget

	function tabbedEvent($item) {
		var index = $item.index();
		parentTabbed = $item.closest(".tabbedWidget");
		parentTabbed.find(".lines .line").hide();
		parentTabbed.find(".lines .line").eq(index).show();
		parentTabbed.find(".tab").stop().css('display', 'none');
		parentTabbed.find(".tab").eq(index).stop().fadeIn(400);
		parentTabbed.find(".tabheading a").removeClass("active");
		$item.addClass("active");
		parentTabbed.find(".tab").eq(index).find("img").unveil(0, function() {
			$(this).load(function() {
				this.style.opacity = 1;
			});
		});

	}

	$(".tabbedWidget").each(function () {
		$(this).find('.tab').first().fadeIn();
		$(this).find('.tabheading a').first().addClass("active");
	});

	$(".desktop .tabbedWidget .tabheading a").hover(function () {
		tabbedEvent($(this));
	}, function() {});

	$(".mobile .tabbedWidget .tabheading a").click(function (e) {
		if ($(this).hasClass('active') == false) {
			if (e.preventDefault) e.preventDefault();
			e.returnValue = false;
			tabbedEvent($(this));
		}
	});



// Sliders

	$(".sliderWidget .slider").hover(function() {
		$(this).find(".owl-nav div").stop().fadeIn();
	}, function() {
		if(!$(this).closest(".sliderWidget").hasClass("addtoyoursite")) {
			$(this).find(".owl-nav div").stop().fadeOut();
		}
	});

	$(".sliderWidget .slider .owl-carousel").owlCarousel({
		mouseDrag: false,
		loop:false,
		navText:owlNavText,
		autoplay:true,
		autoplayTimeout:5000,
		autoplayHoverPause:true,
		rewind:true,
		rewindNav:true,
		dots: true,
		lazyLoad: true,
		responsive:{
			0:{
				items:1,
				nav:true
			},
		},
		onInitialized: makePages,
		onResized: makePages,
		onChanged: owlLazyLoad,
	});

	$( ".sliderWidget .owl-dot" ).hover(function() {
		order = $(this).index();
		$(this).closest(".sliderWidget").find(".owl-carousel").trigger("to.owl.carousel", [order, 500, true]);
	});

	function makePages() {
		$(".sliderWidget").each(function() {
			parentSlider = $(this);
			counter = 1;
			$(this).find(".item").each( function(i) {
				if(counter == parentSlider.attr("data-adsorder")) {
					text = "R";
					parentSlider.find('.slider .owl-dot').eq(counter-1).addClass("ads");
				} else {
					text = counter;
				}
				linkUrl = parentSlider.find('.item').eq(counter-1).find('a').attr('href');
				if(linkUrl == null) {
					linkUrl = "#";
				}
				parentSlider.find('.slider .owl-dot').eq(counter-1)
				.html("<a href='"+linkUrl+"'>"+text+"</a>")
				counter++;
			});
		});
	}

	$('.sliderWidget .owl-carousel .owl-dot a').click(function() {
		window.location = $(this).attr("href");
	});



// Wide Slider

	$(".desktop .wideSlider").hover(function() {
		$(this).closest(".wideSlider").find(".owl-nav div").stop().fadeIn();
	}, function() {
		$(this).closest(".wideSlider").find(".owl-nav div").stop().fadeOut();
	});

	$(".wideSlider .owl-carousel").owlCarousel({
		mouseDrag: false,
		loop:true,
		navText:owlNavText,
		autoplay:true,
		autoplayTimeout:6000,
		autoplayHoverPause:true,
		rewind:true,
		animateIn: 'fadeIn',
		dots: true,
		dotsData: true,
		rewindNav:true,
		lazyLoad: true,
		responsive:{
			0:{
				items:1,
				nav:true
			},
		},
		onChanged: owlLazyLoad,
	});

	$('.wideSlider .owl-carousel .owl-dot').hover(function() {
		$(this).click();
	}, function() {});

	$('.wideSlider .owl-carousel .owl-dot a').click(function() {
		window.location = $(this).attr("href");;
	});



// Clocks

	safirChangeClock();
	function safirChangeClock() {
		nonce = $("body").attr("data-nonce");
		$.ajax({
			type: "post",
			dataType: "json",
			url: safirAjax.ajaxurl,
			data: {
				action: "safirClock",
				nonce: nonce,
			},
			success: function (response) {
				var localTime = +Date.now();
				var timeDiff = response.time - localTime;
				if($("html").attr("lang") == "tr") {
					var monthNames = new Array("Ocak", "Şubat", "Mart", "Nisan", "Mayıs", "Haziran", "Temmuz", "Ağustos", "Eylül", "Ekim", "Kasım", "Aralık");
				} else {
					var monthNames = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "December", "October", "November");
				}
				setInterval(function () {
				    var realtime = +Date.now() + timeDiff;
				    var date = new Date(realtime);
					var day = date.getDate();
					var weekDay = date.getDay();
					var month = monthNames[date.getMonth()];
					var year = date.getFullYear();
				    var hours = date.getHours();
				    var minutes = date.getMinutes();
				    var seconds = date.getSeconds();
				    var formattedTime = day + ' ' + month + ' ' + year + ', ' +  ("0" + hours).slice(-2) + ':' + ("0" + minutes).slice(-2) + ':' + ("0" + seconds).slice(-2);
					$(".safirclock").html(formattedTime);
				}, 1000);
			},
		});
	}

// Weather

	localCity = localStorage.getItem("localCity");
	if (localCity == null) {
		$("#weather .data, .weatherWidget .data").animate({ "opacity": "1" }, 150);
	} else {
		changeWeatherAjax(localCity, false);
	}

	$("#weather .cityListOpen").click(function() {
		$(this).toggleClass("open");
		$(this).closest("#weather").find(".cities").slideToggle();
	});

	$(document).mouseup(function(e) {
		var container = $("#weather");
		if (!container.is(e.target) && container.has(e.target).length === 0) {
			$("#weather .cities").fadeOut(100);
			$("#weather .cityListOpen").removeClass("open");
		}
	});

	$("#weather .cities span").click(function () {
		changeWeatherAjax($(this).attr('data-city'));
	});

	function changeWeatherAjax(city, ajaxrequest = true) {
		element1 = $("#weather");
		element2 = $(".weatherWidget");
		if (ajaxrequest) {
			// Header Weather
			if(element1.length) {
				element1.find(".cityListOpen").hide().removeClass("open");
				element1.find(".cities").slideUp();
				element1.find(".data").hide();
				element1.find(".loading").fadeIn();
			}

			if(element2.length) {
				element2.find(".loading").fadeIn();
				element2.find(".options").hide();
				element2.find(".hamburger").fadeOut();
				element2.find(".data").fadeOut();
			}			
		}

		nonce = $("body").attr("data-nonce");
		$.ajax({
			type: "post",
			dataType: "json",
			url: safirAjax.ajaxurl,
			data: {
				action: "safirAjaxRequest",
				filename: "weatherajax",
				city: city,
				nonce: nonce,
			},
			success: function (response) {
				if (ajaxrequest) {
					element1.find(".loading").fadeOut(function () {
						element1.find(".data").html(response.data).fadeIn();
						element1.find(".cityListOpen").fadeIn();
					});

					element2.find(".loading").fadeOut(function () {
						element2.find(".data").html(response.data).fadeIn();
						element2.find(".hamburger").removeClass("active").fadeIn();
					});
				} else {
					$("#weather .data, .weatherWidget .data").html(response.data).animate({"opacity":"1"}, 150);
				}
				localStorage.setItem("localCity", city);

			},
		});


	};



// Papers Widget

	$(".papersWidget").each(function() {
		parent = $(this);
		if(parent.hasClass("wideWidget")) itemCount = 8;
		if(parent.hasClass("homeWidget")) itemCount = 5;
		if(parent.hasClass("sidebarWidget")) itemCount = 2;
		parent.find(".owl-carousel").owlCarousel({
		mouseDrag: false,
			loop:false,
			navText:owlNavText,
			autoplay:false,
			rewind:true,
			rewindNav:true,
			lazyLoad: true,
			nav:true,
			margin: 10,
			responsive:{
				0:{
					items:1,
				},
				320:{
					items:2,
				},
				550:{
					items:3,
				},
				769:{
					items:4,
				},
				900:{
					items:5,
				},
				1025:{
					items:itemCount,
				},
			},
			onInitialized: owlLazyLoad
		});

	});




// Gallery Widget

	$(".galleryWidget .owl-carousel").owlCarousel({
		mouseDrag: false,
		loop:false,
		navText:owlNavText,
		autoplay:true,
		autoplayTimeout:6000,
		autoplayHoverPause:true,
		rewind:true,
		rewindNav:true,
		lazyLoad: true,
		nav:true,
		responsive:{
			0:{
				items:1,
			},
			500:{
				items:2,
			},
			769:{
				items:3,
			},
		},
		onChanged: owlLazyLoad
	});


// SafirTop

	$(window).scroll(function () {
		if ($(this).scrollTop() > 250) {
			$('.safirTop').fadeIn();
		} else {
			$('.safirTop').fadeOut();
		}
	});

	$('.safirTop').click(function () {
		$('body,html').animate({
			scrollTop: 0
		}, 800);
		return false;
	});



// Add Form

	$("#profile form").on("submit", function (e) {
		let userForm = $(this)
		statusElement = userForm.find("p.status");
		statusElement.removeClass().addClass("status loading").html(statusElement.attr("data-loading"));
	});


// Mobile Membership

	$('.mobileButtons div.loginButton').click(function() {
		$(this).toggleClass("active");
		$('#logo .safirLoginMenu').fadeToggle();
	});



// Vertical Ads

	let fixedAdControlCount = 0
	function checkFixedSize() {
		pageWidth = parseInt(getComputedStyle(document.documentElement).getPropertyValue('--safirWidth'));
		width1 = $('.fixedLeftAd').width()
		width2 = $('.fixedRightAd').width()
		if (width1 == 0) width1 = 120
		if (width2 == 0) width2 = 120
		position1 = ($(window).width() - pageWidth) / 2 - width1
		position2 = ($(window).width() - pageWidth) / 2 - width2
		if (position1 >= 0) {
			$('.fixedLeftAd').css('left', position1 + 'px').fadeIn()
		} else {
			$('.fixedLeftAd').css('left', position1 + 'px').fadeOut()
		}
		if (position2 >= 0) {
			$('.fixedRightAd').css('right', position2 + 'px').fadeIn()
		} else {
			$('.fixedRightAd').css('right', position2 + 'px').fadeOut()
		}
		fixedAdControlCount++
		if(fixedAdControlCount >= 10) clearInterval(fixedAdInterval)
	}

	$(window).on("resize", () => {
		checkFixedSize()
	})

	let fixedAdInterval = setInterval(checkFixedSize, 1000)

// Hamburger

	$(window).scroll(function () {
		if($(window).width() < 1024 ) {
			if ($(this).scrollTop() > 250) {
				$('.hamburgerMenuButton').fadeIn();
			} else {
				$('.hamburgerMenuButton').fadeOut();
			}
		}
	});

	$('.hamburgerMenuButton').click(function() {
		$("#hamburgermenu").stop().animate({"right": "0"},300);
		$('#overlay').fadeIn();
		$('body').css('overflow-y', 'hidden');
	});


	$('#header-cont .toggleMenu').click(function() {
		if($(this).hasClass('open')) {
			$('#header-cont .toggleMenu').removeClass('open');
			$("#hamburgermenu").stop().animate({"right": "-300px"},300);
			$('#overlay').fadeOut();
			$('body').css('overflow-y', 'visible');
		} else {
			$('#header-cont .toggleMenu').addClass('open');
			$("#hamburgermenu").stop().animate({"right": "0"},300);
			$('#overlay').fadeIn();
			$('body').css('overflow-y', 'hidden');
		}
	});

	$('#overlay, #hamburgermenu span.close, #hamburgermenu .logoBlock a, #mobilemenu a').click(function() {
		if(!$(this).parent().hasClass("menu-item-has-children")) closeHamburger();
	});

	function closeHamburger() {
		$('#header-cont .toggleMenu').removeClass('open');
		$("#safirPage").stop().animate({"left": "0"},300);
		$('#overlay').fadeOut();
		$("#hamburgermenu").stop().animate({"right": "-300px"},300, function() {
			$('body').css('overflow-y', 'visible');
		});
	}



// Mobile Menu

	$('#mobilemenu li').each(function() {
		$('<span class="icon"></span>').prependTo($(this).find('a').first());
	});

	$('#mobilemenu li.menu-item-has-children').each(function() {
		$('<span class="mobilearrow">'+themeIcon("plus")+'</span>').appendTo($(this));
	});

	$("#mobilemenu .menu-item-has-children>span.mobilearrow").on("click", function (event) {
		$(this).toggleClass("active").prev().slideToggle();
	});

	$("#mobilemenu .menu-item-has-children>a[href='#']").click(function (event) {
		event.preventDefault();
		$(this).next().slideToggle().next().toggleClass("active");
	});

// CUSTOM CODES

	$("a[rel^='external']").attr("target","_blank");

	$('.sfrIconForm form .fileLabel+input[type=file]').on("change", function () {
		fakeFile = $(this).val()
		if (fakeFile == "") {
			$(this).prev().find('span.text').html($(this).prev().find('span.text').data("text"))
		} else {
			fakeFile = fakeFile.substring(fakeFile.lastIndexOf("\\") + 1, fakeFile.length)
			$(this).prev().find('span.text').html(fakeFile)
		}
	});

// SIDEBAR

	!function(i){i.fn.theiaStickySidebar=function(t){(t=i.extend({containerSelector:"",additionalMarginTop:30,additionalMarginBottom:0,updateSidebarHeight:!0,minWidth:0},t)).additionalMarginTop=parseInt(t.additionalMarginTop)||0,t.additionalMarginBottom=parseInt(t.additionalMarginBottom)||0,i("head").append(i('<>.theiaStickySidebar:after {content: ""; display: table; clear: both;}</>')),this.each(function(){var o={};o.sidebar=i(this),o.options=t||{},o.container=i(o.options.containerSelector),0==o.container.length&&(o.container=o.sidebar.parent()),o.sidebar.parents().css("-webkit-transform","none"),o.sidebar.css({position:"relative",overflow:"visible","-webkit-box-sizing":"border-box","-moz-box-sizing":"border-box","box-sizing":"border-box"}),o.stickySidebar=o.sidebar.find(".theiaStickySidebar"),0==o.stickySidebar.length&&(o.sidebar.find("script").remove(),o.stickySidebar=i("<div>").addClass("theiaStickySidebar").append(o.sidebar.children()),o.sidebar.append(o.stickySidebar)),o.marginTop=parseInt(o.sidebar.css("margin-top")),o.marginBottom=parseInt(o.sidebar.css("margin-bottom")),o.paddingTop=parseInt(o.sidebar.css("padding-top")),o.paddingBottom=parseInt(o.sidebar.css("padding-bottom"));var a=o.stickySidebar.offset().top,e=o.stickySidebar.outerHeight();function d(){o.fixedScrollTop=0,o.sidebar.css({"min-height":"1px"}),o.stickySidebar.css({position:"static",width:""})}o.stickySidebar.css("padding-top",0),o.stickySidebar.css("padding-bottom",0),a-=o.stickySidebar.offset().top,e=o.stickySidebar.outerHeight()-e-a,0==a?(o.stickySidebar.css("padding-top",0),o.stickySidebarPaddingTop=0):o.stickySidebarPaddingTop=0,0==e?(o.stickySidebar.css("padding-bottom",0),o.stickySidebarPaddingBottom=0):o.stickySidebarPaddingBottom=0,o.previousScrollTop=null,o.fixedScrollTop=0,d(),o.onScroll=function(o){if(o.stickySidebar.is(":visible"))if(i("body").width()<o.options.minWidth)d();else if(o.sidebar.outerWidth(!0)+50>o.container.width())d();else{var a,e,s=i(document).scrollTop(),r="static";if(s>=o.container.offset().top+(o.paddingTop+o.marginTop-o.options.additionalMarginTop)){var n,c=o.paddingTop+o.marginTop+t.additionalMarginTop,p=o.paddingBottom+o.marginBottom+t.additionalMarginBottom,b=o.container.offset().top,g=o.container.offset().top+(a=o.container,e=a.height(),a.children().each(function(){e=Math.max(e,i(this).height())}),e),l=0+t.additionalMarginTop;n=o.stickySidebar.outerHeight()+c+p<i(window).height()?l+o.stickySidebar.outerHeight():i(window).height()-o.marginBottom-o.paddingBottom-t.additionalMarginBottom;var h=b-s+o.paddingTop+o.marginTop,S=g-s-o.paddingBottom-o.marginBottom,f=o.stickySidebar.offset().top-s,m=o.previousScrollTop-s;"fixed"==o.stickySidebar.css("position")&&(f+=m),f=m>0?Math.min(f,l):Math.max(f,n-o.stickySidebar.outerHeight()),f=Math.max(f,h),f=Math.min(f,S-o.stickySidebar.outerHeight());var y=o.container.height()==o.stickySidebar.outerHeight();r=(y||f!=l)&&(y||f!=n-o.stickySidebar.outerHeight())?s+f-o.sidebar.offset().top-o.paddingTop<=t.additionalMarginTop?"static":"absolute":"fixed"}if("fixed"==r)o.stickySidebar.css({position:"fixed",width:o.sidebar.width(),top:f,left:o.sidebar.offset().left+parseInt(o.sidebar.css("padding-left"))});else if("absolute"==r){var k={};"absolute"!=o.stickySidebar.css("position")&&(k.position="absolute",k.top=s+f-o.sidebar.offset().top-o.stickySidebarPaddingTop-o.stickySidebarPaddingBottom),k.width=o.sidebar.width(),k.left="",o.stickySidebar.css(k)}else"static"==r&&d();"static"!=r&&1==o.options.updateSidebarHeight&&o.sidebar.css({"min-height":o.stickySidebar.outerHeight()+o.stickySidebar.offset().top-o.sidebar.offset().top+o.paddingBottom}),o.previousScrollTop=s}},o.onScroll(o),i(document).scroll(function(i){return function(){i.onScroll(i)}}(o)),i(window).resize(function(i){return function(){i.stickySidebar.css({position:"static"}),i.onScroll(i)}}(o))})}}(jQuery);

	if($("body").hasClass("stickyMenu")) {
		authorAdditionalMarginTop = 90;
	} else {
		authorAdditionalMarginTop = 30;
	}

	if($("body").is(".desktop, .adminbar")) {
		authorAdditionalMarginTop += 32;
	}

	$('.stickySidebar #aside, .stickySidebar .homeWidgetContainer .rightContainer, #authorPage .profileBlock').theiaStickySidebar({additionalMarginTop:authorAdditionalMarginTop});

// Sticky Menu

	!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):"object"==typeof module&&module.exports?module.exports=a(require("jquery")):a(jQuery)}(function(a){var b=Array.prototype.slice,c=Array.prototype.splice,d={topSpacing:0,bottomSpacing:0,className:"is-sticky",wrapperClassName:"sticky-wrapper",center:!1,getWidthFrom:"",widthFromWrapper:!0,responsiveWidth:!1,zIndex:"auto"},e=a(window),f=a(document),g=[],h=e.height(),i=function(){for(var b=e.scrollTop(),c=f.height(),d=c-h,i=b>d?d-b:0,j=0,k=g.length;k>j;j++){var l=g[j],m=l.stickyWrapper.offset().top,n=m-l.topSpacing-i;if(l.stickyWrapper.css("height",l.stickyElement.outerHeight()),n>=b)null!==l.currentTop&&(l.stickyElement.css({width:"",position:"",top:"","z-index":""}),l.stickyElement.parent().removeClass(l.className),l.stickyElement.trigger("sticky-end",[l]),l.currentTop=null);else{var o=c-l.stickyElement.outerHeight()-l.topSpacing-l.bottomSpacing-b-i;if(0>o?o+=l.topSpacing:o=l.topSpacing,l.currentTop!==o){var p;l.getWidthFrom?p=a(l.getWidthFrom).width()||null:l.widthFromWrapper&&(p=l.stickyWrapper.width()),null==p&&(p=l.stickyElement.width()),l.stickyElement.css("width",p).css("position","fixed").css("top",o).css("z-index",l.zIndex),l.stickyElement.parent().addClass(l.className),null===l.currentTop?l.stickyElement.trigger("sticky-start",[l]):l.stickyElement.trigger("sticky-update",[l]),l.currentTop===l.topSpacing&&l.currentTop>o||null===l.currentTop&&o<l.topSpacing?l.stickyElement.trigger("sticky-bottom-reached",[l]):null!==l.currentTop&&o===l.topSpacing&&l.currentTop<o&&l.stickyElement.trigger("sticky-bottom-unreached",[l]),l.currentTop=o}var q=l.stickyWrapper.parent(),r=l.stickyElement.offset().top+l.stickyElement.outerHeight()>=q.offset().top+q.outerHeight()&&l.stickyElement.offset().top<=l.topSpacing;r?l.stickyElement.css("position","absolute").css("top","").css("bottom",0).css("z-index",""):l.stickyElement.css("position","fixed").css("top",o).css("bottom","").css("z-index",l.zIndex)}}},j=function(){h=e.height();for(var b=0,c=g.length;c>b;b++){var d=g[b],f=null;d.getWidthFrom?d.responsiveWidth&&(f=a(d.getWidthFrom).width()):d.widthFromWrapper&&(f=d.stickyWrapper.width()),null!=f&&d.stickyElement.css("width",f)}},k={init:function(b){var c=a.extend({},d,b);return this.each(function(){var b=a(this),e=b.attr("id"),f=e?e+"-"+d.wrapperClassName:d.wrapperClassName,h=a("<div></div>").attr("id",f).addClass(c.wrapperClassName);b.wrapAll(function(){return 0==a(this).parent("#"+f).length?h:void 0});var i=b.parent();c.center&&i.css({width:b.outerWidth(),marginLeft:"auto",marginRight:"auto"}),"right"===b.css("float")&&b.css({"float":"none"}).parent().css({"float":"right"}),c.stickyElement=b,c.stickyWrapper=i,c.currentTop=null,g.push(c),k.setWrapperHeight(this),k.setupChangeListeners(this)})},setWrapperHeight:function(b){var c=a(b),d=c.parent();d&&d.css("height",c.outerHeight())},setupChangeListeners:function(a){if(window.MutationObserver){var b=new window.MutationObserver(function(b){(b[0].addedNodes.length||b[0].removedNodes.length)&&k.setWrapperHeight(a)});b.observe(a,{subtree:!0,childList:!0})}else a.addEventListener("DOMNodeInserted",function(){k.setWrapperHeight(a)},!1),a.addEventListener("DOMNodeRemoved",function(){k.setWrapperHeight(a)},!1)},update:i,unstick:function(b){return this.each(function(){for(var b=this,d=a(b),e=-1,f=g.length;f-->0;)g[f].stickyElement.get(0)===b&&(c.call(g,f,1),e=f);-1!==e&&(d.unwrap(),d.css({width:"",position:"",top:"","float":"","z-index":""}))})}};window.addEventListener?(window.addEventListener("scroll",i,!1),window.addEventListener("resize",j,!1)):window.attachEvent&&(window.attachEvent("onscroll",i),window.attachEvent("onresize",j)),a.fn.sticky=function(c){return k[c]?k[c].apply(this,b.call(arguments,1)):"object"!=typeof c&&c?void a.error("Method "+c+" does not exist on jQuery.sticky"):k.init.apply(this,arguments)},a.fn.unstick=function(c){return k[c]?k[c].apply(this,b.call(arguments,1)):"object"!=typeof c&&c?void a.error("Method "+c+" does not exist on jQuery.sticky"):k.unstick.apply(this,arguments)},a(function(){setTimeout(i,0)})});

	topMargin = 0
	if($("body.desktop").hasClass("admin-bar")) {
		topMargin = 32;
	}
	$('.stickyMenu.desktop #mainMenu').sticky({topSpacing:topMargin, zIndex: 9990});
	$(".stickyMenuMobile.mobile #logo").sticky();

	function owlLazyLoad(event) {
		$(event.target).find("img").unveil(0, function() {
			$(this).load(function() {
				this.style.opacity = 1;
			});
		});
	}

// Cookie

	(function(e){if(typeof define==="function"&&define.amd){define(["jquery"],e)}else if(typeof exports==="object"){e(require("jquery"))}else{e(jQuery)}})(function(e){function n(e){return u.raw?e:encodeURIComponent(e)}function r(e){return u.raw?e:decodeURIComponent(e)}function i(e){return n(u.json?JSON.stringify(e):String(e))}function s(e){if(e.indexOf('"')===0){e=e.slice(1,-1).replace(/\\"/g,'"').replace(/\\\\/g,"\\")}try{e=decodeURIComponent(e.replace(t," "));return u.json?JSON.parse(e):e}catch(n){}}function o(t,n){var r=u.raw?t:s(t);return e.isFunction(n)?n(r):r}var t=/\+/g;var u=e.cookie=function(t,s,a){if(arguments.length>1&&!e.isFunction(s)){a=e.extend({},u.defaults,a);if(typeof a.expires==="number"){var f=a.expires,l=a.expires=new Date;l.setTime(+l+f*864e5)}return document.cookie=[n(t),"=",i(s),a.expires?"; expires="+a.expires.toUTCString():"",a.path?"; path="+a.path:"",a.domain?"; domain="+a.domain:"",a.secure?"; secure":""].join("")}var c=t?undefined:{};var h=document.cookie?document.cookie.split("; "):[];for(var p=0,d=h.length;p<d;p++){var v=h[p].split("=");var m=r(v.shift());var g=v.join("=");if(t&&t===m){c=o(g,s);break}if(!t&&(g=o(g))!==undefined){c[m]=g}}return c};u.defaults={};e.removeCookie=function(t,n){if(e.cookie(t)===undefined){return false}e.cookie(t,"",e.extend({},n,{expires:-1}));return!e.cookie(t)}});

// Footer Ad

	$(".footerAd .close").click(function() {
		$(".footerAd").fadeOut(function() {
			$(this).remove();
		});
		if($(".footerAd").hasClass("once")) {
			$.cookie("footerAd", "closed", { expires: 1, path: '/' });
		}
	});

	$(window).scroll(function () {
		if ($(this).scrollTop() > 250 && ($(".footerAd").hasClass("once") == false || ($(".footerAd").hasClass("once") && $.cookie("footerAd") != "closed")) ) {
			$('.footerAd').css({"opacity":"1", "z-index":"999"});
		}
	});


// Responsive Video

	$(".reading iframe[src*='youtube.com'], .reading iframe[src*='dailymotion.com']").wrap('<div class="safirVideoWrapper"></div>')

// ICONS
			
	function themeIcon(icon) {
		return '<span class="themeicon icon"><svg class="themeicon-'+icon+'"><use href="#themeicon-'+icon+'"></use></svg></span>';
	}

	$(".commentlist .comment-meta a:first-child").prepend(themeIcon("calendar"));
	$("#comments a.comment-reply-link").prepend(themeIcon("reply2"));
	$("#comments ol.children li .comment-body").prepend(themeIcon("reply1"));

	$(".sfrIconForm .item").each(function() {
		classes = $(this).attr("class").split(/\s+/);
		classes.forEach((item, i) => {
			if(item != "item") {
				$(this).prepend(themeIcon(item));
			}
		});
	});

// has implementation

	$("body:has(#aside)").addClass("hasAside")


//
});