Skip to content

Commit

Permalink
Merge branch 'release/2.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
poteto committed Aug 17, 2015
2 parents 80b86cc + 803beb0 commit 55d07de
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 98 deletions.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ dist/
.npmignore
**/.gitkeep
bower.json
ember-cli-build.js
Brocfile.js
testem.json
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
language: node_js
node_js:
- "0.12"
- "iojs"

sudo: false

Expand Down
16 changes: 0 additions & 16 deletions Brocfile.js

This file was deleted.

64 changes: 17 additions & 47 deletions addon/mixins/in-viewport.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,29 @@ import canUseRAF from 'ember-in-viewport/utils/can-use-raf';
import isInViewport from 'ember-in-viewport/utils/is-in-viewport';
import checkScrollDirection from 'ember-in-viewport/utils/check-scroll-direction';

const get = Ember.get;
const set = Ember.set;

const {
Mixin,
setProperties,
deprecate,
computed,
merge,
typeOf,
assert,
run,
on,
$
$,
get,
set,
run: { scheduleOnce, debounce, bind, next },
computed: { not }
} = Ember;

const {
scheduleOnce,
debounce,
bind,
next
} = run;

const { not } = computed;
const { forEach } = Ember.EnumerableUtils;
const { classify } = Ember.String;

const defaultListeners = [
{ context: window, event: 'scroll.scrollable' },
{ context: window, event: 'resize.resizable' },
{ context: document, event: 'touchmove.scrollable' }
];

const rAFIDS = {};
const lastDirection = {};
const lastPosition = {};

