diff --git a/src/PointerEvent.js b/src/PointerEvent.js index ed296aba..833536b5 100644 --- a/src/PointerEvent.js +++ b/src/PointerEvent.js @@ -86,8 +86,10 @@ // is to call initMouseEvent with a buttonArg value of -1. // // This is fixed with DOM Level 4's use of buttons - var buttons = inDict.buttons; - if (buttons === undefined) { + var buttons; + if (inDict.buttons || HAS_BUTTONS) { + buttons = inDict.buttons; + } else { switch (inDict.which) { case 1: buttons = 1; break; case 2: buttons = 4; break; diff --git a/src/dispatcher.js b/src/dispatcher.js index 5a4deba7..5b6acbad 100644 --- a/src/dispatcher.js +++ b/src/dispatcher.js @@ -57,7 +57,7 @@ 0, null, // DOM Level 3 - undefined, + 0, // PointerEvent 0, 0, diff --git a/tests/constructor.js b/tests/constructor.js index 90df1a0a..1c29ac5d 100644 --- a/tests/constructor.js +++ b/tests/constructor.js @@ -6,7 +6,7 @@ suite('Constructor', function() { test('PointerEvent extends MouseEvent', function() { - var p = new PointerEvent; + var p = new PointerEvent(); expect(p).to.be.an.instanceof(MouseEvent); }); @@ -63,7 +63,7 @@ suite('Constructor', function() { 'hwTimestamp', 'isPrimary' ]; - var p = new PointerEvent; + var p = new PointerEvent(); var v; props.forEach(function(k) { v = p[k]; @@ -71,4 +71,19 @@ suite('Constructor', function() { expect(p[k]).to.equal(v); }); }); + + test('Button properties are used for pressure', function() { + var p = new PointerEvent('foo', {buttons: 1}); + expect(p.pressure).to.equal(0.5); + // test for buttons property + var m = document.createEvent('MouseEvent'); + m.initEvent('test', false, false, null, null, 0, 0, 0, 0, false, false, false, false, 0, null); + // only run this test if .buttons is not supported + if (m.buttons === undefined) { + p = new PointerEvent('baz', {button: 0, which: 1}); + expect(p.pressure).to.equal(0.5); + } + p = new PointerEvent('bar'); + expect(p.pressure).to.equal(0); + }); });