forked from bttf/ember-scroll-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
commit beginnings of this humble add-on
- Loading branch information
Showing
8 changed files
with
177 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import Ember from 'ember'; | ||
|
||
export default Ember.Mixin.create({ | ||
/** | ||
* Scroll to top when route is entered. | ||
*/ | ||
activate() { | ||
Ember.$(window).scrollTop(0); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import Ember from 'ember'; | ||
|
||
export default Ember.Mixin.create({ | ||
scrollingTimeout: 100, | ||
|
||
/** | ||
* Attach on-scroll handler to window/document. Handler will call _scrollTop | ||
* on scroll. | ||
*/ | ||
activate() { | ||
const onScroll = () => { | ||
Ember.run.debounce(this, this._setScrollTop, this.scrollingTimeout); | ||
}; | ||
Ember.$(document).on('touchmove.scrollable', onScroll); | ||
Ember.$(window).on('scroll.scrollable', onScroll); | ||
}, | ||
|
||
/** | ||
* Detach on-scroll handlers on route exit. | ||
*/ | ||
deactivate() { | ||
Ember.$(document).off('.scrollable'); | ||
Ember.$(window).off('.scrollable'); | ||
}, | ||
|
||
/** | ||
* On entering route, decide whether we want to resume previous scrolling | ||
* position or not based on transition. | ||
*/ | ||
beforeModel(transition) { | ||
if (!this._didTransitionViaBackOrForward(transition) && this.controller) { | ||
this.controller.set('currentPosition', 0); | ||
} | ||
}, | ||
|
||
/** | ||
* Scroll to currentPosition value. Uses run-loop's next helper to ensure it | ||
* happens after model hooks have been fully executed. | ||
*/ | ||
setupController(controller) { | ||
Ember.run.next(null, () => { | ||
Ember.$(window).scrollTop(controller.getWithDefault('currentPosition', 0)); | ||
}); | ||
}, | ||
|
||
/** | ||
* Set currentPosition to $(window).scrollTop value. | ||
*/ | ||
_setScrollTop() { | ||
this.set('controller.currentPosition', Ember.$(window).scrollTop()); | ||
}, | ||
|
||
/** | ||
* Determine if transition is triggered by browser forward/back buttons. | ||
* Credit: https://github.com/emberjs/ember.js/issues/3087 | ||
*/ | ||
_didTransitionViaBackOrForward(transition) { | ||
return transition && transition.sequence > 1 && transition.hasOwnProperty('urlMethod'); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import Ember from 'ember'; | ||
import ResetScrollMixin from 'ember-scroll-operator/mixins/reset-scroll'; | ||
|
||
export default ResetScrollMixin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import Ember from 'ember'; | ||
import ScrollOperatorMixin from 'ember-scroll-operator/mixins/scroll-operator'; | ||
|
||
export default ScrollOperatorMixin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Ember from 'ember'; | ||
import ResetScrollMixin from 'ember-scroll-operator/mixins/reset-scroll'; | ||
import { module, test } from 'qunit'; | ||
|
||
module('Unit | Mixin | reset scroll'); | ||
|
||
// Replace this with your real tests. | ||
test('it works', function(assert) { | ||
let ResetScrollObject = Ember.Object.extend(ResetScrollMixin); | ||
let subject = ResetScrollObject.create(); | ||
assert.ok(subject); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Ember from 'ember'; | ||
import ScrollOperatorMixin from 'ember-scroll-operator/mixins/scroll-operator'; | ||
import { module, test } from 'qunit'; | ||
|
||
module('Unit | Mixin | scroll operator'); | ||
|
||
// Replace this with your real tests. | ||
test('it works', function(assert) { | ||
let ScrollOperatorObject = Ember.Object.extend(ScrollOperatorMixin); | ||
let subject = ScrollOperatorObject.create(); | ||
assert.ok(subject); | ||
}); |