$debug("Defining HTMLOptionElement");
/*
* HTMLOptionElement - DOM Level 2
*/
var HTMLOptionElement = function(ownerDocument) {
this.HTMLInputCommon = HTMLInputCommon;
this.HTMLInputCommon(ownerDocument);
};
HTMLOptionElement.prototype = new HTMLInputCommon;
__extend__(HTMLOptionElement.prototype, {
setAttributeNS : function(namespaceURI, qualifiedName, value) {
if (namespaceURI) {
throw new Error("unexpected namespaceURI");
}
this.setAttribute(qualifiedName, value);
},
setAttribute: function(name, value){
if (name != "selected") {
HTMLInputCommon.prototype.setAttribute.apply(this, arguments);
} else {
if(this.defaultSelected===null && this.selected!==null){
this.defaultSelected = this.selected;
}
var selectedValue = (value ? 'selected' : '');
if (this.getAttribute('selected') == selectedValue) {
// prevent inifinite loops (option's selected modifies
// select's value which modifies option's selected)
return;
}
HTMLInputCommon.prototype.setAttribute.call(this, 'selected', selectedValue);
var parent = this.parentNode;
while (parent && parent.tagName === "OPTGROUP") {
parent = parent.parentNode;
}
if (value) {
// set select's value to this option's value (this also
// unselects previously selected value)
parent && (parent.value = this.value);
} else {
// if no other option is selected, select the first option in the select
var i, anythingSelected;
if (parent.options) {
for (i=0; i