| Index: third_party/polymer/v0_8/components-chromium/iron-selector/iron-selection-extracted.js
|
| diff --git a/third_party/polymer/v0_8/components-chromium/iron-selector/iron-selection-extracted.js b/third_party/polymer/v0_8/components-chromium/iron-selector/iron-selection-extracted.js
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..f901d5da9a4f6aafbaee9e16a6e2caf92332f075
|
| --- /dev/null
|
| +++ b/third_party/polymer/v0_8/components-chromium/iron-selector/iron-selection-extracted.js
|
| @@ -0,0 +1,98 @@
|
| +
|
| +
|
| + Polymer.IronSelection = function(selectCallback) {
|
| + this.selection = [];
|
| + this.selectCallback = selectCallback;
|
| + };
|
| +
|
| + Polymer.IronSelection.prototype = {
|
| +
|
| + /**
|
| + * Retrieves the selected item(s).
|
| + *
|
| + * @method get
|
| + * @returns Returns the selected item(s). If the multi property is true,
|
| + * `get` will return an array, otherwise it will return
|
| + * the selected item or undefined if there is no selection.
|
| + */
|
| + get: function() {
|
| + return this.multi ? this.selection : this.selection[0];
|
| + },
|
| +
|
| + /**
|
| + * Clears all the selection except the ones indicated.
|
| + *
|
| + * @method clear
|
| + * @param {Array} excludes items to be excluded.
|
| + */
|
| + clear: function(excludes) {
|
| + this.selection.slice().forEach(function(item) {
|
| + if (!excludes || excludes.indexOf(item) < 0) {
|
| + this.setItemSelected(item, false);
|
| + }
|
| + }, this);
|
| + },
|
| +
|
| + /**
|
| + * 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;
|
| + },
|
| +
|
| + /**
|
| + * Sets the selection state for a given item to either selected or deselected.
|
| + *
|
| + * @method setItemSelected
|
| + * @param {any} item The item to select.
|
| + * @param {Boolean} isSelected True for selected, false for deselected.
|
| + */
|
| + setItemSelected: function(item, isSelected) {
|
| + if (item != null) {
|
| + if (isSelected) {
|
| + this.selection.push(item);
|
| + } else {
|
| + var i = this.selection.indexOf(item);
|
| + if (i >= 0) {
|
| + this.selection.splice(i, 1);
|
| + }
|
| + }
|
| + if (this.selectCallback) {
|
| + this.selectCallback(item, isSelected);
|
| + }
|
| + }
|
| + },
|
| +
|
| + /**
|
| + * Sets 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.get() !== item) {
|
| + this.setItemSelected(this.get(), 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));
|
| + }
|
| +
|
| + };
|
| +
|
|
|