Skip to content

Instantly share code, notes, and snippets.

@Meettya
Created May 16, 2013 18:22
Show Gist options
  • Save Meettya/5593874 to your computer and use it in GitHub Desktop.
Save Meettya/5593874 to your computer and use it in GitHub Desktop.
Just naive cached image loader in coffee with jade
extends includes/layout
block content
:coffeescript
images_srcs = [
'http://st.gdefon.ru/wallpapers_original/wallpapers/241906_kotenok_mordochka_trava_pushistyj_1920x1200_(www.GdeFon.ru).jpg'
'http://www.allfons.ru/pic/201112/1920x1080/allfons.ru-967.jpg'
'http://st.gdefon.ru/wallpapers_original/wallpapers/155879_kotyonok_vzglyad_kotye_1920x1200_(www.GdeFon.ru).jpg'
'http://st.gdefon.ru/wallpapers_original/wallpapers/17769_kotenok_ryzhij_pushistyj_fortepiano_1280x1024.jpg'
'http://catfoto.com/uploads/images/00/00/18/2011/02/12/7999cc.jpg'
'http://catfoto.com/uploads/images/00/00/18/2011/02/12/7999ffcc.jpg'
]
total_counter = images_srcs.length - 1
all_done = ->
console.log 'all done'
console.log images_dementions
$container = $('#content')
for image in images_storage
$(image).attr( height: '20%', width : '20%').appendTo $container
images_storage = []
# here we are save dementions for images
images_dementions = []
image_done_builder = (image_idx) ->->
# console.log @
images_dementions[image_idx] =
width : @width
height : @height
all_done() if total_counter-- is 0
for image_src, idx in images_srcs
images_storage[idx] = image = new Image
image.onload = image_done_builder(idx)
image.onerror = image.onabort = ->
total_counter--
console.log "Loading error |#{image_src}|"
image.src = "#{image_src}?#{+ new Date}"
$ ->
console.log 'worked'
console.log images_dementions
.container
h1 Images
.span12
#content
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment