| Index: third_party/polymer/v0_8/components-chromium/polymer/src/micro/attributes-extracted.js
|
| diff --git a/third_party/polymer/v0_8/components-chromium/polymer/src/micro/attributes-extracted.js b/third_party/polymer/v0_8/components-chromium/polymer/src/micro/attributes-extracted.js
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..bd71fe3dc61fe3dc111952ce0c6a85de5e3edf62
|
| --- /dev/null
|
| +++ b/third_party/polymer/v0_8/components-chromium/polymer/src/micro/attributes-extracted.js
|
| @@ -0,0 +1,167 @@
|
| +
|
| +
|
| + /**
|
| + * Support for `hostAttributes` property.
|
| + *
|
| + * hostAttributes: 'block vertical layout'
|
| + *
|
| + * `hostAttributes` is a space-delimited string of boolean attribute names to
|
| + * set true on each instance.
|
| + *
|
| + * Support for mapping attributes to properties.
|
| + *
|
| + * Properties that are configured in `properties` with a type are mapped
|
| + * to attributes.
|
| + *
|
| + * A value set in an attribute is deserialized into the specified
|
| + * data-type and stored into the matching property.
|
| + *
|
| + * Example:
|
| + *
|
| + * properties: {
|
| + * // values set to index attribute are converted to Number and propagated
|
| + * // to index property
|
| + * index: Number,
|
| + * // values set to label attribute are propagated to index property
|
| + * label: String
|
| + * }
|
| + *
|
| + * Types supported for deserialization:
|
| + *
|
| + * - Number
|
| + * - Boolean
|
| + * - String
|
| + * - Object (JSON)
|
| + * - Array (JSON)
|
| + * - Date
|
| + *
|
| + * This feature implements `attributeChanged` to support automatic
|
| + * propagation of attribute values at run-time. If you override
|
| + * `attributeChanged` be sure to call this base class method
|
| + * if you also want the standard behavior.
|
| + *
|
| + * @class base feature: attributes
|
| + */
|
| +
|
| + Polymer.Base._addFeature({
|
| +
|
| + _marshalAttributes: function() {
|
| + this._takeAttributes();
|
| + },
|
| +
|
| + _installHostAttributes: function(attributes) {
|
| + if (attributes) {
|
| + this.applyAttributes(this, attributes);
|
| + }
|
| + },
|
| +
|
| + applyAttributes: function(node, attr$) {
|
| + for (var n in attr$) {
|
| + this.serializeValueToAttribute(attr$[n], n, this);
|
| + }
|
| + },
|
| +
|
| + _takeAttributes: function() {
|
| + this._takeAttributesToModel(this);
|
| + },
|
| +
|
| + _takeAttributesToModel: function(model) {
|
| + for (var i=0, l=this.attributes.length; i<l; i++) {
|
| + var a = this.attributes[i];
|
| + var property = Polymer.CaseMap.dashToCamelCase(a.name);
|
| + var info = this.getPropertyInfo(property);
|
| + if (info || this._propertyEffects[property]) {
|
| + model[property] =
|
| + this.deserialize(a.value, info.type);
|
| + }
|
| + }
|
| + },
|
| +
|
| + setAttributeToProperty: function(model, attrName) {
|
| + // Don't deserialize back to property if currently reflecting
|
| + if (!this._serializing) {
|
| + var propName = Polymer.CaseMap.dashToCamelCase(attrName);
|
| + if (propName in this.properties) {
|
| + var type = this.getPropertyType(propName);
|
| + var val = this.getAttribute(attrName);
|
| + model[propName] = this.deserialize(val, type);
|
| + }
|
| + }
|
| + },
|
| +
|
| + _serializing: false,
|
| + reflectPropertyToAttribute: function(name) {
|
| + this._serializing = true;
|
| + this.serializeValueToAttribute(this[name],
|
| + Polymer.CaseMap.camelToDashCase(name));
|
| + this._serializing = false;
|
| + },
|
| +
|
| + serializeValueToAttribute: function(value, attribute, node) {
|
| + var str = this.serialize(value);
|
| + (node || this)
|
| + [str === undefined ? 'removeAttribute' : 'setAttribute']
|
| + (attribute, str);
|
| + },
|
| +
|
| + deserialize: function(value, type) {
|
| + switch (type) {
|
| + case Number:
|
| + value = Number(value);
|
| + break;
|
| +
|
| + case Boolean:
|
| + value = (value !== null);
|
| + break;
|
| +
|
| + case Object:
|
| + try {
|
| + value = JSON.parse(value);
|
| + } catch(x) {
|
| + // allow non-JSON literals like Strings and Numbers
|
| + }
|
| + break;
|
| +
|
| + case Array:
|
| + try {
|
| + value = JSON.parse(value);
|
| + } catch(x) {
|
| + value = null;
|
| + console.warn('Polymer::Attributes: couldn`t decode Array as JSON');
|
| + }
|
| + break;
|
| +
|
| + case Date:
|
| + value = new Date(value);
|
| + break;
|
| +
|
| + case String:
|
| + default:
|
| + break;
|
| + }
|
| + return value;
|
| + },
|
| +
|
| + serialize: function(value) {
|
| + switch (typeof value) {
|
| + case 'boolean':
|
| + return value ? '' : undefined;
|
| +
|
| + case 'object':
|
| + if (value instanceof Date) {
|
| + return value;
|
| + } else if (value) {
|
| + try {
|
| + return JSON.stringify(value);
|
| + } catch(x) {
|
| + return '';
|
| + }
|
| + }
|
| +
|
| + default:
|
| + return value != null ? value : undefined;
|
| + }
|
| + }
|
| +
|
| + });
|
| +
|
|
|