1
0
Fork 0
mirror of https://github.com/Oreolek/ifhub.club.git synced 2024-07-03 06:55:03 +03:00
ifhub.club/application/frontend/components/user/js/user-follow.js

94 lines
2.4 KiB
JavaScript
Raw Normal View History

/**
* Follow user
*
* @module ls/user/follow
*
* @license GNU General Public License, version 2
* @copyright 2013 OOO "ЛС-СОФТ" {@link http://livestreetcms.com}
* @author Denis Shakhov <denis.shakhov@gmail.com>
*/
(function($) {
2015-10-27 11:02:57 +02:00
"use strict";
2015-10-27 11:02:57 +02:00
$.widget( "livestreet.lsUserFollow", $.livestreet.lsComponent, {
/**
* Дефолтные опции
*/
options: {
// Ссылки
urls: {
// Подписаться
follow: null,
2015-10-27 11:02:57 +02:00
// Отписаться
unfollow: null
},
selectors: {
item: '> a'
},
2015-10-27 11:02:57 +02:00
classes: {
active: 'active'
},
params: {},
i18n: {
follow: '@user.actions.follow',
unfollow: '@user.actions.unfollow'
}
2015-10-27 11:02:57 +02:00
},
2015-10-27 11:02:57 +02:00
/**
* Конструктор
*
* @constructor
* @private
*/
_create: function () {
this._super();
this._on({ click: 'onClick' });
2016-10-11 14:15:54 +03:00
if ( ! this.elements.item.length) {
this.elements.item = this.element;
}
2015-10-27 11:02:57 +02:00
},
2015-10-27 11:02:57 +02:00
/**
* Коллбэк вызываемый при клике на кнопку подписки
*/
onClick: function( event ) {
2016-01-19 04:34:44 +02:00
this[ this._hasClass( 'active' ) ? 'unfollow' : 'follow' ]();
2015-10-27 11:02:57 +02:00
event.preventDefault();
},
2015-10-27 11:02:57 +02:00
/**
* Подписаться
*/
follow: function() {
this._load( 'follow', { users: [ this.element.data('id') ] }, 'onFollow' );
2015-10-27 11:02:57 +02:00
},
2015-10-27 11:02:57 +02:00
/**
* Коллбэк вызываемый при подписке
*/
onFollow: function( response ) {
this.elements.item.text( this._i18n('unfollow') );
this._addClass( 'active' );
2015-10-27 11:02:57 +02:00
},
2015-10-27 11:02:57 +02:00
/**
* Отписаться
*/
unfollow: function() {
this._load( 'unfollow', { user_id: this.element.data('id') }, 'onUnfollow' );
},
2015-10-27 11:02:57 +02:00
/**
* Коллбэк вызываемый при отписке
*/
onUnfollow: function( response ) {
this.elements.item.text( this._i18n('follow') );
this._removeClass( 'active' );
2015-10-27 11:02:57 +02:00
}
});
})(jQuery);