11/*!
2- * jQuery & Zepto Lazy - v1.7.5
2+ * jQuery & Zepto Lazy - v1.7.6
33 * http://jquery.eisbehr.de/lazy/
44 *
55 * Copyright 2012 - 2017, Daniel 'Eisbehr' Kern
6161 }
6262
6363 // exit here if parameter is not a callable function
64- if ( ! $ . isFunction ( loader ) ) return ;
64+ if ( ! $ . isFunction ( loader ) ) {
65+ return ;
66+ }
6567
6668 // make parameters an array of names to be sure
6769 names = $ . isArray ( names ) ? names : [ names ] ;
7173 forced = config . _f || ( config . _f = { } ) ;
7274
7375 // add the loader plugin for every name
74- for ( var i = 0 , l = names . length ; i < l ; i ++ )
75- if ( config [ names [ i ] ] === undefined || $ . isFunction ( config [ names [ i ] ] ) )
76+ for ( var i = 0 , l = names . length ; i < l ; i ++ ) {
77+ if ( config [ names [ i ] ] === undefined || $ . isFunction ( config [ names [ i ] ] ) ) {
7678 config [ names [ i ] ] = loader ;
79+ }
80+ }
7781
7882 // add forced elements loader
79- for ( var c = 0 , a = elements . length ; c < a ; c ++ )
83+ for ( var c = 0 , a = elements . length ; c < a ; c ++ ) {
8084 forced [ elements [ c ] ] = names [ 0 ] ;
85+ }
8186 } ;
8287
8388 /**
189194 _isRetinaDisplay = window . devicePixelRatio > 1 ;
190195
191196 // prepare all initial items
192- _prepareItems ( items ) ;
197+ items = _prepareItems ( items ) ;
193198
194199 // if delay time is set load all items at once after delay time
195- if ( config . delay >= 0 ) setTimeout ( function ( ) { _lazyLoadItems ( true ) ; } , config . delay ) ;
200+ if ( config . delay >= 0 ) {
201+ setTimeout ( function ( ) {
202+ _lazyLoadItems ( true ) ;
203+ } , config . delay ) ;
204+ }
196205
197206 // if no delay is set or combine usage is active bind events
198207 if ( config . delay < 0 || config . combined ) {
199208 // create unique event function
200209 events . e = _throttle ( config . throttle , function ( event ) {
201210 // reset detected window size on resize event
202- if ( event . type === "resize" )
211+ if ( event . type === "resize" ) {
203212 _actualWidth = _actualHeight = - 1 ;
213+ }
204214
205215 // execute 'lazy magic'
206216 _lazyLoadItems ( event . all ) ;
207217 } ) ;
208218
209219 // create function to add new items to instance
210220 events . a = function ( additionalItems ) {
211- _prepareItems ( additionalItems ) ;
221+ additionalItems = _prepareItems ( additionalItems ) ;
212222 items . push . apply ( items , additionalItems ) ;
213223 } ;
214224
250260 * prepare items before handle them
251261 * @access private
252262 * @param {Array|object|jQuery } items
253- * @return void
263+ * @return { Array|object|jQuery }
254264 */
255265 function _prepareItems ( items ) {
256266 // fetch used configurations before loops
279289 elementImageBase = element . attr ( config . imageBaseAttribute ) || imageBase ;
280290
281291 // generate and update source set if an image base is set
282- if ( tag === _img && elementImageBase && element . attr ( srcsetAttribute ) )
292+ if ( tag === _img && elementImageBase && element . attr ( srcsetAttribute ) ) {
283293 element . attr ( srcsetAttribute , _getCorrectedSrcSet ( element . attr ( srcsetAttribute ) , elementImageBase ) ) ;
294+ }
284295
285296 // add loader to forced element types
286- if ( forcedTags [ tag ] !== undefined && ! element . attr ( loaderAttribute ) )
297+ if ( forcedTags [ tag ] !== undefined && ! element . attr ( loaderAttribute ) ) {
287298 element . attr ( loaderAttribute , forcedTags [ tag ] ) ;
299+ }
288300
289301 // set default image on every element without source
290- if ( tag === _img && defaultImage && ! element . attr ( _src ) )
302+ if ( tag === _img && defaultImage && ! element . attr ( _src ) ) {
291303 element . attr ( _src , defaultImage ) ;
304+ }
292305
293306 // set placeholder on every element without background image
294- else if ( tag !== _img && placeholder && ( ! element . css ( _backgroundImage ) || element . css ( _backgroundImage ) === "none" ) )
307+ else if ( tag !== _img && placeholder && ( ! element . css ( _backgroundImage ) || element . css ( _backgroundImage ) === "none" ) ) {
295308 element . css ( _backgroundImage , "url('" + placeholder + "')" ) ;
309+ }
296310 }
311+
312+ return items ;
297313 }
298314
299315 /**
307323 // skip if no items where left
308324 if ( ! items . length ) {
309325 // destroy instance if option is enabled
310- if ( config . autoDestroy )
326+ if ( config . autoDestroy ) {
311327 // noinspection JSUnresolvedFunction
312328 instance . destroy ( ) ;
329+ }
313330
314331 return ;
315332 }
339356 // and is image tag where attribute is not equal source or source set
340357 ( tag === _img && ( elementImageBase + attribute !== element . attr ( _src ) || element . attr ( srcsetAttribute ) !== element . attr ( _srcset ) ) ) ||
341358 // or is non image tag where attribute is not equal background
342- ( tag !== _img && elementImageBase + attribute !== element . css ( _backgroundImage ) )
359+ ( tag !== _img && elementImageBase + attribute !== element . css ( _backgroundImage ) )
343360 ) ||
344361 // or custom loader is available
345362 customLoader ) )
355372 }
356373
357374 // when something was loaded remove them from remaining items
358- if ( loadTriggered )
375+ if ( loadTriggered ) {
359376 items = $ ( items ) . filter ( function ( ) {
360377 return ! $ ( this ) . data ( handledName ) ;
361378 } ) ;
379+ }
362380 }
363381
364382 /**
400418 // on load callback
401419 var loadCallback = function ( ) {
402420 // remove attribute from element
403- if ( removeAttribute )
421+ if ( removeAttribute ) {
404422 element . removeAttr ( config . loaderAttribute ) ;
423+ }
405424
406425 // mark element as loaded
407426 element . data ( loadedName , true ) ;
451470
452471 // set image back to element
453472 // do it as single 'attr' calls, to be sure 'src' is set after 'srcset'
454- if ( tag === _img )
473+ if ( tag === _img ) {
455474 element . attr ( _sizes , imageObj . attr ( _sizes ) )
456475 . attr ( _srcset , imageObj . attr ( _srcset ) )
457476 . attr ( _src , imageObj . attr ( _src ) ) ;
458- else
477+ }
478+ else {
459479 element . css ( _backgroundImage , "url('" + imageObj . attr ( _src ) + "')" ) ;
480+ }
460481
461482 // bring it back with some effect!
462483 element [ config . effect ] ( config . effectTime ) ;
466487 element . removeAttr ( srcAttribute + " " + srcsetAttribute + " " + retinaAttribute + " " + config . imageBaseAttribute ) ;
467488
468489 // only remove 'sizes' attribute, if it was a custom one
469- if ( sizesAttribute !== _sizes )
490+ if ( sizesAttribute !== _sizes ) {
470491 element . removeAttr ( sizesAttribute ) ;
492+ }
471493 }
472494
473495 // mark element as loaded
514536 // check if element is even in loadable area from right
515537 ( - threshold < elementBound . right ) ;
516538
517- if ( direction === "vertical" ) return vertical ;
518- else if ( direction === "horizontal" ) return horizontal ;
539+ if ( direction === "vertical" ) {
540+ return vertical ;
541+ }
542+ else if ( direction === "horizontal" ) {
543+ return horizontal ;
544+ }
519545
520546 return vertical && horizontal ;
521547 }
561587 var entries = srcset . split ( "," ) ;
562588 srcset = "" ;
563589
564- for ( var i = 0 , l = entries . length ; i < l ; i ++ )
590+ for ( var i = 0 , l = entries . length ; i < l ; i ++ ) {
565591 srcset += imageBase + entries [ i ] . trim ( ) + ( i !== l - 1 ? "," : "" ) ;
592+ }
566593 }
567594
568595 return srcset ;
584611
585612 function run ( ) {
586613 lastExecute = + new Date ( ) ;
614+ // noinspection JSUnresolvedFunction
587615 callback . call ( instance , event ) ;
588616 }
589617
590618 timeout && clearTimeout ( timeout ) ; // jshint ignore : line
591619
592- if ( elapsed > delay || ! config . enableThrottle || ignoreThrottle ) run ( ) ;
593- else timeout = setTimeout ( run , delay - elapsed ) ;
620+ if ( elapsed > delay || ! config . enableThrottle || ignoreThrottle ) {
621+ run ( ) ;
622+ }
623+ else {
624+ timeout = setTimeout ( run , delay - elapsed ) ;
625+ }
594626 } ;
595627 }
596628
603635 -- _awaitingAfterLoad ;
604636
605637 // if no items were left trigger finished event
606- if ( ! items . length && ! _awaitingAfterLoad ) _triggerCallback ( "onFinishedAll" ) ;
638+ if ( ! items . length && ! _awaitingAfterLoad ) {
639+ _triggerCallback ( "onFinishedAll" ) ;
640+ }
607641 }
608642
609643 /**
626660 }
627661
628662 // if event driven or window is already loaded don't wait for page loading
629- if ( config . bind === "event" || windowLoaded )
663+ if ( config . bind === "event" || windowLoaded ) {
630664 _initialize ( ) ;
665+ }
631666
632667 // otherwise load initial items and start lazy after page load
633- else // noinspection JSUnresolvedVariable
668+ else {
669+ // noinspection JSUnresolvedVariable
634670 $ ( window ) . on ( _load + "." + namespace , _initialize ) ;
671+ }
635672 }
636673
637674 /**
683720 * @return {LazyPlugin|* }
684721 */
685722 _instance . config = function ( entryName , value ) {
686- if ( value === undefined )
723+ if ( value === undefined ) {
687724 return _config [ entryName ] ;
725+ }
688726
689727 _config [ entryName ] = value ;
690728 return _instance ;
826864
827865 // register window load event globally to prevent not loading elements
828866 // since jQuery 3.X ready state is fully async and may be executed after 'load'
829- $ ( window ) . on ( "load" , function ( ) { windowLoaded = true ; } ) ;
867+ $ ( window ) . on ( "load" , function ( ) {
868+ windowLoaded = true ;
869+ } ) ;
830870} ) ( window ) ;
0 commit comments