File "infinite.js"
Full Path: /home/ozbarhaber/public_html/19052025___siteeee/wp-content/themes/anka/lib/infinite/infinite.js
File size: 6.35 KB
MIME-type: text/plain
Charset: utf-8
(function(root, factory) {
"use strict";
if (typeof define === "function" && define.amd) {
define(["jquery"], factory);
} else if (typeof exports === "object") {
factory(require("jquery"));
} else {
factory(root.jQuery);
}
})(this, function($) {
"use strict";
$.fn.cleverInfiniteScroll = function(options) {
var windowHeight = (typeof window.outerHeight !== "undefined") ? Math.max(window.outerHeight, $(window).height()) : $(window).height(),
defaults = {
offset: windowHeight,
},
settings = $.extend(defaults, options);
var generateHiddenSpans = function(_title, _path) {
return "<span class='hidden-title' style='display:none'>" + _title + "</span><span class='hidden-url' style='display:none'>" + _path + "</span>";
},
setTitleAndHistory = function(_title, _path) {
history.replaceState(null, _title, _path);
$("title").html(_title);
},
changeTitleAndURL = function(_value) {
var title = $(_value).children(".hidden-title:first").text(),
path = $(_value).children(".hidden-url:first").text();
if ($("title").text() !== title) {
$(settings.contentSelector).removeClass("active");
$(_value).addClass("active");
setTitleAndHistory(title, path);
$(document).trigger('clever-infinite-scroll-url-change', [title, path]);
}
};
var title = $("title").text(),
path = $(location).attr("href"),
documentHeight = $(document).height(),
threshold = settings.offset,
$contents = $(settings.contentSelector);
$(settings.contentSelector + ":last").append(generateHiddenSpans(title, path));
$(settings.contentSelector).addClass("active");
setTitleAndHistory(title, path);
var lastScroll = 0,
currentScroll;
$(window).scroll(function() {
window.clearTimeout($.data("this", "scrollTimer"));
$.data(this, "scrollTimer", window.setTimeout(function() {
currentScroll = $(window).scrollTop();
if (currentScroll > lastScroll) {
$contents.each(function(key, value) {
if ($(value).offset().top + $(value).height() - 20 > currentScroll) {
changeTitleAndURL(value);
return false;
}
});
} else if (currentScroll < lastScroll) {
$contents.each(function(key, value) {
if ($(value).offset().top + $(value).height() - windowHeight / 2 > currentScroll) {
changeTitleAndURL(value);
return false;
}
});
} else {
}
lastScroll = currentScroll;
}, 200));
if ($(window).scrollTop() + windowHeight + threshold >= documentHeight) {
var $url = [$(settings.nextSelector).attr("href")];
$(settings.nextSelector).remove();
if ($url[0] !== undefined) {
$(settings.contentsWrapperSelector).append('<div id="infiniteImage"></div>');
$.ajax({
url: $url[0],
dataType: "html",
success: function(res) {
title = $(res).filter("title").text();
path = $url[0];
path = path.replace("?ajax=1", "");
$(settings.contentsWrapperSelector).append($(res).find(settings.contentSelector).append(generateHiddenSpans(title, path)));
if ($(res).find(settings.contentSelector).find(settings.nextSelector).length === 0) {
$(settings.contentsWrapperSelector).append($(res).find(settings.nextSelector));
}
documentHeight = $(document).height();
$contents = $(settings.contentSelector);
$("#infiniteImage").remove();
$(document).trigger('clever-infinite-scroll-content-loaded');
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);
}
});
}
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(response.data).animate({ "opacity": "1" }, 200)
item.removeClass("active").addClass("passive")
},
error: function (xhr, ajaxOptions, thrownError) {
console.log(xhr.responseText);
}
});
});
}
let numberWithDots = function(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ".");
}
safirUpdateHit(".safirHit.active")
let infiniteContentIDs = []
$(res).find(settings.contentSelector).find(".meta.hit").each(function () {
let id = $(this).data("id")
infiniteContentIDs.push(id)
})
if (infiniteContentIDs.length) safirGetHits(infiniteContentIDs)
$('<div class="icon"><span></span></div>').prependTo($(".haberSingle:last-child #respond form textarea").parent());
if($("body").hasClass("stickyMenu")) {
authorAdditionalMarginTop = 90;
} else {
authorAdditionalMarginTop = 30;
}
if($("body").is(".desktop, .adminbar")) {
authorAdditionalMarginTop += 32;
}
$('#authorPage .profileBlock').theiaStickySidebar({additionalMarginTop:authorAdditionalMarginTop});
$('#single img.lazy').unveil(0, function() {
$(this).load(function() {
this.style.opacity = 1;
});
});
}
});
}
}
});
return (this);
};
});
jQuery(function($) {
$('#single').cleverInfiniteScroll({
contentsWrapperSelector: '#single',
contentSelector: '.haberSingle',
nextSelector: '.infiniteLink a',
});
});