Skip to content

Commit a8b5716

Browse files
committed
FIX: Coudln't scroll while on Qunit page due to browser bindings
1 parent 4cd7197 commit a8b5716

File tree

4 files changed

+40
-14
lines changed

4 files changed

+40
-14
lines changed

app/assets/javascripts/discourse/components/utilities.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,7 @@ Discourse.Utilities = {
158158
}
159159
},
160160

161-
/**
162-
validateFilesForUpload
163161

164-
**/
165162
/**
166163
Validate a list of files to be uploaded
167164

app/assets/javascripts/discourse/mixins/scrolling.js

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
This mixin adds support for being notified every time the browser window
33
is scrolled.
44
5-
@class Discourse.Scrolling
5+
@class Scrolling
66
@extends Ember.Mixin
77
@namespace Discourse
88
@module Discourse
@@ -16,19 +16,22 @@ Discourse.Scrolling = Em.Mixin.create({
1616
@method bindScrolling
1717
*/
1818
bindScrolling: function(opts) {
19-
var onScroll,
20-
_this = this;
21-
2219
opts = opts || {debounce: 100};
2320

21+
var scrollingMixin = this;
22+
var onScrollMethod;
23+
2424
if (opts.debounce) {
25-
onScroll = Discourse.debounce(function() { return _this.scrolled(); }, 100);
25+
onScrollMethod = Discourse.debounce(function() {
26+
return scrollingMixin.scrolled();
27+
}, 100);
2628
} else {
27-
onScroll = function(){ return _this.scrolled(); };
29+
onScrollMethod = function() {
30+
return scrollingMixin.scrolled();
31+
};
2832
}
2933

30-
$(document).bind('touchmove.discourse', onScroll);
31-
$(window).bind('scroll.discourse', onScroll);
34+
Discourse.ScrollingDOMMethods.bindOnScroll(onScrollMethod);
3235
},
3336

3437
/**
@@ -37,10 +40,32 @@ Discourse.Scrolling = Em.Mixin.create({
3740
@method unbindScrolling
3841
*/
3942
unbindScrolling: function() {
40-
$(window).unbind('scroll.discourse');
41-
$(document).unbind('touchmove.discourse');
43+
Discourse.ScrollingDOMMethods.unbindOnScroll();
4244
}
4345

4446
});
4547

4648

49+
/**
50+
This object provides the DOM methods we need for our Mixin to bind to scrolling
51+
methods in the browser. By removing them from the Mixin we can test them
52+
easier.
53+
54+
@class ScrollingDOMMethods
55+
@module Discourse
56+
**/
57+
Discourse.ScrollingDOMMethods = {
58+
59+
bindOnScroll: function(onScrollMethod) {
60+
console.log("BOUND");
61+
$(document).bind('touchmove.discourse', onScrollMethod);
62+
$(window).bind('scroll.discourse', onScrollMethod);
63+
},
64+
65+
unbindOnScroll: function() {
66+
console.log("UNBOUND");
67+
$(window).unbind('scroll.discourse');
68+
$(document).unbind('touchmove.discourse');
69+
}
70+
71+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
function integration(name) {
22
module(name, {
33
setup: function() {
4+
sinon.stub(Discourse.ScrollingDOMMethods, "bindOnScroll");
5+
sinon.stub(Discourse.ScrollingDOMMethods, "unbindOnScroll");
46
Ember.run(Discourse, Discourse.advanceReadiness);
57
},
68

79
teardown: function() {
810
Discourse.reset();
11+
Discourse.ScrollingDOMMethods.bindOnScroll.restore();
12+
Discourse.ScrollingDOMMethods.unbindOnScroll.restore();
913
}
1014
});
1115
}

test/javascripts/test_helper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@
3131
//= require admin
3232
//= require_tree ../../app/assets/javascripts/defer
3333

34-
//= require main_include
3534

3635
//= require sinon-1.7.1.js
3736
//= require sinon-qunit-1.0.0.js
3837

3938
//= require helpers/qunit_helpers
4039
//= require helpers/assertions
40+
4141
//= require_tree ./fixtures
4242
//= require_tree .
4343
//= require_self

0 commit comments

Comments
 (0)