82 this.peerElement.addEventListener("focus", function() { self.focusStateChanged(true); }, false); |
82 this.peerElement.addEventListener("focus", function() { self.focusStateChanged(true); }, false); |
83 this.peerElement.addEventListener("blur", function() { self.focusStateChanged(false); }, false); |
83 this.peerElement.addEventListener("blur", function() { self.focusStateChanged(false); }, false); |
84 this.peerElement.addEventListener("mouseover", function() { self.hoverStateChanged(true); }, false); |
84 this.peerElement.addEventListener("mouseover", function() { self.hoverStateChanged(true); }, false); |
85 this.peerElement.addEventListener("mouseout", function() { self.hoverStateChanged(false); }, false); |
85 this.peerElement.addEventListener("mouseout", function() { self.hoverStateChanged(false); }, false); |
86 this.peerElement.addEventListener("change", function() { self.selectionChanged(); }, false); |
86 this.peerElement.addEventListener("change", function() { self.selectionChanged(); }, false); |
87 } |
87 }; |
88 |
88 |
89 // Returns the enabled state. |
89 // Returns the enabled state. |
90 SelectionMenu.prototype.isEnabled = function() { |
90 SelectionMenu.prototype.isEnabled = function() { |
91 return !this.peerElement.disabled; |
91 return !this.peerElement.disabled; |
92 } |
92 }; |
93 |
93 |
94 // Sets the enabled state. |
94 // Sets the enabled state. |
95 SelectionMenu.prototype.setEnabled = function(enabled) { |
95 SelectionMenu.prototype.setEnabled = function(enabled) { |
96 uiLogger.debug("SelectionMenu.setEnabled(" + enabled + ")"); |
96 uiLogger.debug("SelectionMenu.setEnabled(" + enabled + ")"); |
97 this.peerElement.disabled = !enabled; |
97 this.peerElement.disabled = !enabled; |
98 } |
98 }; |
99 |
99 |
100 // Sets the focused state for the control. |
100 // Sets the focused state for the control. |
101 // Note: This may not always succeed. |
101 // Note: This may not always succeed. |
102 SelectionMenu.prototype.setFocused = function(focused) { |
102 SelectionMenu.prototype.setFocused = function(focused) { |
103 uiLogger.debug("SelectionMenu.setFocused(" + focused + ")"); |
103 uiLogger.debug("SelectionMenu.setFocused(" + focused + ")"); |
104 if (focused) { |
104 if (focused) { |
105 this.peerElement.focus(); |
105 this.peerElement.focus(); |
106 } else { |
106 } else { |
107 this.peerElement.blur(); |
107 this.peerElement.blur(); |
108 } |
108 } |
109 } |
109 }; |
110 |
110 |
111 // Sets the currently selected options. Pass a single option in a single selection |
111 // Sets the currently selected options. Pass a single option in a single selection |
112 // control or an array of selected controls in a multiple selection control. To |
112 // control or an array of selected controls in a multiple selection control. To |
113 // deselect all options pass null in a single selection control and an empty array |
113 // deselect all options pass null in a single selection control and an empty array |
114 // in a multiple selection control. |
114 // in a multiple selection control. |
119 // iterate through the options and set the selected state |
119 // iterate through the options and set the selected state |
120 // on the corresponding option element |
120 // on the corresponding option element |
121 for (var i = 0; i < this.options.length; i++) { |
121 for (var i = 0; i < this.options.length; i++) { |
122 this.optionElements[i].selected = this.isSelected(this.options[i]); |
122 this.optionElements[i].selected = this.isSelected(this.options[i]); |
123 } |
123 } |
124 } |
124 }; |
125 |
125 |
126 // Sets the options in the control. |
126 // Sets the options in the control. |
127 SelectionMenu.prototype.setOptions = function(options) { |
127 SelectionMenu.prototype.setOptions = function(options) { |
128 // call superclass setOptions() |
128 // call superclass setOptions() |
129 SelectionControl.prototype.setOptions.call(this, options); |
129 SelectionControl.prototype.setOptions.call(this, options); |
130 this.updateOptionElements(); |
130 this.updateOptionElements(); |
131 } |
131 }; |
132 |
132 |
133 // Updates the option elements for the peer select element. |
133 // Updates the option elements for the peer select element. |
134 SelectionMenu.prototype.updateOptionElements = function() { |
134 SelectionMenu.prototype.updateOptionElements = function() { |
135 // start by removing all current options from the select element |
135 // start by removing all current options from the select element |
136 while (this.peerElement.firstChild != null) { |
136 while (this.peerElement.firstChild != null) { |