Skip to content

Commit

Permalink
Add fastboot checks
Browse files Browse the repository at this point in the history
  • Loading branch information
RobbieTheWagner committed Aug 12, 2016
1 parent ff0fe7a commit 3f1f472
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
7 changes: 5 additions & 2 deletions addon/mixins/reset-scroll.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import Ember from 'ember';
const { $, Mixin } = Ember;
const { $, inject: { service }, Mixin } = Ember;

export default Mixin.create({
fastboot: service(),
/**
* Scroll to top when route is entered.
*/
activate(...args) {
this._super(...args);
$(window).scrollTop(0);
if (!this.get('fastboot.isFastBoot')) {
$(window).scrollTop(0);
}
}
});
36 changes: 22 additions & 14 deletions addon/mixins/scroll-operator.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
import Ember from 'ember';
const { $, Mixin, run } = Ember;
const { $, inject: { service }, Mixin, run } = Ember;

export default Mixin.create({
_scrollingTimeout: 100,

fastboot: service(),

/**
* Attach on-scroll handler to window/document. Handler will call _scrollTop
* on scroll.
*/
activate(...args) {
this._super(...args);

this._attachEvents();
if (!this.get('fastboot.isFastBoot')) {
this._attachEvents();
}
},

/**
* Detach on-scroll handlers on route exit.
*/
deactivate(...args) {
this._super(...args);

this._detachEvents();
if (!this.get('fastboot.isFastBoot')) {
this._detachEvents();
}
},

/**
Expand All @@ -33,11 +37,13 @@ export default Mixin.create({

this._super(...args);

if (!this._didTransitionViaBackOrForward(transition) && this.controller) {
this.controller.set('currentPosition', 0);
}
if (!this.get('fastboot.isFastBoot')) {
if (!this._didTransitionViaBackOrForward(transition) && this.controller) {
this.controller.set('currentPosition', 0);
}

this._detachEvents();
this._detachEvents();
}
},

/**
Expand All @@ -50,11 +56,13 @@ export default Mixin.create({

this._super(...args);

if (controller) {
run.schedule('afterRender', null, () => {
$(window).scrollTop(controller.getWithDefault('currentPosition', 0));
this._attachEvents();
});
if (!this.get('fastboot.isFastBoot')) {
if (controller) {
run.schedule('afterRender', null, () => {
$(window).scrollTop(controller.getWithDefault('currentPosition', 0));
this._attachEvents();
});
}
}
},

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"ember-cli-app-version": "^1.0.0",
"ember-cli-dependency-checker": "^1.2.0",
"ember-cli-eslint": "1.7.0",
"ember-cli-fastboot": "1.0.0-beta.8",
"ember-cli-htmlbars": "^1.0.3",
"ember-cli-htmlbars-inline-precompile": "^0.3.1",
"ember-cli-inject-live-reload": "^1.4.0",
Expand Down

0 comments on commit 3f1f472

Please sign in to comment.