Skip to content

Instantly share code, notes, and snippets.

@Killavus
Last active August 29, 2015 14:04
Show Gist options
  • Save Killavus/f7ef855717736eb5a984 to your computer and use it in GitHub Desktop.
Save Killavus/f7ef855717736eb5a984 to your computer and use it in GitHub Desktop.
Example of badly written code - loading photos and making it grayed after click
$(document).ready ->
photoHTML = (photo) =>
"<li><a id='photo_#{photo.id}' href='#{photo.url}'><img src='#{photo.url}' alt='#{photo.alt}' /></a></li>"
$.ajax
url: '/photos'
type: 'GET'
contentType: 'application/json'
onSuccess: (response) =>
for photo in response.photos
node = $(photoHTML(photo)).appendTo($("#photos-list"))
node.on('click', (e) =>
e.preventDefault()
node.find('img').prop('src', photo.url + '.grayscaled.jpg')
)
onFailure: =>
$("#photo-list").append("<li>Failed to fetch photos.</li>")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment