Skip to content

Commit

Permalink
Переместил toStringValue в PropertyDescriptor. Теперь принимает 2 арг…
Browse files Browse the repository at this point in the history
…умента : элемент и искомое значение
  • Loading branch information
ColCh committed Jan 19, 2014
1 parent 5263b31 commit 676bac2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
20 changes: 18 additions & 2 deletions src/abstractions.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,19 @@
this.currentValue = [];
this.keyframes = new KeyframesCollection();
this.startingValue = new Keyframe(null);

if ( COLOR_REG.test(propertyName) ) {
this.blender = blendHooks['color'];
} else if (propertyName in blendHooks) {
this.blender = blendHooks[propertyName];
this.toStringValue = toStringValueHooks['color'];
} else {
if (propertyName in blendHooks) {
this.blender = blendHooks[propertyName];
}
if (propertyName in toStringValueHooks) {
this.toStringValue = toStringValueHooks[propertyName];
}
}

}

/**
Expand All @@ -281,6 +289,14 @@
*/
PropertyDescriptor.prototype.blender = blend;

/**
* Функция для данного свойства, предназначенная для
* перевода значения такое, которое можно отрисовать
* (строка для CSS)
* @type {function(!Element, !Array.<number>): string}
*/
PropertyDescriptor.prototype.toStringValue = toStringValue;

/**
* Текущее значение свойства на моменте анимации.
* @type {Array.<number>}
Expand Down
4 changes: 2 additions & 2 deletions src/animate_class.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@
* @param {string=} vendorizedPropName DOM-имя для CSS свойства
*/
Animation.prototype.render = function (propertyDescriptor, currentValue) {
var stringValue = toStringValue(this.animationTarget, propertyDescriptor.propName, currentValue, propertyDescriptor.vendorizedPropName);
var stringValue = propertyDescriptor.toStringValue(this.animationTarget, currentValue);
setStyle(this.animationTarget,propertyDescriptor.propName, stringValue, propertyDescriptor.vendorizedPropName);
};

Expand Down Expand Up @@ -555,7 +555,7 @@

var stringValue;

stringValue = toStringValue(this.animationTarget, propertyDescriptor.propName, propertyKeyframe.getValue(), propertyDescriptor.vendorizedPropName);
stringValue = propertyDescriptor.toStringValue(this.animationTarget, propertyKeyframe.getValue());

cssKeyframe.style[ propertyDescriptor.vendorizedPropName ] = stringValue;
}
Expand Down
13 changes: 4 additions & 9 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,20 +341,15 @@
* @param {!Element} elem
* @param {string} propertyName
* @param {!Array.<number>} numericValue
* @param {string} vendorizedPropName
* @this {PropertyDescriptor}
* @return {string}
*/
function toStringValue (elem, propertyName, numericValue, vendorizedPropName) {
function toStringValue (elem, numericValue) {

//TODO заменить reg_test на заполнение hooks
if ( COLOR_REG.test(vendorizedPropName) ) {
return toStringValueHooks['color'](elem, propertyName, numericValue, vendorizedPropName);
} else if (propertyName in toStringValueHooks) {
return toStringValueHooks[propertyName](elem, propertyName, numericValue, vendorizedPropName);
} else if (numericValue.length === 0) {
if (numericValue.length === 0) {
return '';
} else {
return numericValue + ( propertyName in toStringValueNoPX ? '' : 'px' );
return numericValue + ( this.propName in toStringValueNoPX ? '' : 'px' );
}

}
Expand Down

0 comments on commit 676bac2

Please sign in to comment.