Commit 28bd694f authored by Eric Bidelman's avatar Eric Bidelman Committed by Sam Saccone

Update polymer 1.2.2

parent 2291ad9a
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"dependencies": { "dependencies": {
"todomvc-common": "^1.0.1", "todomvc-common": "^1.0.1",
"todomvc-app-css": "^1.0.0", "todomvc-app-css": "^1.0.0",
"polymer": "Polymer/polymer#^1.1.4", "polymer": "Polymer/polymer#^1.2.2",
"iron-selector": "PolymerElements/iron-selector#^1.0.5", "iron-selector": "PolymerElements/iron-selector#^1.0.5",
"flatiron-director": "PolymerLabs/flatiron-director#^1.0.0", "flatiron-director": "PolymerLabs/flatiron-director#^1.0.0",
"iron-localstorage": "PolymerElements/iron-localstorage#^1.0.4" "iron-localstorage": "PolymerElements/iron-localstorage#^1.0.4"
......
...@@ -72,6 +72,11 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN ...@@ -72,6 +72,11 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
this._selection.multi = multi; this._selection.multi = multi;
}, },
get _shouldUpdateSelection() {
return this.selected != null ||
(this.selectedValues != null && this.selectedValues.length);
},
_updateSelected: function() { _updateSelected: function() {
if (this.multi) { if (this.multi) {
this._selectMulti(this.selectedValues); this._selectMulti(this.selectedValues);
......
...@@ -64,6 +64,8 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN ...@@ -64,6 +64,8 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
/** /**
* Returns the currently selected item. * Returns the currently selected item.
*
* @type {?Object}
*/ */
selectedItem: { selectedItem: {
type: Object, type: Object,
...@@ -104,14 +106,24 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN ...@@ -104,14 +106,24 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
value: null value: null
}, },
/**
* The list of items from which a selection can be made.
*/
items: {
type: Array,
readOnly: true,
value: function() {
return [];
}
},
/** /**
* The set of excluded elements where the key is the `localName` * The set of excluded elements where the key is the `localName`
* of the element that will be ignored from the item list. * of the element that will be ignored from the item list.
* *
* @type {object}
* @default {template: 1} * @default {template: 1}
*/ */
excludedLocalNames: { _excludedLocalNames: {
type: Object, type: Object,
value: function() { value: function() {
return { return {
...@@ -132,33 +144,20 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN ...@@ -132,33 +144,20 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
attached: function() { attached: function() {
this._observer = this._observeItems(this); this._observer = this._observeItems(this);
this._contentObserver = this._observeContent(this); this._updateItems();
if (!this.selectedItem && this.selected) { if (!this._shouldUpdateSelection) {
this._updateSelected(this.attrForSelected,this.selected) this._updateSelected(this.attrForSelected,this.selected)
} }
this._addListener(this.activateEvent);
}, },
detached: function() { detached: function() {
if (this._observer) { if (this._observer) {
this._observer.disconnect(); Polymer.dom(this).unobserveNodes(this._observer);
}
if (this._contentObserver) {
this._contentObserver.disconnect();
} }
this._removeListener(this.activateEvent); this._removeListener(this.activateEvent);
}, },
/**
* Returns an array of selectable items.
*
* @property items
* @type Array
*/
get items() {
var nodes = Polymer.dom(this).queryDistributedElements(this.selectable || '*');
return Array.prototype.filter.call(nodes, this._bindFilterItem);
},
/** /**
* Returns the index of the given item. * Returns the index of the given item.
* *
...@@ -201,6 +200,10 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN ...@@ -201,6 +200,10 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
this.selected = this._indexToValue(index); this.selected = this._indexToValue(index);
}, },
get _shouldUpdateSelection() {
return this.selected != null;
},
_addListener: function(eventName) { _addListener: function(eventName) {
this.listen(this, eventName, '_activateHandler'); this.listen(this, eventName, '_activateHandler');
}, },
...@@ -214,6 +217,12 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN ...@@ -214,6 +217,12 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
this._addListener(eventName); this._addListener(eventName);
}, },
_updateItems: function() {
var nodes = Polymer.dom(this).queryDistributedElements(this.selectable || '*');
nodes = Array.prototype.filter.call(nodes, this._bindFilterItem);
this._setItems(nodes);
},
_updateSelected: function() { _updateSelected: function() {
this._selectSelected(this.selected); this._selectSelected(this.selected);
}, },
...@@ -223,7 +232,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN ...@@ -223,7 +232,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
}, },
_filterItem: function(node) { _filterItem: function(node) {
return !this.excludedLocalNames[node.localName]; return !this._excludedLocalNames[node.localName];
}, },
_valueToItem: function(value) { _valueToItem: function(value) {
...@@ -272,18 +281,9 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN ...@@ -272,18 +281,9 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
this._setSelectedItem(this._selection.get()); this._setSelectedItem(this._selection.get());
}, },
// observe content changes under the given node.
_observeContent: function(node) {
var content = node.querySelector('content');
if (content && content.parentElement === node) {
return this._observeItems(node.domHost);
}
},
// observe items change under the given node. // observe items change under the given node.
_observeItems: function(node) { _observeItems: function(node) {
// TODO(cdata): Update this when we get distributed children changed. return Polymer.dom(node).observeNodes(function(mutations) {
var observer = new MutationObserver(function(mutations) {
// Let other interested parties know about the change so that // Let other interested parties know about the change so that
// we don't have to recreate mutation observers everywher. // we don't have to recreate mutation observers everywher.
this.fire('iron-items-changed', mutations, { this.fire('iron-items-changed', mutations, {
...@@ -291,15 +291,12 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN ...@@ -291,15 +291,12 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
cancelable: false cancelable: false
}); });
if (this.selected != null) { this._updateItems();
if (this._shouldUpdateSelection) {
this._updateSelected(); this._updateSelected();
} }
}.bind(this));
observer.observe(node, {
childList: true,
subtree: true
}); });
return observer;
}, },
_activateHandler: function(e) { _activateHandler: function(e) {
......
...@@ -23,10 +23,11 @@ addEventListener('DOMContentLoaded', resolve); ...@@ -23,10 +23,11 @@ addEventListener('DOMContentLoaded', resolve);
window.Polymer = { window.Polymer = {
Settings: function () { Settings: function () {
var user = window.Polymer || {}; var user = window.Polymer || {};
location.search.slice(1).split('&').forEach(function (o) { var parts = location.search.slice(1).split('&');
for (var i = 0, o; i < parts.length && (o = parts[i]); i++) {
o = o.split('='); o = o.split('=');
o[0] && (user[o[0]] = o[1] || true); o[0] && (user[o[0]] = o[1] || true);
}); }
var wantShadow = user.dom === 'shadow'; var wantShadow = user.dom === 'shadow';
var hasShadow = Boolean(Element.prototype.createShadowRoot); var hasShadow = Boolean(Element.prototype.createShadowRoot);
var nativeShadow = hasShadow && !window.ShadowDOMPolyfill; var nativeShadow = hasShadow && !window.ShadowDOMPolyfill;
...@@ -113,15 +114,43 @@ this._callbacks.push(cb); ...@@ -113,15 +114,43 @@ this._callbacks.push(cb);
}, },
_makeReady: function () { _makeReady: function () {
this._ready = true; this._ready = true;
this._callbacks.forEach(function (cb) { for (var i = 0; i < this._callbacks.length; i++) {
cb(); this._callbacks[i]();
}); }
this._callbacks = []; this._callbacks = [];
}, },
_catchFirstRender: function () { _catchFirstRender: function () {
requestAnimationFrame(function () { requestAnimationFrame(function () {
Polymer.RenderStatus._makeReady(); Polymer.RenderStatus._makeReady();
}); });
},
_afterNextRenderQueue: [],
_waitingNextRender: false,
afterNextRender: function (element, fn, args) {
if (!this._waitingNextRender) {
this._waitingNextRender = true;
this.whenReady(this._flushAfterNextRender);
}
this._afterNextRenderQueue.push([
element,
fn,
args
]);
},
_flushAfterNextRender: function () {
requestAnimationFrame(function () {
setTimeout(Polymer.RenderStatus.__flushAfterNextRender);
});
},
__flushAfterNextRender: function () {
var self = Polymer.RenderStatus;
self._waitingNextRender = false;
for (var i = 0, h; i < self._afterNextRenderQueue.length; i++) {
h = self._afterNextRenderQueue[i];
h[1].apply(h[0], h[2] || Polymer.nar);
}
;
self._afterNextRenderQueue = [];
} }
}; };
if (window.HTMLImports) { if (window.HTMLImports) {
...@@ -151,27 +180,33 @@ this._doBehavior('created'); ...@@ -151,27 +180,33 @@ this._doBehavior('created');
this._initFeatures(); this._initFeatures();
}, },
attachedCallback: function () { attachedCallback: function () {
var self = this;
Polymer.RenderStatus.whenReady(function () { Polymer.RenderStatus.whenReady(function () {
this.isAttached = true; self.isAttached = true;
this._doBehavior('attached'); self._doBehavior('attached');
}.bind(this)); });
}, },
detachedCallback: function () { detachedCallback: function () {
this.isAttached = false; this.isAttached = false;
this._doBehavior('detached'); this._doBehavior('detached');
}, },
attributeChangedCallback: function (name) { attributeChangedCallback: function (name, oldValue, newValue) {
this._attributeChangedImpl(name); this._attributeChangedImpl(name);
this._doBehavior('attributeChanged', arguments); this._doBehavior('attributeChanged', [
name,
oldValue,
newValue
]);
}, },
_attributeChangedImpl: function (name) { _attributeChangedImpl: function (name) {
this._setAttributeToProperty(this, name); this._setAttributeToProperty(this, name);
}, },
extend: function (prototype, api) { extend: function (prototype, api) {
if (prototype && api) { if (prototype && api) {
Object.getOwnPropertyNames(api).forEach(function (n) { var n$ = Object.getOwnPropertyNames(api);
for (var i = 0, n; i < n$.length && (n = n$[i]); i++) {
this.copyOwnProperty(n, api, prototype); this.copyOwnProperty(n, api, prototype);
}, this); }
} }
return prototype || api; return prototype || api;
}, },
...@@ -264,7 +299,7 @@ document.registerElement('dom-module', DomModule); ...@@ -264,7 +299,7 @@ document.registerElement('dom-module', DomModule);
function forceDocumentUpgrade() { function forceDocumentUpgrade() {
if (cePolyfill) { if (cePolyfill) {
var script = document._currentScript || document.currentScript; var script = document._currentScript || document.currentScript;
var doc = script && script.ownerDocument; var doc = script && script.ownerDocument || document;
if (doc) { if (doc) {
CustomElements.upgradeAll(doc); CustomElements.upgradeAll(doc);
} }
...@@ -301,7 +336,8 @@ return behaviors; ...@@ -301,7 +336,8 @@ return behaviors;
}, },
_flattenBehaviorsList: function (behaviors) { _flattenBehaviorsList: function (behaviors) {
var flat = []; var flat = [];
behaviors.forEach(function (b) { for (var i = 0; i < behaviors.length; i++) {
var b = behaviors[i];
if (b instanceof Array) { if (b instanceof Array) {
flat = flat.concat(this._flattenBehaviorsList(b)); flat = flat.concat(this._flattenBehaviorsList(b));
} else if (b) { } else if (b) {
...@@ -309,31 +345,16 @@ flat.push(b); ...@@ -309,31 +345,16 @@ flat.push(b);
} else { } else {
this._warn(this._logf('_flattenBehaviorsList', 'behavior is null, check for missing or 404 import')); this._warn(this._logf('_flattenBehaviorsList', 'behavior is null, check for missing or 404 import'));
} }
}, this); }
return flat; return flat;
}, },
_mixinBehavior: function (b) { _mixinBehavior: function (b) {
Object.getOwnPropertyNames(b).forEach(function (n) { var n$ = Object.getOwnPropertyNames(b);
switch (n) { for (var i = 0, n; i < n$.length && (n = n$[i]); i++) {
case 'hostAttributes': if (!Polymer.Base._behaviorProperties[n] && !this.hasOwnProperty(n)) {
case 'registered':
case 'properties':
case 'observers':
case 'listeners':
case 'created':
case 'attached':
case 'detached':
case 'attributeChanged':
case 'configure':
case 'ready':
break;
default:
if (!this.hasOwnProperty(n)) {
this.copyOwnProperty(n, b, this); this.copyOwnProperty(n, b, this);
} }
break;
} }
}, this);
}, },
_prepBehaviors: function () { _prepBehaviors: function () {
this._prepFlattenedBehaviors(this.behaviors); this._prepFlattenedBehaviors(this.behaviors);
...@@ -345,9 +366,9 @@ this._prepBehavior(behaviors[i]); ...@@ -345,9 +366,9 @@ this._prepBehavior(behaviors[i]);
this._prepBehavior(this); this._prepBehavior(this);
}, },
_doBehavior: function (name, args) { _doBehavior: function (name, args) {
this.behaviors.forEach(function (b) { for (var i = 0; i < this.behaviors.length; i++) {
this._invokeBehavior(b, name, args); this._invokeBehavior(this.behaviors[i], name, args);
}, this); }
this._invokeBehavior(this, name, args); this._invokeBehavior(this, name, args);
}, },
_invokeBehavior: function (b, name, args) { _invokeBehavior: function (b, name, args) {
...@@ -357,12 +378,24 @@ fn.apply(this, args || Polymer.nar); ...@@ -357,12 +378,24 @@ fn.apply(this, args || Polymer.nar);
} }
}, },
_marshalBehaviors: function () { _marshalBehaviors: function () {
this.behaviors.forEach(function (b) { for (var i = 0; i < this.behaviors.length; i++) {
this._marshalBehavior(b); this._marshalBehavior(this.behaviors[i]);
}, this); }
this._marshalBehavior(this); this._marshalBehavior(this);
} }
}); });
Polymer.Base._behaviorProperties = {
hostAttributes: true,
registered: true,
properties: true,
observers: true,
listeners: true,
created: true,
attached: true,
detached: true,
attributeChanged: true,
ready: true
};
Polymer.Base._addFeature({ Polymer.Base._addFeature({
_getExtendedPrototype: function (tag) { _getExtendedPrototype: function (tag) {
return this._getExtendedNativePrototype(tag); return this._getExtendedNativePrototype(tag);
...@@ -414,9 +447,13 @@ properties: {}, ...@@ -414,9 +447,13 @@ properties: {},
getPropertyInfo: function (property) { getPropertyInfo: function (property) {
var info = this._getPropertyInfo(property, this.properties); var info = this._getPropertyInfo(property, this.properties);
if (!info) { if (!info) {
this.behaviors.some(function (b) { for (var i = 0; i < this.behaviors.length; i++) {
return info = this._getPropertyInfo(property, b.properties); info = this._getPropertyInfo(property, this.behaviors[i].properties);
}, this); if (info) {
return info;
}
}
;
} }
return info || Polymer.nob; return info || Polymer.nob;
}, },
...@@ -429,6 +466,40 @@ if (p) { ...@@ -429,6 +466,40 @@ if (p) {
p.defined = true; p.defined = true;
} }
return p; return p;
},
_prepPropertyInfo: function () {
this._propertyInfo = {};
for (var i = 0, p; i < this.behaviors.length; i++) {
this._addPropertyInfo(this._propertyInfo, this.behaviors[i].properties);
}
this._addPropertyInfo(this._propertyInfo, this.properties);
this._addPropertyInfo(this._propertyInfo, this._propertyEffects);
},
_addPropertyInfo: function (target, source) {
if (source) {
var t, s;
for (var i in source) {
t = target[i];
s = source[i];
if (i[0] === '_' && !s.readOnly) {
continue;
}
if (!target[i]) {
target[i] = {
type: typeof s === 'function' ? s : s.type,
readOnly: s.readOnly,
attribute: Polymer.CaseMap.camelToDashCase(i)
};
} else {
if (!t.type) {
t.type = s.type;
}
if (!t.readOnly) {
t.readOnly = s.readOnly;
}
}
}
}
} }
}); });
Polymer.CaseMap = { Polymer.CaseMap = {
...@@ -456,21 +527,24 @@ return g[0] + '-' + g[1].toLowerCase(); ...@@ -456,21 +527,24 @@ return g[0] + '-' + g[1].toLowerCase();
} }
}; };
Polymer.Base._addFeature({ Polymer.Base._addFeature({
_prepAttributes: function () {
this._aggregatedAttributes = {};
},
_addHostAttributes: function (attributes) { _addHostAttributes: function (attributes) {
if (!this._aggregatedAttributes) {
this._aggregatedAttributes = {};
}
if (attributes) { if (attributes) {
this.mixin(this._aggregatedAttributes, attributes); this.mixin(this._aggregatedAttributes, attributes);
} }
}, },
_marshalHostAttributes: function () { _marshalHostAttributes: function () {
if (this._aggregatedAttributes) {
this._applyAttributes(this, this._aggregatedAttributes); this._applyAttributes(this, this._aggregatedAttributes);
}
}, },
_applyAttributes: function (node, attr$) { _applyAttributes: function (node, attr$) {
for (var n in attr$) { for (var n in attr$) {
if (!this.hasAttribute(n) && n !== 'class') { if (!this.hasAttribute(n) && n !== 'class') {
this.serializeValueToAttribute(attr$[n], n, this); var v = attr$[n];
this.serializeValueToAttribute(v, n, this);
} }
} }
}, },
...@@ -478,29 +552,40 @@ _marshalAttributes: function () { ...@@ -478,29 +552,40 @@ _marshalAttributes: function () {
this._takeAttributesToModel(this); this._takeAttributesToModel(this);
}, },
_takeAttributesToModel: function (model) { _takeAttributesToModel: function (model) {
for (var i = 0, l = this.attributes.length; i < l; i++) { if (this.hasAttributes()) {
this._setAttributeToProperty(model, this.attributes[i].name); for (var i in this._propertyInfo) {
var info = this._propertyInfo[i];
if (this.hasAttribute(info.attribute)) {
this._setAttributeToProperty(model, info.attribute, i, info);
}
}
} }
}, },
_setAttributeToProperty: function (model, attrName) { _setAttributeToProperty: function (model, attribute, property, info) {
if (!this._serializing) { if (!this._serializing) {
var propName = Polymer.CaseMap.dashToCamelCase(attrName); var property = property || Polymer.CaseMap.dashToCamelCase(attribute);
var info = this.getPropertyInfo(propName); info = info || this._propertyInfo && this._propertyInfo[property];
if (info.defined || this._propertyEffects && this._propertyEffects[propName]) { if (info && !info.readOnly) {
var val = this.getAttribute(attrName); var v = this.getAttribute(attribute);
model[propName] = this.deserialize(val, info.type); model[property] = this.deserialize(v, info.type);
} }
} }
}, },
_serializing: false, _serializing: false,
reflectPropertyToAttribute: function (name) { reflectPropertyToAttribute: function (property, attribute, value) {
this._serializing = true; this._serializing = true;
this.serializeValueToAttribute(this[name], Polymer.CaseMap.camelToDashCase(name)); value = value === undefined ? this[property] : value;
this.serializeValueToAttribute(value, attribute || Polymer.CaseMap.camelToDashCase(property));
this._serializing = false; this._serializing = false;
}, },
serializeValueToAttribute: function (value, attribute, node) { serializeValueToAttribute: function (value, attribute, node) {
var str = this.serialize(value); var str = this.serialize(value);
(node || this)[str === undefined ? 'removeAttribute' : 'setAttribute'](attribute, str); node = node || this;
if (str === undefined) {
node.removeAttribute(attribute);
} else {
node.setAttribute(attribute, str);
}
}, },
deserialize: function (value, type) { deserialize: function (value, type) {
switch (type) { switch (type) {
...@@ -576,13 +661,13 @@ debouncer.stop(); ...@@ -576,13 +661,13 @@ debouncer.stop();
} }
} }
}); });
Polymer.version = '1.1.4'; Polymer.version = '1.2.2';
Polymer.Base._addFeature({ Polymer.Base._addFeature({
_registerFeatures: function () { _registerFeatures: function () {
this._prepIs(); this._prepIs();
this._prepAttributes();
this._prepBehaviors(); this._prepBehaviors();
this._prepConstructor(); this._prepConstructor();
this._prepPropertyInfo();
}, },
_prepBehavior: function (b) { _prepBehavior: function (b) {
this._addHostAttributes(b.hostAttributes); this._addHostAttributes(b.hostAttributes);
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
}, },
getActiveCount: function () { getActiveCount: function () {
return this.items.length - this.getCompletedCount(this.items); return this.items ? (this.items.length - this.getCompletedCount(this.items)) : 0;
}, },
matchesFilter: function(item, filter) { matchesFilter: function(item, filter) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment