Created
November 2, 2012 15:31
-
-
Save oreshinya/4002019 to your computer and use it in GitHub Desktop.
create js for preload images
This file contains hidden or 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
| IMAGES_PATH = "images/" | |
| OUTPUT_PATH = "javascripts/" | |
| images = Dir.glob(IMAGES_PATH + "**/*.jpg").join("','") | |
| js_str = <<-JS_STR | |
| (function() { | |
| var image_preloader = { | |
| images: ['#{images}'], | |
| done: function() { | |
| for (var i = 0; i < this.images.length; i += 1) { | |
| (new Image()).src = this.images[i]; | |
| } | |
| } | |
| }; | |
| image_preloader.done(); | |
| })(); | |
| JS_STR | |
| open(OUTPUT_PATH + 'preload_images.js', 'w'){|f| f.write js_str} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment