Skip to content

Commit c8b1752

Browse files
committed
Review update : Fixed select() issue with existing dropdown
1 parent b7d5d2b commit c8b1752

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

lib/addons/p5.dom.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -528,10 +528,11 @@
528528

529529
/**
530530
* Creates a dropdown menu <select></select> element in the DOM.
531-
* It also helps to asssign select-box methods to p5.Element when selecting existing select box
531+
* It also helps to assign select-box methods to p5.Element when selecting existing select box
532532
* @method createSelect
533-
* @param {boolean} [multiple] true if dropdown should support multiple selections
534-
* @return {Object|p5.Element} pointer to p5.Element holding created node
533+
* @param {boolean} [multiple] true if dropdown should support multiple selections OR
534+
* @param {Object [P5.Element] if wrapping methods to existing select
535+
* @return {Object|p5.Element} pointer to p5.Element holding created or existing node
535536
* @example
536537
* <div><code>
537538
* var sel;
@@ -555,17 +556,18 @@
555556
* </code></div>
556557
*/
557558

558-
p5.prototype.createSelect = function(mult) {
559-
560-
if( typeof mult === 'object' && mult.elt.nodeName == 'SELECT' ){
561-
var self = mult;
562-
var elt = this.elt = mult.elt;
559+
p5.prototype.createSelect = function() {
560+
var elt,self;
561+
var arg = arguments[0];
562+
if( typeof arg === 'object' && arg.elt.nodeName == 'SELECT' ){
563+
self = arg;
564+
elt = this.elt = arg.elt;
563565
}else{
564-
var elt = document.createElement('select');
565-
if( mult && typeof mult === 'boolean' ){
566+
elt = document.createElement('select');
567+
if( arg && typeof arg === 'boolean' ){
566568
elt.setAttribute('multiple', 'true');
567569
}
568-
var self = addElement(elt, this);
570+
self = addElement(elt, this);
569571
}
570572
self.option = function(name, value){
571573
var opt = document.createElement('option');
@@ -586,7 +588,7 @@
586588
}
587589
return this;
588590
}else{
589-
if (mult){
591+
if (arg){
590592
for (var i = 0; i < this.elt.selectedOptions.length; i++){
591593
arr.push(this.elt.selectedOptions[i].value);
592594
}

0 commit comments

Comments
 (0)