File tree Expand file tree Collapse file tree 2 files changed +28
-12
lines changed
Expand file tree Collapse file tree 2 files changed +28
-12
lines changed Original file line number Diff line number Diff line change 211211 p5 . prototype . createImg = function ( ) {
212212 var elt = document . createElement ( 'img' ) ;
213213 var args = arguments ;
214- var self = { } ;
214+ var self ;
215215 var setAttrs = function ( ) {
216- self . width = elt . width ;
217- self . height = elt . height ;
218- if ( args . length === 3 && typeof args [ 2 ] === 'function' ) {
216+ self . width = elt . offsetWidth ;
217+ self . height = elt . offsetHeight ;
218+ if ( args . length > 1 && typeof args [ 1 ] === 'function' ) {
219+ self . fn = args [ 1 ] ;
220+ self . fn ( ) ;
221+ } else if ( args . length > 1 && typeof args [ 2 ] === 'function' ) {
219222 self . fn = args [ 2 ] ;
220223 self . fn ( ) ;
221224 }
224227 if ( args . length > 1 && typeof args [ 1 ] === 'string' ) {
225228 elt . alt = args [ 1 ] ;
226229 }
227- if ( elt . complete ) {
230+ elt . onload = function ( ) {
228231 setAttrs ( ) ;
229- } else {
230- elt . onload = function ( ) {
231- setAttrs ( ) ;
232- }
233232 }
234233 self = addElement ( elt , this ) ;
235234 return self ;
Original file line number Diff line number Diff line change @@ -237,19 +237,36 @@ p5.Element.prototype.mouseOver = function (fxn) {
237237
238238
239239/**
240- * The .changed() function is called when the value of an element is changed.
240+ * The .changed() function is called when the value of an
241+ * element is changed.
241242 * This can be used to attach an element specific event listener.
242243 *
243244 * @method changed
244- * @param {Function } fxn function to be fired when mouse is
245- * moved over the element.
245+ * @param {Function } fxn function to be fired when the value of an
246+ * element changes .
246247 * @return {p5.Element }
247248 */
248249p5 . Element . prototype . changed = function ( fxn ) {
249250 attachListener ( 'change' , fxn , this ) ;
250251 return this ;
251252} ;
252253
254+ /**
255+ * The .input() function is called when any user input is
256+ * detected with an element. The input event is often used
257+ * to detect keystrokes in a input element, or changes on a
258+ * slider element. This can be used to attach an element specific
259+ * event listener.
260+ *
261+ * @method input
262+ * @param {Function } fxn function to be fired on user input.
263+ * @return {p5.Element }
264+ */
265+ p5 . Element . prototype . input = function ( fxn ) {
266+ attachListener ( 'input' , fxn , this ) ;
267+ return this ;
268+ } ;
269+
253270/**
254271 * The .mouseOut() function is called once after every time a
255272 * mouse moves off the element. This can be used to attach an
You can’t perform that action at this time.
0 commit comments