1
0
Fork 0
mirror of https://github.com/Oreolek/ifhub.club.git synced 2024-07-08 17:34:26 +03:00
ifhub.club/application/frontend/components/toolbar-scrollup/js/toolbar.scrollup.js

89 lines
2.1 KiB
JavaScript
Raw Normal View History

2014-06-17 12:54:39 +03:00
/**
* Прокрутка вверх
*
* @module ls/toolbar/scrollup
*
* @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.lsToolbarScrollUp", {
/**
* Дефолтные опции
*/
options: {
// Продолжительность прокрутки, мс
duration: 500
},
/**
* Конструктор
*
* @constructor
* @private
*/
_create: function () {
this._on({ click: 'onClick' });
this._on( this.window, { scroll: 'onScroll' } );
2014-06-17 12:54:39 +03:00
},
/**
* Показывает/скрывает кнопку прокрутки в зависимости от значения scrollTop
2014-06-17 12:54:39 +03:00
*/
onScroll: function() {
if ( this.prev && this.isTop && this.window.scrollTop() > 0 ) {
this.element.removeClass( ls.options.classes.states.active );
this.isTop = false;
this.prev = null;
}
! this.prev && this.element[ this.window.scrollTop() > this.window.height() / 2 ? 'fadeIn' : 'fadeOut' ]( 500 );
},
/**
* Обработка клика
*/
onClick: function() {
// Не обрабатываем клики в процессе скролла
! this.isScroll && this[ this.prev && this.isTop ? 'back' : 'up' ]();
2014-06-17 12:54:39 +03:00
},
/**
* Прокрутка вверх
*/
up: function() {
this.prev = this.window.scrollTop();
this.isScroll = true;
$.scrollTo( 0, this.options.duration, {
onAfter: function () {
this.isTop = true;
this.isScroll = false;
this.element.addClass( ls.options.classes.states.active );
}.bind(this)
});
},
/**
* Прокрутка к предыдущей позиции
*/
back: function() {
if ( ! this.prev ) return;
this.isTop = false;
this.isScroll = true;
$.scrollTo( this.prev, this.options.duration, {
onAfter: function () {
this.element.removeClass( ls.options.classes.states.active );
this.isScroll = false;
this.prev = null;
}.bind(this)
});
2014-06-17 12:54:39 +03:00
}
});
})(jQuery);