diff options
author | jlklein <jlklein@chromium.org> | 2015-06-03 01:33:34 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-03 08:34:26 +0000 |
commit | 9e500768d8abf6ca4f16550be4c2729312d221b2 (patch) | |
tree | 0ade10ed3ff939c55eee2e96737aa0e6900278dd /third_party/polymer/v1_0/components-chromium/iron-selector | |
parent | 6a852f7ee7eafd16834701a19e48b3cf9a5b64db (diff) | |
download | chromium_src-9e500768d8abf6ca4f16550be4c2729312d221b2.zip chromium_src-9e500768d8abf6ca4f16550be4c2729312d221b2.tar.gz chromium_src-9e500768d8abf6ca4f16550be4c2729312d221b2.tar.bz2 |
Rolling forward https://codereview.chromium.org/1155683008/ which was
reverted by https://codereview.chromium.org/1162963002.
Rename polymer and cr_elements v0_8 to v1_0
Fix what caused the revert: Merge in the appearence page and update
compile.py from v0_8 to v1_0.
BUG=489785
Review URL: https://codereview.chromium.org/1158973006
Cr-Commit-Position: refs/heads/master@{#332568}
Diffstat (limited to 'third_party/polymer/v1_0/components-chromium/iron-selector')
13 files changed, 755 insertions, 0 deletions
diff --git a/third_party/polymer/v1_0/components-chromium/iron-selector/.bower.json b/third_party/polymer/v1_0/components-chromium/iron-selector/.bower.json new file mode 100644 index 0000000..31050826 --- /dev/null +++ b/third_party/polymer/v1_0/components-chromium/iron-selector/.bower.json @@ -0,0 +1,41 @@ +{ + "name": "iron-selector", + "version": "1.0.2", + "description": "Manages a set of elements that can be selected", + "private": true, + "license": "http://polymer.github.io/LICENSE.txt", + "main": [ + "iron-selector.html" + ], + "authors": [ + "The Polymer Authors" + ], + "keywords": [ + "web-components", + "polymer", + "selector" + ], + "repository": { + "type": "git", + "url": "git://github.com/PolymerElements/iron-selector.git" + }, + "dependencies": { + "polymer": "Polymer/polymer#^1.0.0" + }, + "devDependencies": { + "iron-component-page": "PolymerElements/iron-component-page#^1.0.0", + "test-fixture": "PolymerElements/test-fixture#^1.0.0", + "web-component-tester": "*", + "webcomponentsjs": "webcomponents/webcomponentsjs#^0.7.0" + }, + "homepage": "https://github.com/PolymerElements/iron-selector", + "_release": "1.0.2", + "_resolution": { + "type": "version", + "tag": "v1.0.2", + "commit": "ea22d91d11ba6f72c01faa952d5e600f9d1773cf" + }, + "_source": "git://github.com/PolymerElements/iron-selector.git", + "_target": "^1.0.0", + "_originalSource": "PolymerElements/iron-selector" +}
\ No newline at end of file diff --git a/third_party/polymer/v1_0/components-chromium/iron-selector/.gitignore b/third_party/polymer/v1_0/components-chromium/iron-selector/.gitignore new file mode 100644 index 0000000..b13058c --- /dev/null +++ b/third_party/polymer/v1_0/components-chromium/iron-selector/.gitignore @@ -0,0 +1,2 @@ +bower_components +.DS_Store diff --git a/third_party/polymer/v1_0/components-chromium/iron-selector/README.md b/third_party/polymer/v1_0/components-chromium/iron-selector/README.md new file mode 100644 index 0000000..8bb3d64 --- /dev/null +++ b/third_party/polymer/v1_0/components-chromium/iron-selector/README.md @@ -0,0 +1,50 @@ +iron-selector +============= + +`iron-selector` is an element which can be used to manage a list of elements +that can be selected. Tapping on the item will make the item selected. The `selected` indicates +which item is being selected. The default is to use the index of the item. + +Example: + +```html +<iron-selector selected="0"> + <div>Item 1</div> + <div>Item 2</div> + <div>Item 3</div> +</iron-selector> +``` + +If you want to use the attribute value of an element for `selected` instead of the index, +set `attrForSelected` to the name of the attribute. For example, if you want to select item by +`name`, set `attrForSelected` to `name`. + +Example: + +```html +<iron-selector attr-for-selected="name" selected="foo"> + <div name="foo">Foo</div> + <div name="bar">Bar</div> + <div name="zot">Zot</div> +</iron-selector> +``` + +`iron-selector` is not styled. Use the `iron-selected` CSS class to style the selected element. + +Example: + +```html +<style> + .iron-selected { + background: #eee; + } +</style> + +... + +<iron-selector selected="0"> + <div>Item 1</div> + <div>Item 2</div> + <div>Item 3</div> +</iron-selector> +``` diff --git a/third_party/polymer/v1_0/components-chromium/iron-selector/bower.json b/third_party/polymer/v1_0/components-chromium/iron-selector/bower.json new file mode 100644 index 0000000..b9751df --- /dev/null +++ b/third_party/polymer/v1_0/components-chromium/iron-selector/bower.json @@ -0,0 +1,31 @@ +{ + "name": "iron-selector", + "version": "1.0.2", + "description": "Manages a set of elements that can be selected", + "private": true, + "license": "http://polymer.github.io/LICENSE.txt", + "main": [ + "iron-selector.html" + ], + "authors": [ + "The Polymer Authors" + ], + "keywords": [ + "web-components", + "polymer", + "selector" + ], + "repository": { + "type": "git", + "url": "git://github.com/PolymerElements/iron-selector.git" + }, + "dependencies": { + "polymer": "Polymer/polymer#^1.0.0" + }, + "devDependencies": { + "iron-component-page": "PolymerElements/iron-component-page#^1.0.0", + "test-fixture": "PolymerElements/test-fixture#^1.0.0", + "web-component-tester": "*", + "webcomponentsjs": "webcomponents/webcomponentsjs#^0.7.0" + } +} diff --git a/third_party/polymer/v1_0/components-chromium/iron-selector/index.html b/third_party/polymer/v1_0/components-chromium/iron-selector/index.html new file mode 100644 index 0000000..741693c --- /dev/null +++ b/third_party/polymer/v1_0/components-chromium/iron-selector/index.html @@ -0,0 +1,28 @@ +<!doctype html> +<!-- +@license +Copyright (c) 2015 The Polymer Project Authors. All rights reserved. +This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt +The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt +The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt +Code distributed by Google as part of the polymer project is also +subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt +--> + +<html> +<head> + + <title>iron-selector</title> + <meta charset="utf-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + + <script src="../webcomponentsjs/webcomponents-lite.js"></script> + <link rel="import" href="../iron-component-page/iron-component-page.html"> + +</head> +<body> + + <iron-component-page></iron-component-page> + +</body> +</html> diff --git a/third_party/polymer/v1_0/components-chromium/iron-selector/iron-multi-selectable-extracted.js b/third_party/polymer/v1_0/components-chromium/iron-selector/iron-multi-selectable-extracted.js new file mode 100644 index 0000000..a595e49 --- /dev/null +++ b/third_party/polymer/v1_0/components-chromium/iron-selector/iron-multi-selectable-extracted.js @@ -0,0 +1,106 @@ + + /** @polymerBehavior Polymer.IronMultiSelectableBehavior */ + Polymer.IronMultiSelectableBehaviorImpl = { + properties: { + + /** + * If true, multiple selections are allowed. + */ + multi: { + type: Boolean, + value: false, + observer: 'multiChanged' + }, + + /** + * Gets or sets the selected elements. This is used instead of `selected` when `multi` + * is true. + */ + selectedValues: { + type: Array, + notify: true + }, + + /** + * Returns an array of currently selected items. + */ + selectedItems: { + type: Array, + readOnly: true, + notify: true + }, + + }, + + observers: [ + '_updateSelected(attrForSelected, selectedValues)' + ], + + /** + * Selects the given value. If the `multi` property is true, then the selected state of the + * `value` will be toggled; otherwise the `value` will be selected. + * + * @method select + * @param {string} value the value to select. + */ + select: function(value) { + if (this.multi) { + if (this.selectedValues) { + this._toggleSelected(value); + } else { + this.selectedValues = [value]; + } + } else { + this.selected = value; + } + }, + + multiChanged: function(multi) { + this._selection.multi = multi; + }, + + _updateSelected: function() { + if (this.multi) { + this._selectMulti(this.selectedValues); + } else { + this._selectSelected(this.selected); + } + }, + + _selectMulti: function(values) { + this._selection.clear(); + if (values) { + for (var i = 0; i < values.length; i++) { + this._selection.setItemSelected(this._valueToItem(values[i]), true); + } + } + }, + + _selectionChange: function() { + var s = this._selection.get(); + if (this.multi) { + this._setSelectedItems(s); + } else { + this._setSelectedItems([s]); + this._setSelectedItem(s); + } + }, + + _toggleSelected: function(value) { + var i = this.selectedValues.indexOf(value); + var unselected = i < 0; + if (unselected) { + this.selectedValues.push(value); + } else { + this.selectedValues.splice(i, 1); + } + this._selection.setItemSelected(this._valueToItem(value), unselected); + } + }; + + /** @polymerBehavior */ + Polymer.IronMultiSelectableBehavior = [ + Polymer.IronSelectableBehavior, + Polymer.IronMultiSelectableBehaviorImpl + ]; + diff --git a/third_party/polymer/v1_0/components-chromium/iron-selector/iron-multi-selectable.html b/third_party/polymer/v1_0/components-chromium/iron-selector/iron-multi-selectable.html new file mode 100644 index 0000000..233ff60 --- /dev/null +++ b/third_party/polymer/v1_0/components-chromium/iron-selector/iron-multi-selectable.html @@ -0,0 +1,12 @@ +<!-- +@license +Copyright (c) 2015 The Polymer Project Authors. All rights reserved. +This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt +The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt +The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt +Code distributed by Google as part of the polymer project is also +subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt +--><html><head><link rel="import" href="../polymer/polymer.html"> +<link rel="import" href="iron-selectable.html"> + +</head><body><script src="iron-multi-selectable-extracted.js"></script></body></html>
\ No newline at end of file diff --git a/third_party/polymer/v1_0/components-chromium/iron-selector/iron-selectable-extracted.js b/third_party/polymer/v1_0/components-chromium/iron-selector/iron-selectable-extracted.js new file mode 100644 index 0000000..a17f626 --- /dev/null +++ b/third_party/polymer/v1_0/components-chromium/iron-selector/iron-selectable-extracted.js @@ -0,0 +1,294 @@ + + + /** @polymerBehavior */ + Polymer.IronSelectableBehavior = { + + properties: { + + /** + * If you want to use the attribute value of an element for `selected` instead of the index, + * set this to the name of the attribute. + * + * @attribute attrForSelected + * @type {string} + */ + attrForSelected: { + type: String, + value: null + }, + + /** + * Gets or sets the selected element. The default is to use the index of the item. + * + * @attribute selected + * @type {string} + */ + selected: { + type: String, + notify: true + }, + + /** + * Returns the currently selected item. + * + * @attribute selectedItem + * @type {Object} + */ + selectedItem: { + type: Object, + readOnly: true, + notify: true + }, + + /** + * The event that fires from items when they are selected. Selectable + * will listen for this event from items and update the selection state. + * Set to empty string to listen to no events. + * + * @attribute activateEvent + * @type {string} + * @default 'tap' + */ + activateEvent: { + type: String, + value: 'tap', + observer: '_activateEventChanged' + }, + + /** + * This is a CSS selector sting. If this is set, only items that matches the CSS selector + * are selectable. + * + * @attribute selectable + * @type {string} + */ + selectable: String, + + /** + * The class to set on elements when selected. + * + * @attribute selectedClass + * @type {string} + */ + selectedClass: { + type: String, + value: 'iron-selected' + }, + + /** + * The attribute to set on elements when selected. + * + * @attribute selectedAttribute + * @type {string} + */ + selectedAttribute: { + type: String, + value: null + } + + }, + + observers: [ + '_updateSelected(attrForSelected, selected)' + ], + + excludedLocalNames: { + 'template': 1 + }, + + created: function() { + this._bindFilterItem = this._filterItem.bind(this); + this._selection = new Polymer.IronSelection(this._applySelection.bind(this)); + }, + + attached: function() { + this._observer = this._observeItems(this); + this._contentObserver = this._observeContent(this); + }, + + detached: function() { + if (this._observer) { + this._observer.disconnect(); + } + if (this._contentObserver) { + this._contentObserver.disconnect(); + } + 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. + * + * @method indexOf + * @param {Object} item + * @returns Returns the index of the item + */ + indexOf: function(item) { + return this.items.indexOf(item); + }, + + /** + * Selects the given value. + * + * @method select + * @param {string} value the value to select. + */ + select: function(value) { + this.selected = value; + }, + + /** + * Selects the previous item. + * + * @method selectPrevious + */ + selectPrevious: function() { + var length = this.items.length; + var index = (Number(this._valueToIndex(this.selected)) - 1 + length) % length; + this.selected = this._indexToValue(index); + }, + + /** + * Selects the next item. + * + * @method selectNext + */ + selectNext: function() { + var index = (Number(this._valueToIndex(this.selected)) + 1) % this.items.length; + this.selected = this._indexToValue(index); + }, + + _addListener: function(eventName) { + this.listen(this, eventName, '_activateHandler'); + }, + + _removeListener: function(eventName) { + // There is no unlisten yet... + // https://github.com/Polymer/polymer/issues/1639 + //this.removeEventListener(eventName, this._bindActivateHandler); + }, + + _activateEventChanged: function(eventName, old) { + this._removeListener(old); + this._addListener(eventName); + }, + + _updateSelected: function() { + this._selectSelected(this.selected); + }, + + _selectSelected: function(selected) { + this._selection.select(this._valueToItem(this.selected)); + }, + + _filterItem: function(node) { + return !this.excludedLocalNames[node.localName]; + }, + + _valueToItem: function(value) { + return (value == null) ? null : this.items[this._valueToIndex(value)]; + }, + + _valueToIndex: function(value) { + if (this.attrForSelected) { + for (var i = 0, item; item = this.items[i]; i++) { + if (this._valueForItem(item) == value) { + return i; + } + } + } else { + return Number(value); + } + }, + + _indexToValue: function(index) { + if (this.attrForSelected) { + var item = this.items[index]; + if (item) { + return this._valueForItem(item); + } + } else { + return index; + } + }, + + _valueForItem: function(item) { + return item[this.attrForSelected] || item.getAttribute(this.attrForSelected); + }, + + _applySelection: function(item, isSelected) { + if (this.selectedClass) { + this.toggleClass(this.selectedClass, isSelected, item); + } + if (this.selectedAttribute) { + this.toggleAttribute(this.selectedAttribute, isSelected, item); + } + this._selectionChange(); + this.fire('iron-' + (isSelected ? 'select' : 'deselect'), {item: item}); + }, + + _selectionChange: function() { + 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) { + var observer = new MutationObserver(function() { + if (this.selected != null) { + this._updateSelected(); + } + }.bind(this)); + observer.observe(node, { + childList: true, + subtree: true + }); + return observer; + }, + + _activateHandler: function(e) { + // TODO: remove this when https://github.com/Polymer/polymer/issues/1639 is fixed so we + // can just remove the old event listener. + if (e.type !== this.activateEvent) { + return; + } + var t = e.target; + var items = this.items; + while (t && t != this) { + var i = items.indexOf(t); + if (i >= 0) { + var value = this._indexToValue(i); + this._itemActivate(value, t); + return; + } + t = t.parentNode; + } + }, + + _itemActivate: function(value, item) { + if (!this.fire('iron-activate', + {selected: value, item: item}, {cancelable: true}).defaultPrevented) { + this.select(value); + } + } + + }; + diff --git a/third_party/polymer/v1_0/components-chromium/iron-selector/iron-selectable.html b/third_party/polymer/v1_0/components-chromium/iron-selector/iron-selectable.html new file mode 100644 index 0000000..3d38f77 --- /dev/null +++ b/third_party/polymer/v1_0/components-chromium/iron-selector/iron-selectable.html @@ -0,0 +1,11 @@ +<!-- +Copyright (c) 2015 The Polymer Project Authors. All rights reserved. +This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt +The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt +The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt +Code distributed by Google as part of the polymer project is also +subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt +--><html><head><link rel="import" href="../polymer/polymer.html"> +<link rel="import" href="iron-selection.html"> + +</head><body><script src="iron-selectable-extracted.js"></script></body></html>
\ No newline at end of file diff --git a/third_party/polymer/v1_0/components-chromium/iron-selector/iron-selection-extracted.js b/third_party/polymer/v1_0/components-chromium/iron-selector/iron-selection-extracted.js new file mode 100644 index 0000000..2758326 --- /dev/null +++ b/third_party/polymer/v1_0/components-chromium/iron-selector/iron-selection-extracted.js @@ -0,0 +1,102 @@ + + + /** + * @param {!Function} selectCallback + * @constructor + */ + 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 {*} 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 {*} 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 {*} 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 {*} item The item to toggle. + */ + toggle: function(item) { + this.setItemSelected(item, !this.isSelected(item)); + } + + }; + diff --git a/third_party/polymer/v1_0/components-chromium/iron-selector/iron-selection.html b/third_party/polymer/v1_0/components-chromium/iron-selector/iron-selection.html new file mode 100644 index 0000000..0fe482f --- /dev/null +++ b/third_party/polymer/v1_0/components-chromium/iron-selector/iron-selection.html @@ -0,0 +1,10 @@ +<!-- +Copyright (c) 2015 The Polymer Project Authors. All rights reserved. +This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt +The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt +The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt +Code distributed by Google as part of the polymer project is also +subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt +--><html><head><link rel="import" href="../polymer/polymer.html"> + +</head><body><script src="iron-selection-extracted.js"></script></body></html>
\ No newline at end of file diff --git a/third_party/polymer/v1_0/components-chromium/iron-selector/iron-selector-extracted.js b/third_party/polymer/v1_0/components-chromium/iron-selector/iron-selector-extracted.js new file mode 100644 index 0000000..d430655 --- /dev/null +++ b/third_party/polymer/v1_0/components-chromium/iron-selector/iron-selector-extracted.js @@ -0,0 +1,57 @@ + + /** + `iron-selector` is an element which can be used to manage a list of elements + that can be selected. Tapping on the item will make the item selected. The `selected` indicates + which item is being selected. The default is to use the index of the item. + + Example: + + <iron-selector selected="0"> + <div>Item 1</div> + <div>Item 2</div> + <div>Item 3</div> + </iron-selector> + + If you want to use the attribute value of an element for `selected` instead of the index, + set `attrForSelected` to the name of the attribute. For example, if you want to select item by + `name`, set `attrForSelected` to `name`. + + Example: + + <iron-selector attr-for-selected="name" selected="foo"> + <div name="foo">Foo</div> + <div name="bar">Bar</div> + <div name="zot">Zot</div> + </iron-selector> + + `iron-selector` is not styled. Use the `iron-selected` CSS class to style the selected element. + + Example: + + <style> + .iron-selected { + background: #eee; + } + </style> + + ... + + <iron-selector selected="0"> + <div>Item 1</div> + <div>Item 2</div> + <div>Item 3</div> + </iron-selector> + + @demo demo/index.html + */ + + Polymer({ + + is: 'iron-selector', + + behaviors: [ + Polymer.IronMultiSelectableBehavior + ] + + }); + diff --git a/third_party/polymer/v1_0/components-chromium/iron-selector/iron-selector.html b/third_party/polymer/v1_0/components-chromium/iron-selector/iron-selector.html new file mode 100644 index 0000000..f7afa25 --- /dev/null +++ b/third_party/polymer/v1_0/components-chromium/iron-selector/iron-selector.html @@ -0,0 +1,11 @@ +<!-- +Copyright (c) 2015 The Polymer Project Authors. All rights reserved. +This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt +The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt +The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt +Code distributed by Google as part of the polymer project is also +subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt +--><html><head><link rel="import" href="../polymer/polymer.html"> +<link rel="import" href="iron-multi-selectable.html"> + +</head><body><script src="iron-selector-extracted.js"></script></body></html>
\ No newline at end of file |