Skip to content

Commit 0e56e59

Browse files
author
Lauren McCarthy
committed
Merge branch 'master' of github.com:processing/p5.js
2 parents e4e51ad + 30c4607 commit 0e56e59

File tree

34 files changed

+1286
-509
lines changed

34 files changed

+1286
-509
lines changed

.all-contributorsrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,6 +1270,13 @@
12701270
"avatar_url": "https://avatars3.githubusercontent.com/u/7667514?s=460&v=4",
12711271
"profile": "https://github.com/hackertron",
12721272
"contributions": []
1273+
},
1274+
{
1275+
"login": "bansalnitish",
1276+
"name": "Nitish Bansal",
1277+
"avatar_url": "https://avatars1.githubusercontent.com/u/22434689?v=4",
1278+
"profile": "https://github.com/bansalnitish",
1279+
"contributions": []
12731280
}
12741281
]
12751282
}

Gruntfile.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,11 @@ module.exports = function(grunt) {
328328
}
329329
}
330330
},
331+
open: {
332+
yui: {
333+
path: 'http://0.0.0.0:9001/docs/reference/'
334+
}
335+
},
331336
'saucelabs-mocha': {
332337
all: {
333338
options: {
@@ -391,6 +396,7 @@ module.exports = function(grunt) {
391396
// Load the external libraries used.
392397
grunt.loadNpmTasks('grunt-contrib-compress');
393398
grunt.loadNpmTasks('grunt-contrib-connect');
399+
grunt.loadNpmTasks('grunt-open');
394400
grunt.loadNpmTasks('grunt-contrib-copy');
395401
grunt.loadNpmTasks('grunt-eslint');
396402
grunt.loadNpmTasks('grunt-contrib-watch');
@@ -433,6 +439,13 @@ module.exports = function(grunt) {
433439
grunt.registerTask('test:nobuild', ['eslint:test', 'connect', 'mocha']);
434440
grunt.registerTask('yui', ['yuidoc:prod', 'minjson', 'typescript']);
435441
grunt.registerTask('yui:test', ['yuidoc:prod', 'connect', 'mocha:yui']);
442+
grunt.registerTask('yui:dev', [
443+
'yui:prod',
444+
'browserify',
445+
'connect',
446+
'open:yui',
447+
'watch:yui'
448+
]);
436449
grunt.registerTask('default', ['test']);
437450
grunt.registerTask('saucetest', ['connect', 'saucelabs-mocha']);
438451
};

lib/addons/p5.dom.js

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@
179179
* Helper function for getElement and getElements.
180180
*/
181181
p5.prototype._wrapElement = function(elt) {
182+
var children = Array.prototype.slice.call(elt.children);
182183
if (elt.tagName === 'INPUT' && elt.type === 'checkbox') {
183184
var converted = new p5.Element(elt);
184185
converted.checked = function() {
@@ -196,6 +197,13 @@
196197
return new p5.MediaElement(elt);
197198
} else if (elt.tagName === 'SELECT') {
198199
return this.createSelect(new p5.Element(elt));
200+
} else if (
201+
children.length > 0 &&
202+
children.every(function(c) {
203+
return c.tagName === 'INPUT' || c.tagName === 'LABEL';
204+
})
205+
) {
206+
return this.createRadio(new p5.Element(elt));
199207
} else {
200208
return new p5.Element(elt);
201209
}
@@ -675,8 +683,9 @@
675683
* }
676684
* </code></div>
677685
*/
678-
p5.prototype.createRadio = function() {
686+
p5.prototype.createRadio = function(existing_radios) {
679687
p5._validateParameters('createRadio', arguments);
688+
// do some prep by counting number of radios on page
680689
var radios = document.querySelectorAll('input[type=radio]');
681690
var count = 0;
682691
if (radios.length > 1) {
@@ -694,14 +703,30 @@
694703
} else if (radios.length === 1) {
695704
count = 1;
696705
}
697-
var elt = document.createElement('div');
698-
var self = addElement(elt, this);
706+
// see if we got an existing set of radios from callee
707+
var elt, self;
708+
if (typeof existing_radios === 'object') {
709+
// use existing elements
710+
self = existing_radios;
711+
elt = this.elt = existing_radios.elt;
712+
} else {
713+
// create a set of radio buttons
714+
elt = document.createElement('div');
715+
self = addElement(elt, this);
716+
}
717+
// setup member functions
718+
self._getInputChildrenArray = function() {
719+
return Array.prototype.slice.call(this.elt.children).filter(function(c) {
720+
return c.tagName === 'INPUT';
721+
});
722+
};
723+
699724
var times = -1;
700725
self.option = function(name, value) {
701726
var opt = document.createElement('input');
702727
opt.type = 'radio';
703728
opt.innerHTML = name;
704-
if (arguments.length > 1) opt.value = value;
729+
if (value) opt.value = value;
705730
else opt.value = name;
706731
opt.setAttribute('name', 'defaultradio' + count);
707732
elt.appendChild(opt);
@@ -715,35 +740,31 @@
715740
}
716741
return opt;
717742
};
718-
self.selected = function() {
719-
var i,
720-
length = this.elt.childNodes.length;
721-
if (arguments.length === 1) {
722-
for (i = 0; i < length; i += 2) {
723-
if (this.elt.childNodes[i].value === arguments[0])
724-
this.elt.childNodes[i].checked = true;
743+
self.selected = function(value) {
744+
var i;
745+
var inputChildren = self._getInputChildrenArray();
746+
if (value) {
747+
for (i = 0; i < inputChildren.length; i++) {
748+
if (inputChildren[i].value === value) inputChildren[i].checked = true;
725749
}
726750
return this;
727751
} else {
728-
for (i = 0; i < length; i += 2) {
729-
if (this.elt.childNodes[i].checked)
730-
return this.elt.childNodes[i].value;
752+
for (i = 0; i < inputChildren.length; i++) {
753+
if (inputChildren[i].checked === true) return inputChildren[i].value;
731754
}
732755
}
733756
};
734-
self.value = function() {
735-
var i,
736-
length = this.elt.childNodes.length;
737-
if (arguments.length === 1) {
738-
for (i = 0; i < length; i += 2) {
739-
if (this.elt.childNodes[i].value === arguments[0])
740-
this.elt.childNodes[i].checked = true;
757+
self.value = function(value) {
758+
var i;
759+
var inputChildren = self._getInputChildrenArray();
760+
if (value) {
761+
for (i = 0; i < inputChildren.length; i++) {
762+
if (inputChildren[i].value === value) inputChildren[i].checked = true;
741763
}
742764
return this;
743765
} else {
744-
for (i = 0; i < length; i += 2) {
745-
if (this.elt.childNodes[i].checked)
746-
return this.elt.childNodes[i].value;
766+
for (i = 0; i < inputChildren.length; i++) {
767+
if (inputChildren[i].checked === true) return inputChildren[i].value;
747768
}
748769
return '';
749770
}

0 commit comments

Comments
 (0)