Skip to content

Commit 5fe1f90

Browse files
author
jlengstorf
committed
Added more comments, minor formatting.
1 parent affe7c1 commit 5fe1f90

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

js/main.js

+25-10
Original file line numberDiff line numberDiff line change
@@ -32,40 +32,49 @@ jQuery(function($){
3232
// Sets the new min ID for loading images
3333
min_ID = pagination.next_min_id;
3434

35+
// Loops through the loaded photos
3536
for (x in new_photos) {
3637
var photoCont = $("#photos"),
3738
photo = new_photos[x],
3839
caption = null;
3940

41+
// If a caption exists, sets it
4042
if (photo.caption!==null) {
4143
caption = photo.caption.text;
4244
}
4345

46+
// Creates a new image element
4447
$('<img />', {
4548
src: photo.images.thumbnail.url,
4649
alt: caption,
4750
data: {
48-
info: photo
51+
info: photo // Passes photo info to the callback
4952
}
5053
})
5154
.load(function(){
52-
var photo = $(this).data('info'),
55+
56+
// Sets up shortcut vars and byline markup
57+
var cont = $("#photos"),
58+
photo = $(this).data('info'), // Reads photo data
5359
byline = $('<strong />', {
5460
text: 'Photo by ' + photo.user.username
5561
});
5662

63+
// Creates a new link around the image
5764
$('<a />', {
5865
href: photo.link,
5966
html: this
6067
})
61-
.css({opacity: 0})
62-
.delay(delay)
63-
.prependTo($("#photos"))
64-
.append(byline)
65-
.wrap('<li />')
66-
.animate({ opacity: 1 }, anim_speed);
67-
68-
delay += anim_speed
68+
.css({opacity: 0}) // Starts the effect
69+
.delay(delay) // Adds a delay
70+
.prependTo(cont) // Adds the new element to the DOM
71+
.append(byline) // Inserts the attribution
72+
.wrap('<li />') // Wraps the whole thing in a LI
73+
.animate({
74+
opacity: 1
75+
}, anim_speed); // Finishes the effect
76+
77+
delay += anim_speed // Simulates sequential loading
6978
});
7079
}
7180
})
@@ -74,23 +83,29 @@ jQuery(function($){
7483
});
7584
};
7685

86+
// Adds a realtime listener
7787
channel.bind('new-photo', function(data){
7888

89+
// Keeps a running tally of new photos not yet loaded
7990
newcount += data.newcount;
8091

92+
// Grammar stuffs
8193
var plural = (newcount===1) ? 'photo' : 'photos';
8294
phrase = newcount+' new '+plural+' uploaded.';
8395

96+
// Updates the count bar with the new information
8497
$('#count-bar').removeClass('hidden').find('#count').text(phrase);
8598

8699
});
87100

101+
// Click handler for the "Load the New Images" button
88102
$("#image-loader").bind('click', function(event){
89103
event.preventDefault();
90104

91105
load_photos();
92106
});
93107

108+
// For initialization purposes, loads the photos once the DOM is ready
94109
load_photos();
95110

96111
});

0 commit comments

Comments
 (0)