Skip to content

Commit 79dd089

Browse files
committed
tweaks style, adds style for docs
1 parent 9967605 commit 79dd089

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

lib/addons/p5.dom.js

Lines changed: 17 additions & 10 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.");
@@ -915,7 +922,7 @@
915922
var self = this;
916923

917924
if (typeof val === 'undefined') {
918-
if (!prop.match(/:/)) {
925+
if (prop.indexOf(':') === -1) {
919926
var styles = window.getComputedStyle(self.elt);
920927
var style = styles.getPropertyValue(prop);
921928
return style;
@@ -929,7 +936,7 @@
929936
}
930937
}
931938
} else {
932-
if (prop.match(/rotate/)) {
939+
if (prop === 'rotate'){
933940
if (arguments.length === 2) {
934941
var style = this.elt.style.transform.replace(/rotate3d\(.*\)/g, '');
935942
style = style.replace(/rotate[X-Z]?\(.*\)/g, '');
@@ -948,7 +955,7 @@
948955
this.elt.style.transform += 'rotateZ(' + arguments[2] + 'deg)';
949956
this.elt.style.transform += style;
950957
}
951-
} else if (prop.match(/translate/)) {
958+
} else if (prop === 'translate') {
952959
if (arguments.length === 3) {
953960
var style = this.elt.style.transform.replace(/translate3d\(.*\)/g, '');
954961
style = style.replace(/translate[X-Z]?\(.*\)/g, '');
@@ -967,7 +974,7 @@
967974
this.elt.style.transform += style;
968975
this.elt.parentElement.style.perspective = arguments[3] + 'px';
969976
}
970-
} else if (prop.match(/position/)) {
977+
} else if (prop === 'position') {
971978
this.elt.style.left = arguments[1] + 'px';
972979
this.elt.style.top = arguments[2] + 'px';
973980
this.x = arguments[1];
@@ -976,7 +983,7 @@
976983
this.elt.style[prop] = val;
977984
if (prop === 'width' || prop === 'height' || prop === 'left' || prop === 'top') {
978985
var numVal = val.replace(/\D+/g, '');
979-
this[prop] = parseInt(numVal);
986+
this[prop] = parseInt(numVal, 10);
980987
}
981988
}
982989
}

0 commit comments

Comments
 (0)