Skip to content

Commit 043e079

Browse files
committed
Bugfixes and improvements for plugin Image
1 parent 4c7a384 commit 043e079

File tree

4 files changed

+51
-4
lines changed

4 files changed

+51
-4
lines changed

Demo/Demo.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,10 @@ $('#Notice-4').click(function() {
253253
/* Image */
254254

255255

256-
new jBox('Image');
256+
new jBox('Image', {
257+
imageCounter: true,
258+
imageCounterSeparator: ' of '
259+
});
257260

258261

259262
/* Additional JS for demo purposes */

Source/plugins/Image/jBox.Image.css

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,26 @@
8686
left: 0;
8787
}
8888

89+
.jBox-image-counter-container {
90+
position: absolute;
91+
right: 40px;
92+
height: 40px;
93+
line-height: 40px;
94+
font-size: 13px;
95+
color: #fff;
96+
text-align: right;
97+
display: none;
98+
}
99+
100+
.jBox-image-has-counter .jBox-image-counter-container {
101+
display: block;
102+
}
103+
104+
.jBox-image-has-counter .jBox-image-label:not(.expanded) {
105+
padding-right: 80px;
106+
text-indent: 40px;
107+
}
108+
89109
.jBox-overlay.jBox-overlay-Image {
90110
background: #000;
91111
}

Source/plugins/Image/jBox.Image.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ jQuery(document).ready(function () {
2020
imageLabel: 'title', // The attribute where jBox gets the image label from, e.g. title="My label"
2121
imageFade: 360, // The fade duration for images in ms
2222
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 '
2325
target: window,
2426
attach: '[data-jbox-image]',
2527
fixed: true,
@@ -79,7 +81,7 @@ jQuery(document).ready(function () {
7981
// Create image container
8082
var image = jQuery('<div/>', {
8183
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' : '')
8385
}).css({
8486
backgroundImage: error ? '' : 'url("' + this.images[gallery][id].src + '")',
8587
backgroundSize: this.options.imageSize,
@@ -123,12 +125,17 @@ jQuery(document).ready(function () {
123125
jQuery('.jBox-image-pointer-prev, .jBox-image-pointer-next').css({display: (this.images[gallery].length > 1 ? 'block' : 'none')});
124126
}
125127

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+
126133
// Set new current image
127134
this.currentImage = {gallery: gallery, id: id};
128135

129136
// Show image if it already exists
130137
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);
132139
showLabel(gallery, id);
133140

134141
// Load image
@@ -155,6 +162,17 @@ jQuery(document).ready(function () {
155162
}.bind(this));
156163
}
157164

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+
158176
// Preload next image
159177
var next_id = id + 1;
160178
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 () {
185203
// Append image label containers
186204
this.imageLabel = jQuery('<div/>', {'class': 'jBox-image-label-container'}).appendTo(this.wrapper);
187205
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+
}
188212
},
189213

190214

Source/plugins/Image/jBox.Image.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)