diff --git a/src/PointerEvent.js b/src/PointerEvent.js index f1896c99..79d9eeb8 100644 --- a/src/PointerEvent.js +++ b/src/PointerEvent.js @@ -29,6 +29,40 @@ } catch(e) { } + var MOUSE_PROPS = [ + 'bubbles', + 'cancelable', + 'view', + 'detail', + 'screenX', + 'screenY', + 'clientX', + 'clientY', + 'ctrlKey', + 'altKey', + 'shiftKey', + 'metaKey', + 'button', + 'relatedTarget', + ]; + + var MOUSE_DEFAULTS = [ + false, + false, + null, + null, + 0, + 0, + 0, + 0, + false, + false, + false, + false, + 0, + null + ]; + function PointerEvent(inType, inDict) { inDict = inDict || {}; // According to the w3c spec, @@ -67,29 +101,13 @@ e = new MouseEvent(inType, inDict); } else { e = document.createEvent('MouseEvent'); - // import values from the given dictionary - var props = { - bubbles: false, - cancelable: false, - view: null, - detail: null, - screenX: 0, - screenY: 0, - clientX: 0, - clientY: 0, - ctrlKey: false, - altKey: false, - shiftKey: false, - metaKey: false, - button: 0, - relatedTarget: null - }; - Object.keys(props).forEach(function(k) { - if (k in inDict) { - props[k] = inDict[k]; - } - }); + // import values from the given dictionary + var props = {}, p; + for(var i = 0; i < MOUSE_PROPS.length; i++) { + p = MOUSE_PROPS[i]; + props[p] = inDict[p] || MOUSE_DEFAULTS[i]; + } // define the properties inherited from MouseEvent e.initMouseEvent( diff --git a/src/dispatcher.js b/src/dispatcher.js index d80608a5..442f51a3 100644 --- a/src/dispatcher.js +++ b/src/dispatcher.js @@ -5,6 +5,73 @@ */ (function(scope) { + var CLONE_PROPS = [ + // MouseEvent + 'bubbles', + 'cancelable', + 'view', + 'detail', + 'screenX', + 'screenY', + 'clientX', + 'clientY', + 'ctrlKey', + 'altKey', + 'shiftKey', + 'metaKey', + 'button', + 'relatedTarget', + // DOM Level 3 + 'buttons', + // PointerEvent + 'pointerId', + 'width', + 'height', + 'pressure', + 'tiltX', + 'tiltY', + 'pointerType', + 'hwTimestamp', + 'isPrimary', + // event instance + 'type', + 'target', + 'currentTarget' + ]; + + var CLONE_DEFAULTS = [ + // MouseEvent + false, + false, + null, + null, + 0, + 0, + 0, + 0, + false, + false, + false, + false, + 0, + null, + // DOM Level 3 + 0, + // PointerEvent + 0, + 0, + 0, + 0, + 0, + 0, + '', + 0, + false, + // event instance + '', + null, + null + ]; /** * This module is for normalizing events. Mouse and Touch events will be @@ -19,9 +86,9 @@ * - pointercancel: a pointer will no longer generate events */ var dispatcher = { - targets: new SideTable, - handledEvents: new SideTable, - pointermap: new scope.PointerMap, + targets: new SideTable(), + handledEvents: new SideTable(), + pointermap: new scope.PointerMap(), eventMap: {}, // Scope objects for native events. // This exists for ease of testing. @@ -163,9 +230,10 @@ * properties. */ cloneEvent: function(inEvent) { - var eventCopy = {}; - for (var n in inEvent) { - eventCopy[n] = inEvent[n]; + var eventCopy = {}, p; + for (var i = 0; i < CLONE_PROPS.length; i++) { + p = CLONE_PROPS[i]; + eventCopy[p] = inEvent[p] || CLONE_DEFAULTS[i]; } return eventCopy; },