1
0
mirror of https://github.com/keeweb/keeweb.git synced 2024-06-23 07:26:40 +02:00
keeweb/app/scripts/mixins/scrollable.js
2016-07-17 14:30:38 +03:00

57 lines
1.6 KiB
JavaScript

'use strict';
var Backbone = require('backbone'),
FeatureDetector = require('../util/feature-detector'),
baron = require('baron');
var isEnabled = FeatureDetector.isDesktop();
var Scrollable = {
createScroll: function(opts) {
opts.$ = Backbone.$;
// opts.cssGuru = true;
if (isEnabled) {
if (this.scroll) {
this.removeScroll();
}
this.scroll = baron(opts);
}
this.scroller = this.$el.find('.scroller');
this.scrollerBar = this.$el.find('.scroller__bar');
this.scrollerBarWrapper = this.$el.find('.scroller__bar-wrapper');
},
removeScroll: function() {
if (this.scroll) {
this.scroll.dispose();
this.scroll = null;
}
},
pageResized: function() {
// TODO: check size on window resize
// if (this.checkSize && (!e || e.source === 'window')) {
// this.checkSize();
// }
if (this.scroll) {
this.scroll.update();
this.requestAnimationFrame(function() {
if (this.scroll) {
this.scroll.update();
var barHeight = this.scrollerBar.height(),
wrapperHeight = this.scrollerBarWrapper.height();
this.scrollerBarWrapper.toggleClass('invisible', barHeight >= wrapperHeight);
}
});
}
},
initScroll: function() {
if (isEnabled) {
this.listenTo(Backbone, 'page-geometry', this.pageResized);
}
}
};
module.exports = Scrollable;