176 lines
5.8 KiB
JavaScript
176 lines
5.8 KiB
JavaScript
|
"use strict";
|
||
|
|
||
|
var siteUrl = window.location.protocol + "//" + window.location.hostname;
|
||
|
|
||
|
/*
|
||
|
(function ($, undefined) {
|
||
|
function get_posts() {
|
||
|
var offset = localStorage.getItem("current-offset");
|
||
|
var banner = !localStorage.getItem("banner-displayed");
|
||
|
var tag = localStorage.getItem("search-tag");
|
||
|
$.ajax({
|
||
|
type: "POST",
|
||
|
url: myajax.url,
|
||
|
dataType: "html",
|
||
|
data: {
|
||
|
action: "get_ajax_blog_posts",
|
||
|
offset: offset,
|
||
|
tag: tag,
|
||
|
numberposts: 11
|
||
|
},
|
||
|
success: function success(response) {
|
||
|
$("#articles-container").append(response);
|
||
|
$.ajax({
|
||
|
type: "POST",
|
||
|
url: myajax.url,
|
||
|
dataType: "html",
|
||
|
data: {
|
||
|
action: "get_ajax_blog_posts",
|
||
|
offset: offset * 1 + 11,
|
||
|
tag: tag,
|
||
|
numberposts: 11
|
||
|
},
|
||
|
success: function success(response) {
|
||
|
if (!response) {
|
||
|
$("#show-more").remove();
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
*/
|
||
|
|
||
|
(function ($, undefined) {
|
||
|
function get_posts() {
|
||
|
|
||
|
var offset = localStorage.getItem("current-offset");
|
||
|
var banner = !localStorage.getItem("banner-displayed");
|
||
|
var tag = localStorage.getItem("search-tag");
|
||
|
|
||
|
jQuery.ajax({
|
||
|
type: "POST",
|
||
|
url: myajax.url,
|
||
|
data: {'action': 'get_ajax_blog_posts', 'offset':offset, 'tag': tag, numberposts: 11 },
|
||
|
success: function (response) {
|
||
|
var data = JSON.parse(response);
|
||
|
// console.log(data);
|
||
|
if (data.results == true)
|
||
|
{
|
||
|
console.log('success');
|
||
|
jQuery("#articles-container").append(data.response);
|
||
|
var pagen = (offset / 11) + 1;
|
||
|
|
||
|
if ((pagen) && (pagen > 0))
|
||
|
{
|
||
|
var pageUrl = '?' + 'PAGEN=' + pagen;
|
||
|
var pageUrlPrev = '?' + 'PAGEN=' + (pagen - 1);
|
||
|
window.history.pushState('', '', pageUrl);
|
||
|
document.title = document.title + " Страница " + pagen;
|
||
|
var meta=document.getElementsByTagName("meta");
|
||
|
for (var i=0; i<meta.length; i++) {
|
||
|
if (meta[i].name.toLowerCase()=="description") {
|
||
|
meta[i].content = meta[i].content + " Страница " + pagen;
|
||
|
console.log('description ', meta[i].content);
|
||
|
}
|
||
|
}
|
||
|
console.log('pushState ', pageUrl);
|
||
|
ym(55127530, 'hit', pageUrl, {title: document.title, referer: pageUrlPrev});
|
||
|
ga('send', 'pageview', pageUrl);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
window.history.pushState('', '', siteUrl);
|
||
|
console.log('pushState ', siteUrl);
|
||
|
}
|
||
|
console.log('success pagen ', pagen);
|
||
|
}
|
||
|
else if ( data.results == false )
|
||
|
{
|
||
|
console.log('not success');
|
||
|
jQuery("#show-more").hide();
|
||
|
jQuery("#rel_next").remove();
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
jQuery(document).ready(function () {
|
||
|
console.log("Start Site jQuery, current Link:", siteUrl);
|
||
|
|
||
|
|
||
|
var offset = jQuery('#articles-container').data('paged');
|
||
|
|
||
|
if (offset > 1)
|
||
|
{
|
||
|
offset = (offset * 11 ) - 11;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
offset = 0;
|
||
|
}
|
||
|
|
||
|
localStorage.setItem("current-offset", offset);
|
||
|
console.log('offset ', offset);
|
||
|
localStorage.setItem("banner-displayed", false);
|
||
|
var selectedTag = $('.blog-tag.active').attr("id");
|
||
|
localStorage.setItem("search-tag", selectedTag === "all" ? "" : selectedTag);
|
||
|
// var offset = 0; // get_posts();
|
||
|
|
||
|
$(".show-more").on("click", function () {
|
||
|
localStorage.setItem("current-offset", localStorage.getItem("current-offset") * 1 + 11);
|
||
|
get_posts();
|
||
|
});
|
||
|
$(".blog-tag").on("click", function () {
|
||
|
$(".blog-tag").removeClass("active");
|
||
|
localStorage.setItem("search-tag", $(this).attr("id"));
|
||
|
$(this).addClass("active");
|
||
|
$("#articles-container").empty();
|
||
|
get_posts();
|
||
|
});
|
||
|
$(".sm-headbar-control").on("click", function () {
|
||
|
$(this).toggleClass('opened');
|
||
|
$(".mobile-menu").toggle();
|
||
|
});
|
||
|
$("#menu-mobilnoe-menyu>.menu-item-has-children").on("click", function () {
|
||
|
$(this).toggleClass('opened');
|
||
|
$(this).find('.sub-menu').toggle();
|
||
|
});
|
||
|
$("#footer-mobile-menu>.menu-item-has-children").on("click", function () {
|
||
|
$(this).toggleClass('opened');
|
||
|
$(this).find('.sub-menu').toggle();
|
||
|
});
|
||
|
$('#menu-item-1042 > a').on("click", function () {
|
||
|
carrotquest.open();
|
||
|
});
|
||
|
$(".sub-menu").on("click", function (e) {
|
||
|
e.stopPropagation();
|
||
|
}); //localStorage.setItem("banner-displayed", true);
|
||
|
}); //utm_links
|
||
|
|
||
|
$("a").each(function () {
|
||
|
var href = $(this).attr("href");
|
||
|
var anchor = '';
|
||
|
|
||
|
if (href) {
|
||
|
if (href.indexOf('#') != -1) {
|
||
|
anchor = '#' + href.split('#')[1];
|
||
|
href = href.split('#')[0];
|
||
|
}
|
||
|
|
||
|
var search = "?" + window.location.search.split("&").filter(function (val) {
|
||
|
return val.replace('?', '').indexOf('s_') !== 0;
|
||
|
}).join("&").replace('?', '');
|
||
|
|
||
|
if (search !== "?" && href != undefined && href.includes(".")) {
|
||
|
if (!href.includes("?")) {
|
||
|
$(this).attr("href", href + search + anchor);
|
||
|
} else {
|
||
|
$(this).attr("href", href + search.replace("?", "&") + anchor);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
})(jQuery);
|