diff --git a/app/assets/javascripts/discourse/components/utilities.js b/app/assets/javascripts/discourse/components/utilities.js index 60719fe0e..8da0b1cf9 100644 --- a/app/assets/javascripts/discourse/components/utilities.js +++ b/app/assets/javascripts/discourse/components/utilities.js @@ -158,10 +158,7 @@ Discourse.Utilities = { } }, - /** - validateFilesForUpload - **/ /** Validate a list of files to be uploaded diff --git a/app/assets/javascripts/discourse/mixins/scrolling.js b/app/assets/javascripts/discourse/mixins/scrolling.js index bf731909d..bf4f6d7d9 100644 --- a/app/assets/javascripts/discourse/mixins/scrolling.js +++ b/app/assets/javascripts/discourse/mixins/scrolling.js @@ -2,7 +2,7 @@ This mixin adds support for being notified every time the browser window is scrolled. - @class Discourse.Scrolling + @class Scrolling @extends Ember.Mixin @namespace Discourse @module Discourse @@ -16,19 +16,22 @@ Discourse.Scrolling = Em.Mixin.create({ @method bindScrolling */ bindScrolling: function(opts) { - var onScroll, - _this = this; - opts = opts || {debounce: 100}; + var scrollingMixin = this; + var onScrollMethod; + if (opts.debounce) { - onScroll = Discourse.debounce(function() { return _this.scrolled(); }, 100); + onScrollMethod = Discourse.debounce(function() { + return scrollingMixin.scrolled(); + }, 100); } else { - onScroll = function(){ return _this.scrolled(); }; + onScrollMethod = function() { + return scrollingMixin.scrolled(); + }; } - $(document).bind('touchmove.discourse', onScroll); - $(window).bind('scroll.discourse', onScroll); + Discourse.ScrollingDOMMethods.bindOnScroll(onScrollMethod); }, /** @@ -37,10 +40,32 @@ Discourse.Scrolling = Em.Mixin.create({ @method unbindScrolling */ unbindScrolling: function() { - $(window).unbind('scroll.discourse'); - $(document).unbind('touchmove.discourse'); + Discourse.ScrollingDOMMethods.unbindOnScroll(); } }); +/** + This object provides the DOM methods we need for our Mixin to bind to scrolling + methods in the browser. By removing them from the Mixin we can test them + easier. + + @class ScrollingDOMMethods + @module Discourse +**/ +Discourse.ScrollingDOMMethods = { + + bindOnScroll: function(onScrollMethod) { + console.log("BOUND"); + $(document).bind('touchmove.discourse', onScrollMethod); + $(window).bind('scroll.discourse', onScrollMethod); + }, + + unbindOnScroll: function() { + console.log("UNBOUND"); + $(window).unbind('scroll.discourse'); + $(document).unbind('touchmove.discourse'); + } + +} \ No newline at end of file diff --git a/test/javascripts/helpers/qunit_helpers.js b/test/javascripts/helpers/qunit_helpers.js index b219aa794..3a08c29fd 100644 --- a/test/javascripts/helpers/qunit_helpers.js +++ b/test/javascripts/helpers/qunit_helpers.js @@ -1,11 +1,15 @@ function integration(name) { module(name, { setup: function() { + sinon.stub(Discourse.ScrollingDOMMethods, "bindOnScroll"); + sinon.stub(Discourse.ScrollingDOMMethods, "unbindOnScroll"); Ember.run(Discourse, Discourse.advanceReadiness); }, teardown: function() { Discourse.reset(); + Discourse.ScrollingDOMMethods.bindOnScroll.restore(); + Discourse.ScrollingDOMMethods.unbindOnScroll.restore(); } }); } \ No newline at end of file diff --git a/test/javascripts/test_helper.js b/test/javascripts/test_helper.js index d40c49033..71cd89059 100644 --- a/test/javascripts/test_helper.js +++ b/test/javascripts/test_helper.js @@ -31,13 +31,13 @@ //= require admin //= require_tree ../../app/assets/javascripts/defer -//= require main_include //= require sinon-1.7.1.js //= require sinon-qunit-1.0.0.js //= require helpers/qunit_helpers //= require helpers/assertions + //= require_tree ./fixtures //= require_tree . //= require_self