export default Ember.Mixin.create({
export default Mixin.create({
viewportExited: not('viewportEntered').readOnly(),

_setInitialState: on('init', function() {
Expand All @@ -64,15 +50,14 @@ export default Ember.Mixin.create({
return;
}

this._deprecateOldTriggers();
this._setInitialViewport(window);
this._addObserverIfNotSpying();
this._bindScrollDirectionListener(window, get(this, 'viewportScrollSensitivity'));

const listeners = get(this, 'viewportListeners');

if (!get(this, 'viewportUseRAF')) {
forEach(listeners, (listener) => {
listeners.forEach((listener) => {
const { context, event } = listener;
this._bindListeners(context, event);
});
Expand Down Expand Up @@ -121,31 +106,30 @@ export default Ember.Mixin.create({
assert('You must pass a valid context element to _triggerDidScrollDirection', $contextEl);
assert('sensitivity cannot be 0', sensitivity);

const elementId = get(this, 'elementId');
const viewportEntered = get(this, 'viewportEntered');
const elementId = get(this, 'elementId');
const viewportEntered = get(this, 'viewportEntered');
const lastDirectionForEl = lastDirection[elementId];
const lastPositionForEl = lastPosition[elementId];
const lastPositionForEl = lastPosition[elementId];
const newPosition = {
top: $contextEl.scrollTop(),
left: $contextEl.scrollLeft()
};

const scrollDirection = checkScrollDirection(lastPositionForEl, newPosition, sensitivity);
const scrollDirection = checkScrollDirection(lastPositionForEl, newPosition, sensitivity);
const directionChanged = scrollDirection !== lastDirectionForEl;

if (scrollDirection && directionChanged && viewportEntered) {
this.trigger('didScroll', scrollDirection);
this.trigger(`didScroll${classify(scrollDirection)}`, scrollDirection);
lastDirection[elementId] = scrollDirection;
}

lastPosition[elementId] = newPosition;
},

_triggerDidAccessViewport(hasEnteredViewport = false) {
const viewportEntered = get(this, 'viewportEntered');
const didEnter = !viewportEntered && hasEnteredViewport;
const didLeave = viewportEntered && !hasEnteredViewport;
const viewportEntered = get(this, 'viewportEntered');
const didEnter = !viewportEntered && hasEnteredViewport;
const didLeave = viewportEntered && !hasEnteredViewport;
let triggeredEventName = '';

if (didEnter) {
Expand Down Expand Up @@ -179,8 +163,7 @@ export default Ember.Mixin.create({

_debouncedEventHandler(methodName, ...args) {
assert('You must pass a methodName to _debouncedEventHandler', methodName);
const validMethodString = typeOf(methodName) === 'string';
assert('methodName must be a string', validMethodString);
assert('methodName must be a string', typeOf(methodName) === 'string');

debounce(this, () => {
this[methodName](...args);
Expand Down Expand Up @@ -228,24 +211,11 @@ export default Ember.Mixin.create({
});
}

forEach(listeners, (listener) => {
listeners.forEach((listener) => {
const { context, event } = listener;
$(context).off(`${event}.${elementId}`);
});

this._unbindScrollDirectionListener(window);
},

_deprecateOldTriggers() {
const directions = [ 'Up', 'Down', 'Left', 'Right' ];

forEach(directions, (direction) => {
const triggerName = `didScroll${direction}`;
const isListening = this.has(triggerName);
deprecate(
`[ember-in-viewport] ${triggerName} is deprecated, please use \`didScroll(direction)\` instead.`,
!isListening
);
});
}
});
14 changes: 7 additions & 7 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "ember-in-viewport",
"dependencies": {
"ember": "1.12.0",
"ember": "1.13.7",
"ember-cli-shims": "ember-cli/ember-cli-shims#0.0.3",
"ember-cli-test-loader": "ember-cli-test-loader#0.1.3",
"ember-load-initializers": "ember-cli/ember-load-initializers#0.1.4",
"ember-qunit": "0.3.3",
"ember-load-initializers": "ember-cli/ember-load-initializers#0.1.5",
"ember-qunit": "0.4.9",
"ember-qunit-notifications": "0.0.7",
"ember-resolver": "~0.1.15",
"jquery": "^1.11.1",
"loader.js": "ember-cli/loader.js#3.2.0",
"qunit": "~1.17.1"
"ember-resolver": "~0.1.18",
"jquery": "^1.11.3",
"loader.js": "ember-cli/loader.js#3.2.1",
"qunit": "~1.18.0"
}
}
17 changes: 17 additions & 0 deletions ember-cli-build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* global require, module */
var EmberApp = require('ember-cli/lib/broccoli/ember-addon');

module.exports = function(defaults) {
var app = new EmberApp(defaults, {
// Add options here
});

/*
This build file specifes the options for the dummy test app of this
addon, located in `/tests/dummy`
This build file does *not* influence how the addon or the app using it
behave. You most likely want to be modifying `./index.js` or app's build file
*/

return app.toTree();
};
29 changes: 16 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ember-in-viewport",
"version": "1.2.5",
"version": "2.0.0",
"description": "Detect if an Ember View or Component is in the viewport @ 60FPS",
"directories": {
"doc": "doc",
Expand All @@ -18,20 +18,23 @@
"author": "Lauren Tan",
"license": "MIT",
"devDependencies": {
"broccoli-asset-rev": "^2.0.2",
"ember-cli": "^0.2.7",
"ember-cli-app-version": "0.3.3",
"broccoli-asset-rev": "^2.1.2",
"ember-cli": "1.13.8",
"ember-cli-app-version": "0.5.0",
"ember-cli-content-security-policy": "0.4.0",
"ember-cli-dependency-checker": "^1.0.0",
"ember-cli-htmlbars": "0.7.6",
"ember-cli-ic-ajax": "0.1.1",
"ember-cli-inject-live-reload": "^1.3.0",
"ember-cli-qunit": "0.3.13",
"ember-cli-uglify": "^1.0.1",
"ember-cli-dependency-checker": "^1.0.1",
"ember-cli-htmlbars": "0.7.9",
"ember-cli-htmlbars-inline-precompile": "^0.2.0",
"ember-cli-ic-ajax": "0.2.1",
"ember-cli-inject-live-reload": "^1.3.1",
"ember-cli-qunit": "^1.0.0",
"ember-cli-release": "0.2.3",
"ember-cli-sri": "^1.0.3",
"ember-cli-uglify": "^1.2.0",
"ember-disable-prototype-extensions": "^1.0.0",
"ember-disable-proxy-controllers": "^1.0.0",
"ember-export-application-global": "^1.0.2",
"ember-suave": "0.1.9",
"ember-export-application-global": "^1.0.3",
"ember-suave": "1.0.0",
"ember-try": "0.0.6"
},
"keywords": [
Expand All @@ -44,7 +47,7 @@
"scrollspy"
],
"dependencies": {
"ember-cli-babel": "^5.0.0"
"ember-cli-babel": "^5.1.3"
},
"ember-addon": {
"configPath": "tests/dummy/config",
Expand Down
5 changes: 3 additions & 2 deletions tests/.jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"node": false,
"browser": false,
"boss": true,
"curly": false,
"curly": true,
"debug": false,
"devel": false,
"eqeqeq": true,
Expand All @@ -47,5 +47,6 @@
"strict": false,
"white": false,
"eqnull": true,
"esnext": true
"esnext": true,
"unused": true
}
7 changes: 1 addition & 6 deletions tests/acceptance/integration-test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import Ember from 'ember';
import {
module,
test,
skip
test
} from 'qunit';
import startApp from '../helpers/start-app';
import { lookupComponent } from '../helpers/utils/lookup';

let application;
const { run } = Ember;

module('Acceptance: Integration', {
beforeEach() {
Expand All @@ -25,8 +22,6 @@ test('Component is active when in viewport', function(assert) {
visit('/');

andThen(() => {
const component = lookupComponent(application, 'foo-bar');

assert.ok(find('.fooBar.active').length);
});
});
1 change: 0 additions & 1 deletion tests/helpers/start-app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Ember from 'ember';
import Application from '../../app';
import Router from '../../router';
import config from '../../config/environment';

export default function startApp(attrs) {
Expand Down
7 changes: 2 additions & 5 deletions tests/unit/utils/check-scroll-direction-test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import Ember from 'ember';
import checkScrollDirection from 'ember-in-viewport/utils/check-scroll-direction';
import { module, test } from 'qunit';

let lastPosition;

const { forEach } = Ember.EnumerableUtils;

module('checkScrollDirection', {
beforeEach() {
lastPosition = {
Expand All @@ -25,7 +22,7 @@ test('returns the right direction', function(assert) {

assert.expect(movements.length);

forEach(movements, (movement) => {
movements.forEach((movement) => {
const { direction, position } = movement;
const scrollDirection = checkScrollDirection(lastPosition, position);

Expand All @@ -42,7 +39,7 @@ test('adjusts for sensitivity', function(assert) {

assert.expect(movements.length);

forEach(movements, (movement) => {
movements.forEach((movement) => {
const { direction, position } = movement;
const scrollDirection = checkScrollDirection(lastPosition, position, 100);

Expand Down

0 comments on commit 55d07de

Please sign in to comment.