323
323
* @private
324
324
*/
325
325
getStepTarget : function ( step ) {
326
- var result ;
326
+ var result ,
327
+ queriedTarged ;
327
328
328
- if ( ! step || ! step . target ) { return null ; }
329
- if ( typeof step . target === 'string' ) {
329
+ function runTargetTest ( toTest ) {
330
+ alert ( "Checking for: " + toTest ) ;
330
331
// Check if it's querySelector-eligible. Only accepting IDs and classes,
331
332
// because that's the only thing that makes sense. Tag name and pseudo-class
332
333
// are just silly.
333
- if ( / ^ [ # \. ] / . test ( step . target ) ) {
334
+ if ( / ^ [ # \. ] / . test ( toTest ) ) {
334
335
if ( document . querySelector ) {
335
- return document . querySelector ( step . target ) ;
336
+ return document . querySelector ( toTest ) ;
336
337
}
337
338
if ( hasJquery ) {
338
- result = jQuery ( step . target ) ;
339
+ result = jQuery ( toTest ) ;
339
340
return result . length ? result [ 0 ] : null ;
340
341
}
341
342
if ( Sizzle ) {
342
- result = new Sizzle ( step . target ) ;
343
+ result = new Sizzle ( toTest ) ;
343
344
return result . length ? result [ 0 ] : null ;
344
345
}
345
346
if ( step . target [ 0 ] === '#' && step . target . indexOf ( ' ' ) === - 1 ) {
346
- return document . getElementById ( step . target . substring ( 1 ) ) ;
347
+ return document . getElementById ( toTest . substring ( 1 ) ) ;
347
348
}
348
349
// Can't extract element. Likely IE <=7 and no jQuery/Sizzle.
349
350
return null ;
350
351
}
351
352
// Else assume it's a string id.
352
- return document . getElementById ( step . target ) ;
353
+ return document . getElementById ( toTest ) ;
354
+ }
355
+
356
+ if ( ! step || ! step . target ) { return null ; }
357
+
358
+ if ( typeof step . target === 'string' ) {
359
+ //Just one target to test. Check, cache, and return its results.
360
+ return step . target = runTargetTest ( step . target ) ;
361
+ }
362
+ else if ( Array . isArray ( step . target ) ) {
363
+ //Multiple items to check. Check each and break on first success.
364
+ var arrSize = step . target . length ,
365
+ i ;
366
+ for ( i = 0 ; i < arrSize ; i ++ ) {
367
+ queriedTarget = runTargetTest ( step . target [ i ] ) ;
368
+ if ( queriedTarget !== null ) { break ; }
369
+ }
370
+ //Cache and return.
371
+ return step . target = queriedTarget ;
353
372
}
373
+ //Hey, our result's already been cached. Sweet!
354
374
return step . target ;
355
375
} ,
356
376
2081
2101
2082
2102
winHopscotch = new Hopscotch ( ) ;
2083
2103
context [ namespace ] = winHopscotch ;
2084
- } ( window , 'hopscotch' ) ) ;
2104
+ } ( window , 'hopscotch' ) ) ;
0 commit comments