update polymer components
This commit is contained in:
parent
0320ad7256
commit
3c08769c6c
29 changed files with 961 additions and 844 deletions
|
@ -64,6 +64,8 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
|||
|
||||
/**
|
||||
* Returns the currently selected item.
|
||||
*
|
||||
* @type {?Object}
|
||||
*/
|
||||
selectedItem: {
|
||||
type: Object,
|
||||
|
@ -104,11 +106,21 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
|||
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`
|
||||
* of the element that will be ignored from the item list.
|
||||
*
|
||||
* @type {object}
|
||||
* @default {template: 1}
|
||||
*/
|
||||
_excludedLocalNames: {
|
||||
|
@ -128,15 +140,12 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
|||
created: function() {
|
||||
this._bindFilterItem = this._filterItem.bind(this);
|
||||
this._selection = new Polymer.IronSelection(this._applySelection.bind(this));
|
||||
// TODO(cdata): When polymer/polymer#2535 lands, we do not need to do this
|
||||
// book keeping anymore:
|
||||
this.__listeningForActivate = false;
|
||||
},
|
||||
|
||||
attached: function() {
|
||||
this._observer = this._observeItems(this);
|
||||
this._contentObserver = this._observeContent(this);
|
||||
if (!this.selectedItem && this.selected) {
|
||||
this._updateItems();
|
||||
if (!this._shouldUpdateSelection) {
|
||||
this._updateSelected(this.attrForSelected,this.selected)
|
||||
}
|
||||
this._addListener(this.activateEvent);
|
||||
|
@ -144,25 +153,11 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
|||
|
||||
detached: function() {
|
||||
if (this._observer) {
|
||||
this._observer.disconnect();
|
||||
}
|
||||
if (this._contentObserver) {
|
||||
this._contentObserver.disconnect();
|
||||
Polymer.dom(this).unobserveNodes(this._observer);
|
||||
}
|
||||
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.
|
||||
*
|
||||
|
@ -205,18 +200,16 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
|||
this.selected = this._indexToValue(index);
|
||||
},
|
||||
|
||||
_addListener: function(eventName) {
|
||||
if (!this.isAttached || this.__listeningForActivate) {
|
||||
return;
|
||||
}
|
||||
get _shouldUpdateSelection() {
|
||||
return this.selected != null;
|
||||
},
|
||||
|
||||
this.__listeningForActivate = true;
|
||||
_addListener: function(eventName) {
|
||||
this.listen(this, eventName, '_activateHandler');
|
||||
},
|
||||
|
||||
_removeListener: function(eventName) {
|
||||
this.unlisten(this, eventName, '_activateHandler');
|
||||
this.__listeningForActivate = false;
|
||||
},
|
||||
|
||||
_activateEventChanged: function(eventName, old) {
|
||||
|
@ -224,6 +217,12 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
|||
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() {
|
||||
this._selectSelected(this.selected);
|
||||
},
|
||||
|
@ -282,18 +281,9 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
|||
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.
|
||||
_observeItems: function(node) {
|
||||
// TODO(cdata): Update this when we get distributed children changed.
|
||||
var observer = new MutationObserver(function(mutations) {
|
||||
return Polymer.dom(node).observeNodes(function(mutations) {
|
||||
// Let other interested parties know about the change so that
|
||||
// we don't have to recreate mutation observers everywher.
|
||||
this.fire('iron-items-changed', mutations, {
|
||||
|
@ -301,15 +291,12 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
|||
cancelable: false
|
||||
});
|
||||
|
||||
if (this.selected != null) {
|
||||
this._updateItems();
|
||||
|
||||
if (this._shouldUpdateSelection) {
|
||||
this._updateSelected();
|
||||
}
|
||||
}.bind(this));
|
||||
observer.observe(node, {
|
||||
childList: true,
|
||||
subtree: true
|
||||
});
|
||||
return observer;
|
||||
},
|
||||
|
||||
_activateHandler: function(e) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue