Commit f2421ca

mo khan <mo@mokhan.ca>
2014-11-30 06:47:42
extract scrollable mixin.
1 parent 76226d3
Changed files (3)
app
mixins
views
tests
app/mixins/scrollable.js
@@ -0,0 +1,15 @@
+import Ember from 'ember';
+
+export default Ember.Mixin.create({
+  didScroll: function(){
+    if(this.isScrolledToBottom()) {
+      this.get('controller').send('more');
+    }
+  },
+
+  isScrolledToBottom: function() {
+    var distanceToTop = Ember.$(document).height() - Ember.$(window).height();
+    var top = Ember.$(document).scrollTop();
+    return top === distanceToTop;
+  }
+});
app/views/cakes/index.js
@@ -1,6 +1,7 @@
 import Ember from 'ember';
+import Scrollable from 'cakery/mixins/scrollable';
 
-export default Ember.View.extend({
+export default Ember.View.extend(Scrollable, {
   didInsertElement: function(){
     var view = this;
     Ember.$(window).bind('scroll', function(){
@@ -11,16 +12,4 @@ export default Ember.View.extend({
   willDestroyElement: function(){
     Ember.$(window).unbind('scroll');
   },
-
-  didScroll: function(){
-    if(this.isScrolledToBottom()) {
-      this.get('controller').send('more');
-    }
-  },
-
-  isScrolledToBottom: function() {
-    var distanceToTop = Ember.$(document).height() - Ember.$(window).height();
-    var top = Ember.$(document).scrollTop();
-    return top === distanceToTop;
-  }
 });
tests/unit/mixins/scrollable-test.js
@@ -0,0 +1,11 @@
+import Ember from 'ember';
+import ScrollableMixin from 'cakery/mixins/scrollable';
+
+module('ScrollableMixin');
+
+// Replace this with your real tests.
+test('it works', function() {
+  var ScrollableObject = Ember.Object.extend(ScrollableMixin);
+  var subject = ScrollableObject.create();
+  ok(subject);
+});