Last active
August 29, 2015 14:04
-
-
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
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
$(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