mirror of
https://github.com/Oreolek/ifhub.club.git
synced 2024-07-01 05:55:02 +03:00
Доработана кнопка обновления комментариев в тулбаре
This commit is contained in:
parent
a466fca099
commit
74ce92d58d
104
application/frontend/common/js/toolbar.comments.js
Normal file
104
application/frontend/common/js/toolbar.comments.js
Normal file
|
@ -0,0 +1,104 @@
|
|||
/**
|
||||
* Кнопка подгрузки и навигации по новым комментариям
|
||||
*
|
||||
* @module ls/toolbar/comments
|
||||
*
|
||||
* @license GNU General Public License, version 2
|
||||
* @copyright 2013 OOO "ЛС-СОФТ" {@link http://livestreetcms.com}
|
||||
* @author Denis Shakhov <denis.shakhov@gmail.com>
|
||||
*/
|
||||
|
||||
|
||||
(function($) {
|
||||
"use strict";
|
||||
|
||||
$.widget( "livestreet.lsToolbarComments", {
|
||||
/**
|
||||
* Дефолтные опции
|
||||
*/
|
||||
options: {
|
||||
// Блок с комментариями
|
||||
target: '.js-comments',
|
||||
|
||||
// Селекторы
|
||||
selectors: {
|
||||
// Кнопка обновления
|
||||
update: '.js-toolbar-comments-update',
|
||||
|
||||
// Счетчик новых комментариев
|
||||
counter: '.js-toolbar-comments-count'
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Конструктор
|
||||
*
|
||||
* @constructor
|
||||
* @private
|
||||
*/
|
||||
_create: function () {
|
||||
this.elements = {
|
||||
update: this.element.find(this.options.selectors.update),
|
||||
counter: this.element.find(this.options.selectors.counter),
|
||||
comments: typeof target === 'object' ? target : $(this.options.target)
|
||||
};
|
||||
|
||||
// Обновляем счетчик новых комментариев
|
||||
this.updateCounter();
|
||||
|
||||
//
|
||||
// События
|
||||
//
|
||||
|
||||
// Обновление
|
||||
this.elements.update.on('click', this.update.bind(this));
|
||||
|
||||
// Прокрутка к следующему новому комментарию
|
||||
this.elements.counter.on('click', this.scroll.bind(this));
|
||||
},
|
||||
|
||||
/**
|
||||
* Обновление счетчика
|
||||
*
|
||||
* @param {Number} count (optional) Кол-во новых комментариев
|
||||
*/
|
||||
updateCounter: function(count) {
|
||||
count = typeof count === 'undefined' ? this.elements.comments.lsComments('getCommentsNew').length : count;
|
||||
count ? this.elements.counter.show().text( count ) : this.elements.counter.hide();
|
||||
},
|
||||
|
||||
/**
|
||||
* Обновление
|
||||
*/
|
||||
update: function() {
|
||||
this.elements.update.addClass( ls.options.classes.states.active );
|
||||
this.elements.comments.lsComments('load', null, true, {
|
||||
done: function () {
|
||||
this.updateCounter();
|
||||
}.bind(this),
|
||||
success: function () {
|
||||
this.elements.update.removeClass( ls.options.classes.states.active );
|
||||
}.bind(this)
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Прокрутка к следующему новому комментарию
|
||||
*/
|
||||
scroll: function() {
|
||||
var commentsNew = this.elements.comments.lsComments('getCommentsNew'),
|
||||
comment = commentsNew.eq(0);
|
||||
|
||||
if ( ! commentsNew.length ) return;
|
||||
|
||||
// Если новый комментарий находится в свернутой ветке разворачиваем все ветки
|
||||
if ( ! comment.is(':visible') ) this.elements.comments.lsComments('unfoldAll');
|
||||
|
||||
// Обновляем счетчик новых комментариев
|
||||
this.updateCounter( commentsNew.length - 1 );
|
||||
|
||||
comment.removeClass( this.elements.comments.lsComments('option', 'classes.states.new') );
|
||||
this.elements.comments.lsComments('scrollToComment', comment);
|
||||
}
|
||||
});
|
||||
})(jQuery);
|
|
@ -23,10 +23,10 @@
|
|||
*
|
||||
* @template toolbar/toolbar.comment.tpl
|
||||
*/
|
||||
.toolbar-item--update .update-comments { padding: 9px; }
|
||||
.toolbar-item--update .update-comments i { display: block; width: 16px; height: 16px; background: url(../images/update.gif) no-repeat; }
|
||||
.toolbar-item--update .update-comments.active i { background-position: -16px 0; }
|
||||
.toolbar-item--update .new-comments { border-top: 1px solid #eee; padding: 10px 0; color: #333; text-align: center; font-size: 11px; }
|
||||
.toolbar-item--comments .toolbar-comments-update { padding: 9px; cursor: pointer; }
|
||||
.toolbar-item--comments .toolbar-comments-update i { display: block; width: 16px; height: 16px; background: url(../images/update.gif) no-repeat; }
|
||||
.toolbar-item--comments .toolbar-comments-update.active i { background-position: -16px 0; }
|
||||
.toolbar-item--comments .toolbar-comments-count { border-top: 1px solid #eee; padding: 10px 0; color: #333; text-align: center; font-size: 11px; cursor: pointer; }
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,17 +9,13 @@
|
|||
{extends 'components/toolbar/toolbar.item.tpl'}
|
||||
|
||||
{block 'toolbar_item_options' append}
|
||||
{$_sMods = 'update'}
|
||||
{$_sMods = 'comments'}
|
||||
{$_bShow = !! $oUserCurrent}
|
||||
{$_sAttributes = 'id="update" style="{if $aPagingCmt and $aPagingCmt.iCountPage > 1}display: none;{/if}"'}
|
||||
|
||||
{$aPagingCmt = $params.aPagingCmt}
|
||||
{$_sClasses = 'js-toolbar-comments'}
|
||||
{$_sAttributes = 'data-target=".js-comment"'}
|
||||
{/block}
|
||||
|
||||
{block 'toolbar_item'}
|
||||
<a href="#" class="update-comments" id="update-comments" data-target-id="{$params.iTargetId}" data-target-type="{$params.sTargetType}"><i></i></a>
|
||||
<a href="#" class="new-comments" id="new_comments_counter" style="display: none;" title="{$aLang.comments.comment.count_new}"></a>
|
||||
|
||||
<input type="hidden" id="comment_last_id" value="{$params.iMaxIdComment}" />
|
||||
<input type="hidden" id="comment_use_paging" value="{if $aPagingCmt and $aPagingCmt.iCountPage>1}1{/if}" />
|
||||
<div class="toolbar-comments-update js-toolbar-comments-update"><i></i></div>
|
||||
<div class="toolbar-comments-count js-toolbar-comments-count" style="display: none;" title="{$aLang.comments.comment.count_new}"></div>
|
||||
{/block}
|
Loading…
Reference in a new issue