rsence-pre 2.1.0.7.pre → 2.1.0.8.pre

Sign up to get free protection for your applications and to get access to all the features.
data/js/core/elem/elem.js CHANGED
@@ -24,6 +24,9 @@ BROWSER_TYPE = {
24
24
  /* Microsoft Internet Explorer version 8 */
25
25
  ie8: false,
26
26
 
27
+ /* Microsoft Internet Explorer version 9 */
28
+ ie9: false,
29
+
27
30
  /* Any version of Opera */
28
31
  opera: false,
29
32
 
@@ -57,7 +60,8 @@ ELEM = {
57
60
  * The interval to flush the buffer specified in milliseconds.
58
61
  * Defaults to 60fps which is the most common refresh rate of displays.
59
62
  **/
60
- ELEMTickerInterval: 16.667,
63
+ // ELEMTickerInterval: 16.667,
64
+ ELEMTickerInterval: 33,
61
65
 
62
66
  // stuff moved inside this function, because (surprise, surprise!) ie6 had some issues with it.
63
67
  _constructor: function() {
@@ -225,14 +229,16 @@ ELEM = {
225
229
  **/
226
230
  setHTML: function(_id, _html) {
227
231
  try {
228
- var _this = ELEM;
229
- if (!_this._elements[_id]) {
232
+ var _this = ELEM, _elem = _this._elements[_id];
233
+ if (!_elem) {
230
234
  return;
231
235
  }
232
236
  if (! ((typeof _html === 'string') || (typeof _html === 'number'))) {
233
237
  return;
234
238
  }
235
- _this._elements[_id].innerHTML = _html;
239
+ if (_elem.innerHTML !== _html ){
240
+ _elem.innerHTML = _html;
241
+ }
236
242
  } catch(e) {}
237
243
  //_this._initCache(_id);
238
244
  },
@@ -376,14 +382,7 @@ ELEM = {
376
382
  h = _elem.offsetHeight,
377
383
  _parent = _elem.parentNode;
378
384
  while (_parent && _parent.nodeName.toLowerCase() !== 'body') {
379
- if (!BROWSER_TYPE.ie) {
380
- _parentOverflow = document.defaultView.getComputedStyle(
381
- _parent, null
382
- ).getPropertyValue('overflow');
383
- }
384
- else {
385
- _parentOverflow = _parent.currentStyle.getAttribute('overflow');
386
- }
385
+ _this._getComputedStyle( _parent, 'overflow' );
387
386
  _parentOverflow = _parentOverflow !== 'visible';
388
387
  if (w > _parent.clientWidth && _parentOverflow) {
389
388
  w = _parent.clientWidth - _elem.offsetLeft;
@@ -433,6 +432,38 @@ ELEM = {
433
432
  return [w, h];
434
433
  },
435
434
 
435
+ _getVisibleLeftPosition: function(_id){
436
+ var
437
+ _this = ELEM,
438
+ x = 0,
439
+ _elem = _this._elements[_id];
440
+ while (_elem !== document) {
441
+ x += _elem.offsetLeft;
442
+ x -= _elem.scrollLeft;
443
+ _elem = _elem.parentNode;
444
+ if (!_elem) {
445
+ break;
446
+ }
447
+ }
448
+ return x;
449
+ },
450
+
451
+ _getVisibleTopPosition: function(_id){
452
+ var
453
+ _this = ELEM,
454
+ y = 0,
455
+ _elem = _this._elements[_id];
456
+ while (_elem !== document) {
457
+ y += _elem.offsetTop;
458
+ y -= _elem.scrollTop;
459
+ _elem = _elem.parentNode;
460
+ if (!_elem) {
461
+ break;
462
+ }
463
+ }
464
+ return y;
465
+ },
466
+
436
467
  /** = Description
437
468
  * Returns the real position of the element, subtracting whatever
438
469
  * scroll bars do to the position..
@@ -445,21 +476,11 @@ ELEM = {
445
476
  *
446
477
  **/
447
478
  getVisiblePosition: function(_id) {
448
- var _this = ELEM,
449
- x = 0,
450
- y = 0,
451
- _elem = _this._elements[_id];
452
- while (_elem !== document) {
453
- x += _elem.offsetLeft;
454
- y += _elem.offsetTop;
455
- x -= _elem.scrollLeft;
456
- y -= _elem.scrollTop;
457
- _elem = _elem.parentNode;
458
- if (!_elem) {
459
- break;
460
- }
461
- }
462
- return [x, y];
479
+ var _this = ELEM;
480
+ return [
481
+ _this._getVisibleLeftPosition(_id),
482
+ _this._getVisibleTopPosition(_id)
483
+ ];
463
484
  },
464
485
 
465
486
  /** = Description
@@ -473,28 +494,20 @@ ELEM = {
473
494
  *
474
495
  **/
475
496
  getOpacity: function(_id) {
476
- var _opacity,
477
- _try_opacity,
478
- _this = ELEM,
479
- _getStyle = _this.getStyle;
480
- // old safari (1.x):
481
- if (_opacity === _getStyle(_id, '-khtml-opacity')) {
482
- return parseFloat(_opacity);
483
- }
484
- // old mozilla (ff 1.0 and below):
485
- if (_opacity === _getStyle(_id, '-moz-opacity')) {
486
- return parseFloat(_opacity);
487
- }
488
- _try_opacity = _getStyle(_id, 'opacity', true);
489
- if (_opacity === _try_opacity || (_try_opacity === 0)) {
490
- return parseFloat(_opacity);
491
- }
492
- if (_opacity === (_this._elements[_id].currentStyle['filter'] || '').match(/alpha(opacity=(.*))/)) {
493
- if (_opacity[1]) {
494
- return parseFloat(_opacity[1]) / 100;
495
- }
496
- }
497
- return 1.0;
497
+ throw "ELEM.getOpacity: known error.";
498
+ // var
499
+ // _this = ELEM,
500
+ // _elem = _this.get(_id),
501
+ // _opacity = _this._getComputedStyle( _elem, 'opacity' );
502
+ // if (ELEM.ie && (_elem.currentStyle['filter'] || '').match(/alpha(opacity=(.*))/)) {
503
+ // if (_opacity[1]) {
504
+ // return parseFloat(_opacity[1]) / 100;
505
+ // }
506
+ // }
507
+ // else ( === 0)) {
508
+ // return parseFloat(_opacity);
509
+ // }
510
+ // return 1.0;
498
511
  },
499
512
 
500
513
  /** = Description
@@ -518,9 +531,6 @@ ELEM = {
518
531
  var _prevAlpha = _this.getStyle(_id, 'filter', true);
519
532
  _this._elements[_id].style.setAttribute('filter', _prevAlpha.replace(/alpha([^)]*)/gi, '') + 'alpha(opacity=' + _opacity * 100 + ')');
520
533
  }
521
- else if (BROWSER_TYPE.ie) {
522
- _this._elements[_id].style.setAttribute('opacity', _opacity);
523
- }
524
534
  else {
525
535
  _this._elements[_id].style.setProperty('opacity', _opacity, '');
526
536
  }
@@ -539,8 +549,7 @@ ELEM = {
539
549
  *
540
550
  **/
541
551
  getIntStyle: function(_id, _key) {
542
- var _value = ELEM.getStyle(_id, _key);
543
- return parseInt(_value, 10);
552
+ return parseInt(ELEM.getStyle(_id, _key), 10);
544
553
  },
545
554
 
546
555
  /** = Description
@@ -559,6 +568,16 @@ ELEM = {
559
568
  ELEM.setStyle(_id, 'height', _coords[3] + 'px');
560
569
  },
561
570
 
571
+ _getExtraLeftWidth: function(_id){
572
+ var _int = ELEM.getIntStyle;
573
+ return _int(_id, 'padding-left') + _int(_id, 'border-left-width');
574
+ },
575
+
576
+ _getExtraRightWidth: function(_id){
577
+ var _int = ELEM.getIntStyle;
578
+ return _int(_id, 'padding-right') + _int(_id, 'border-right-width');
579
+ },
580
+
562
581
  /** = Description
563
582
  * Returns the amount of width of the element taken by 'extra' space: border
564
583
  * and padding size.
@@ -571,8 +590,18 @@ ELEM = {
571
590
  *
572
591
  **/
573
592
  getExtraWidth: function(_id) {
593
+ var _this = ELEM;
594
+ return _this._getExtraLeftWidth(_id) + _this._getExtraRightWidth(_id);
595
+ },
596
+
597
+ _getExtraTopWidth: function(_id){
574
598
  var _int = ELEM.getIntStyle;
575
- return _int(_id, 'padding-left') + _int(_id, 'padding-right') + _int(_id, 'border-left-width') + _int(_id, 'border-right-width');
599
+ return _int(_id, 'padding-top') + _int(_id, 'border-top-width');
600
+ },
601
+
602
+ _getExtraBottomWidth: function(_id){
603
+ var _int = ELEM.getIntStyle;
604
+ return _int(_id, 'padding-bottom') + _int(_id, 'border-bottom-width');
576
605
  },
577
606
 
578
607
  /** = Description
@@ -587,8 +616,8 @@ ELEM = {
587
616
  *
588
617
  **/
589
618
  getExtraHeight: function(_id) {
590
- var _int = ELEM.getIntStyle;
591
- return _int(_id, 'padding-top') + _int(_id, 'padding-bottom') + _int(_id, 'border-top-width') + _int(_id, 'border-bottom-width');
619
+ var _this = ELEM;
620
+ return _this._getExtraTopWidth(_id) + _this._getExtraBottomWidth(_id);
592
621
  },
593
622
 
594
623
  /** = Description
@@ -930,6 +959,26 @@ ELEM = {
930
959
  }
931
960
  },
932
961
 
962
+ _setElementStyle: function(_elem,_key,_value){
963
+ _elem.style.setProperty(_key, _value, '');
964
+ },
965
+ _setElementStyleIE: function(_elem,_key,_value){
966
+ var
967
+ _this = ELEM,
968
+ _camelKey = _key.replace(
969
+ /((-)([a-z])(\w))/g,
970
+ function($0, $1, $2, $3, $4) {
971
+ return $3.toUpperCase() + $4;
972
+ }
973
+ );
974
+ _elem.style[_camelKey] = _value;
975
+ if (BROWSER_TYPE.ie6) {
976
+ if (iefix._traverseStyleProperties.indexOf(_key) !== -1) {
977
+ _this._ieFixesNeeded = true;
978
+ }
979
+ }
980
+ },
981
+
933
982
  /** = Description
934
983
  * Sets the named element style attribute value.
935
984
  *
@@ -948,8 +997,7 @@ ELEM = {
948
997
  var _this = ELEM,
949
998
  _cached = _this._styleCache[_id],
950
999
  _elems = _this._elements,
951
- _differs,
952
- _styleTodo;
1000
+ _differs;
953
1001
  _this._setStyleCount++;
954
1002
  if (_cached === undefined) {
955
1003
  _this._initCache(_id);
@@ -964,27 +1012,12 @@ ELEM = {
964
1012
  _this.setOpacity(_id, _value);
965
1013
  }
966
1014
  else {
967
- if( BROWSER_TYPE.ie ) {
968
- var _camelKey = _key.replace(
969
- /((-)([a-z])(\w))/g,
970
- function($0, $1, $2, $3, $4) {
971
- return $3.toUpperCase() + $4;
972
- }
973
- );
974
- _elems[_id].style[_camelKey] = _cached[_key];
975
- }
976
- else {
977
- _elems[_id].style.setProperty(_key, _cached[_key], '');
978
- }
979
- }
980
- if (BROWSER_TYPE.ie6) {
981
- if (iefix._traverseStyleProperties.indexOf(_key) !== -1) {
982
- _this._ieFixesNeeded = true;
983
- }
1015
+ _this._setElementStyle( _elems[_id], _key, _cached[_key] );
984
1016
  }
985
1017
  }
986
1018
  else {
987
- _elemTodoH = _this._elemTodoH;
1019
+ var
1020
+ _elemTodoH = _this._elemTodoH,
988
1021
  _styleTodo = _this._styleTodo[_id];
989
1022
  if (_styleTodo.indexOf(_key) === -1) {
990
1023
  _styleTodo.push(_key);
@@ -1071,6 +1104,19 @@ ELEM = {
1071
1104
  ];
1072
1105
  },
1073
1106
 
1107
+ _getComputedStyle: function(_elem,_key){
1108
+ return document.defaultView.getComputedStyle(_elem,null).getPropertyValue(_key);
1109
+ },
1110
+ _getComputedStyleIE: function(_elem,_key){
1111
+ var _camelName = _key.replace(
1112
+ /((-)([a-z])(\w))/g,
1113
+ function($0, $1, $2, $3, $4) {
1114
+ return $3.toUpperCase() + $4;
1115
+ }
1116
+ );
1117
+ return _elem.currentStyle[_camelName];
1118
+ },
1119
+
1074
1120
  /** = Description
1075
1121
  * Gets the named element style attribute value.
1076
1122
  *
@@ -1087,30 +1133,6 @@ ELEM = {
1087
1133
  *
1088
1134
  **/
1089
1135
  getStyle: function(_id, _key, _bypass){
1090
- var _this=ELEM,
1091
- _cached=_this._styleCache[_id],
1092
- _retval;
1093
- _this._getStyleCount++;
1094
- if ((_cached[_key] === undefined) || _bypass) {
1095
- if (!_bypass) {
1096
- _this._getStyleMissCount++;
1097
- }
1098
- if ((_key === 'opacity') && _bypass) {
1099
- _retval = _this.getOpacity(_id);
1100
- }
1101
- else if (BROWSER_TYPE.ie7 || BROWSER_TYPE.ie8){
1102
- _retval = _this._elements[_id].style[_key];
1103
- }
1104
- else {
1105
- _retval = document.defaultView.getComputedStyle(_this._elements[_id], null).getPropertyValue(_key);
1106
- }
1107
- _cached[_key] = _retval;
1108
- }
1109
- return _cached[_key];
1110
- },
1111
-
1112
- /* The Internet Explorer version of getStyle */
1113
- _getStyleIE: function( _id, _key, _bypass){
1114
1136
  var _this=ELEM,
1115
1137
  _cached=_this._styleCache[_id],
1116
1138
  _retval;
@@ -1123,13 +1145,7 @@ ELEM = {
1123
1145
  _retval = _this.getOpacity(_id);
1124
1146
  }
1125
1147
  else {
1126
- _camelName = _key.replace(
1127
- /((-)([a-z])(\w))/g,
1128
- function($0, $1, $2, $3, $4) {
1129
- return $3.toUpperCase() + $4;
1130
- }
1131
- );
1132
- _retval = _this._elements[_id].currentStyle[_camelName];
1148
+ _retval = _this._getComputedStyle(_this._elements[_id],_key);
1133
1149
  }
1134
1150
  _cached[_key] = _retval;
1135
1151
  }
@@ -1151,63 +1167,16 @@ ELEM = {
1151
1167
  if (!_elem) {
1152
1168
  return;
1153
1169
  }
1154
- _elemS = _elem.style;
1155
1170
  _loopMaxP = _styleTodo.length;
1156
1171
  _currTodo = _styleTodo.splice(0, _loopMaxP);
1157
1172
  for (_cid = 0; _cid !== _loopMaxP; _cid++) {
1158
- _key = _currTodo.pop();
1159
- _this._flushStylCount++;
1160
- if (_key === 'opacity') {
1161
- _retval = _this.setOpacity(_id, _cached[_key]);
1162
- }
1163
- else {
1164
- _elemS.setProperty(_key, _cached[_key], '');
1165
- }
1166
- }
1167
- },
1168
-
1169
- /* Internet Explorer version of _flushStyleCache */
1170
- _flushStyleCacheIE: function(_id) {
1171
- var _this = ELEM,
1172
- _styleTodo = _this._styleTodo[_id],
1173
- _cached = _this._styleCache[_id],
1174
- _elem = _this._elements[_id];
1175
- if (!_elem) {
1176
- return;
1177
- }
1178
- var _elemS = _elem.style,
1179
- _loopMaxP = _styleTodo.length,
1180
- i = 0,
1181
- _key,
1182
- _currTodo = _styleTodo.splice(0, _loopMaxP);
1183
- for (; i !== _loopMaxP; i++) {
1184
1173
  _key = _currTodo.pop();
1185
1174
  _this._flushStylCount++;
1186
1175
  if (_key === 'opacity') {
1187
1176
  _this.setOpacity(_id, _cached[_key]);
1188
1177
  }
1189
1178
  else {
1190
- if (BROWSER_TYPE.ie6) {
1191
- if (iefix._traverseStyleProperties.indexOf(_key) !== -1) {
1192
- _this._ieFixesNeeded = true;
1193
- }
1194
- }
1195
- try {
1196
- var _camelKey = _key.replace(
1197
- /((-)([a-z])(\w))/g,
1198
- function($0, $1, $2, $3, $4) {
1199
- return $3.toUpperCase() + $4;
1200
- }
1201
- );
1202
- // _elemS[_camelKey] = _cached[_key];
1203
- _elemS.setAttribute(
1204
- _camelKey,
1205
- _cached[_key]
1206
- );
1207
- }
1208
- catch(e) {
1209
- console.log(e);
1210
- }
1179
+ _this._setElementStyle( _elem, _key, _cached[_key] );
1211
1180
  }
1212
1181
  }
1213
1182
  },
@@ -1218,10 +1187,8 @@ ELEM = {
1218
1187
  var _this = ELEM;
1219
1188
 
1220
1189
  if (BROWSER_TYPE.ie) {
1221
- _this.getStyle = _this._getStyleIE;
1222
- // }
1223
- // if (BROWSER_TYPE.ie) {
1224
- _this._flushStyleCache = _this._flushStyleCacheIE;
1190
+ _this._getComputedStyle = _this._getComputedStyleIE;
1191
+ _this._setElementStyle = _this._setElementStyleIE;
1225
1192
  }
1226
1193
 
1227
1194
  if(!_this['_timer']){
@@ -1293,6 +1260,13 @@ ELEM = {
1293
1260
  _browserType.ie6 = _isIE && (_ua.indexOf("MSIE 6") !== -1);
1294
1261
  _browserType.ie7 = _isIE && (_ua.indexOf("MSIE 7") !== -1);
1295
1262
  _browserType.ie8 = _isIE && (_ua.indexOf("MSIE 8") !== -1);
1263
+ _browserType.ie9 = _isIE && (_ua.indexOf("MSIE 9") !== -1);
1264
+
1265
+ // Experimental; don't treat IE9 as an IE at all.
1266
+ if(_browserType.ie9){
1267
+ _browserType.ie = false;
1268
+ }
1269
+
1296
1270
  _browserType.firefox = _ua.indexOf("Firefox") !== -1;
1297
1271
  _browserType.firefox2 = _ua.indexOf("Firefox/2.") !== -1;
1298
1272
  _browserType.firefox3 = _ua.indexOf("Firefox/3.") !== -1;
@@ -131,7 +131,7 @@ EVENT = {
131
131
  var _this = EVENT;
132
132
  _this.hovered = [];
133
133
  // items currently under the mouse cursor
134
- _this.hoverInterval = 50;
134
+ _this.hoverInterval = 200;
135
135
  // 50 means send hover events at most with 50ms intervals
136
136
  _this.hoverTimer = new Date().getTime();
137
137
  // Time since last hover event triggered
@@ -479,12 +479,14 @@ EVENT = {
479
479
  _hoverIndex = _this.hovered[j];
480
480
  if (_hoverIndex !== _elemId && _this.focusOptions[_hoverIndex].ctrl) {
481
481
  _dropCtrl = _this.focusOptions[_hoverIndex].ctrl;
482
- if (!_this.topmostDroppable ||
483
- // First time
484
- _dropCtrl.zIndex() > _this.topmostDroppable.zIndex() ||
485
- // Z beaten
486
- _dropCtrl.supr === _this.topmostDroppable) {
482
+ if (
483
+ // First time
484
+ !_this.topmostDroppable ||
485
+ // Z beaten
486
+ _dropCtrl.zIndex() > _this.topmostDroppable.zIndex() ||
487
487
  // subview
488
+ _dropCtrl.parent === _this.topmostDroppable
489
+ ) {
488
490
  if (_this.focusOptions[_dropCtrl.elemId].droppable) {
489
491
  _this.topmostDroppable = _dropCtrl;
490
492
  // Finally, the item must accept drop events.
@@ -526,6 +528,7 @@ EVENT = {
526
528
  i = 0,
527
529
  _ctrl,
528
530
  _elem,
531
+ _rect,
529
532
  _pos,
530
533
  _size,
531
534
  _coords,
@@ -538,10 +541,13 @@ EVENT = {
538
541
  if(_ctrl.drawn){
539
542
  _elem = ELEM.get(i);
540
543
  if (!_this._coordCacheFlag || !_this._coordCache[i]) {
541
- _pos = ELEM.getVisiblePosition(_ctrl.elemId);
542
- // [x,y]
543
- _size = ELEM.getVisibleSize(_ctrl.elemId);
544
- // [w,h]
544
+ _rect = _ctrl.rect;
545
+ _pos = [_rect.left,_rect.top];
546
+ _size = [_rect.width,_rect.height];
547
+ // _pos = ELEM.getVisiblePosition(_ctrl.elemId);
548
+ // // [x,y]
549
+ // _size = ELEM.getVisibleSize(_ctrl.elemId);
550
+ // // [w,h]
545
551
  _this._coordCache[i] = [_pos[0], _pos[1], _size[0], _size[1]];
546
552
  }
547
553
  _coords = _this._coordCache[i];
@@ -713,28 +719,40 @@ EVENT = {
713
719
  }
714
720
  return true;
715
721
  },
716
-
722
+
723
+ focusTrace: false,
724
+ prevActiveCtrl: null,
725
+
717
726
  /** Changes active ctrl.
718
727
  * The previous active ctrl gets the _lostActiveStatus pseudo-event,
719
728
  * The new active ctrl gets the _gainedActiveStatus pseudo-event
720
729
  **/
721
730
  changeActiveControl: function(_ctrl) {
722
- //console.log('EVENT.changeActiveControl: ',_ctrl);
723
- var _this = EVENT,
724
- // Store the currently active control so we can inform it, if it no longer is the active control.
725
- _prevActiveCtrl = _this.activeControl;
731
+ var
732
+ _this = EVENT,
733
+ // Store the currently active control so we can inform it,
734
+ // if it's no longer the active control.
735
+ _prevActiveCtrl = _this.activeControl;
726
736
  // Did the active control change?
727
- if (_ctrl !== _prevActiveCtrl) {
728
- if (_prevActiveCtrl) {
737
+ if ((_ctrl !== _prevActiveCtrl) && (_ctrl._gainedActiveStatus || _prevActiveCtrl._lostActiveStatus)) {
738
+ if (_prevActiveCtrl && _prevActiveCtrl._lostActiveStatus) {
729
739
  // Previously active control just lost the active status.
730
740
  _prevActiveCtrl.active = false;
731
741
  _prevActiveCtrl._lostActiveStatus(_ctrl);
742
+ if(_this.focusTrace){
743
+ _prevActiveCtrl.setStyle('border','2px solid green');
744
+ _this.prevActiveCtrl && _this.prevActiveCtrl.setStyle('border','2px solid blue');
745
+ }
746
+ _this.prevActiveCtrl = _prevActiveCtrl;
732
747
  }
733
- if (_ctrl) {
748
+ if (_ctrl && _ctrl._gainedActiveStatus) {
734
749
  // A new control gained the active status.
735
750
  _ctrl.active = true;
736
751
  _this.activeControl = _ctrl;
737
752
  _ctrl._gainedActiveStatus(_prevActiveCtrl);
753
+ if(_this.focusTrace){
754
+ _ctrl.setStyle('border','2px solid red');
755
+ }
738
756
  }
739
757
  else {
740
758
  _this.activeControl = null;
@@ -63,7 +63,7 @@ HMorphAnimation = HClass.extend({
63
63
  this._animateTo(_obj, _duration);
64
64
  }
65
65
  else {
66
- throw "Wrong argument type.";
66
+ this._animateTo(_obj, _duration);
67
67
  }
68
68
  return this;
69
69
  },
@@ -77,7 +77,7 @@ HMorphAnimation = HClass.extend({
77
77
  * is still in action.
78
78
  *
79
79
  */
80
- stopAnimation: function() {
80
+ stopAnimation: function(_target) {
81
81
  if (this._animateInterval) {
82
82
  // Stop the animation interval only if it has been set.
83
83
  window.clearInterval(this._animateInterval);
@@ -102,10 +102,45 @@ HMorphAnimation = HClass.extend({
102
102
  return this;
103
103
  },
104
104
 
105
+ _animFunction: function(_that,_target,_startTime,_duration){
106
+ return function(){
107
+ if(!_that){
108
+ return;
109
+ }
110
+ var _rect = _target;
111
+ _that._animateStep({
112
+ startTime: _startTime,
113
+ duration: _duration,
114
+ // Linear transition effect.
115
+ transition: function(t, b, c, d) { return c * t / d + b; },
116
+ props: [{
117
+ prop: 'left',
118
+ from: _that.rect.left,
119
+ to: _rect.left,
120
+ unit: 'px'
121
+ },{
122
+ prop: 'top',
123
+ from: _that.rect.top,
124
+ to: _rect.top,
125
+ unit: 'px'
126
+ },{
127
+ prop: 'width',
128
+ from: _that.rect.width,
129
+ to: _rect.width,
130
+ unit: 'px'
131
+ },{
132
+ prop: 'height',
133
+ from: _that.rect.height,
134
+ to: _rect.height,
135
+ unit: 'px'
136
+ }]
137
+ });
138
+ };
139
+ },
105
140
 
106
141
  // --Private method.++
107
142
  // --Starts the animation with the target _rect.++
108
- _animateTo: function(_rect, _duration, _fps) {
143
+ _animateTo: function(_target, _duration, _fps) {
109
144
 
110
145
  if (null === _duration || undefined === _duration) {
111
146
  _duration = 500; // default duration is half second
@@ -120,41 +155,9 @@ HMorphAnimation = HClass.extend({
120
155
  this.onAnimationStart();
121
156
 
122
157
  var _startTime = new Date().getTime();
123
-
124
- var _that = this;
125
158
  this._animateInterval = window.setInterval(
126
- function() {
127
- if(!_that){
128
- return;
129
- }
130
- _that._animateStep({
131
- startTime: _startTime,
132
- duration: _duration,
133
- // Linear transition effect.
134
- transition: function(t, b, c, d) { return c * t / d + b; },
135
- props: [{
136
- prop: 'left',
137
- from: _that.rect.left,
138
- to: _rect.left,
139
- unit: 'px'
140
- },{
141
- prop: 'top',
142
- from: _that.rect.top,
143
- to: _rect.top,
144
- unit: 'px'
145
- },{
146
- prop: 'width',
147
- from: _that.rect.width,
148
- to: _rect.width,
149
- unit: 'px'
150
- },{
151
- prop: 'height',
152
- from: _that.rect.height,
153
- to: _rect.height,
154
- unit: 'px'
155
- }]
156
- });
157
- }, Math.round(1000 / _fps)
159
+ this._animFunction(this, _target, _startTime, _duration),
160
+ Math.round(1000 / _fps)
158
161
  );
159
162
  }
160
163
  return this;
@@ -165,21 +168,28 @@ HMorphAnimation = HClass.extend({
165
168
  // --Moves the view for one step. This gets called repeatedly when the animation++
166
169
  // --is happening.++
167
170
  _animateStep: function(_obj) {
168
-
169
171
  var _time = new Date().getTime(), i;
170
172
  if (_time < _obj.startTime + _obj.duration) {
171
173
  var _cTime = _time - _obj.startTime;
172
174
 
173
175
  // Handle all the defined properties.
174
176
  for (i = 0; i < _obj.props.length; i++) {
175
- var _from = _obj.props[i].from;
176
- var _to = _obj.props[i].to;
177
+ var
178
+ _from = _obj.props[i].from,
179
+ _to = _obj.props[i].to;
177
180
 
178
181
  if (_from !== _to) {
179
182
  // The value of the property at this time.
180
- var _propNow = _obj.transition(_cTime, _from, (_to - _from),
181
- _obj.duration);
182
- ELEM.setStyle(this.elemId,_obj.props[i].prop, _propNow + _obj.props[i].unit);
183
+ var
184
+ _key = _obj.props[i].prop,
185
+ _propNow = _obj.transition(
186
+ _cTime, _from, (_to - _from), _obj.duration
187
+ ),
188
+ _unit = _obj.props[i].unit;
189
+ if(_unit){
190
+ _propNow += _unit;
191
+ }
192
+ ELEM.setStyle(this.elemId,_key, _propNow);
183
193
  }
184
194
  }
185
195