Skip to content

Commit

Permalink
Merge pull request #20 from yahoo/v1
Browse files Browse the repository at this point in the history
V1
  • Loading branch information
hankhsiao committed Nov 24, 2015
2 parents a0b23b8 + 3bcc286 commit f2f5386
Show file tree
Hide file tree
Showing 21 changed files with 503 additions and 603 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ tmp/
dist/
*.log
*.tap
tests/functional/css
tests/functional/bundle.js
tests/functional/subscribe-functional.js
5 changes: 0 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
sudo: false
language: node_js
matrix:
allow_failures:
- node_js: "0.13"
node_js:
- "iojs"
- "0.13"
- "0.12"
after_success:
- "npm run func"
Expand Down
1 change: 1 addition & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ module.exports = function (grunt) {
{
expand: true,
src: [
'<%= project.unit %>/../lib/**/*.*',
'<%= project.unit %>/**/*.*'
],
dest: '<%= project.tmp %>',
Expand Down
13 changes: 2 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ npm install subscribe-ui-event
Subscription subscribe(String eventType, Function callback, Object? options)
```
Provide throttled version of window or document events, such like `scroll`, `resize` and `visibilitychange` to subscribe. It also provides some higher, compound events, such like `viewportchange`, which combines `scroll`, `resize` and `visibilitychange` events.
Provide throttled version of window or document events, such like `scroll`, `resize` and `visibilitychange` to subscribe.
**Note on IE8 or the below, the throttle will be turned off because the event object is global and will be deleted for setTimeout or rAF.**
Expand Down Expand Up @@ -102,16 +102,7 @@ The format of the payload is:
4. resize - window.resize
5. resizeStart - The start window.resize
6. resizeEnd - The end window.resize
7. visibilitychange - document.visibilitychange
8. viewportchange - scroll + resize + visibilitychange
### unsubscribe
```js
Void unsubscribe(String eventType, Function callback)
```
Unsubscribe an event. **Note that all subscriptions with the same eventHandler and the same event type will be unsubscribed together even if they have different options**.
7. visibilitychange - document.visibilitychange (IE8 doesn't support)
## License
Expand Down
6 changes: 2 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ function warn() {

if (typeof window !== 'undefined') {
module.exports = {
subscribe: require('./dist/subscribe'),
unsubscribe: require('./dist/unsubscribe')
subscribe: require('./dist/subscribe')
};
} else {
module.exports = {
subscribe: warn,
unsubscribe: warn
subscribe: warn
};
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "subscribe-ui-event",
"version": "0.2.10",
"version": "1.0.0",
"description": "A single, throttle built-in solution to subscribe to browser UI Events.",
"main": "index.js",
"scripts": {
Expand All @@ -25,6 +25,7 @@
"dependencies": {
"eventemitter3": "^1.1.0",
"lodash.throttle": "^3.0.3",
"lodash.clone": "^3.0.3",
"raf": "^3.0.0"
},
"devDependencies": {
Expand All @@ -45,11 +46,11 @@
"grunt-webpack": "^1.0.8",
"grunt": "^0.4.5",
"istanbul": "^0.3.0",
"jsdom": "^6.0.0",
"jshint": "^2.5.1",
"minimist": "^1.0.0",
"mocha": "^2.0",
"mockery": "^1.4.0",
"node-jsdom": "^3.0.0",
"pre-commit": "^1.0.0",
"react": "^0.14.0",
"react-dom": "^0.14.0",
Expand Down
44 changes: 40 additions & 4 deletions src/AugmentedEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,28 @@
*/
'use strict';

var scroll = {
delta: 0,
top: 0
};
var globalVars = require('./globalVars');
var resize = {
width: 0,
height: 0
};
var scroll = {
delta: 0,
top: 0
};

// global variables
var doc;
var docBody;
var docEl;
var win;

if (typeof window !== 'undefined') {
win = window;
doc = win.document || document;
docEl = doc.documentElement;
docBody = doc.body;
}

/**
* ArgmentedEvent will hold some global information, such like window scroll postion,
Expand All @@ -25,4 +39,26 @@ function ArgmentedEvent(option) {
this.resize = resize;
}

ArgmentedEvent.prototype = {
update: function update (mainType) {
var top;

if (globalVars.enableScrollInfo &&
(mainType === 'scroll' || mainType === 'touchmove')
) {
top = docEl.scrollTop + docBody.scrollTop;
// Prevent delta from being 0
if (top !== this.scroll.top) {
this.scroll.delta = top - this.scroll.top;
this.scroll.top = top;
console.log(top);
}
}
if (globalVars.enableResizeInfo && mainType === 'resize') {
this.resize.width = win.innerWidth || docEl.clientWidth;
this.resize.height = win.innerHeight || docEl.clientHeight;
}
}
};

module.exports = ArgmentedEvent;
10 changes: 10 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Copyright 2015, Yahoo! Inc.
* Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
*/
'use strict';

module.exports = {
EVENT_END_DELAY: 200,
DEFAULT_THROTTLE_RATE: 50
};
224 changes: 0 additions & 224 deletions src/eventHandlers/index.js

This file was deleted.

Loading

0 comments on commit f2f5386

Please sign in to comment.