Skip to content

Commit

Permalink
Merge branch 'release/2.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
poteto committed Oct 13, 2015
2 parents c9a5134 + 0e99221 commit b4115db
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 27 deletions.
14 changes: 2 additions & 12 deletions addon/mixins/in-viewport.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,9 @@ const {
run: { scheduleOnce, debounce, bind, next },
computed: { not }
} = Ember;
const defaultListeners = [
{ context: window, event: 'scroll.scrollable' },
{ context: window, event: 'resize.resizable' },
{ context: document, event: 'touchmove.scrollable' }
];
const rAFIDS = {};
const lastDirection = {};
const lastPosition = {};
const lastPosition = {};

export default Mixin.create({
viewportExited: not('viewportEntered').readOnly(),
Expand All @@ -32,8 +27,7 @@ export default Mixin.create({
this._super(...arguments);
const options = merge({
viewportUseRAF: canUseRAF(),
viewportEntered: false,
viewportListeners: defaultListeners
viewportEntered: false
}, this._buildOptions());

setProperties(this, options);
Expand Down Expand Up @@ -132,10 +126,6 @@ export default Mixin.create({
const didLeave = viewportEntered && !hasEnteredViewport;
let triggeredEventName = '';

if (!didEnter && !didLeave) {
return;
}

if (didEnter) {
triggeredEventName = 'didEnterViewport';
}
Expand Down
8 changes: 4 additions & 4 deletions addon/utils/check-scroll-direction.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import Ember from 'ember';

const { assert } = Ember;
const { floor } = Math;

export default function checkScrollDirection(lastPosition = null, newPosition = {}, sensitivity = 1) {
if (!lastPosition) {
return 'none';
}

Ember.assert('sensitivity cannot be 0', sensitivity);
assert('sensitivity cannot be 0', sensitivity);

const { top, left } = newPosition;
const { top: lastTop, left: lastLeft } = lastPosition;
Expand All @@ -17,11 +18,11 @@ export default function checkScrollDirection(lastPosition = null, newPosition =
left: floor((left - lastLeft) / sensitivity) * sensitivity
};

if (delta.top > 0) {
if (delta.top > 0) {
return 'down';
}

if (delta.top < 0) {
if (delta.top < 0) {
return 'up';
}

Expand All @@ -32,5 +33,4 @@ export default function checkScrollDirection(lastPosition = null, newPosition =
if (delta.left < 0) {
return 'left';
}

}
24 changes: 14 additions & 10 deletions app/initializers/viewport-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,27 @@ import Ember from 'ember';
import config from '../config/environment';

const defaultConfig = {
viewportSpy : false,
viewportScrollSensitivity : 1,
viewportRefreshRate : 100,
viewportListeners : [],
viewportSpy: false,
viewportScrollSensitivity: 1,
viewportRefreshRate: 100,
viewportListeners: [
{ context: window, event: 'scroll.scrollable' },
{ context: window, event: 'resize.resizable' },
{ context: document, event: 'touchmove.scrollable' }
],
viewportTolerance: {
top : 0,
left : 0,
bottom : 0,
right : 0
top: 0,
left: 0,
bottom: 0,
right: 0
}
};

const { merge } = Ember;

export function initialize(_container, application) {
export function initialize() {
const application = arguments[1] || arguments[0];
const { viewportConfig = {} } = config;

const mergedConfig = merge(defaultConfig, viewportConfig);

application.register('config:in-viewport', mergedConfig, { instantiate: false });
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ember-in-viewport",
"version": "2.0.1",
"version": "2.0.2",
"description": "Detect if an Ember View or Component is in the viewport @ 60FPS",
"directories": {
"doc": "doc",
Expand Down

0 comments on commit b4115db

Please sign in to comment.