Skip to content

Commit 1b59c74

Browse files
author
Lauren McCarthy
committed
Merge branch 'master' of github.com:processing/p5.js
2 parents 6963806 + 0073073 commit 1b59c74

File tree

6 files changed

+90
-28
lines changed

6 files changed

+90
-28
lines changed

examples/loadingscreen/preload_success_callbacks.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ function successFont() {
3333

3434
function preload() {
3535
// try with callbacks
36-
myJson = loadJSON('http://api.openweathermap.org/data/2.5/weather?q=London,uk', successJSON);
36+
myJson = loadJSON('test.json', successJSON);
3737
banana = loadImage('banana.png', successImage);
3838
strings = loadStrings('test.txt', successStrings);
3939
xml = loadXML('test.xml', successXML);
4040
myTable = loadTable('mammals.csv', 'csv', 'header', successTable);
4141
myFont = loadFont('AvenirNextLTPro-Demi.otf', successFont);
4242

4343
// try with no callbacks
44-
myJson2 = loadJSON('http://api.openweathermap.org/data/2.5/weather?q=London,uk');
44+
myJson2 = loadJSON('test.json');
4545
banana2 = loadImage('banana.png');
4646
strings2 = loadStrings('test.txt');
4747
xml2 = loadXML('test.xml');
@@ -62,8 +62,8 @@ function draw() {
6262
image(banana, 0, y);
6363
image(banana2, 0, y += 50);
6464

65-
text(myJson.main.humidity, 0, y += 50);
66-
text(myJson2.main.humidity, 0, y += 50);
65+
text(myJson.a, 0, y += 50);
66+
text(myJson2.a, 0, y += 50);
6767

6868
text(strings.length, 0, y += 50);
6969
text(strings2.length, 0, y += 50);

examples/loadingscreen/test.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"a": 1
3+
}

lib/addons/p5.dom.js

Lines changed: 74 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -895,15 +895,22 @@
895895
};
896896

897897
/**
898-
* Sets the given style (css) property of the element with the given value.
899-
* If no value is specified, returns the value of the given property,
900-
* or undefined if the property is not.
898+
* Sets the given style (css) property (1st arg) of the element with the
899+
* given value (2nd arg). If a single argument is given, .style()
900+
* returns the value of the given property; however, if the single argument
901+
* is given in css syntax ('text-align:center'), .style() sets the css
902+
* appropriatly. .style() also handles 2d and 3d css transforms. If
903+
* the 1st arg is 'rotate', 'translate', or 'position', the following arguments
904+
* accept Numbers as values. ('translate', 10, 100, 50);
901905
*
902906
* @method style
903907
* @param {String} property property to be set
904-
* @param {String} [value] value to assign to property
908+
* @param {String|Number} [value] value to assign to property
909+
* @param {String|Number} [value] value to assign to property (rotate/translate)
910+
* @param {String|Number} [value] value to assign to property (rotate/translate)
911+
* @param {String|Number} [value] value to assign to property (translate)
905912
* @return {String|Object/p5.Element} value of property, if no value is specified
906-
* or p5.Element
913+
* or p5.Element
907914
* @example
908915
* <div><code class="norender">
909916
* var myDiv = createDiv("I like pandas.");
@@ -912,19 +919,72 @@
912919
* </code></div>
913920
*/
914921
p5.Element.prototype.style = function(prop, val) {
922+
var self = this;
923+
915924
if (typeof val === 'undefined') {
916-
var attrs = prop.split(';');
917-
for (var i=0; i<attrs.length; i++) {
918-
var parts = attrs[i].split(':');
919-
if (parts[0] && parts[1]) {
920-
this.elt.style[parts[0].trim()] = parts[1].trim();
925+
if (prop.indexOf(':') === -1) {
926+
var styles = window.getComputedStyle(self.elt);
927+
var style = styles.getPropertyValue(prop);
928+
return style;
929+
} else {
930+
var attrs = prop.split(';');
931+
for (var i = 0; i < attrs.length; i++) {
932+
var parts = attrs[i].split(':');
933+
if (parts[0] && parts[1]) {
934+
this.elt.style[parts[0].trim()] = parts[1].trim();
935+
}
921936
}
922937
}
923938
} else {
924-
this.elt.style[prop] = val;
925-
if (prop === 'width' || prop === 'height' || prop === 'left' || prop === 'top'){
926-
var numVal = val.replace(/\D+/g,'');
927-
this[prop] = parseInt(numVal);
939+
if (prop === 'rotate'){
940+
if (arguments.length === 2) {
941+
var style = this.elt.style.transform.replace(/rotate3d\(.*\)/g, '');
942+
style = style.replace(/rotate[X-Z]?\(.*\)/g, '');
943+
this.elt.style.transform = 'rotate(' + arguments[0] + 'deg)';
944+
this.elt.style.transform += style;
945+
} else if (arguments.length === 3) {
946+
var style = this.elt.style.transform.replace(/rotate3d\(.*\)/g, '');
947+
style = style.replace(/rotate[X-Z]?\(.*\)/g, '');
948+
this.elt.style.transform = 'rotate(' + arguments[0] + 'deg, ' + arguments[1] + 'deg)';
949+
this.elt.style.transform += style;
950+
} else if (arguments.length === 4) {
951+
var style = this.elt.style.transform.replace(/rotate3d\(.*\)/g, '');
952+
style = style.replace(/rotate[X-Z]?\(.*\)/g, '');
953+
this.elt.style.transform = 'rotateX(' + arguments[0] + 'deg)';
954+
this.elt.style.transform += 'rotateY(' + arguments[1] + 'deg)';
955+
this.elt.style.transform += 'rotateZ(' + arguments[2] + 'deg)';
956+
this.elt.style.transform += style;
957+
}
958+
} else if (prop === 'translate') {
959+
if (arguments.length === 3) {
960+
var style = this.elt.style.transform.replace(/translate3d\(.*\)/g, '');
961+
style = style.replace(/translate[X-Z]?\(.*\)/g, '');
962+
this.elt.style.transform = 'translate(' + arguments[0] + 'px, ' + arguments[1] + 'px)';
963+
this.elt.style.transform += style;
964+
} else if (arguments.length === 4) {
965+
var style = this.elt.style.transform.replace(/translate3d\(.*\)/g, '');
966+
style = style.replace(/translate[X-Z]?\(.*\)/g, '');
967+
this.elt.style.transform = 'translate3d(' + arguments[0] + 'px,' + arguments[1] + 'px,' + arguments[2] + 'px)';
968+
this.elt.style.transform += style;
969+
this.elt.parentElement.style.perspective = '1000px';
970+
} else if (arguments.length === 5) {
971+
var style = this.elt.style.transform.replace(/translate3d\(.*\)/g, '');
972+
style = style.replace(/translate[X-Z]?\(.*\)/g, '');
973+
this.elt.style.transform = 'translate3d(' + arguments[0] + 'px,' + arguments[1] + 'px,' + arguments[2] + 'px)';
974+
this.elt.style.transform += style;
975+
this.elt.parentElement.style.perspective = arguments[3] + 'px';
976+
}
977+
} else if (prop === 'position') {
978+
this.elt.style.left = arguments[1] + 'px';
979+
this.elt.style.top = arguments[2] + 'px';
980+
this.x = arguments[1];
981+
this.y = arguments[2];
982+
} else {
983+
this.elt.style[prop] = val;
984+
if (prop === 'width' || prop === 'height' || prop === 'left' || prop === 'top') {
985+
var numVal = val.replace(/\D+/g, '');
986+
this[prop] = parseInt(numVal, 10);
987+
}
928988
}
929989
}
930990
return this;

src/events/acceleration.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ var shake_threshold = 30;
246246

247247
/**
248248
* The setMoveThreshold() function is used to set the movement threshold for
249-
* the deviceMoved() function.
249+
* the deviceMoved() function. The default threshold is set to 0.5.
250250
*
251251
* @method setMoveThreshold
252252
* @param {number} value The threshold value
@@ -271,8 +271,9 @@ p5.prototype.setShakeThreshold = function(val){
271271
};
272272

273273
/**
274-
* The deviceMoved() function is called when the devices orientation changes
275-
* by more than the threshold value.
274+
* The deviceMoved() function is called when the device is moved by more than
275+
* the threshold value along X, Y or Z axis. The default threshold is set to
276+
* 0.5.
276277
* @method deviceMoved
277278
* @example
278279
* <div>

src/image/loading_displaying.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ require('../core/error_helpers');
6161
p5.prototype.loadImage = function(path, successCallback, failureCallback) {
6262
var img = new Image();
6363
var pImg = new p5.Image(1, 1, this);
64-
var decrementPreload = p5._getDecrementPreload.call(this,
65-
path, successCallback, failureCallback);
64+
var decrementPreload = p5._getDecrementPreload.apply(this, arguments);
6665

6766
img.onload = function() {
6867
pImg.width = pImg.canvas.width = img.width;

src/io/files.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ p5._getDecrementPreload = function() {
8888
p5.prototype.loadFont = function(path, onSuccess, onError) {
8989

9090
var p5Font = new p5.Font(this);
91-
var decrementPreload = p5._getDecrementPreload.call(this,
92-
path, onSuccess, onError);
91+
var decrementPreload = p5._getDecrementPreload.apply(this, arguments);
9392

9493
opentype.load(path, function(err, font) {
9594

@@ -292,7 +291,7 @@ p5.prototype.loadJSON = function() {
292291
p5.prototype.loadStrings = function (path, callback) {
293292
var ret = [];
294293
var req = new XMLHttpRequest();
295-
var decrementPreload = p5._getDecrementPreload.call(this, path, callback);
294+
var decrementPreload = p5._getDecrementPreload.apply(this, arguments);
296295

297296
req.addEventListener('error', function () {
298297
console.log('An error occurred loading strings: ' + path);
@@ -407,7 +406,7 @@ p5.prototype.loadTable = function (path) {
407406
var header = false;
408407
var sep = ',';
409408
var separatorSet = false;
410-
var decrementPreload = p5._getDecrementPreload.call(this, path);
409+
var decrementPreload = p5._getDecrementPreload.apply(this, arguments);
411410

412411
for (var i = 1; i < arguments.length; i++) {
413412
if ((typeof(arguments[i]) === 'function') &&
@@ -635,7 +634,7 @@ function makeObject(row, headers) {
635634
*/
636635
p5.prototype.loadXML = function(path, callback) {
637636
var ret = document.implementation.createDocument(null, null);
638-
var decrementPreload = p5._getDecrementPreload.call(this, path, callback);
637+
var decrementPreload = p5._getDecrementPreload.apply(this, arguments);
639638

640639
reqwest({
641640
url: path,

0 commit comments

Comments
 (0)