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

Side by Side Diff: third_party/polymer/v1_0/components-chromium/paper-radio-group/paper-radio-group-extracted.js

Issue 1187823002: Update Polymer components and re-run reproduce.sh (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 6 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 unified diff | Download patch
OLDNEW
1 1
2 Polymer({ 2 Polymer({
3 is: 'paper-radio-group', 3 is: 'paper-radio-group',
4 4
5 behaviors: [ 5 behaviors: [
6 Polymer.IronA11yKeysBehavior 6 Polymer.IronA11yKeysBehavior,
7 Polymer.IronSelectableBehavior
7 ], 8 ],
8 9
9 hostAttributes: { 10 hostAttributes: {
10 role: 'radiogroup', 11 role: 'radiogroup',
11 tabindex: 0 12 tabindex: 0
12 }, 13 },
13 14
14 properties: { 15 properties: {
15 /** 16 /**
16 * Fired when the selected element changes to user interaction. 17 * Overriden from Polymer.IronSelectableBehavior
17 *
18 * @event paper-radio-group-changed
19 */ 18 */
19 attrForSelected: {
20 type: String,
21 value: 'name'
22 },
20 23
21 /** 24 /**
22 * Gets or sets the selected element. Use the `name` attribute of the 25 * Overriden from Polymer.IronSelectableBehavior
23 * <paper-radio-button> that should be selected.
24 *
25 * @attribute selected
26 * @type String
27 * @default null
28 */ 26 */
29 27 selectedAttribute: {
30 selected: {
31 type: String, 28 type: String,
32 value: null, 29 value: 'checked'
33 notify: true,
34 reflectToAttribute: true,
35 observer: "_selectedChanged"
36 } 30 }
37 }, 31 },
38 32
39 keyBindings: { 33 keyBindings: {
40 'left up': '_selectPrevious', 34 'left up': 'selectPrevious',
41 'right down': '_selectNext', 35 'right down': 'selectNext',
42 },
43
44 _selectedChanged: function() {
45 // TODO: This only needs to be async while a domReady event is unavailable .
46 this.async(function() {
47 this._selectIndex(this._valueToIndex(this.items, this.selected));
48 this.fire('paper-radio-group-changed');
49 });
50 },
51
52 _selectNext: function() {
53 this.selected = this._nextNode();
54 },
55
56 _selectPrevious: function() {
57 this.selected = this._previousNode();
58 }, 36 },
59 37
60 /** 38 /**
61 * Returns an array of all items. 39 * Selects the given value.
62 *
63 * @property items
64 * @type array
65 */ 40 */
66 get items() { 41 select: function(value) {
67 return Polymer.dom(this.$.items).getDistributedNodes(); 42 if (this.selected) {
43 var oldItem = this._valueToItem(this.selected);
44
45 // Do not allow unchecking the selected item.
46 if (this.selected == value) {
47 oldItem.checked = true;
48 return;
49 }
50
51 if (oldItem)
52 oldItem.checked = false;
53 }
54
55 Polymer.IronSelectableBehavior.select.apply(this, [value]);
56 this.fire('paper-radio-group-changed');
68 }, 57 },
69 58
70 _nextNode: function() { 59 /**
71 var items = this.items; 60 * Selects the previous item. If the previous item is disabled, then it is
72 var index = this._selectedIndex; 61 * skipped, and its previous item is selected
73 var newIndex = index; 62 */
63 selectPrevious: function() {
64 var length = this.items.length;
65 var newIndex = Number(this._valueToIndex(this.selected));
66
74 do { 67 do {
75 newIndex = (newIndex + 1) % items.length; 68 newIndex = (newIndex - 1 + length) % length;
76 if (newIndex === index) { 69 } while (this.items[newIndex].disabled)
77 break; 70
78 } 71 this.select(this._indexToValue(newIndex));
79 } while (items[newIndex].disabled);
80 return this._valueForNode(items[newIndex]);
81 }, 72 },
82 73
83 _previousNode: function() { 74 /**
84 var items = this.items; 75 * Selects the next item. If the next item is disabled, then it is
85 var index = this._selectedIndex; 76 * skipped, and its nexy item is selected
86 var newIndex = index; 77 */
78 selectNext: function() {
79 var length = this.items.length;
80 var newIndex = Number(this._valueToIndex(this.selected));
81
87 do { 82 do {
88 newIndex = (newIndex || items.length) - 1; 83 newIndex = (newIndex + 1 + length) % length;
89 if (newIndex === index) { 84 } while (this.items[newIndex].disabled)
90 break; 85
91 } 86 this.select(this._indexToValue(newIndex));
92 } while (items[newIndex].disabled);
93 return this._valueForNode(items[newIndex]);
94 }, 87 },
95
96 _selectIndex: function(index) {
97 if (index == this._selectedIndex)
98 return;
99
100 var nodes = this.items;
101
102 // If there was a previously selected node, deselect it.
103 if (nodes[this._selectedIndex]) {
104 nodes[this._selectedIndex].checked = false;
105 }
106
107 // Select a new node.
108 nodes[index].checked = true;
109 nodes[index].focus();
110 this._selectedIndex = index;
111 },
112
113 _valueForNode: function(node) {
114 return node["name"] || node.getAttribute("name");
115 },
116
117 // Finds an item with value == |value| and return its index.
118 _valueToIndex: function(items, value) {
119 for (var index = 0, node; (node = items[index]); index++) {
120 if (this._valueForNode(node) == value) {
121 return index;
122 }
123 }
124 // If no item found, the value itself is probably the index.
125 return value;
126 }
127 }); 88 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698