Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 33 additions & 7 deletions lib/addons/p5.dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -574,13 +574,39 @@
self = addElement(elt, this);
}
self.option = function(name, value) {
var opt = document.createElement('option');
opt.innerHTML = name;
if (arguments.length > 1)
opt.value = value;
else
opt.value = name;
elt.appendChild(opt);
var index;
//see if there is already an option with this name
for (var i = 0; i < this.elt.length; i++) {
if(this.elt[i].innerHTML == name) {
index = i;
break;
}
}
//if there is an option with this name we will modify it
if(index !== undefined) {
//if the user passed in false then delete that option
if(value === false) {
this.elt.remove(index);
} else {
//otherwise if the name and value are the same then change both
if(this.elt[index].innerHTML == this.elt[index].value) {
this.elt[index].innerHTML = this.elt[index].value = value;
//otherwise just change the value
} else {
this.elt[index].value = value;
}
}
}
//if it doesn't exist make it
else {
var opt = document.createElement('option');
opt.innerHTML = name;
if (arguments.length > 1)
opt.value = value;
else
opt.value = name;
elt.appendChild(opt);
}
};
self.selected = function(value) {
var arr = [];
Expand Down