Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Unified Diff: third_party/polymer/v0_8/components-chromium/paper-radio-group/paper-radio-group-extracted.js

Issue 1162563004: Upgrade to 1.0 and switch clients to dom-repeat where needed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix a layout import and remove the gzipped webanimation in reproduce.sh Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/polymer/v0_8/components-chromium/paper-radio-group/paper-radio-group-extracted.js
diff --git a/third_party/polymer/v0_8/components-chromium/paper-radio-group/paper-radio-group-extracted.js b/third_party/polymer/v0_8/components-chromium/paper-radio-group/paper-radio-group-extracted.js
new file mode 100644
index 0000000000000000000000000000000000000000..6de17dc0b7ebc43582e45461b1438a287255ab9b
--- /dev/null
+++ b/third_party/polymer/v0_8/components-chromium/paper-radio-group/paper-radio-group-extracted.js
@@ -0,0 +1,127 @@
+
+ Polymer({
+ is: 'paper-radio-group',
+
+ behaviors: [
+ Polymer.IronA11yKeysBehavior
+ ],
+
+ hostAttributes: {
+ role: 'radiogroup',
+ tabindex: 0
+ },
+
+ properties: {
+ /**
+ * Fired when the selected element changes to user interaction.
+ *
+ * @event paper-radio-group-changed
+ */
+
+ /**
+ * Gets or sets the selected element. Use the `name` attribute of the
+ * <paper-radio-button> that should be selected.
+ *
+ * @attribute selected
+ * @type String
+ * @default null
+ */
+
+ selected: {
+ type: String,
+ value: null,
+ notify: true,
+ reflectToAttribute: true,
+ observer: "_selectedChanged"
+ }
+ },
+
+ keyBindings: {
+ 'left up': '_selectPrevious',
+ 'right down': '_selectNext',
+ },
+
+ _selectedChanged: function() {
+ // TODO: This only needs to be async while a domReady event is unavailable.
+ this.async(function() {
+ this._selectIndex(this._valueToIndex(this.items, this.selected));
+ this.fire('paper-radio-group-changed');
+ });
+ },
+
+ _selectNext: function() {
+ this.selected = this._nextNode();
+ },
+
+ _selectPrevious: function() {
+ this.selected = this._previousNode();
+ },
+
+ /**
+ * Returns an array of all items.
+ *
+ * @property items
+ * @type array
+ */
+ get items() {
+ return Polymer.dom(this.$.items).getDistributedNodes();
+ },
+
+ _nextNode: function() {
+ var items = this.items;
+ var index = this._selectedIndex;
+ var newIndex = index;
+ do {
+ newIndex = (newIndex + 1) % items.length;
+ if (newIndex === index) {
+ break;
+ }
+ } while (items[newIndex].disabled);
+ return this._valueForNode(items[newIndex]);
+ },
+
+ _previousNode: function() {
+ var items = this.items;
+ var index = this._selectedIndex;
+ var newIndex = index;
+ do {
+ newIndex = (newIndex || items.length) - 1;
+ if (newIndex === index) {
+ break;
+ }
+ } while (items[newIndex].disabled);
+ return this._valueForNode(items[newIndex]);
+ },
+
+ _selectIndex: function(index) {
+ if (index == this._selectedIndex)
+ return;
+
+ var nodes = this.items;
+
+ // If there was a previously selected node, deselect it.
+ if (nodes[this._selectedIndex]) {
+ nodes[this._selectedIndex].checked = false;
+ }
+
+ // Select a new node.
+ nodes[index].checked = true;
+ nodes[index].focus();
+ this._selectedIndex = index;
+ },
+
+ _valueForNode: function(node) {
+ return node["name"] || node.getAttribute("name");
+ },
+
+ // Finds an item with value == |value| and return its index.
+ _valueToIndex: function(items, value) {
+ for (var index = 0, node; (node = items[index]); index++) {
+ if (this._valueForNode(node) == value) {
+ return index;
+ }
+ }
+ // If no item found, the value itself is probably the index.
+ return value;
+ }
+ });

Powered by Google App Engine
This is Rietveld 408576698