Index: third_party/polymer/components-chromium/core-selection/core-selection-extracted.js |
diff --git a/third_party/polymer/components-chromium/core-selection/core-selection-extracted.js b/third_party/polymer/components-chromium/core-selection/core-selection-extracted.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..86994c98c2218109634a13b4eb24c0e964b6eeef |
--- /dev/null |
+++ b/third_party/polymer/components-chromium/core-selection/core-selection-extracted.js |
@@ -0,0 +1,73 @@ |
+ |
+ Polymer('core-selection', { |
+ /** |
+ * If true, multiple selections are allowed. |
+ * |
+ * @attribute multi |
+ * @type boolean |
+ * @default false |
+ */ |
+ multi: false, |
+ ready: function() { |
+ this.clear(); |
+ }, |
+ clear: function() { |
+ this.selection = []; |
+ }, |
+ /** |
+ * Retrieves the selected item(s). |
+ * @method getSelection |
+ * @returns Returns the selected item(s). If the multi property is true, |
+ * getSelection will return an array, otherwise it will return |
+ * the selected item or undefined if there is no selection. |
+ */ |
+ getSelection: function() { |
+ return this.multi ? this.selection : this.selection[0]; |
+ }, |
+ /** |
+ * Indicates if a given item is selected. |
+ * @method isSelected |
+ * @param {any} item The item whose selection state should be checked. |
+ * @returns Returns true if `item` is selected. |
+ */ |
+ isSelected: function(item) { |
+ return this.selection.indexOf(item) >= 0; |
+ }, |
+ setItemSelected: function(item, isSelected) { |
+ if (item !== undefined && item !== null) { |
+ if (isSelected) { |
+ this.selection.push(item); |
+ } else { |
+ var i = this.selection.indexOf(item); |
+ if (i >= 0) { |
+ this.selection.splice(i, 1); |
+ } |
+ } |
+ this.fire("core-select", {isSelected: isSelected, item: item}); |
+ } |
+ }, |
+ /** |
+ * Set the selection state for a given `item`. If the multi property |
+ * is true, then the selected state of `item` will be toggled; otherwise |
+ * the `item` will be selected. |
+ * @method select |
+ * @param {any} item: The item to select. |
+ */ |
+ select: function(item) { |
+ if (this.multi) { |
+ this.toggle(item); |
+ } else if (this.getSelection() !== item) { |
+ this.setItemSelected(this.getSelection(), false); |
+ this.setItemSelected(item, true); |
+ } |
+ }, |
+ /** |
+ * Toggles the selection state for `item`. |
+ * @method toggle |
+ * @param {any} item: The item to toggle. |
+ */ |
+ toggle: function(item) { |
+ this.setItemSelected(item, !this.isSelected(item)); |
+ } |
+ }); |
+ |