@@ -20,6 +20,8 @@ jQuery(document).ready(function () {
20
20
imageLabel : 'title' , // The attribute where jBox gets the image label from, e.g. title="My label"
21
21
imageFade : 360 , // The fade duration for images in ms
22
22
imageSize : 'contain' , // How to display the images. Use CSS background-position values, e.g. 'cover', 'contain', 'auto', 'initial', '50% 50%'
23
+ imageCounter : false , // Set to true to add an image counter, e.g. 4/20
24
+ imageCounterSeparator : '/' , // HTML to separate the current image number from all image numbers, e.g. '/' or ' of '
23
25
target : window ,
24
26
attach : '[data-jbox-image]' ,
25
27
fixed : true ,
@@ -79,7 +81,7 @@ jQuery(document).ready(function () {
79
81
// Create image container
80
82
var image = jQuery ( '<div/>' , {
81
83
id : 'jBox-image-' + gallery + '-' + id ,
82
- 'class' : 'jBox-image-container' + ( error ? ' jBox-image-not-found' : '' )
84
+ 'class' : 'jBox-image-container' + ( error ? ' jBox-image-not-found' : '' ) + ( ! open && ! preload ? ' jBox-image-' + gallery + '-current' : '' )
83
85
} ) . css ( {
84
86
backgroundImage : error ? '' : 'url("' + this . images [ gallery ] [ id ] . src + '")' ,
85
87
backgroundSize : this . options . imageSize ,
@@ -123,12 +125,17 @@ jQuery(document).ready(function () {
123
125
jQuery ( '.jBox-image-pointer-prev, .jBox-image-pointer-next' ) . css ( { display : ( this . images [ gallery ] . length > 1 ? 'block' : 'none' ) } ) ;
124
126
}
125
127
128
+ // If there is a current image already shown, hide it
129
+ if ( jQuery ( '.jBox-image-' + gallery + '-current' ) . length ) {
130
+ jQuery ( '.jBox-image-' + gallery + '-current' ) . removeClass ( 'jBox-image-' + gallery + '-current' ) . animate ( { opacity : 0 } , ( img == 'open' ) ? 0 : this . options . imageFade ) ;
131
+ }
132
+
126
133
// Set new current image
127
134
this . currentImage = { gallery : gallery , id : id } ;
128
135
129
136
// Show image if it already exists
130
137
if ( jQuery ( '#jBox-image-' + gallery + '-' + id ) . length ) {
131
- jQuery ( '#jBox-image-' + gallery + '-' + id ) . css ( { zIndex : this . imageZIndex ++ , opacity : 0 } ) . animate ( { opacity : 1 } , ( img == 'open' ) ? 0 : this . options . imageFade ) ;
138
+ jQuery ( '#jBox-image-' + gallery + '-' + id ) . addClass ( 'jBox-image-' + gallery + '-current' ) . css ( { zIndex : this . imageZIndex ++ , opacity : 0 } ) . animate ( { opacity : 1 } , ( img == 'open' ) ? 0 : this . options . imageFade ) ;
132
139
showLabel ( gallery , id ) ;
133
140
134
141
// Load image
@@ -155,6 +162,17 @@ jQuery(document).ready(function () {
155
162
} . bind ( this ) ) ;
156
163
}
157
164
165
+ // Update the image counter numbers
166
+ if ( this . imageCounter ) {
167
+ if ( this . images [ gallery ] . length > 1 ) {
168
+ this . wrapper . addClass ( 'jBox-image-has-counter' ) ;
169
+ this . imageCounter . find ( '.jBox-image-counter-all' ) . html ( this . images [ gallery ] . length ) ;
170
+ this . imageCounter . find ( '.jBox-image-counter-current' ) . html ( id + 1 ) ;
171
+ } else {
172
+ this . wrapper . removeClass ( 'jBox-image-has-counter' ) ;
173
+ }
174
+ }
175
+
158
176
// Preload next image
159
177
var next_id = id + 1 ;
160
178
next_id = next_id > ( this . images [ gallery ] . length - 1 ) ? 0 : ( next_id < 0 ? ( this . images [ gallery ] . length - 1 ) : next_id ) ;
@@ -185,6 +203,12 @@ jQuery(document).ready(function () {
185
203
// Append image label containers
186
204
this . imageLabel = jQuery ( '<div/>' , { 'class' : 'jBox-image-label-container' } ) . appendTo ( this . wrapper ) ;
187
205
this . imageLabel . append ( jQuery ( '<div/>' , { 'class' : 'jBox-image-pointer-prev' , click : function ( ) { this . showImage ( 'prev' ) ; } . bind ( this ) } ) ) . append ( jQuery ( '<div/>' , { 'class' : 'jBox-image-pointer-next' , click : function ( ) { this . showImage ( 'next' ) ; } . bind ( this ) } ) ) ;
206
+
207
+ // Creating the image counter containers
208
+ if ( this . options . imageCounter ) {
209
+ this . imageCounter = jQuery ( '<div/>' , { 'class' : 'jBox-image-counter-container' } ) . appendTo ( this . wrapper ) ;
210
+ this . imageCounter . append ( jQuery ( '<span/>' , { 'class' : 'jBox-image-counter-current' } ) ) . append ( jQuery ( '<span/>' ) . html ( this . options . imageCounterSeparator ) ) . append ( jQuery ( '<span/>' , { 'class' : 'jBox-image-counter-all' } ) ) ;
211
+ }
188
212
} ,
189
213
190
214
0 commit comments