aboutsummaryrefslogtreecommitdiff
path: root/node_modules/montage/ui/composer/translate-composer.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/montage/ui/composer/translate-composer.js')
-rw-r--r--node_modules/montage/ui/composer/translate-composer.js133
1 files changed, 90 insertions, 43 deletions
diff --git a/node_modules/montage/ui/composer/translate-composer.js b/node_modules/montage/ui/composer/translate-composer.js
index 4ce165dc..6e762af9 100644
--- a/node_modules/montage/ui/composer/translate-composer.js
+++ b/node_modules/montage/ui/composer/translate-composer.js
@@ -4,7 +4,7 @@
4 (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. 4 (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5 </copyright> */ 5 </copyright> */
6/** 6/**
7 @module montage/ui/composer/long-press-composer 7 @module montage/ui/composer/translate-composer
8 @requires montage 8 @requires montage
9 @requires montage/ui/composer/composer 9 @requires montage/ui/composer/composer
10*/ 10*/
@@ -66,6 +66,11 @@ var TranslateComposer = exports.TranslateComposer = Montage.create(Composer,/**
66 value: null 66 value: null
67 }, 67 },
68 68
69 _shouldDispatchTranslate: {
70 value: false,
71 enumerable: false
72 },
73
69 _isSelfUpdate: { 74 _isSelfUpdate: {
70 enumerable: false, 75 enumerable: false,
71 value: false 76 value: false
@@ -203,7 +208,19 @@ var TranslateComposer = exports.TranslateComposer = Montage.create(Composer,/**
203 } 208 }
204 }, 209 },
205 210
206 invertAxis: {value: null}, 211 _invertAxis: {
212 value: false,
213 enumerable: false
214 },
215
216 invertAxis: {
217 get: function() {
218 return this._invertAxis;
219 },
220 set: function(value) {
221 this._invertAxis=value?true:false;
222 }
223 },
207 224
208 _hasMomentum: { 225 _hasMomentum: {
209 enumerable: false, 226 enumerable: false,
@@ -233,33 +250,34 @@ var TranslateComposer = exports.TranslateComposer = Montage.create(Composer,/**
233 } 250 }
234 }, 251 },
235 252
236 _momentumDuration: { 253 __momentumDuration: {
237 enumerable: false, 254 enumerable: false,
238 value: 650 255 value: 650
239 }, 256 },
240 257
241 momentumDuration: { 258 _momentumDuration: {
242 get: function () { 259 get: function () {
243 return this._momentumDuration; 260 return this.__momentumDuration;
244 }, 261 },
245 set: function (value) { 262 set: function (value) {
246 this._momentumDuration=isNaN(value)?1:value>>0; 263 this.__momentumDuration=isNaN(value)?1:value>>0;
247 if (this._momentumDuration<1) this._momentumDuration=1; 264 if (this.__momentumDuration<1) this.__momentumDuration=1;
248 } 265 },
266 enumerable: false
249 }, 267 },
250 268
251 _bouncingDuration: { 269 __bouncingDuration: {
252 enumerable: false, 270 enumerable: false,
253 value: 750 271 value: 750
254 }, 272 },
255 273
256 bouncingDuration: { 274 _bouncingDuration: {
257 get: function () { 275 get: function () {
258 return this._bouncingDuration; 276 return this.__bouncingDuration;
259 }, 277 },
260 set: function (value) { 278 set: function (value) {
261 this._bouncingDuration=isNaN(value)?1:value>>0; 279 this.__bouncingDuration=isNaN(value)?1:value>>0;
262 if (this._bouncingDuration<1) this._bouncingDuration=1; 280 if (this.__bouncingDuration<1) this.__bouncingDuration=1;
263 } 281 }
264 }, 282 },
265 283
@@ -538,38 +556,44 @@ var TranslateComposer = exports.TranslateComposer = Montage.create(Composer,/**
538 value: function (event) { 556 value: function (event) {
539 var self = this; 557 var self = this;
540 558
559 var oldTranslateY = this._translateY;
541 this.translateY = this._translateY - (event.wheelDeltaY * 20) / 120; 560 this.translateY = this._translateY - (event.wheelDeltaY * 20) / 120;
542 this._dispatchTranslateStart(); 561 this._dispatchTranslateStart();
543 window.clearTimeout(this._translateEndTimeout); 562 window.clearTimeout(this._translateEndTimeout);
544 this._translateEndTimeout = window.setTimeout(function () { 563 this._translateEndTimeout = window.setTimeout(function () {
545 self._dispatchTranslateEnd(); 564 self._dispatchTranslateEnd();
546 }, 400); 565 }, 400);
547 event.preventDefault(); 566
567 // If we're not at one of the extremes (i.e. the scroll actully
568 // changed the translate) then we want to preventDefault to stop
569 // the page scrolling.
570 if (oldTranslateY !== this._translateY) {
571 event.preventDefault();
572 }
548 } 573 }
549 }, 574 },
550 575
551 _move: { 576 _move: {
552 enumerable: false, 577 enumerable: false,
553 value: function (x, y) { 578 value: function (x, y) {
554 579 var pointerDelta;
555 this._isSelfUpdate=true; 580 this._isSelfUpdate=true;
556 var delta;
557 if (this._axis!="vertical") { 581 if (this._axis!="vertical") {
558 var delta = this.invertAxis ? (x-this._pointerX) : (this._pointerX-x); 582 pointerDelta = this._invertAxis ? (this._pointerX-x) : (x-this._pointerX);
559 if ((this._translateX<0)||(this._translateX>this._maxTranslateX)) { 583 if ((this._translateX<0)||(this._translateX>this._maxTranslateX)) {
560 this.translateX+=(delta/2)*this._pointerSpeedMultiplier; 584 this.translateX+=((pointerDelta)/2)*this._pointerSpeedMultiplier;
561 } else { 585 } else {
562 this.translateX+=(delta)*this._pointerSpeedMultiplier; 586 this.translateX+=(pointerDelta)*this._pointerSpeedMultiplier;
563 } 587 }
564 } 588 }
565 if (this._axis!="horizontal") { 589 if (this._axis!="horizontal") {
590 pointerDelta = this._invertAxis ? (this._pointerY-y) : (y-this._pointerY);
566 if ((this._translateY<0)||(this._translateY>this._maxTranslateY)) { 591 if ((this._translateY<0)||(this._translateY>this._maxTranslateY)) {
567 this.translateY+=((this._pointerY-y)/2)*this._pointerSpeedMultiplier; 592 this.translateY+=((pointerDelta)/2)*this._pointerSpeedMultiplier;
568 } else { 593 } else {
569 this.translateY+=(this._pointerY-y)*this._pointerSpeedMultiplier; 594 this.translateY+=(pointerDelta)*this._pointerSpeedMultiplier;
570 } 595 }
571 } 596 }
572
573 this._isSelfUpdate=false; 597 this._isSelfUpdate=false;
574 this._pointerX=x; 598 this._pointerX=x;
575 this._pointerY=y; 599 this._pointerY=y;
@@ -577,6 +601,9 @@ var TranslateComposer = exports.TranslateComposer = Montage.create(Composer,/**
577 this._dispatchTranslateStart(); 601 this._dispatchTranslateStart();
578 this._isFirstMove = false; 602 this._isFirstMove = false;
579 } 603 }
604 if (this._shouldDispatchTranslate) {
605 this._dispatchTranslate();
606 }
580 } 607 }
581 }, 608 },
582 609
@@ -627,6 +654,17 @@ var TranslateComposer = exports.TranslateComposer = Montage.create(Composer,/**
627 } 654 }
628 }, 655 },
629 656
657 _dispatchTranslate: {
658 enumerable: false,
659 value: function() {
660 var translateEvent = document.createEvent("CustomEvent");
661 translateEvent.initCustomEvent("translate", true, true, null);
662 translateEvent.translateX = this._translateX;
663 translateEvent.translateY = this._translateY;
664 this.dispatchEvent(translateEvent);
665 }
666 },
667
630 668
631 _end: { 669 _end: {
632 enumerable: false, 670 enumerable: false,
@@ -662,8 +700,8 @@ var TranslateComposer = exports.TranslateComposer = Montage.create(Composer,/**
662 } else { 700 } else {
663 momentumY=0; 701 momentumY=0;
664 } 702 }
665 endX=startX-(momentumX*this._momentumDuration/2000); 703 endX=startX-(momentumX*this.__momentumDuration/2000);
666 endY=startY-(momentumY*this._momentumDuration/2000); 704 endY=startY-(momentumY*this.__momentumDuration/2000);
667 animateMomentum=true; 705 animateMomentum=true;
668 }