diff options
author | Valerio Virgillito | 2012-02-16 22:08:04 -0800 |
---|---|---|
committer | Valerio Virgillito | 2012-02-16 22:08:04 -0800 |
commit | 0175cb67e426a27a3ecfb7b81317caa383c8a5a5 (patch) | |
tree | b4fbfcaabaadff508ad5463e8f71fd643995aacb /node_modules/montage/ui/scrollview.reel | |
parent | fe71cb9aa1700199c0089166ad54fc56eb760644 (diff) | |
parent | 9f0c4efe2ed9a00f2c5d85c9d88a8040fedb5d8f (diff) | |
download | ninja-0175cb67e426a27a3ecfb7b81317caa383c8a5a5.tar.gz |
Merge branch 'refs/heads/master' into components
Diffstat (limited to 'node_modules/montage/ui/scrollview.reel')
-rwxr-xr-x | node_modules/montage/ui/scrollview.reel/scrollview.js | 43 |
1 files changed, 33 insertions, 10 deletions
diff --git a/node_modules/montage/ui/scrollview.reel/scrollview.js b/node_modules/montage/ui/scrollview.reel/scrollview.js index 389b1858..3ac195e8 100755 --- a/node_modules/montage/ui/scrollview.reel/scrollview.js +++ b/node_modules/montage/ui/scrollview.reel/scrollview.js | |||
@@ -20,6 +20,19 @@ var Scrollview = exports.Scrollview = Montage.create(Component, /** @lends modul | |||
20 | enumerable: false, | 20 | enumerable: false, |
21 | value: false | 21 | value: false |
22 | }, | 22 | }, |
23 | |||
24 | /** | ||
25 | These elements perform some native action when clicked/touched and so we | ||
26 | should not preventDefault when a mousedown/touchstart happens on them. | ||
27 | @private | ||
28 | */ | ||
29 | _NATIVE_ELEMENTS: { | ||
30 | value: ["A", "IFRAME", "EMBED", "OBJECT", "VIDEO", "AUDIO", "CANVAS", | ||
31 | "LABEL", "INPUT", "BUTTON", "SELECT", "TEXTAREA", "KEYGEN", | ||
32 | "DETAILS", "COMMAND" | ||
33 | ] | ||
34 | }, | ||
35 | |||
23 | /** | 36 | /** |
24 | Description TODO | 37 | Description TODO |
25 | @private | 38 | @private |
@@ -356,6 +369,19 @@ var Scrollview = exports.Scrollview = Montage.create(Component, /** @lends modul | |||
356 | enumerable: false, | 369 | enumerable: false, |
357 | value: null | 370 | value: null |
358 | }, | 371 | }, |
372 | |||
373 | /** | ||
374 | Returns if we should preventDefault on a touchstart/mousedown event. | ||
375 | @param {Event} The event | ||
376 | @returns {Boolean} Whether preventDefault should be called | ||
377 | @private | ||
378 | */ | ||
379 | _shouldPreventDefault: { | ||
380 | value: function(event) { | ||
381 | return !!event.target.tagName && Scrollview._NATIVE_ELEMENTS.indexOf(event.target.tagName) === -1 && !event.target.isContentEditable; | ||
382 | } | ||
383 | }, | ||
384 | |||
359 | /** | 385 | /** |
360 | Description TODO | 386 | Description TODO |
361 | @function | 387 | @function |
@@ -364,13 +390,7 @@ var Scrollview = exports.Scrollview = Montage.create(Component, /** @lends modul | |||
364 | captureMousedown: { | 390 | captureMousedown: { |
365 | enumerable: false, | 391 | enumerable: false, |
366 | value: function (event) { | 392 | value: function (event) { |
367 | 393 | if (this._shouldPreventDefault(event)) { | |
368 | // TODO this is a bit of a temporary workaround to ensure that we allow input fields | ||
369 | //to receive the mousedown that gives them focus and sets the cursor a the mousedown coordinates | ||
370 | if (!(event.target.tagName && | ||
371 | ("INPUT" === event.target.tagName || "SELECT" === event.target.tagName || "TEXTAREA" === event.target.tagName)) && | ||
372 | !event.target.isContentEditable) { | ||
373 | |||
374 | event.preventDefault(); | 394 | event.preventDefault(); |
375 | } | 395 | } |
376 | 396 | ||
@@ -458,8 +478,9 @@ var Scrollview = exports.Scrollview = Montage.create(Component, /** @lends modul | |||
458 | captureTouchstart: { | 478 | captureTouchstart: { |
459 | enumerable: false, | 479 | enumerable: false, |
460 | value: function (event) { | 480 | value: function (event) { |
461 | 481 | if (this._shouldPreventDefault(event)) { | |
462 | event.preventDefault(); | 482 | event.preventDefault(); |
483 | } | ||
463 | 484 | ||
464 | // If already scrolling the scrollview, ignore any new touchstarts | 485 | // If already scrolling the scrollview, ignore any new touchstarts |
465 | if (this._observedPointer !== null && this.eventManager.isPointerClaimedByComponent(this._observedPointer, this)) { | 486 | if (this._observedPointer !== null && this.eventManager.isPointerClaimedByComponent(this._observedPointer, this)) { |
@@ -482,7 +503,9 @@ var Scrollview = exports.Scrollview = Montage.create(Component, /** @lends modul | |||
482 | if (!this.eventManager.componentClaimingPointer(this._observedPointer)) { | 503 | if (!this.eventManager.componentClaimingPointer(this._observedPointer)) { |
483 | 504 | ||
484 | if (event.targetTouches.length === 1) { | 505 | if (event.targetTouches.length === 1) { |
485 | event.preventDefault(); | 506 | if (this._shouldPreventDefault(event)) { |
507 | event.preventDefault(); | ||
508 | } | ||
486 | 509 | ||
487 | this.eventManager.claimPointer(this._observedPointer, this); | 510 | this.eventManager.claimPointer(this._observedPointer, this); |
488 | this._start(event.targetTouches[0].clientX, event.targetTouches[0].clientY); | 511 | this._start(event.targetTouches[0].clientX, event.targetTouches[0].clientY); |