subscribe-ui-event
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -7,2 +7,11 @@ /** | ||
var scroll = { | ||
delta: 0, | ||
top: 0 | ||
}; | ||
var resize = { | ||
width: 0, | ||
height: 0 | ||
}; | ||
/** | ||
@@ -16,12 +25,6 @@ * ArgmentedEvent will hold some global information, such like window scroll postion, | ||
this.type = option.type || ''; | ||
this.scroll = { | ||
delta: 0, | ||
top: 0 | ||
}; | ||
this.resize = { | ||
width: 0, | ||
height: 0 | ||
}; | ||
this.scroll = scroll; | ||
this.resize = resize; | ||
} | ||
module.exports = ArgmentedEvent; |
@@ -10,11 +10,16 @@ /** | ||
var AugmentedEvent = require('../AugmentedEvent'); | ||
var ee = require('../eventEmitter').eventEmitter; | ||
var leIE8 = require('../lib/leIE8'); | ||
// constants | ||
var EVENT_END_DELAY = 200; | ||
// global variables | ||
var doc; | ||
var docBody; | ||
var docEl; | ||
var ee = require('../eventEmitter').eventEmitter; | ||
var leIE8 = require('../lib/leIE8'); | ||
var enableResizeInfo = false; | ||
var enableScrollInfo = false; | ||
var win; | ||
var EVENT_END_DELAY = 200; | ||
if (typeof window !== 'undefined' && typeof document !== 'undefined') { | ||
@@ -46,2 +51,19 @@ win = window; | ||
/** | ||
* Update global scroll/resize info | ||
* @param {Object} ae - The additional event object | ||
* @param {String} eventType - The event type | ||
*/ | ||
function updateAdditionalInfo(ae, eventType) { | ||
var top; | ||
if (eventType === 'scroll' && enableScrollInfo) { | ||
top = docEl.scrollTop + docBody.scrollTop; | ||
ae.scroll.delta = top - ae.scroll.top; | ||
ae.scroll.top = top; | ||
} else if (eventType === 'resize' && enableResizeInfo) { | ||
ae.resize.width = win.innerWidth || docEl.clientWidth; | ||
ae.resize.height = win.innerHeight || docEl.clientHeight; | ||
} | ||
} | ||
/** | ||
* Cross-browser addEventListener. | ||
@@ -88,3 +110,3 @@ * @method listen | ||
var throttle = options.throttleFunc; | ||
var augmentedEvent = new AugmentedEvent({type: eventType + (eventStart ? 'Start' : 'End')}); | ||
var ae = new AugmentedEvent({type: eventType + (eventStart ? 'Start' : 'End')}); | ||
var timer; | ||
@@ -94,3 +116,4 @@ | ||
if (!eventStart) { | ||
ee.emit(eeType, e, augmentedEvent); | ||
updateAdditionalInfo(ae, eventType); | ||
ee.emit(eeType, e, ae); | ||
} | ||
@@ -103,3 +126,4 @@ timer = null; | ||
if (eventStart) { | ||
ee.emit(eeType, e, augmentedEvent); | ||
updateAdditionalInfo(ae, eventType); | ||
ee.emit(eeType, e, ae); | ||
} | ||
@@ -136,5 +160,2 @@ } | ||
function generateContinuousEventHandler(target, eventType, noThrottle) { | ||
var enableScrollInfo = false; | ||
var enableResizeInfo = false; | ||
return function(eeType, options) { | ||
@@ -147,3 +168,3 @@ if (ee.listeners(eeType, true)) { | ||
var throttle = options.throttleFunc; | ||
var augmentedEvent = new AugmentedEvent({type: eventType}); | ||
var ae = new AugmentedEvent({type: eventType}); | ||
enableScrollInfo = enableScrollInfo || options.enableScrollInfo; | ||
@@ -153,13 +174,3 @@ enableResizeInfo = enableResizeInfo || options.enableResizeInfo; | ||
function eventHandler(e) { | ||
var ae = augmentedEvent; | ||
var top; | ||
if (enableScrollInfo && ae.type === 'scroll') { | ||
top = docEl.scrollTop + docBody.scrollTop; | ||
ae.scroll.delta = top - ae.scroll.top; | ||
ae.scroll.top = top; | ||
} | ||
if (enableResizeInfo && ae.type === 'resize') { | ||
ae.resize.width = win.innerWidth || docEl.clientWidth; | ||
ae.resize.height = win.innerHeight || docEl.clientHeight; | ||
} | ||
updateAdditionalInfo(ae, eventType); | ||
ee.emit(eeType, e, ae); | ||
@@ -180,5 +191,5 @@ } | ||
var throttle = options.throttleFunc; | ||
var augmentedEvent = new AugmentedEvent({type: 'viewportchange'}); | ||
var ae = new AugmentedEvent({type: 'viewportchange'}); | ||
function eventHandler(e) { | ||
ee.emit(eeType, e, augmentedEvent); | ||
ee.emit(eeType, e, ae); | ||
} | ||
@@ -185,0 +196,0 @@ |
{ | ||
"name": "subscribe-ui-event", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "A single, throttle built-in solution to subscribe to browser UI Events.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
47077
1038