Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / third_party / polymer / v1_0 / components / iron-selector / iron-selection.html
blob0ff04cfae4679fe0d4cd551f6ebcf6dbbaf479cf
2 <!--
3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
4 This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6 The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
7 Code distributed by Google as part of the polymer project is also
8 subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
9 -->
11 <link rel="import" href="../polymer/polymer.html">
13 <script>
15 /**
16 * @param {!Function} selectCallback
17 * @constructor
19 Polymer.IronSelection = function(selectCallback) {
20 this.selection = [];
21 this.selectCallback = selectCallback;
24 Polymer.IronSelection.prototype = {
26 /**
27 * Retrieves the selected item(s).
29 * @method get
30 * @returns Returns the selected item(s). If the multi property is true,
31 * `get` will return an array, otherwise it will return
32 * the selected item or undefined if there is no selection.
34 get: function() {
35 return this.multi ? this.selection : this.selection[0];
38 /**
39 * Clears all the selection except the ones indicated.
41 * @method clear
42 * @param {Array} excludes items to be excluded.
44 clear: function(excludes) {
45 this.selection.slice().forEach(function(item) {
46 if (!excludes || excludes.indexOf(item) < 0) {
47 this.setItemSelected(item, false);
49 }, this);
52 /**
53 * Indicates if a given item is selected.
55 * @method isSelected
56 * @param {*} item The item whose selection state should be checked.
57 * @returns Returns true if `item` is selected.
59 isSelected: function(item) {
60 return this.selection.indexOf(item) >= 0;
63 /**
64 * Sets the selection state for a given item to either selected or deselected.
66 * @method setItemSelected
67 * @param {*} item The item to select.
68 * @param {boolean} isSelected True for selected, false for deselected.
70 setItemSelected: function(item, isSelected) {
71 if (item != null) {
72 if (isSelected) {
73 this.selection.push(item);
74 } else {
75 var i = this.selection.indexOf(item);
76 if (i >= 0) {
77 this.selection.splice(i, 1);
80 if (this.selectCallback) {
81 this.selectCallback(item, isSelected);
86 /**
87 * Sets the selection state for a given item. If the `multi` property
88 * is true, then the selected state of `item` will be toggled; otherwise
89 * the `item` will be selected.
91 * @method select
92 * @param {*} item The item to select.
94 select: function(item) {
95 if (this.multi) {
96 this.toggle(item);
97 } else if (this.get() !== item) {
98 this.setItemSelected(this.get(), false);
99 this.setItemSelected(item, true);
104 * Toggles the selection state for `item`.
106 * @method toggle
107 * @param {*} item The item to toggle.
109 toggle: function(item) {
110 this.setItemSelected(item, !this.isSelected(item));
115 </script>