Skip to content

Commit 4162f49

Browse files
author
Jack Moore
committed
Fixed bug related to using the 'fixed' property.
Removed use of $.browser.
1 parent 6f2442d commit 4162f49

File tree

6 files changed

+56
-57
lines changed

6 files changed

+56
-57
lines changed

colorbox/jquery.colorbox.js

+51-52
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// ColorBox v1.3.18 - a full featured, light-weight, customizable lightbox based on jQuery 1.3+
2-
// Copyright (c) 2011 Jack Moore - jack@colorpowered.com
3-
// Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
1+
// ColorBox v1.3.19 - a full featured, light-weight, customizable lightbox based on jQuery 1.3+
2+
// Copyright (c) 2011 Jack Moore - jacklmoore.com
3+
// License: http://www.opensource.org/licenses/mit-license.php
44

55
(function ($, document, window) {
66
var
@@ -35,6 +35,7 @@
3535
close: "close",
3636
open: false,
3737
returnFocus: true,
38+
reposition: true,
3839
loop: true,
3940
slideshow: false,
4041
slideshowAuto: true,
@@ -71,10 +72,10 @@
7172
event_purge = prefix + '_purge',
7273

7374
// Special Handling for IE
74-
isIE = $.browser.msie && !$.support.opacity, // Detects IE6,7,8. IE9 supports opacity. Feature detection alone gave a false positive on at least one phone browser and on some development versions of Chrome, hence the user-agent test.
75-
isIE6 = isIE && $.browser.version < 7,
75+
isIE = !$.support.opacity && !$.support.style, // IE7 & IE8
76+
isIE6 = isIE && !window.XMLHttpRequest, // IE6
7677
event_ie6 = prefix + '_IE6',
77-
78+
7879
// Cached jQuery Object Variables
7980
$overlay,
8081
$box,
@@ -119,17 +120,17 @@
119120

120121
// Convience function for creating new jQuery objects
121122
function $tag(tag, id, css) {
122-
var element = document.createElement(tag);
123-
124-
if (id) {
125-
element.id = prefix + id;
126-
}
127-
128-
if (css) {
129-
element.style.cssText = css;
130-
}
131-
132-
return $(element);
123+
var element = document.createElement(tag);
124+
125+
if (id) {
126+
element.id = prefix + id;
127+
}
128+
129+
if (css) {
130+
element.style.cssText = css;
131+
}
132+
133+
return $(element);
133134
}
134135

135136
// Determine the next and previous members in a group.
@@ -195,7 +196,7 @@
195196
.text(settings.slideshowStop)
196197
.unbind(click)
197198
.bind(event_complete, function () {
198-
if (index < $related.length - 1 || settings.loop) {
199+
if (settings.loop || $related[index + 1]) {
199200
timeOut = setTimeout(publicMethod.next, settings.slideshowSpeed);
200201
}
201202
})
@@ -260,18 +261,9 @@
260261
$box.show();
261262

262263
if (settings.returnFocus) {
263-
try {
264-
element.blur();
265-
$(element).one(event_closed, function () {
266-
try {
267-
this.focus();
268-
} catch (e) {
269-
// do nothing
270-
}
271-
});
272-
} catch (e) {
273-
// do nothing
274-
}
264+
$(element).blur().one(event_closed, function () {
265+
$(this).focus();
266+
});
275267
}
276268

277269
// +settings.opacity avoids a problem in IE when using non-zero-prefixed-string-values, like '.5'
@@ -327,8 +319,7 @@
327319

328320
$this.each(function () {
329321
$.data(this, colorbox, $.extend({}, $.data(this, colorbox) || defaults, options));
330-
$(this).addClass(boxElement);
331-
});
322+
}).addClass(boxElement);
332323

333324
if (($.isFunction(options.open) && options.open.call($this)) || options.open) {
334325
launch($this[0]);
@@ -342,7 +333,7 @@
342333
// having to run once, instead of each time colorbox is opened.
343334
publicMethod.init = function () {
344335
if (!$box) {
345-
336+
346337
// If the body is not present yet, wait for DOM ready
347338
if (!$('body')[0]) {
348339
$(publicMethod.init);
@@ -385,7 +376,7 @@
385376

386377
$loadingBay = $tag(div, false, 'position:absolute; width:9999px; visibility:hidden; display:none');
387378

388-
$('body').prepend($overlay, $box.append($wrap, $loadingBay));
379+
$('body').append($overlay, $box.append($wrap, $loadingBay));
389380

390381
// Cache values needed for size calculations
391382
interfaceHeight = $topBorder.height() + $bottomBorder.height() + $content.outerHeight(true) - $content.height();//Subtraction needed for IE6
@@ -443,18 +434,25 @@
443434
};
444435

445436
publicMethod.position = function (speed, loadedCallback) {
446-
var top = 0, left = 0, offset = $box.offset();
437+
var
438+
top = 0,
439+
left = 0,
440+
offset = $box.offset(),
441+
scrollTop = $window.scrollTop(),
442+
scrollLeft = $window.scrollLeft();
447443

448444
$window.unbind('resize.' + prefix);
449445

450446
// remove the modal so that it doesn't influence the document width/height
451-
$box.css({top: -99999, left: -99999});
447+
$box.css({top: -9e4, left: -9e4});
452448

453449
if (settings.fixed && !isIE6) {
450+
offset.top -= scrollTop;
451+
offset.left -= scrollLeft;
454452
$box.css({position: 'fixed'});
455453
} else {
456-
top = $window.scrollTop();
457-
left = $window.scrollLeft();
454+
top = scrollTop;
455+
left = scrollLeft;
458456
$box.css({position: 'absolute'});
459457
}
460458

@@ -474,9 +472,9 @@
474472
} else {
475473
top += Math.round(Math.max($window.height() - settings.h - loadedHeight - interfaceHeight, 0) / 2);
476474
}
477-
475+
478476
$box.css({top: offset.top, left: offset.left});
479-
477+
480478
// setting the speed to 0 to reduce the delay between same-sized content.
481479
speed = ($box.width() === settings.w + loadedWidth && $box.height() === settings.h + loadedHeight) ? 0 : speed || 0;
482480

@@ -486,9 +484,8 @@
486484
$wrap[0].style.width = $wrap[0].style.height = "9999px";
487485

488486
function modalDimensions(that) {
489-
// loading overlay height has to be explicitly set for IE6.
490487
$topBorder[0].style.width = $bottomBorder[0].style.width = $content[0].style.width = that.style.width;
491-
$loadingOverlay[0].style.height = $loadingOverlay[1].style.height = $content[0].style.height = $leftBorder[0].style.height = $rightBorder[0].style.height = that.style.height;
488+
$content[0].style.height = $leftBorder[0].style.height = $rightBorder[0].style.height = that.style.height;
492489
}
493490

494491
$box.dequeue().animate({width: settings.w + loadedWidth, height: settings.h + loadedHeight, top: top, left: left}, {
@@ -501,14 +498,16 @@
501498
// shrink the wrapper down to exactly the size of colorbox to avoid a bug in IE's iframe implementation.
502499
$wrap[0].style.width = (settings.w + loadedWidth + interfaceWidth) + "px";
503500
$wrap[0].style.height = (settings.h + loadedHeight + interfaceHeight) + "px";
504-
501+
502+
if (settings.reposition) {
503+
setTimeout(function () { // small delay before binding onresize due to an IE8 bug.
504+
$window.bind('resize.' + prefix, publicMethod.position);
505+
}, 1);
506+
}
507+
505508
if (loadedCallback) {
506509
loadedCallback();
507510
}
508-
509-
setTimeout(function () { // small delay before binding onresize due to an IE8 bug.
510-
$window.bind('resize.' + prefix, publicMethod.position);
511-
}, 1);
512511
},
513512
step: function () {
514513
modalDimensions(this);
@@ -633,7 +632,7 @@
633632
getIndex(-1),
634633
getIndex(1)
635634
];
636-
while ((i = $related[preload.pop()])) {
635+
while (i = $related[preload.pop()]) {
637636
src = $.data(i, colorbox).href || i.href;
638637
if ($.isFunction(src)) {
639638
src = src.call(i);
@@ -780,7 +779,7 @@
780779
photo.style.marginTop = Math.max(settings.h - photo.height, 0) / 2 + 'px';
781780
}
782781

783-
if ($related[1] && (index < $related.length - 1 || settings.loop)) {
782+
if ($related[1] && (settings.loop || $related[index + 1])) {
784783
photo.style.cursor = 'pointer';
785784
photo.onclick = function () {
786785
publicMethod.next();
@@ -808,14 +807,14 @@
808807

809808
// Navigates to the next page/image in a set.
810809
publicMethod.next = function () {
811-
if (!active && $related[1] && (index < $related.length - 1 || settings.loop)) {
810+
if (!active && $related[1] && (settings.loop || $related[index + 1])) {
812811
index = getIndex(1);
813812
publicMethod.load();
814813
}
815814
};
816815

817816
publicMethod.prev = function () {
818-
if (!active && $related[1] && (index || settings.loop)) {
817+
if (!active && $related[1] && (settings.loop || index)) {
819818
index = getIndex(-1);
820819
publicMethod.load();
821820
}
@@ -858,7 +857,7 @@
858857
};
859858

860859
publicMethod.settings = defaults;
861-
860+
862861
// Bind the live event before DOM-ready for maximum performance in IE6 & 7.
863862
$('.' + boxElement, document).live('click', function (e) {
864863
// ignore non-left-mouse-clicks and clicks modified with ctrl / command, shift, or alt.

example1/colorbox.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#cboxContent{position:relative;}
99
#cboxLoadedContent{overflow:auto;}
1010
#cboxTitle{margin:0;}
11-
#cboxLoadingOverlay, #cboxLoadingGraphic{position:absolute; top:0; left:0; width:100%;}
11+
#cboxLoadingOverlay, #cboxLoadingGraphic{position:absolute; top:0; left:0; width:100%; height:100%;}
1212
#cboxPrevious, #cboxNext, #cboxClose, #cboxSlideshow{cursor:pointer;}
1313
.cboxPhoto{float:left; margin:auto; border:0; display:block;}
1414
.cboxIframe{width:100%; height:100%; display:block; border:0;}

example2/colorbox.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#cboxContent{position:relative;}
99
#cboxLoadedContent{overflow:auto;}
1010
#cboxTitle{margin:0;}
11-
#cboxLoadingOverlay, #cboxLoadingGraphic{position:absolute; top:0; left:0; width:100%;}
11+
#cboxLoadingOverlay, #cboxLoadingGraphic{position:absolute; top:0; left:0; width:100%; height:100%;}
1212
#cboxPrevious, #cboxNext, #cboxClose, #cboxSlideshow{cursor:pointer;}
1313
.cboxPhoto{float:left; margin:auto; border:0; display:block;}
1414
.cboxIframe{width:100%; height:100%; display:block; border:0;}

example3/colorbox.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#cboxContent{position:relative;}
99
#cboxLoadedContent{overflow:auto;}
1010
#cboxTitle{margin:0;}
11-
#cboxLoadingOverlay, #cboxLoadingGraphic{position:absolute; top:0; left:0; width:100%;}
11+
#cboxLoadingOverlay, #cboxLoadingGraphic{position:absolute; top:0; left:0; width:100%; height:100%;}
1212
#cboxPrevious, #cboxNext, #cboxClose, #cboxSlideshow{cursor:pointer;}
1313
.cboxPhoto{float:left; margin:auto; border:0; display:block;}
1414
.cboxIframe{width:100%; height:100%; display:block; border:0;}

example4/colorbox.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#cboxContent{position:relative;}
99
#cboxLoadedContent{overflow:auto;}
1010
#cboxTitle{margin:0;}
11-
#cboxLoadingOverlay, #cboxLoadingGraphic{position:absolute; top:0; left:0; width:100%;}
11+
#cboxLoadingOverlay, #cboxLoadingGraphic{position:absolute; top:0; left:0; width:100%; height:100%;}
1212
#cboxPrevious, #cboxNext, #cboxClose, #cboxSlideshow{cursor:pointer;}
1313
.cboxPhoto{float:left; margin:auto; border:0; display:block;}
1414
.cboxIframe{width:100%; height:100%; display:block; border:0;}

example5/colorbox.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#cboxContent{position:relative;}
99
#cboxLoadedContent{overflow:auto;}
1010
#cboxTitle{margin:0;}
11-
#cboxLoadingOverlay, #cboxLoadingGraphic{position:absolute; top:0; left:0; width:100%;}
11+
#cboxLoadingOverlay, #cboxLoadingGraphic{position:absolute; top:0; left:0; width:100%; height:100%;}
1212
#cboxPrevious, #cboxNext, #cboxClose, #cboxSlideshow{cursor:pointer;}
1313
.cboxPhoto{float:left; margin:auto; border:0; display:block;}
1414
.cboxIframe{width:100%; height:100%; display:block; border:0;}

0 commit comments

Comments
 (0)