Skip to content

Commit

Permalink
Merge branch 'release/1.2.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
poteto committed Jun 1, 2015
2 parents cd59c95 + 09f4145 commit 01ed226
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 61 deletions.
3 changes: 3 additions & 0 deletions .watchmanconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"ignore_dirs": ["tmp"]
}
21 changes: 8 additions & 13 deletions Brocfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,14 @@

var EmberAddon = require('ember-cli/lib/broccoli/ember-addon');

var app = new EmberAddon();
/*
This Brocfile specifes the options for the dummy test app of this
addon, located in `/tests/dummy`
This Brocfile does *not* influence how the addon or the app using it
behave. You most likely want to be modifying `./index.js` or app's Brocfile
*/

// Use `app.import` to add additional libraries to the generated
// output files.
//
// If you need to use different assets in different
// environments, specify an object as the first parameter. That
// object's keys should be the environment name and the values
// should be the asset to use in that environment.
//
// If the library that you are including contains AMD or ES6
// modules that you would like to import into your application
// please specify an object with the list of modules as keys
// along with the exports of each module as its value.
var app = new EmberAddon();

module.exports = app.toTree();
22 changes: 5 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,13 @@ export default Ember.Component.extend(InViewportMixin, {
});
```

##### `didScroll{Up,Down,Left,Right}`
The appropriate scroll hook fires when an element enters the viewport. For example, if you scrolled down in order to move the element in the viewport, the `didScrollDown` hook would fire. You can then handle it like another hook as in the above example. Optionally, you can also receive the direction as a string by passing a single argument to the hook.
##### `didScroll(up,down,left,right)`
The `didScroll` hook fires when an element enters the viewport. For example, if you scrolled down in order to move the element in the viewport, the `didScroll` hook would fire and also receieve the direction as a string. You can then handle it like another hook as in the above example.

```js
export default Ember.Component.extend(InViewportMixin, {
didScrollUp(direction) {
console.log(direction); // 'up'
},

didScrollDown(direction) {
console.log(direction); // 'down'
},

didScrollLeft(direction) {
console.log(direction); // 'left'
},

didScrollRight(direction) {
console.log(direction); // 'right'
didScroll(direction) {
console.log(direction); // 'up' || 'down' || 'left' || 'right'
}
});
```
Expand Down Expand Up @@ -178,7 +166,7 @@ For more information on using ember-cli, visit [http://www.ember-cli.com/](http:

## Legal

[DockYard](http://dockyard.com), Inc © 2015
[DockYard](http://dockyard.com/ember-consulting), Inc © 2015

[@dockyard](http://twitter.com/dockyard)

Expand Down
65 changes: 41 additions & 24 deletions addon/mixins/in-viewport.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ const set = Ember.set;

const {
setProperties,
deprecate,
computed,
merge,
typeOf,
assert,
run,
on,
$
Expand All @@ -24,17 +26,17 @@ const {
next
} = run;

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

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

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

Expand Down Expand Up @@ -62,6 +64,7 @@ export default Ember.Mixin.create({
return;
}

this._deprecateOldTriggers();
this._setInitialViewport(window);
this._addObserverIfNotSpying();
this._bindScrollDirectionListener(window, get(this, 'viewportScrollSensitivity'));
Expand All @@ -87,20 +90,20 @@ export default Ember.Mixin.create({
},

_setViewportEntered(context = null) {
Ember.assert('You must pass a valid context to _setViewportEntered', context);
assert('You must pass a valid context to _setViewportEntered', context);

const element = get(this, 'element');

if (!element) {
return;
}

const elementId = get(this, 'elementId');
const viewportUseRAF = get(this, 'viewportUseRAF');
const viewportTolerance = get(this, 'viewportTolerance');
const $contextEl = $(context);
const height = $contextEl.height();
const width = $contextEl.width();
const elementId = get(this, 'elementId');
const viewportUseRAF = get(this, 'viewportUseRAF');
const viewportTolerance = get(this, 'viewportTolerance');
const $contextEl = $(context);
const height = $contextEl.height();
const width = $contextEl.width();
const boundingClientRect = element.getBoundingClientRect();

this._triggerDidAccessViewport(
Expand All @@ -115,8 +118,8 @@ export default Ember.Mixin.create({
},

_triggerDidScrollDirection($contextEl = null, sensitivity = 1) {
Ember.assert('You must pass a valid context element to _triggerDidScrollDirection', $contextEl);
Ember.assert('sensitivity cannot be 0', sensitivity);
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');
Expand All @@ -131,6 +134,7 @@ export default Ember.Mixin.create({
const directionChanged = scrollDirection !== lastDirectionForEl;

if (scrollDirection && directionChanged && viewportEntered) {
this.trigger('didScroll', scrollDirection);
this.trigger(`didScroll${classify(scrollDirection)}`, scrollDirection);
lastDirection[elementId] = scrollDirection;
}
Expand Down Expand Up @@ -166,26 +170,26 @@ export default Ember.Mixin.create({
},

_setInitialViewport(context = null) {
Ember.assert('You must pass a valid context to _setInitialViewport', context);
assert('You must pass a valid context to _setInitialViewport', context);

return scheduleOnce('afterRender', this, () => {
this._setViewportEntered(context);
});
},

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

debounce(this, () => {
this[methodName](...args);
}, get(this, 'viewportRefreshRate'));
},

_bindScrollDirectionListener(context = null, sensitivity = 1) {
Ember.assert('You must pass a valid context to _bindScrollDirectionListener', context);
Ember.assert('sensitivity cannot be 0', sensitivity);
assert('You must pass a valid context to _bindScrollDirectionListener', context);
assert('sensitivity cannot be 0', sensitivity);

const $contextEl = $(context);

Expand All @@ -195,7 +199,7 @@ export default Ember.Mixin.create({
},

_unbindScrollDirectionListener(context = null) {
Ember.assert('You must pass a valid context to _bindScrollDirectionListener', context);
assert('You must pass a valid context to _bindScrollDirectionListener', context);

const elementId = get(this, 'elementId');

Expand All @@ -205,10 +209,10 @@ export default Ember.Mixin.create({
},

_bindListeners(context = null, event = null) {
Ember.assert('You must pass a valid context to _bindListeners', context);
Ember.assert('You must pass a valid event to _bindListeners', event);
assert('You must pass a valid context to _bindListeners', context);
assert('You must pass a valid event to _bindListeners', event);

$(context).on(`${event}#${get(this, 'elementId')}`, () => {
$(context).on(`${event}.${get(this, 'elementId')}`, () => {
this._debouncedEventHandler('_setViewportEntered', context);
});
},
Expand All @@ -226,9 +230,22 @@ export default Ember.Mixin.create({

forEach(listeners, (listener) => {
const { context, event } = listener;
$(context).off(`${event}#${elementId}`);
$(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
);
});
}
});
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,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.2",
"ember-qunit": "0.3.3",
"ember-qunit-notifications": "0.0.7",
"ember-resolver": "~0.1.15",
"jquery": "^1.11.1",
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ember-in-viewport",
"version": "1.2.3",
"version": "1.2.4",
"description": "Detect if an Ember View or Component is in the viewport @ 60FPS",
"directories": {
"doc": "doc",
Expand All @@ -19,17 +19,17 @@
"license": "MIT",
"devDependencies": {
"broccoli-asset-rev": "^2.0.2",
"ember-cli": "0.2.4",
"ember-cli": "0.2.6",
"ember-cli-app-version": "0.3.3",
"ember-cli-content-security-policy": "0.4.0",
"ember-cli-dependency-checker": "1.0.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.12",
"ember-cli-uglify": "1.0.1",
"ember-cli-qunit": "0.3.13",
"ember-cli-uglify": "^1.0.1",
"ember-disable-prototype-extensions": "^1.0.0",
"ember-disable-proxy-controllers": "^0.7.0",
"ember-disable-proxy-controllers": "^1.0.0",
"ember-export-application-global": "^1.0.2",
"ember-suave": "0.1.9",
"ember-try": "0.0.4"
Expand Down

0 comments on commit 01ed226

Please sign in to comment.