-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor timer and image loader into separate files
- Loading branch information
Showing
8 changed files
with
62 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
'use strict'; | ||
|
||
!function($) { | ||
|
||
/** | ||
* Runs a callback function when images are fully loaded. | ||
* @param {Object} images - Image(s) to check if loaded. | ||
* @param {Func} callback - Function to execute when image is fully loaded. | ||
*/ | ||
function onImagesLoaded(images, callback){ | ||
var self = this, | ||
unloaded = images.length; | ||
|
||
if (unloaded === 0) { | ||
callback(); | ||
} | ||
|
||
images.each(function() { | ||
// Check if image is loaded | ||
if (this.complete || (this.readyState === 4) || (this.readyState === 'complete')) { | ||
singleImageLoaded(); | ||
} | ||
// Force load the image | ||
else { | ||
// fix for IE. See https://css-tricks.com/snippets/jquery/fixing-load-in-ie-for-cached-images/ | ||
var src = $(this).attr('src'); | ||
$(this).attr('src', src + (src.indexOf('?') >= 0 ? '&' : '?') + (new Date().getTime())); | ||
$(this).one('load', function() { | ||
singleImageLoaded(); | ||
}); | ||
} | ||
}); | ||
|
||
function singleImageLoaded() { | ||
unloaded--; | ||
if (unloaded === 0) { | ||
callback(); | ||
} | ||
} | ||
} | ||
|
||
Foundation.onImagesLoaded = onImagesLoaded; | ||
|
||
}(jQuery); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters