Skip to content

Commit

Permalink
Merge pull request bttf#6 from rwwagner90/master
Browse files Browse the repository at this point in the history
Fastboot, destructuring, and ESLint
  • Loading branch information
bttf authored Aug 19, 2016
2 parents 4518d29 + e978f60 commit 750c859
Show file tree
Hide file tree
Showing 16 changed files with 103 additions and 171 deletions.
14 changes: 0 additions & 14 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,8 @@ insert_final_newline = true
indent_style = space
indent_size = 2

[*.js]
indent_style = space
indent_size = 2

[*.hbs]
insert_final_newline = false
indent_style = space
indent_size = 2

[*.css]
indent_style = space
indent_size = 2

[*.html]
indent_style = space
indent_size = 2

[*.{diff,md}]
trim_trailing_whitespace = false
7 changes: 7 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var path = require('path');

module.exports = {
extends: [
require.resolve('ember-cli-eslint/coding-standard/ember-application.js')
]
};
32 changes: 0 additions & 32 deletions .jshintrc

This file was deleted.

17 changes: 10 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
language: node_js
node_js:
- "0.12"
- "4"

sudo: false

Expand All @@ -11,7 +11,7 @@ cache:

env:
- EMBER_TRY_SCENARIO=default
- EMBER_TRY_SCENARIO=ember-1-13
- EMBER_TRY_SCENARIO=ember-1.13
- EMBER_TRY_SCENARIO=ember-release
- EMBER_TRY_SCENARIO=ember-beta
- EMBER_TRY_SCENARIO=ember-canary
Expand All @@ -22,14 +22,17 @@ matrix:
- env: EMBER_TRY_SCENARIO=ember-canary

before_install:
- export PATH=/usr/local/phantomjs-2.0.0/bin:$PATH
- "npm config set spin false"
- "npm install -g npm@^2"
- npm config set spin false
- npm install -g bower
- bower --version
- npm install phantomjs-prebuilt
- phantomjs --version

install:
- npm install -g bower
- npm install
- bower install

script:
- ember try $EMBER_TRY_SCENARIO test
# Usually, it's ok to finish the test scenario without reverting
# to the addon's original dependency state, skipping "cleanup".
- ember try:one $EMBER_TRY_SCENARIO test --skip-cleanup
13 changes: 10 additions & 3 deletions addon/mixins/reset-scroll.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import Ember from 'ember';
import getOwner from 'ember-getowner-polyfill';
const { $, computed, Mixin } = Ember;

