diff --git a/README b/README index 7f7c17f..020f7fc 100644 --- a/README +++ b/README @@ -11,6 +11,17 @@ http://groups.google.com/group/colorbox/topics RELEASE NOTES: ---------------------------------------------------------------------------------------------------------- +Version 1.3.7 - June 11 2010 +Files Changed: jquery.colorbox.js/jquery.colorbox-min.js +* $.colorbox can now be used for direct calls and accessing public methods. Example: $.colorbox.close(); +* Resize now accepts 'width', 'innerWidth', 'height' and 'innerHeight'. Example: $.colorbox.resize({width:"100%"}) +* Added option to disable looping in a group. +* Added option to disable esc-key and arrow-key bindings. +* Fixed a bug where iframed URLs would be truncated if they contained an unencoded apostrophe. +* Now uses the exact href specified on an anchor, rather than the version returned by 'this.href'. + This was causing "#example" to be normalized to "http://domain/#example" which interfered with how some + users were setting up links to inline content. + Version 1.3.6 - Jan 13 2010 Files Changed: jquery.colorbox.js/jquery.colorbox-min.js * Small change to make Colorbox compatible with jQuery 1.4 diff --git a/colorbox/jquery.colorbox-min.js b/colorbox/jquery.colorbox-min.js index 0e5a539..2c304fa 100644 --- a/colorbox/jquery.colorbox-min.js +++ b/colorbox/jquery.colorbox-min.js @@ -1,2 +1,2 @@ -/* ColorBox v1.3.6 - a full featured, light-weight, customizable lightbox based on jQuery 1.3 */ -(function(c){function r(b,d){d=d==="x"?m.width():m.height();return typeof b==="string"?Math.round(b.match(/%/)?d/100*parseInt(b,10):parseInt(b,10)):b}function M(b){b=c.isFunction(b)?b.call(i):b;return a.photo||b.match(/\.(gif|png|jpg|jpeg|bmp)(?:\?([^#]*))?(?:#(\.*))?$/i)}function Y(){for(var b in a)if(c.isFunction(a[b])&&b.substring(0,2)!=="on")a[b]=a[b].call(i);a.rel=a.rel||i.rel;a.href=a.href||i.href;a.title=a.title||i.title}function Z(b){i=b;a=c(i).data(q);Y();if(a.rel&&a.rel!=="nofollow"){g= c(".cboxElement").filter(function(){return(c(this).data(q).rel||this.rel)===a.rel});j=g.index(i);if(j<0){g=g.add(i);j=g.length-1}}else{g=c(i);j=0}if(!B){C=B=n;N=i;N.blur();c(document).bind("keydown.cbox_close",function(d){if(d.keyCode===27){d.preventDefault();e.close()}}).bind("keydown.cbox_arrows",function(d){if(g.length>1)if(d.keyCode===37){d.preventDefault();D.click()}else if(d.keyCode===39){d.preventDefault();E.click()}});a.overlayClose&&s.css({cursor:"pointer"}).one("click",e.close);c.event.trigger(aa); a.onOpen&&a.onOpen.call(i);s.css({opacity:a.opacity}).show();a.w=r(a.initialWidth,"x");a.h=r(a.initialHeight,"y");e.position(0);O&&m.bind("resize.cboxie6 scroll.cboxie6",function(){s.css({width:m.width(),height:m.height(),top:m.scrollTop(),left:m.scrollLeft()})}).trigger("scroll.cboxie6")}P.add(D).add(E).add(t).add(Q).hide();R.html(a.close).show();e.slideshow();e.load()}var q="colorbox",F="hover",n=true,e,x=c.browser.msie&&!c.support.opacity,O=x&&c.browser.version<7,aa="cbox_open",H="cbox_load",S= "cbox_complete",T="resize.cbox_resize",s,k,u,p,U,V,W,X,g,m,l,I,J,K,Q,P,t,E,D,R,y,z,v,w,i,N,j,a,B,C,$={transition:"elastic",speed:350,width:false,height:false,innerWidth:false,innerHeight:false,initialWidth:"400",initialHeight:"400",maxWidth:false,maxHeight:false,scalePhotos:n,scrolling:n,inline:false,html:false,iframe:false,photo:false,href:false,title:false,rel:false,opacity:0.9,preloading:n,current:"image {current} of {total}",previous:"previous",next:"next",close:"close",open:false,overlayClose:n, slideshow:false,slideshowAuto:n,slideshowSpeed:2500,slideshowStart:"start slideshow",slideshowStop:"stop slideshow",onOpen:false,onLoad:false,onComplete:false,onCleanup:false,onClosed:false};e=c.fn.colorbox=function(b,d){var h=this;if(!h.length)if(h.selector===""){h=c("");b.open=n}else return this;h.each(function(){var f=c.extend({},c(this).data(q)?c(this).data(q):$,b);c(this).data(q,f).addClass("cboxElement");if(d)c(this).data(q).onComplete=d});b&&b.open&&Z(h);return this};e.init=function(){function b(d){return c('
')}m=c(window);k=c('
');s=b("Overlay").hide();u=b("Wrapper");p=b("Content").append(l=b("LoadedContent").css({width:0,height:0}),J=b("LoadingOverlay"),K=b("LoadingGraphic"),Q=b("Title"),P=b("Current"),t=b("Slideshow"),E=b("Next"),D=b("Previous"),R=b("Close"));u.append(c("
").append(b("TopLeft"),U=b("TopCenter"),b("TopRight")),c("
").append(V=b("MiddleLeft"),p,W=b("MiddleRight")),c("
").append(b("BottomLeft"),X=b("BottomCenter"),b("BottomRight"))).children().children().css({"float":"left"}); I=c("
");c("body").prepend(s,k.append(u,I));if(x){k.addClass("cboxIE");O&&s.css("position","absolute")}p.children().bind("mouseover mouseout",function(){c(this).toggleClass(F)}).addClass(F);y=U.height()+X.height()+p.outerHeight(n)-p.height();z=V.width()+W.width()+p.outerWidth(n)-p.width();v=l.outerHeight(n);w=l.outerWidth(n);k.css({"padding-bottom":y,"padding-right":z}).hide();E.click(e.next);D.click(e.prev);R.click(e.close);p.children().removeClass(F); c(".cboxElement").live("click",function(d){if(d.button!==0&&typeof d.button!=="undefined")return n;else{Z(this);return false}})};e.position=function(b,d){function h(A){U[0].style.width=X[0].style.width=p[0].style.width=A.style.width;K[0].style.height=J[0].style.height=p[0].style.height=V[0].style.height=W[0].style.height=A.style.height}var f=m.height();f=Math.max(f-a.h-v-y,0)/2+m.scrollTop();var o=Math.max(document.documentElement.clientWidth-a.w-w-z,0)/2+m.scrollLeft();b=k.width()===a.w+w&&k.height()=== a.h+v?0:b;u[0].style.width=u[0].style.height="9999px";k.dequeue().animate({width:a.w+w,height:a.h+v,top:f,left:o},{duration:b,complete:function(){h(this);C=false;u[0].style.width=a.w+w+z+"px";u[0].style.height=a.h+v+y+"px";d&&d()},step:function(){h(this)}})};e.resize=function(b){function d(){a.w=a.w||l.width();a.w=a.mw&&a.mw");l.show();Q.show().html(a.title);if(g.length>1){P.html(a.current.replace(/\{current\}/,j+1).replace(/\{total\}/,g.length)).show();E.html(a.next).show();D.html(a.previous).show();a.slideshow&&t.show()}J.hide();K.hide();c.event.trigger(S);a.onComplete&&a.onComplete.call(i);a.transition==="fade"&&k.fadeTo(L,1,function(){x&&k[0].style.removeAttribute("filter")}); m.bind(T,function(){e.position(0)})}})}if(B){var o,A,L=a.transition==="none"?0:a.speed;m.unbind(T);if(b){l.remove();l=c('
').html(b);l.hide().appendTo(I).css({width:d(),overflow:a.scrolling?"auto":"hidden"}).css({height:h()}).prependTo(p);c("#cboxPhoto").css({cssFloat:"none"});O&&c("select:not(#colorbox select)").filter(function(){return this.style.visibility!=="hidden"}).css({visibility:"hidden"}).one("cbox_cleanup",function(){this.style.visibility="inherit"});a.transition=== "fade"&&k.fadeTo(L,0,function(){f(0)})||f(L);if(a.preloading&&g.length>1){b=j>0?g[j-1]:g[g.length-1];o=j").attr("src",o);M(b)&&c("").attr("src",b)}}else setTimeout(function(){var G=l.wrapInner("
").children();a.h=G.height();l.css({height:a.h});G.replaceWith(G.children());e.position(L)},1)}};e.load=function(){var b,d,h,f=e.resize;C=n;i=g[j];a=c(i).data(q);Y();c.event.trigger(H); a.onLoad&&a.onLoad.call(i);a.h=a.height?r(a.height,"y")-v-y:a.innerHeight?r(a.innerHeight,"y"):false;a.w=a.width?r(a.width,"x")-w-z:a.innerWidth?r(a.innerWidth,"x"):false;a.mw=a.w;a.mh=a.h;if(a.maxWidth){a.mw=r(a.maxWidth,"x")-w-z;a.mw=a.w&&a.w').hide().insertBefore(c(b)[0]).bind(H+" cbox_cleanup",function(){c(this).replaceWith(l.children())}); f(c(b))}else if(a.iframe)f(" ");else if(a.html)f(a.html);else if(M(b)){d=new Image;d.onload=function(){var o;d.onload=null;d.id="cboxPhoto";c(d).css({margin:"auto",border:"none",display:"block",cssFloat:"left"});if(a.scalePhotos){h=function(){d.height-=d.height*o;d.width-=d.width*o};if(a.mw&&d.width>a.mw){o=(d.width-a.mw)/d.width;h()}if(a.mh&&d.height>a.mh){o=(d.height-a.mh)/d.height;h()}}if(a.h)d.style.marginTop=Math.max(a.h-d.height,0)/2+"px";f(d);g.length>1&&c(d).css({cursor:"pointer"}).click(e.next); if(x)d.style.msInterpolationMode="bicubic"};d.src=b}else c("
").appendTo(I).load(b,function(o,A){A==="success"?f(this):f(c("

Request unsuccessful.

"))})};e.next=function(){if(!C){j=j0?j-1:g.length-1;e.load()}};e.slideshow=function(){function b(){t.text(a.slideshowStop).bind(S,function(){h=setTimeout(e.next,a.slideshowSpeed)}).bind(H,function(){clearTimeout(h)}).one("click",function(){d();c(this).removeClass(F)});k.removeClass(f+ "off").addClass(f+"on")}var d,h,f="cboxSlideshow_";t.bind("cbox_closed",function(){t.unbind();clearTimeout(h);k.removeClass(f+"off "+f+"on")});d=function(){clearTimeout(h);t.text(a.slideshowStart).unbind(S+" "+H).one("click",function(){b();h=setTimeout(e.next,a.slideshowSpeed);c(this).removeClass(F)});k.removeClass(f+"on").addClass(f+"off")};if(a.slideshow&&g.length>1)a.slideshowAuto?b():d()};e.close=function(){c.event.trigger("cbox_cleanup");a.onCleanup&&a.onCleanup.call(i);B=false;c(document).unbind("keydown.cbox_close keydown.cbox_arrows"); m.unbind(T+" resize.cboxie6 scroll.cboxie6");s.css({cursor:"auto"}).fadeOut("fast");k.stop(n,false).fadeOut("fast",function(){c("#colorbox iframe").attr("src","about:blank");l.remove();k.css({opacity:1});try{N.focus()}catch(b){}c.event.trigger("cbox_closed");a.onClosed&&a.onClosed.call(i)})};e.element=function(){return c(i)};e.settings=$;c(e.init)})(jQuery); \ No newline at end of file +/* ColorBox v1.3.7 - a full featured, light-weight, customizable lightbox based on jQuery 1.3 */ +(function(c){function p(b,d){d=d==="x"?l.width():l.height();return typeof b==="string"?Math.round(b.match(/%/)?d/100*parseInt(b,10):parseInt(b,10)):b}function O(b){b=c.isFunction(b)?b.call(g):b;return a.photo||b.match(/\.(gif|png|jpg|jpeg|bmp)(?:\?([^#]*))?(?:#(\.*))?$/i)}function $(){for(var b in a)if(c.isFunction(a[b])&&b.substring(0,2)!=="on")a[b]=a[b].call(g);a.rel=a.rel||g.rel||"nofollow";a.href=a.href||c(g).attr("href");a.title=a.title||g.title}function aa(b){g=b;a=c.extend({},c(g).data(u)); $();if(a.rel!=="nofollow"){i=c(".cboxElement").filter(function(){return(c(this).data(u).rel||this.rel)===a.rel});h=i.index(g);if(h<0){i=i.add(g);h=i.length-1}}else{i=c(g);h=0}if(!q){z=q=m;P=g;P.blur();c.event.trigger(ca);a.onOpen&&a.onOpen.call(g);r.css({opacity:a.opacity,cursor:a.overlayClose?"pointer":"auto"}).show();a.w=p(a.initialWidth,"x");a.h=p(a.initialHeight,"y");e.position(0);Q&&l.bind("resize.cboxIE6 scroll.cboxIE6",function(){r.css({width:l.width(),height:l.height(),top:l.scrollTop(),left:l.scrollLeft()})}).trigger("scroll.cboxIE6")}R.add(G).add(H).add(s).add(S).hide(); T.html(a.close).show();e.slideshow();e.load()}var u="colorbox",I="hover",m=true,e,A=c.browser.msie&&!c.support.opacity,Q=A&&c.browser.version<7,ca="cbox_open",K="cbox_load",U="cbox_complete",r,j,v,o,V,W,X,Y,i,l,n,L,M,N,S,R,s,H,G,T,B,C,w,x,g,P,h,a,q,z,ba={transition:"elastic",speed:350,width:false,height:false,innerWidth:false,innerHeight:false,initialWidth:"400",initialHeight:"400",maxWidth:false,maxHeight:false,scalePhotos:m,scrolling:m,inline:false,html:false,iframe:false,photo:false,href:false, title:false,rel:false,opacity:0.9,preloading:m,current:"image {current} of {total}",previous:"previous",next:"next",close:"close",open:false,overlayClose:m,loop:false,slideshow:false,slideshowAuto:m,slideshowSpeed:2500,slideshowStart:"start slideshow",slideshowStop:"stop slideshow",onOpen:false,onLoad:false,onComplete:false,onCleanup:false,onClosed:false,escKey:m,arrowKey:m};e=c.fn.colorbox=c.colorbox=function(b,d){var f=this;b||(b={});if(d)b.onComplete=d;if(!f.selector||f.selector===""){f=c(""); b.open=m}f.each(function(){c(this).data(u,c.extend({},c(this).data(u)||ba,b)).addClass("cboxElement")});b.open&&aa(f[0]);return f};e.init=function(){function b(d){return c('
')}l=c(window);j=c('
');r=b("Overlay").hide();v=b("Wrapper");o=b("Content").append(n=b("LoadedContent").css({width:0,height:0}),M=b("LoadingOverlay"),N=b("LoadingGraphic"),S=b("Title"),R=b("Current"),s=b("Slideshow"),H=b("Next"),G=b("Previous"),T=b("Close"));v.append(c("
").append(b("TopLeft"), V=b("TopCenter"),b("TopRight")),c("
").append(W=b("MiddleLeft"),o,X=b("MiddleRight")),c("
").append(b("BottomLeft"),Y=b("BottomCenter"),b("BottomRight"))).children().children().css({"float":"left"});L=c("
");c("body").prepend(r,j.append(v,L));if(A){j.addClass("cboxIE");Q&&r.css("position","absolute")}o.children().bind("mouseover mouseout",function(){c(this).toggleClass(I)}).addClass(I);B=V.height()+Y.height()+o.outerHeight(m)- o.height();C=W.width()+X.width()+o.outerWidth(m)-o.width();w=n.outerHeight(m);x=n.outerWidth(m);j.css({"padding-bottom":B,"padding-right":C}).hide();H.click(e.next);G.click(e.prev);T.click(e.close);o.children().removeClass(I);c(".cboxElement").live("click",function(d){if(d.button!==0&&typeof d.button!=="undefined"||d.ctrlKey||d.shiftKey||d.altKey)return m;else{aa(this);return false}});r.click(function(){a.overlayClose&&e.close()});c(document).bind("keydown",function(d){if(q&&a.escKey&&d.keyCode=== 27){d.preventDefault();e.close()}if(q&&a.arrowKey&&!z&&i.length>1)if(d.keyCode===37){d.preventDefault();G.click()}else if(d.keyCode===39){d.preventDefault();H.click()}})};e.position=function(b,d){function f(y){V[0].style.width=Y[0].style.width=o[0].style.width=y.style.width;N[0].style.height=M[0].style.height=o[0].style.height=W[0].style.height=X[0].style.height=y.style.height}var k=Math.max(l.height()-a.h-w-B,0)/2+l.scrollTop(),t=Math.max(l.width()-a.w-x-C,0)/2+l.scrollLeft();b=j.width()===a.w+x&& j.height()===a.h+w?0:b;v[0].style.width=v[0].style.height="9999px";j.dequeue().animate({width:a.w+x,height:a.h+w,top:k,left:t},{duration:b,complete:function(){f(this);z=false;v[0].style.width=a.w+x+C+"px";v[0].style.height=a.h+w+B+"px";d&&d()},step:function(){f(this)}})};e.resize=function(b){function d(){a.w=a.w||n.width();a.w=a.mw&&a.mw");n.show();S.show().html(a.title);(function(){var D,E,F=i.length,Z=a.loop;if(F>1){R.html(a.current.replace(/\{current\}/,h+1).replace(/\{total\}/,F)).show();H[Z||h0?"show":"hide"]().html(a.prev);D=h>0?i[h-1]:i[F-1];E=h")[0].src=E;if(O(D))c("")[0].src=D}}})();M.hide();N.hide();a.transition==="fade"&&j.fadeTo(y,1,function(){A&&j[0].style.removeAttribute("filter")});l.bind("resize.cbox",function(){e.position(0)});c.event.trigger(U);a.onComplete&&a.onComplete.call(g)}})}if(q){var t,y=a.transition==="none"?0:a.speed;l.unbind("resize.cbox"); if(b){n.remove();n=c('
').html(b);n.hide().appendTo(L).css({width:d(),overflow:a.scrolling?"auto":"hidden"}).css({height:f()}).prependTo(o);c("#cboxPhoto").css({cssFloat:"none"});Q&&c("select:not(#colorbox select)").filter(function(){return this.style.visibility!=="hidden"}).css({visibility:"hidden"}).one("cbox_cleanup",function(){this.style.visibility="inherit"});a.transition==="fade"&&j.fadeTo(y,0,function(){k(0)})||k(y)}else setTimeout(function(){var J=n.wrapInner("
").children(); a.h=J.height();n.css({height:a.h});J.replaceWith(J.children());e.position(y)},1)}};e.load=function(){var b,d,f,k=e.resize;z=m;g=i[h];a=c.extend({},c(g).data(u));$();c.event.trigger(K);a.onLoad&&a.onLoad.call(g);a.h=a.height?p(a.height,"y")-w-B:a.innerHeight?p(a.innerHeight,"y"):false;a.w=a.width?p(a.width,"x")-x-C:a.innerWidth?p(a.innerWidth,"x"):false;a.mw=a.w;a.mh=a.h;if(a.maxWidth){a.mw=p(a.maxWidth,"x")-x-C;a.mw=a.w&&a.w').hide().insertBefore(c(b)[0]).bind(K+" cbox_cleanup",function(){c(this).replaceWith(n.children())});k(c(b))}else if(a.iframe)k(" ");else if(a.html)k(a.html);else if(O(b)){d=new Image;d.onload=function(){var t;d.onload=null;d.id="cboxPhoto";c(d).css({margin:"auto",border:"none",display:"block",cssFloat:"left"});if(a.scalePhotos){f=function(){d.height-=d.height*t;d.width-=d.width*t};if(a.mw&&d.width>a.mw){t=(d.width- a.mw)/d.width;f()}if(a.mh&&d.height>a.mh){t=(d.height-a.mh)/d.height;f()}}if(a.h)d.style.marginTop=Math.max(a.h-d.height,0)/2+"px";k(d);i.length>1&&c(d).css({cursor:"pointer"}).click(e.next);if(A)d.style.msInterpolationMode="bicubic"};d.src=b}else c("

Request unsuccessful.

").appendTo(L).load(b,function(){k(this)})};e.next=function(){if(!z){h=h0?h-1:i.length-1;e.load()}};e.slideshow=function(){function b(){s.text(a.slideshowStop).bind(U, function(){f=setTimeout(e.next,a.slideshowSpeed)}).bind(K,function(){clearTimeout(f)}).one("click",function(){d();c(this).removeClass(I)});j.removeClass(k+"off").addClass(k+"on")}var d,f,k="cboxSlideshow_";s.bind("cbox_closed",function(){s.unbind();clearTimeout(f);j.removeClass(k+"off "+k+"on")});d=function(){clearTimeout(f);s.text(a.slideshowStart).unbind(U+" "+K).one("click",function(){b();f=setTimeout(e.next,a.slideshowSpeed);c(this).removeClass(I)});j.removeClass(k+"on").addClass(k+"off")};if(a.slideshow&& i.length>1)a.slideshowAuto?b():d()};e.close=function(){if(q){q=false;c.event.trigger("cbox_cleanup");a.onCleanup&&a.onCleanup.call(g);l.unbind(".cbox .cboxIE6");j.add(r).stop().fadeTo("fast",0,function(){c("#colorbox iframe").attr("src","about:blank");n.remove();j.add(r).css({opacity:1,cursor:"auto"}).hide();try{P.focus()}catch(b){}setTimeout(function(){c.event.trigger("cbox_closed");a.onClosed&&a.onClosed.call(g)},1)})}};e.element=function(){return c(g)};e.settings=ba;c(e.init)})(jQuery); \ No newline at end of file diff --git a/colorbox/jquery.colorbox.js b/colorbox/jquery.colorbox.js index d6827c4..55e6127 100644 --- a/colorbox/jquery.colorbox.js +++ b/colorbox/jquery.colorbox.js @@ -1,4 +1,4 @@ -// ColorBox v1.3.6 - a full featured, light-weight, customizable lightbox based on jQuery 1.3 +// ColorBox v1.3.7 - a full featured, light-weight, customizable lightbox based on jQuery 1.3 // c) 2009 Jack Moore - www.colorpowered.com - jack@colorpowered.com // Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php @@ -9,7 +9,7 @@ TRUE = true, FALSE = false, cboxPublic, - isIE = $.browser.msie && !$.support.opacity, // feature detection alone gave false positives in some browsers + isIE = $.browser.msie && !$.support.opacity, // feature detection alone gave a false positive on at least one phone browser isIE6 = isIE && $.browser.version < 7, // Event Strings (to increase compression) @@ -18,7 +18,6 @@ cbox_complete = 'cbox_complete', cbox_cleanup = 'cbox_cleanup', cbox_closed = 'cbox_closed', - cbox_resize = 'resize.cbox_resize', // Cached jQuery Object Variables $overlay, @@ -34,7 +33,6 @@ $loaded, $loadingBay, $loadingOverlay, - $loadingGraphic, $title, $current, $slideshow, @@ -84,6 +82,7 @@ close: "close", open: FALSE, overlayClose: TRUE, + loop: TRUE, slideshow: FALSE, slideshowAuto: TRUE, @@ -95,7 +94,10 @@ onLoad: FALSE, onComplete: FALSE, onCleanup: FALSE, - onClosed: FALSE + onClosed: FALSE, + + escKey:TRUE, + arrowKey:TRUE }; // **************** @@ -122,8 +124,8 @@ settings[i] = settings[i].call(element); } } - settings.rel = settings.rel || element.rel; - settings.href = settings.href || element.href; + settings.rel = settings.rel || element.rel || 'nofollow'; + settings.href = settings.href || $(element).attr('href'); settings.title = settings.title || element.title; } @@ -131,11 +133,11 @@ element = elem; - settings = $(element).data(colorbox); + settings = $.extend({}, $(element).data(colorbox)); process(); // Convert functions to their returned values. - if (settings.rel && settings.rel !== 'nofollow') { + if (settings.rel !== 'nofollow') { $related = $('.cboxElement').filter(function () { var relRelated = $(this).data(colorbox).rel || this.rel; return (relRelated === settings.rel); @@ -159,36 +161,16 @@ bookmark = element; - bookmark.blur(); // Remove the focus from the calling element. - - // Set Navigation Key Bindings - $(document).bind("keydown.cbox_close", function (e) { - if (e.keyCode === 27) { - e.preventDefault(); - cboxPublic.close(); - } - }).bind("keydown.cbox_arrows", function (e) { - if ($related.length > 1) { - if (e.keyCode === 37) { - e.preventDefault(); - $prev.click(); - } else if (e.keyCode === 39) { - e.preventDefault(); - $next.click(); - } - } - }); - - if (settings.overlayClose) { - $overlay.css({"cursor": "pointer"}).one('click', cboxPublic.close); - } + try{ + bookmark.blur(); // Remove the focus from the calling element. + }catch(e){} $.event.trigger(cbox_open); if (settings.onOpen) { settings.onOpen.call(element); } - $overlay.css({"opacity": settings.opacity}).show(); + $overlay.css({"opacity": parseFloat(settings.opacity), "cursor": settings.overlayClose ? "pointer" : "auto"}).show(); // Opens inital empty ColorBox prior to content being loaded. settings.w = setSize(settings.initialWidth, 'x'); @@ -196,9 +178,9 @@ cboxPublic.position(0); if (isIE6) { - $window.bind('resize.cboxie6 scroll.cboxie6', function () { + $window.bind('resize.cboxIE6 scroll.cboxIE6', function () { $overlay.css({width: $window.width(), height: $window.height(), top: $window.scrollTop(), left: $window.scrollLeft()}); - }).trigger("scroll.cboxie6"); + }).trigger("scroll.cboxIE6"); } } @@ -217,33 +199,33 @@ // Usage from within an iframe: parent.$.fn.colorbox.close(); // **************** - cboxPublic = $.fn.colorbox = function (options, callback) { + cboxPublic = $.fn.colorbox = $.colorbox = function (options, callback) { var $this = this; - if (!$this.length) { - if ($this.selector === '') { // empty selector means a direct call, ie: $.fn.colorbox(); - $this = $('
'); - options.open = TRUE; - } else { // else the selector didn't match anything, and colorbox should go ahead and return. - return this; - } + if($this.selector && !$this.length){ + return $this; + } + + options = options || {}; + + if(callback){ + options.onComplete = callback; + } + + if(!$this.length || $this.selector === undefined){ // detects $.colorbox() and $.fn.colorbox() + $this = $(''); + options.open = TRUE; // assume an immediate open } $this.each(function () { - var data = $.extend({}, $(this).data(colorbox) ? $(this).data(colorbox) : defaults, options); - - $(this).data(colorbox, data).addClass("cboxElement"); - - if (callback) { - $(this).data(colorbox).onComplete = callback; - } + $(this).data(colorbox, $.extend({}, $(this).data(colorbox) || defaults, options)).addClass("cboxElement"); }); - if (options && options.open) { - launch($this); + if(options.open){ + launch($this[0]); } - return this; + return $this; }; // Initialize ColorBox: store common calculations, preload the interface graphics, append the html. @@ -263,13 +245,12 @@ $wrap = $div("Wrapper"); $content = $div("Content").append( $loaded = $div("LoadedContent").css({width: 0, height: 0}), - $loadingOverlay = $div("LoadingOverlay"), - $loadingGraphic = $div("LoadingGraphic"), + $loadingOverlay = $div("LoadingOverlay").add($div("LoadingGraphic")), $title = $div("Title"), $current = $div("Current"), - $slideshow = $div("Slideshow"), $next = $div("Next"), $prev = $div("Previous"), + $slideshow = $div("Slideshow"), $close = $div("Close") ); $wrap.append( // The 3x3 Grid that makes up ColorBox @@ -290,9 +271,9 @@ ) ).children().children().css({'float': 'left'}); - $loadingBay = $("
"); + $loadingBay = $("
"); - $('body').prepend($overlay, $cbox.append($wrap, $loadingBay)); + $('body').prepend($overlay, $cbox.append($wrap), $loadingBay); if (isIE) { $cbox.addClass('cboxIE'); @@ -316,7 +297,7 @@ // Setting padding to remove the need to do size conversions during the animation step. $cbox.css({"padding-bottom": interfaceHeight, "padding-right": interfaceWidth}).hide(); - // Setup button & key events. + // Setup button events. $next.click(cboxPublic.next); $prev.click(cboxPublic.prev); $close.click(cboxPublic.close); @@ -326,22 +307,46 @@ $content.children().removeClass(hover); $('.cboxElement').live('click', function (e) { - if (e.button !== 0 && typeof e.button !== 'undefined') {// checks to see if it was a non-left mouse-click. + // checks to see if it was a non-left mouse-click and for clicks modified with ctrl, shift, or alt. + if ((e.button !== 0 && typeof e.button !== 'undefined') || e.ctrlKey || e.shiftKey || e.altKey) { return TRUE; } else { launch(this); return FALSE; } }); + + $overlay.click(function(){ + if (settings.overlayClose) { + cboxPublic.close(); + } + }); + + // Set Navigation Key Bindings + $(document).bind("keydown", function (e) { + if(open && settings.escKey && e.keyCode === 27) { + e.preventDefault(); + cboxPublic.close(); + } + if (open && settings.arrowKey && !active && $related.length > 1) { + if (e.keyCode === 37 && (index > 0 || settings.loop)) { + e.preventDefault(); + $prev.click(); + } else if (e.keyCode === 39 && (index < $related.length - 1 || settings.loop)) { + e.preventDefault(); + $next.click(); + } + } + }); + }; cboxPublic.position = function (speed, loadedCallback) { var animate_speed, - winHeight = $window.height(), // keeps the top and left positions within the browser's viewport. - posTop = Math.max(winHeight - settings.h - loadedHeight - interfaceHeight,0)/2 + $window.scrollTop(), - posLeft = Math.max(document.documentElement.clientWidth - settings.w - loadedWidth - interfaceWidth,0)/2 + $window.scrollLeft(); + posTop = Math.max($window.height() - settings.h - loadedHeight - interfaceHeight,0)/2 + $window.scrollTop(), + posLeft = Math.max($window.width() - settings.w - loadedWidth - interfaceWidth,0)/2 + $window.scrollLeft(); // setting the speed to 0 to reduce the delay between same-sized content. animate_speed = ($cbox.width() === settings.w+loadedWidth && $cbox.height() === settings.h+loadedHeight) ? 0 : speed; @@ -352,9 +357,9 @@ $wrap[0].style.width = $wrap[0].style.height = "9999px"; function modalDimensions (that) { - // loading overlay size has to be sure that IE6 uses the correct height. + // loading overlay height has to be explicitly set for IE6. $topBorder[0].style.width = $bottomBorder[0].style.width = $content[0].style.width = that.style.width; - $loadingGraphic[0].style.height = $loadingOverlay[0].style.height = $content[0].style.height = $leftBorder[0].style.height = $rightBorder[0].style.height = that.style.height; + $loadingOverlay[0].style.height = $loadingOverlay[1].style.height = $content[0].style.height = $leftBorder[0].style.height = $rightBorder[0].style.height = that.style.height; } $cbox.dequeue().animate({width:settings.w+loadedWidth, height:settings.h+loadedHeight, top:posTop, left:posLeft}, {duration: animate_speed, @@ -375,30 +380,43 @@ }); }; - cboxPublic.resize = function (object) { + cboxPublic.resize = function(options){ + if(open){ + options = options || {}; + + if(options.width){ + settings.w = setSize(options.width, 'x') - loadedWidth - interfaceWidth; + } + if(options.innerWidth){ + settings.w = setSize(options.innerWidth, 'x'); + } + $loaded.css({width:settings.w}); + + if(options.height){ + settings.h = setSize(options.height, 'y') - loadedHeight - interfaceHeight; + } + if(options.innerHeight){ + settings.h = setSize(options.innerHeight, 'y'); + } + if(!options.innerHeight && !options.height){ + var $child = $loaded.wrapInner("
").children(); // temporary wrapper to get an accurate estimate of just how high the total content should be. + settings.h = $child.height(); + $child.replaceWith($child.children()); // ditch the temporary wrapper div used in height calculation + } + $loaded.css({height:settings.h}); + + cboxPublic.position(settings.transition==="none" ? 0 : settings.speed); + } + }; + + cboxPublic.prep = function (object) { if(!open){ return; } var topMargin, - prev, - prevSrc, - next, - nextSrc, photo, - timeout, speed = settings.transition==="none" ? 0 : settings.speed; - $window.unbind(cbox_resize); - - if(!object){ - timeout = setTimeout(function(){ // timer allows IE to render the dimensions before attempting to calculate the height - var $child = $loaded.wrapInner("
").children(); // temporary wrapper to get an accurate estimate of just how high the total content should be. - settings.h = $child.height(); - $loaded.css({height:settings.h}); - $child.replaceWith($child.children()); // ditch the temporary wrapper div used in height calculation - cboxPublic.position(speed); - }, 1); - return; - } + $window.unbind('resize.cbox'); $loaded.remove(); $loaded = $('
').html(object); @@ -432,6 +450,7 @@ } function setPosition (s) { + var prev, prevSrc, next, nextSrc, total = $related.length, loop = settings.loop; cboxPublic.position(s, function(){ if (!open) { return; } @@ -445,30 +464,47 @@ //Waited until the iframe is added to the DOM & it is visible before setting the src. //This increases compatability with pages using DOM dependent JavaScript. if(settings.iframe){ - $loaded.append("