From ad81ae4c61eb5857cd444ef0caf5b0b33e8072ba Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Sun, 29 Jan 2012 00:26:20 -0800 Subject: Moved the ninja components out of the Montage folder Signed-off-by: Valerio Virgillito --- node_modules/ninja-components/flow-offset.js | 389 +++++++++++++++++++++++++++ 1 file changed, 389 insertions(+) create mode 100644 node_modules/ninja-components/flow-offset.js (limited to 'node_modules/ninja-components/flow-offset.js') diff --git a/node_modules/ninja-components/flow-offset.js b/node_modules/ninja-components/flow-offset.js new file mode 100644 index 00000000..e45a14f3 --- /dev/null +++ b/node_modules/ninja-components/flow-offset.js @@ -0,0 +1,389 @@ +/* +This file contains proprietary software owned by Motorola Mobility, Inc.
+No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.
+(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. +
*/ + +var Montage = require("montage").Montage; + +var FlowOffset = exports.FlowOffset = Montage.create(Montage, { + + hasTemplate: { + value: false + }, + + isAnimating: { + enumerable: false, + value: false + }, + + component: { + value: null + }, + + draw: { + value: function () { + if (this.isAnimating) { + this._interval(); + } + } + }, + + deserializedFromTemplate: { + value: function () { + var oldComponentDraw = this.component.draw, + self = this; + + this.component.draw = function () { + self.draw(); + oldComponentDraw.call(self.component); + }; + } + }, + + _hasElasticScrolling: { + enumerable: false, + value: true + }, + + hasElasticScrolling: { + get: function () { + return this._hasElasticScrolling; + }, + set: function (value) { + this._hasElasticScrolling=(value===true)?true:false; + } + }, + + _selectedSlideIndex: { + enumerable: false, + value: null + }, + + selectedSlideIndex: { + get: function () { + return this._selectedSlideIndex; + }, + set: function (value) { + this._selectedSlideIndex=value; + if (typeof this.animatingHash[this._selectedSlideIndex] !== "undefined") { + var tmp=this.slide[this._selectedSlideIndex].x; + this.origin+=(this._selectedSlideIndex*this._scale)-tmp; + } + } + }, + + _selectedComponent: { + enumerable: false, + value: null + }, + + selectedComponent: { + get: function () { + return this._selectedComponent; + }, + set: function (value) { + this._selectedComponent=value; + this.selectedSlideIndex=value; + } + }, + + _animating: { + enumerable: false, + value: null + }, + + animating: { + enumerable: false, + get: function () { + if (!this._animating) { + this._animating=[]; + } + return this._animating; + }, + set: function () { + } + }, + + _animatingHash: { + enumerable: false, + value: null + }, + + animatingHash: { + enumerable: false, + get: function () { + if (!this._animatingHash) { + this._animatingHash={}; + } + return this._animatingHash; + }, + set: function () { + } + }, + + _slide: { + enumerable: false, + value: null + }, + + slide: { + enumerable: false, + get: function () { + if (!this._slide) { + this._slide={}; + } + return this._slide; + }, + set: function () { + } + }, + + startAnimating: { + enumerable: false, + value: function (index, pos) { + if (typeof this.animatingHash[index] === "undefined") { + var length=this.animating.length; + + this.animating[length]=index; + this.animatingHash[index]=length; + this.slide[index]={ + speed: 0, + x: pos + }; + } else { + this.slide[index].x=pos; + } + } + }, + + stopAnimating: { + enumerable: false, + value: function (index) { + if (typeof this.animatingHash[index] !== "undefined") { + this.animating[this.animatingHash[index]]=this.animating[this.animating.length-1]; + this.animatingHash[this.animating[this.animating.length-1]]=this.animatingHash[index]; + this.animating.pop(); + delete this.animatingHash[index]; + delete this.slide[index]; + } + } + }, + + _range: { + value: 15 + }, + + lastDrawTime: { + value: null + }, + + _origin: { + enumerable: false, + value: 0 + }, + + origin: { + get: function () { + return this._origin; + }, + set: function (value) { + if (this._hasElasticScrolling) { + var i, + n, + min=this._selectedSlideIndex-this._range, + max=this._selectedSlideIndex+this._range+1, + tmp, + j, + x, + self=this; + + tmp=value-this._origin; + if (min<0) { + min=0; + } + + if (!this.isAnimating) { + this.lastDrawTime=Date.now(); + } + for (i=min; ii*this._scale) { + this.startAnimating(i, x); + } + } + } + } + this.stopAnimating(this._selectedSlideIndex); + + if (!this.isAnimating) { + this._interval=function () { + var animatingLength=self.animating.length, + n, j, i, _iterations=8, + time=Date.now(), + interval1=self.lastDrawTime?(time-self.lastDrawTime)*0.015:0, + interval=interval1/_iterations, + mW=self._scale, x, + epsilon=.5; + + for (n=0; n<_iterations; n++) { + for (j=0; ji*self._scale-epsilon) { + self.stopAnimating(i); + animatingLength--; + } else { + j++; + } + } else { + if (self.slide[i].x