export default Ember.Mixin.create({
export default Mixin.create({
fastboot: computed(function() {
return getOwner(this).lookup('service:fastboot');
}),
/**
* Scroll to top when route is entered.
*/
activate(...args) {
this._super(...args);
Ember.$(window).scrollTop(0);
},
if(!this.get('fastboot') || !this.get('fastboot.isFastBoot')) {
$(window).scrollTop(0);
}
}
});
52 changes: 31 additions & 21 deletions addon/mixins/scroll-operator.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import Ember from 'ember';
import getOwner from 'ember-getowner-polyfill';
const { $, computed, Mixin, run } = Ember;

export default Ember.Mixin.create({
export default Mixin.create({
_scrollingTimeout: 100,

fastboot: computed(function() {
return getOwner(this).lookup('service:fastboot');
}),

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

this._attachEvents();
},

Expand All @@ -18,7 +23,6 @@ export default Ember.Mixin.create({
*/
deactivate(...args) {
this._super(...args);

this._detachEvents();
},

Expand Down Expand Up @@ -49,33 +53,30 @@ export default Ember.Mixin.create({

this._super(...args);

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

_attachEvents() {
const onScroll = () => {
const scrollPosition = Ember.$(window).scrollTop();
Ember.run.debounce(this, this._setScrollTop, scrollPosition, this._scrollingTimeout);
};
Ember.$(document).on('touchmove.scrollable', onScroll);
Ember.$(window).on('scroll.scrollable', onScroll);
if(!this.get('fastboot') || !this.get('fastboot.isFastBoot')) {
const onScroll = () => {
const scrollPosition = $(window).scrollTop();
run.debounce(this, this._setScrollTop, scrollPosition, this._scrollingTimeout);
};
$(document).on('touchmove.scrollable', onScroll);
$(window).on('scroll.scrollable', onScroll);
}
},

_detachEvents() {
Ember.$(document).off('.scrollable');
Ember.$(window).off('.scrollable');
},

/**
* Set currentPosition to $(window).scrollTop value.
*/
_setScrollTop(scrollPosition = 0) {
this.set('controller.currentPosition', scrollPosition);
if(!this.get('fastboot') || !this.get('fastboot.isFastBoot')) {
$(document).off('.scrollable');
$(window).off('.scrollable');
}
},

/**
Expand All @@ -85,4 +86,13 @@ export default Ember.Mixin.create({
_didTransitionViaBackOrForward(transition) {
return transition && transition.sequence > 1 && transition.hasOwnProperty('urlMethod');
},

/**
* Set currentPosition to $(window).scrollTop value.
*/
_setScrollTop(scrollPosition = 0) {
if(!this.get('fastboot') || !this.get('fastboot.isFastBoot')) {
this.set('controller.currentPosition', scrollPosition);
}
}
});
5 changes: 2 additions & 3 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"name": "ember-scroll-operator",
"dependencies": {
"ember": "~2.4.1",
"ember-cli-shims": "0.1.0",
"ember-cli-test-loader": "0.2.2",
"ember": "~2.7.0",
"ember-cli-shims": "0.1.1",
"ember-qunit-notifications": "0.1.0"
}
}
2 changes: 1 addition & 1 deletion config/ember-try.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
}
},
{
name: 'ember-1-13',
name: 'ember-1.13',
bower: {
dependencies: {
'ember': '~1.13.0'
Expand Down
32 changes: 17 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"scripts": {
"build": "ember build",
"start": "ember server",
"test": "ember try:testall"
"test": "ember try:each"
},
"repository": "https://github.com/bttf/ember-scroll-operator",
"engines": {
Expand All @@ -18,26 +18,28 @@
"author": "",
"license": "MIT",
"devDependencies": {
"broccoli-asset-rev": "^2.2.0",
"ember-ajax": "0.7.1",
"ember-cli": "2.4.2",
"broccoli-asset-rev": "^2.4.2",
"ember-ajax": "^2.0.1",
"ember-cli": "2.7.0",
"ember-cli-app-version": "^1.0.0",
"ember-cli-dependency-checker": "^1.2.0",
"ember-cli-htmlbars": "^1.0.1",
"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.3.1",
"ember-cli-qunit": "^1.2.1",
"ember-cli-release": "0.2.8",
"ember-cli-inject-live-reload": "^1.4.0",
"ember-cli-qunit": "^2.0.0",
"ember-cli-release": "^0.2.9",
"ember-cli-sri": "^2.1.0",
"ember-cli-test-loader": "^1.1.0",
"ember-cli-uglify": "^1.2.0",
"ember-data": "^2.4.0",
"ember-data": "^2.7.0",
"ember-disable-prototype-extensions": "^1.1.0",
"ember-disable-proxy-controllers": "^1.0.1",
"ember-export-application-global": "^1.0.4",
"ember-load-initializers": "^0.5.0",
"ember-export-application-global": "^1.0.5",
"ember-getowner-polyfill": "1.0.1",
"ember-load-initializers": "^0.5.1",
"ember-resolver": "^2.0.3",
"ember-try": "^0.1.2",
"loader.js": "^4.0.0"
"loader.js": "^4.0.1"
},
"keywords": [
"ember-addon",
Expand All @@ -46,7 +48,7 @@
"browser history"
],
"dependencies": {
"ember-cli-babel": "^5.1.5"
"ember-cli-babel": "^5.1.6"
},
"ember-addon": {
"configPath": "tests/dummy/config"
Expand Down
3 changes: 3 additions & 0 deletions tests/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: '../node_modules/ember-cli-eslint/coding-standard/ember-testing.js'
};
52 changes: 0 additions & 52 deletions tests/.jshintrc

This file was deleted.

8 changes: 4 additions & 4 deletions tests/dummy/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@

{{content-for "head"}}

<link rel="stylesheet" href="assets/vendor.css">
<link rel="stylesheet" href="assets/dummy.css">
<link rel="stylesheet" href="{{rootURL}}assets/vendor.css">
<link rel="stylesheet" href="{{rootURL}}assets/dummy.css">

{{content-for "head-footer"}}
</head>
<body>
{{content-for "body"}}

<script src="assets/vendor.js"></script>
<script src="assets/dummy.js"></script>
<script src="{{rootURL}}assets/vendor.js"></script>
<script src="{{rootURL}}assets/dummy.js"></script>

{{content-for "body-footer"}}
</body>
Expand Down
3 changes: 2 additions & 1 deletion tests/dummy/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import Ember from 'ember';
import config from './config/environment';

const Router = Ember.Router.extend({
location: config.locationType
location: config.locationType,
rootURL: config.rootURL
});

Router.map(function() {
Expand Down
Loading

0 comments on commit 750c859

Please sign in to comment.