@@ -32,40 +32,49 @@ jQuery(function($){
32
32
// Sets the new min ID for loading images
33
33
min_ID = pagination . next_min_id ;
34
34
35
+ // Loops through the loaded photos
35
36
for ( x in new_photos ) {
36
37
var photoCont = $ ( "#photos" ) ,
37
38
photo = new_photos [ x ] ,
38
39
caption = null ;
39
40
41
+ // If a caption exists, sets it
40
42
if ( photo . caption !== null ) {
41
43
caption = photo . caption . text ;
42
44
}
43
45
46
+ // Creates a new image element
44
47
$ ( '<img />' , {
45
48
src : photo . images . thumbnail . url ,
46
49
alt : caption ,
47
50
data : {
48
- info : photo
51
+ info : photo // Passes photo info to the callback
49
52
}
50
53
} )
51
54
. 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
53
59
byline = $ ( '<strong />' , {
54
60
text : 'Photo by ' + photo . user . username
55
61
} ) ;
56
62
63
+ // Creates a new link around the image
57
64
$ ( '<a />' , {
58
65
href : photo . link ,
59
66
html : this
60
67
} )
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
69
78
} ) ;
70
79
}
71
80
} )
@@ -74,23 +83,29 @@ jQuery(function($){
74
83
} ) ;
75
84
} ;
76
85
86
+ // Adds a realtime listener
77
87
channel . bind ( 'new-photo' , function ( data ) {
78
88
89
+ // Keeps a running tally of new photos not yet loaded
79
90
newcount += data . newcount ;
80
91
92
+ // Grammar stuffs
81
93
var plural = ( newcount === 1 ) ? 'photo' : 'photos' ;
82
94
phrase = newcount + ' new ' + plural + ' uploaded.' ;
83
95
96
+ // Updates the count bar with the new information
84
97
$ ( '#count-bar' ) . removeClass ( 'hidden' ) . find ( '#count' ) . text ( phrase ) ;
85
98
86
99
} ) ;
87
100
101
+ // Click handler for the "Load the New Images" button
88
102
$ ( "#image-loader" ) . bind ( 'click' , function ( event ) {
89
103
event . preventDefault ( ) ;
90
104
91
105
load_photos ( ) ;
92
106
} ) ;
93
107
108
+ // For initialization purposes, loads the photos once the DOM is ready
94
109
load_photos ( ) ;
95
110
96
111
} ) ;
0 commit comments