4 (
function ($, window) {
10 transition:
"elastic",
31 current:
"image {current} of {total}",
40 slideshowStart:
"start slideshow",
41 slideshowStop:
"stop slideshow",
53 colorbox =
'colorbox',
57 event_open = prefix +
'_open',
58 event_load = prefix +
'_load',
59 event_complete = prefix +
'_complete',
60 event_cleanup = prefix +
'_cleanup',
61 event_closed = prefix +
'_closed',
64 isIE = $.browser.msie && !$.support.opacity,
65 isIE6 = isIE && $.browser.version < 7,
66 event_ie6 = prefix +
'_IE6',
102 boxElement = prefix +
'Element';
109 function $div(
id, css) {
110 id =
id ?
' id="' + prefix +
id +
'"' :
'';
111 css = css ?
' style="' + css +
'"' :
'';
112 return $(
'<div' +
id + css +
'/>');
116 function setSize(size, dimension) {
117 dimension = dimension ===
'x' ? $window.width() : $window.height();
118 return (typeof size ===
'string') ? Math.round((size.match(/%/) ? (dimension / 100) * parseInt(size, 10) : parseInt(size, 10))) : size;
123 function isImage(url) {
124 url = $.isFunction(url) ? url.call(element) : url;
125 return settings.photo || url.match(/\.(gif|png|jpg|jpeg|bmp)(?:\?([^#]*))?(?:#(\.*))?$/i);
130 for (var i in settings) {
131 if ($.isFunction(settings[i]) && i.substring(0, 2) !==
'on') {
132 settings[i] = settings[i].call(element);
135 settings.rel = settings.rel || element.rel ||
'nofollow';
136 settings.href = settings.href || $(element).attr(
'href');
137 settings.title = settings.title || element.title;
140 function launch(elem) {
144 settings = $.extend({}, $(element).data(colorbox));
148 if (settings.rel !==
'nofollow') {
149 $related = $(
'.' + boxElement).filter(
function () {
150 var relRelated = $(
this).data(colorbox).rel || this.rel;
151 return (relRelated === settings.rel);
153 index = $related.index(element);
157 $related = $related.add(element);
158 index = $related.length - 1;
161 $related = $(element);
166 open = active =
true;
174 $.event.trigger(event_open);
175 if (settings.onOpen) {
176 settings.onOpen.call(element);
180 $overlay.css({
"opacity": +settings.opacity,
"cursor": settings.overlayClose ?
"pointer" :
"auto"}).show();
183 settings.w = setSize(settings.initialWidth,
'x');
184 settings.h = setSize(settings.initialHeight,
'y');
185 publicMethod.position(0);
188 $window.bind(
'resize.' + event_ie6 +
' scroll.' + event_ie6,
function () {
189 $overlay.css({width: $window.width(), height: $window.height(), top: $window.scrollTop(), left: $window.scrollLeft()});
190 }).trigger(
'scroll.' + event_ie6);
194 $current.add($prev).add($next).add($slideshow).add($title).hide();
196 $close.html(settings.close).show();
198 publicMethod.slideshow();
209 publicMethod = $.fn[colorbox] = $[colorbox] =
function (options, callback) {
212 if (!$this[0] && $this.selector) {
216 options = options || {};
219 options.onComplete = callback;
222 if (!$this[0] || $this.selector === undefined) {
227 $this.each(
function () {
228 $(
this).data(colorbox, $.
extend({}, $(
this).data(colorbox) || defaults, options)).addClass(boxElement);
241 publicMethod.init =
function () {
244 $box = $div().attr({
id: colorbox,
'class': isIE ? prefix +
'IE' :
''});
245 $overlay = $div(
"Overlay", isIE6 ?
'position:absolute' :
'').hide();
247 $wrap = $div(
"Wrapper");
248 $content = $div(
"Content").append(
249 $loaded = $div(
"LoadedContent",
'width:0; height:0'),
250 $loadingOverlay = $div(
"LoadingOverlay").add($div(
"LoadingGraphic")),
251 $title = $div(
"Title"),
252 $current = $div(
"Current"),
253 $next = $div(
"Next"),
254 $prev = $div(
"Previous"),
255 $slideshow = $div(
"Slideshow"),
256 $close = $div(
"Close")
261 $topBorder = $div(
"TopCenter"),
265 $leftBorder = $div(
"MiddleLeft"),
267 $rightBorder = $div(
"MiddleRight")
271 $bottomBorder = $div(
"BottomCenter"),
274 ).children().children().css({
'float':
'left'});
276 $loadingBay = $div(
false,
'position:absolute; width:9999px; visibility:hidden; display:none');
278 $(
'body').prepend($overlay, $box.append($wrap, $loadingBay));
282 $(
this).addClass(
'hover');
284 $(
this).removeClass(
'hover');
285 }).addClass(
'hover');
288 interfaceHeight = $topBorder.height() + $bottomBorder.height() + $content.outerHeight(
true) - $content.height();
289 interfaceWidth = $leftBorder.width() + $rightBorder.width() + $content.outerWidth(
true) - $content.width();
290 loadedHeight = $loaded.outerHeight(
true);
291 loadedWidth = $loaded.outerWidth(
true);
294 $box.css({
"padding-bottom": interfaceHeight,
"padding-right": interfaceWidth}).hide();
297 $next.click(publicMethod.next);
298 $prev.click(publicMethod.prev);
299 $close.click(publicMethod.close);
303 $content.children().removeClass(
'hover');
305 $(
'.' + boxElement).live(
'click',
function (e) {
307 if ((e.button !== 0 && typeof e.button !==
'undefined') || e.ctrlKey || e.shiftKey || e.altKey) {
315 $overlay.click(
function () {
316 if (settings.overlayClose) {
317 publicMethod.close();
322 $(document).bind(
"keydown",
function (e) {
323 if (open && settings.escKey && e.keyCode === 27) {
325 publicMethod.close();
327 if (open && settings.arrowKey && !active && $related[1]) {
328 if (e.keyCode === 37 && (index || settings.loop)) {
331 }
else if (e.keyCode === 39 && (index < $related.length - 1 || settings.loop)) {
339 publicMethod.remove =
function () {
340 $box.add($overlay).remove();
341 $(
'.' + boxElement).die(
'click').removeData(colorbox).removeClass(boxElement);
344 publicMethod.position =
function (speed, loadedCallback) {
348 posTop = Math.max($window.height() - settings.h - loadedHeight - interfaceHeight, 0) / 2 + $window.scrollTop(),
349 posLeft = Math.max($window.width() - settings.w - loadedWidth - interfaceWidth, 0) / 2 + $window.scrollLeft();
352 animate_speed = ($box.width() === settings.w + loadedWidth && $box.height() === settings.h + loadedHeight) ? 0 : speed;
357 $wrap[0].style.width = $wrap[0].style.height =
"9999px";
359 function modalDimensions(that) {
361 $topBorder[0].style.width = $bottomBorder[0].style.width = $content[0].style.width = that.style.width;
362 $loadingOverlay[0].style.height = $loadingOverlay[1].style.height = $content[0].style.height = $leftBorder[0].style.height = $rightBorder[0].style.height = that.style.height;
365 $box.dequeue().animate({width: settings.w + loadedWidth, height: settings.h + loadedHeight, top: posTop, left: posLeft}, {
366 duration: animate_speed,
367 complete:
function () {
368 modalDimensions(
this);
373 $wrap[0].style.width = (settings.w + loadedWidth + interfaceWidth) +
"px";
374 $wrap[0].style.height = (settings.h + loadedHeight + interfaceHeight) +
"px";
376 if (loadedCallback) {
381 modalDimensions(
this);
386 publicMethod.resize =
function (options) {
388 options = options || {};
391 settings.w = setSize(options.width,
'x') - loadedWidth - interfaceWidth;
393 if (options.innerWidth) {
394 settings.w = setSize(options.innerWidth,
'x');
396 $loaded.css({width: settings.w});
398 if (options.height) {
399 settings.h = setSize(options.height,
'y') - loadedHeight - interfaceHeight;
401 if (options.innerHeight) {
402 settings.h = setSize(options.innerHeight,
'y');
404 if (!options.innerHeight && !options.height) {
405 var $child = $loaded.wrapInner(
"<div style='overflow:auto'></div>").children();
406 settings.h = $child.height();
407 $child.replaceWith($child.children());
409 $loaded.css({height: settings.h});
411 publicMethod.position(settings.transition ===
"none" ? 0 : settings.speed);
415 publicMethod.prep =
function (object) {
421 speed = settings.transition ===
"none" ? 0 : settings.speed;
423 $window.unbind(
'resize.' + prefix);
425 $loaded = $div(
'LoadedContent').html(
object);
427 function getWidth() {
428 settings.w = settings.w || $loaded.width();
429 settings.w = settings.mw && settings.mw < settings.w ? settings.mw : settings.w;
432 function getHeight() {
433 settings.h = settings.h || $loaded.height();
434 settings.h = settings.mh && settings.mh < settings.h ? settings.mh : settings.h;
439 .appendTo($loadingBay.show())
440 .css({width: getWidth(), overflow: settings.scrolling ?
'auto' :
'hidden'})
441 .css({height: getHeight()})
442 .prependTo($content);
446 $(
'#' + prefix +
'Photo').css({cssFloat:
'none'});
450 $(
'select').not($box.find(
'select')).filter(
function () {
451 return this.style.visibility !==
'hidden';
452 }).css({
'visibility':
'hidden'}).one(event_cleanup,
function () {
453 this.style.visibility =
'inherit';
457 function setPosition(s) {
458 var prev, prevSrc, next, nextSrc, total = $related.length, loop = settings.loop;
459 publicMethod.position(s,
function () {
460 function defilter() {
463 $box[0].style.removeAttribute(
"filter");
480 if (settings.iframe) {
481 $(
"<iframe frameborder=0" + (settings.scrolling ?
"" :
" scrolling='no'") + (isIE ?
" allowtransparency='true'" :
'') +
"/>")
482 .attr({src: settings.href, name:
new Date().getTime()})
488 $title.show().html(settings.title);
491 $current.html(settings.current.replace(/\{current\}/, index + 1).replace(/\{total\}/, total)).show();
493 $next[(loop || index < total - 1) ?
"show" :
"hide"]().html(settings.next);
494 $prev[(loop || index) ?
"show" :
"hide"]().html(settings.previous);
496 prev = index ? $related[index - 1] : $related[total - 1];
497 next = index < total - 1 ? $related[index + 1] : $related[0];
499 if (settings.slideshow) {
501 if (index === total - 1 && !loop && $box.is(
'.' + prefix +
'Slideshow_on')) {
507 if (settings.preloading) {
508 nextSrc = $(next).data(colorbox).href || next.href;
509 prevSrc = $(prev).data(colorbox).href || prev.href;
511 if (isImage(nextSrc)) {
512 $(
'<img/>')[0].src = nextSrc;
515 if (isImage(prevSrc)) {
516 $(
'<img/>')[0].src = prevSrc;
521 $loadingOverlay.hide();
523 if (settings.transition ===
'fade') {
524 $box.fadeTo(speed, 1,
function () {
531 $window.bind(
'resize.' + prefix,
function () {
532 publicMethod.position(0);
535 $.event.trigger(event_complete);
536 if (settings.onComplete) {
537 settings.onComplete.call(element);
542 if (settings.transition ===
'fade') {
543 $box.fadeTo(speed, 0,
function () {
551 publicMethod.load =
function () {
552 var href, img, setResize, prep = publicMethod.prep;
556 element = $related[index];
558 settings = $.extend({}, $(element).data(colorbox));
563 $.event.trigger(event_load);
564 if (settings.onLoad) {
565 settings.onLoad.call(element);
568 settings.h = settings.height ?
569 setSize(settings.height,
'y') - loadedHeight - interfaceHeight :
570 settings.innerHeight && setSize(settings.innerHeight,
'y');
572 settings.w = settings.width ?
573 setSize(settings.width,
'x') - loadedWidth - interfaceWidth :
574 settings.innerWidth && setSize(settings.innerWidth,
'x');
577 settings.mw = settings.w;
578 settings.mh = settings.h;
582 if (settings.maxWidth) {
583 settings.mw = setSize(settings.maxWidth,
'x') - loadedWidth - interfaceWidth;
584 settings.mw = settings.w && settings.w < settings.mw ? settings.w : settings.mw;
586 if (settings.maxHeight) {
587 settings.mh = setSize(settings.maxHeight,
'y') - loadedHeight - interfaceHeight;
588 settings.mh = settings.h && settings.h < settings.mh ? settings.h : settings.mh;
591 href = settings.href;
593 $loadingOverlay.show();
595 if (settings.inline) {
598 $div(
'InlineTemp').hide().insertBefore($(href)[0]).bind(event_load +
' ' + event_cleanup,
function () {
599 $(
this).replaceWith($loaded.children());
602 }
else if (settings.iframe) {
606 }
else if (settings.html) {
608 }
else if (isImage(href)) {
610 img.onload =
function () {
614 img.id = prefix +
'Photo';
615 $(img).css({margin:
'auto', border:
'none', display:
'block', cssFloat:
'left'});
617 if (settings.scalePhotos) {
618 setResize =
function () {
619 img.height -= img.height * percent;
620 img.width -= img.width * percent;
622 if (settings.mw && img.width > settings.mw) {
623 percent = (img.width - settings.mw) / img.width;
626 if (settings.mh && img.height > settings.mh) {
627 percent = (img.height - settings.mh) / img.height;
633 img.style.marginTop = Math.max(settings.h - img.height, 0) / 2 +
'px';
636 setTimeout(
function () {
640 if ($related[1] && (index < $related.length - 1 || settings.loop)) {
641 $(img).css({cursor:
'pointer'}).click(publicMethod.next);
645 img.style.msInterpolationMode =
'bicubic';
650 $div().appendTo($loadingBay).load(href,
function (data, status, xhr) {
651 prep(status ===
'error' ?
'Request unsuccessful: ' + xhr.statusText :
this);
657 publicMethod.next =
function () {
659 index = index < $related.length - 1 ? index + 1 : 0;
664 publicMethod.prev =
function () {
666 index = index ? index - 1 : $related.length - 1;
671 publicMethod.slideshow =
function () {
672 var stop, timeOut, className = prefix +
'Slideshow_';
674 $slideshow.bind(event_closed,
function () {
676 clearTimeout(timeOut);
677 $box.removeClass(className +
"off " + className +
"on");
682 .text(settings.slideshowStop)
683 .bind(event_complete,
function () {
684 timeOut = setTimeout(publicMethod.next, settings.slideshowSpeed);
686 .bind(event_load,
function () {
687 clearTimeout(timeOut);
688 }).one(
"click",
function () {
691 $box.removeClass(className +
"off").addClass(className +
"on");
695 clearTimeout(timeOut);
697 .text(settings.slideshowStart)
698 .unbind(event_complete +
' ' + event_load)
699 .one(
"click",
function () {
701 timeOut = setTimeout(publicMethod.next, settings.slideshowSpeed);
703 $box.removeClass(className +
"on").addClass(className +
"off");
706 if (settings.slideshow && $related[1]) {
707 if (settings.slideshowAuto) {
716 publicMethod.close =
function () {
720 $.event.trigger(event_cleanup);
722 if (settings.onCleanup) {
723 settings.onCleanup.call(element);
726 $window.unbind(
'.' + prefix +
' .' + event_ie6);
728 $overlay.fadeTo(
'fast', 0);
730 $box.stop().fadeTo(
'fast', 0,
function () {
731 $box.find(
'iframe').attr(
'src',
'about:blank');
735 $box.add($overlay).css({
'opacity': 1, cursor:
'auto'}).hide();
743 setTimeout(
function () {
744 $.event.trigger(event_closed);
745 if (settings.onClosed) {
746 settings.onClosed.call(element);
755 publicMethod.element =
function () {
759 publicMethod.settings = defaults;
762 $(publicMethod.init);