Commit f2421ca
Changed files (3)
app
mixins
views
cakes
tests
unit
mixins
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);
+});