This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/mixins/scrolling.js
2013-03-22 20:18:10 -07:00

47 lines
1.0 KiB
JavaScript

/**
This mixin adds support for being notified every time the browser window
is scrolled.
@class Discourse.Scrolling
@extends Ember.Mixin
@namespace Discourse
@module Discourse
**/
Discourse.Scrolling = Em.Mixin.create({
/**
Begin watching for scroll events. By default they will be called at max every 100ms.
call with {debounce: N} for a diff time
@method bindScrolling
*/
bindScrolling: function(opts) {
var onScroll,
_this = this;
opts = opts || {debounce: 100};
if (opts.debounce) {
onScroll = Discourse.debounce(function() { return _this.scrolled(); }, 100);
} else {
onScroll = function(){ return _this.scrolled(); };
}
$(document).bind('touchmove.discourse', onScroll);
$(window).bind('scroll.discourse', onScroll);
},
/**
Begin watching for scroll events. They will be called at max every 100ms.
@method unbindScrolling
*/
unbindScrolling: function() {
$(window).unbind('scroll.discourse');
$(document).unbind('touchmove.discourse');
}
});