Commit 512d9a52 authored by Vadim's avatar Vadim

Version 2.6

Обновляет счетчики после прокрутки страницы, если добавлены элементы. (обеспечивает совместимость плагина с бесконечной прокруткой страниц индекса).
parent 29563a75
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
Plugin Name: Bg Az-Counter Plugin Name: Bg Az-Counter
Plugin URI: https://bogaiskov.ru Plugin URI: https://bogaiskov.ru
Description: Подсчет количества посещений страниц на базе stat.azbyka.ru Description: Подсчет количества посещений страниц на базе stat.azbyka.ru
Version: 2.5.5 Version: 2.6
Author: VBog Author: VBog
Author URI: https://bogaiskov.ru Author URI: https://bogaiskov.ru
License: GPL2 License: GPL2
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
if ( !defined('ABSPATH') ) { if ( !defined('ABSPATH') ) {
die( 'Sorry, you are not allowed to access this page directly.' ); die( 'Sorry, you are not allowed to access this page directly.' );
} }
define('BG_COUNTER_VERSION', '2.5.5'); define('BG_COUNTER_VERSION', '2.6');
define('BG_COUNTER_LOG', dirname(__FILE__ ).'/bg_counter.log'); define('BG_COUNTER_LOG', dirname(__FILE__ ).'/bg_counter.log');
define('BG_COUNTER_STAT_COUNTERS','https://stat.azbyka.ru/counters'); define('BG_COUNTER_STAT_COUNTERS','https://stat.azbyka.ru/counters');
......
var bg_counter_elements = 0;
jQuery( document ).ready(function() { jQuery( document ).ready(function() {
if (bg_counter.ID) { if (bg_counter.ID) {
SendOnce(bg_counter.type, bg_counter.ID); SendOnce(bg_counter.type, bg_counter.ID);
var request = bg_counter.websocket+bg_counter.project+"/"+bg_counter.type+"/"+bg_counter.ID; var request = bg_counter.websocket+bg_counter.project+"/"+bg_counter.type+"/"+bg_counter.ID;
...@@ -27,6 +29,8 @@ jQuery( document ).ready(function() { ...@@ -27,6 +29,8 @@ jQuery( document ).ready(function() {
}; };
} }
} else GetAllCounters(); } else GetAllCounters();
bg_counter_elements_reloaded_on_scroll();
/********************************************************************************* /*********************************************************************************
Просомтр счетчиков читающих в реальном времени. Просомтр счетчиков читающих в реальном времени.
...@@ -186,6 +190,7 @@ function GetAllCounters() { ...@@ -186,6 +190,7 @@ function GetAllCounters() {
jQuery('span.bg-az-counter').each (function () { jQuery('span.bg-az-counter').each (function () {
var el = jQuery(this); var el = jQuery(this);
bg_counter_elements = el.length;
var type = el.attr('data-type'); var type = el.attr('data-type');
var id = el.attr('data-ID'); var id = el.attr('data-ID');
var project = el.attr('data-project'); var project = el.attr('data-project');
...@@ -272,3 +277,22 @@ function bg_counter_number_format (num) { ...@@ -272,3 +277,22 @@ function bg_counter_number_format (num) {
} }
return num; return num;
} }
/*********************************************************************************
Обновляет счетчики после прокрутки страницы,
если добавлены элементы.
**********************************************************************************/
function bg_counter_elements_reloaded_on_scroll() {
jQuery(window).on('scroll', function() {
var elem = jQuery('span.bg-az-counter');
if( typeof elem == 'undefined' ) {
return;
}
if (elem.length > bg_counter_elements) {
GetAllCounters();
// getAllRates();
}
});
}
...@@ -2,10 +2,13 @@ var start_rate_index, rating_voted; ...@@ -2,10 +2,13 @@ var start_rate_index, rating_voted;
var options={}; var options={};
options.expires=60*60*24; // Кука на сутки options.expires=60*60*24; // Кука на сутки
options.path=window.location.pathname; // Текущий путь options.path=window.location.pathname; // Текущий путь
var bg_counter_ratings = 0;
jQuery( document ).ready(function() { jQuery( document ).ready(function() {
getAllRates();
// getAllRates();
bg_counter_ratings_reloaded_on_scroll();
if (!bg_counter.ID) return; // У объекта нет ID if (!bg_counter.ID) return; // У объекта нет ID
if (jQuery("div").is(".bg_counter_rating") == false) return; // На странице нет счетчика if (jQuery("div").is(".bg_counter_rating") == false) return; // На странице нет счетчика
...@@ -129,6 +132,7 @@ function getAllRates() { ...@@ -129,6 +132,7 @@ function getAllRates() {
jQuery('span.bg-az-counter').each (function () { jQuery('span.bg-az-counter').each (function () {
var el = jQuery(this); var el = jQuery(this);
bg_counter_ratings = el.length;
var type = el.attr('data-type'); var type = el.attr('data-type');
var id = el.attr('data-ID'); var id = el.attr('data-ID');
var project = el.attr('data-project'); var project = el.attr('data-project');
...@@ -222,3 +226,20 @@ function sendRate(type, id, number) { ...@@ -222,3 +226,20 @@ function sendRate(type, id, number) {
xhr.send('{"rating": '+number+'}'); xhr.send('{"rating": '+number+'}');
} }
/*********************************************************************************
Обновляет рейтинги после прокрутки страницы,
если добавлены элементы.
**********************************************************************************/
function bg_counter_ratings_reloaded_on_scroll() {
jQuery(window).on('scroll', function() {
var elem = jQuery('span.bg-az-counter');
if( typeof elem == 'undefined' ) {
return;
}
if (elem.length > bg_counter_ratings) {
getAllRates();
}
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment