Index: polymer_0.5.0/bower_components/core-selector/core-selector.html |
diff --git a/bower_components/core-selector/core-selector.html b/polymer_0.5.0/bower_components/core-selector/core-selector.html |
similarity index 85% |
rename from bower_components/core-selector/core-selector.html |
rename to polymer_0.5.0/bower_components/core-selector/core-selector.html |
index 1e29e1bb13f612faf1f4c74c02594dda525b03a9..c3ca140b8d0a5b17617470f1994eb9e4ca5d6536 100644 |
--- a/bower_components/core-selector/core-selector.html |
+++ b/polymer_0.5.0/bower_components/core-selector/core-selector.html |
@@ -264,6 +264,10 @@ Fired when an item element is tapped. |
notap: false, |
defaultExcludedLocalNames: 'template', |
+ |
+ observe: { |
+ 'selected multi': 'selectedChanged' |
+ }, |
ready: function() { |
this.activateListener = this.activateHandler.bind(this); |
@@ -336,15 +340,21 @@ Fired when an item element is tapped. |
}, |
selectedChanged: function() { |
- this.updateSelected(); |
+ // TODO(ffu): Right now this is the only way to know that the `selected` |
+ // is an array and was mutated, as opposed to newly assigned. |
+ if (arguments.length === 1) { |
+ this.processSplices(arguments[0]); |
+ } else { |
+ this.updateSelected(); |
+ } |
}, |
- |
+ |
updateSelected: function() { |
this.validateSelected(); |
if (this.multi) { |
- this.clearSelection(); |
+ this.clearSelection(this.selected) |
this.selected && this.selected.forEach(function(s) { |
- this.valueToSelection(s); |
+ this.setValueSelected(s, true) |
}, this); |
} else { |
this.valueToSelection(this.selected); |
@@ -354,28 +364,47 @@ Fired when an item element is tapped. |
validateSelected: function() { |
// convert to an array for multi-selection |
if (this.multi && !Array.isArray(this.selected) && |
- this.selected !== null && this.selected !== undefined) { |
+ this.selected != null) { |
this.selected = [this.selected]; |
+ // use the first selected in the array for single-selection |
+ } else if (!this.multi && Array.isArray(this.selected)) { |
+ var s = this.selected[0]; |
+ this.clearSelection([s]); |
+ this.selected = s; |
} |
}, |
- |
- clearSelection: function() { |
- if (this.multi) { |
- this.selection.slice().forEach(function(s) { |
- this.$.selection.setItemSelected(s, false); |
- }, this); |
- } else { |
- this.$.selection.setItemSelected(this.selection, false); |
+ |
+ processSplices: function(splices) { |
+ for (var i = 0, splice; splice = splices[i]; i++) { |
+ for (var j = 0; j < splice.removed.length; j++) { |
+ this.setValueSelected(splice.removed[j], false); |
+ } |
+ for (var j = 0; j < splice.addedCount; j++) { |
+ this.setValueSelected(this.selected[splice.index + j], true); |
+ } |
} |
- this.selectedItem = null; |
- this.$.selection.clear(); |
+ }, |
+ |
+ clearSelection: function(excludes) { |
+ this.$.selection.selection.slice().forEach(function(item) { |
+ var v = this.valueForNode(item) || this.items.indexOf(item); |
+ if (!excludes || excludes.indexOf(v) < 0) { |
+ this.$.selection.setItemSelected(item, false); |
+ } |
+ }, this); |
}, |
valueToSelection: function(value) { |
- var item = (value === null || value === undefined) ? |
- null : this.items[this.valueToIndex(value)]; |
+ var item = this.valueToItem(value); |
this.$.selection.select(item); |
}, |
+ |
+ setValueSelected: function(value, isSelected) { |
+ var item = this.valueToItem(value); |
+ if (isSelected ^ this.$.selection.isSelected(item)) { |
+ this.$.selection.setItemSelected(item, isSelected); |
+ } |
+ }, |
updateSelectedItem: function() { |
this.selectedItem = this.selection; |
@@ -391,6 +420,11 @@ Fired when an item element is tapped. |
this.selectedIndex = this.selectedItem ? |
parseInt(this.valueToIndex(this.selected)) : -1; |
}, |
+ |
+ valueToItem: function(value) { |
+ return (value === null || value === undefined) ? |
+ null : this.items[this.valueToIndex(value)]; |
+ }, |
valueToIndex: function(value) { |
// find an item with value == value and return it's index |
@@ -459,7 +493,6 @@ Fired when an item element is tapped. |
} else { |
this.selected.push(value); |
} |
- this.valueToSelection(value); |
}, |
findDistributedTarget: function(target, nodes) { |
@@ -483,14 +516,16 @@ Fired when an item element is tapped. |
}, |
/** |
- * Selects the previous item. This should be used in single selection only. |
+ * Selects the previous item. This should be used in single selection only. |
* |
* @method selectPrevious |
- * @param {boolean} wrap if true and it is already at the first item, wrap to the end |
+ * @param {boolean} wrapped if true and it is already at the first item, |
+ * wrap to the end |
* @returns the previous item or undefined if there is none |
*/ |
- selectPrevious: function(wrap) { |
- var i = wrap && !this.selectedIndex ? this.items.length - 1 : this.selectedIndex - 1; |
+ selectPrevious: function(wrapped) { |
+ var i = wrapped && !this.selectedIndex ? |
+ this.items.length - 1 : this.selectedIndex - 1; |
return this.selectIndex(i); |
}, |
@@ -498,11 +533,13 @@ Fired when an item element is tapped. |
* Selects the next item. This should be used in single selection only. |
* |
* @method selectNext |
- * @param {boolean} wrap if true and it is already at the last item, wrap to the front |
+ * @param {boolean} wrapped if true and it is already at the last item, |
+ * wrap to the front |
* @returns the next item or undefined if there is none |
*/ |
- selectNext: function(wrap) { |
- var i = wrap && this.selectedIndex >= this.items.length - 1 ? 0 : this.selectedIndex + 1; |
+ selectNext: function(wrapped) { |
+ var i = wrapped && this.selectedIndex >= this.items.length - 1 ? |
+ 0 : this.selectedIndex + 1; |
return this.selectIndex(i); |
} |