Changeset 7949
- Timestamp:
- Nov 30, 2010, 12:20:24 PM (13 years ago)
- Location:
- extensions/lightbox
- Files:
-
- 1 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/lightbox/js/jquery.colorbox-min.js
r6373 r7949 1 /* ColorBox v1.3.6 - a full featured, light-weight, customizable lightbox based on jQuery 1.3 */ 2 (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("<a/>");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('<div id="cbox'+ d+'"/>')}m=c(window);k=c('<div id="colorbox"/>');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("<div/>").append(b("TopLeft"),U=b("TopCenter"),b("TopRight")),c("<div/>").append(V=b("MiddleLeft"),p,W=b("MiddleRight")),c("<div/>").append(b("BottomLeft"),X=b("BottomCenter"),b("BottomRight"))).children().children().css({"float":"left"}); I=c("<div style='position:absolute; top:0; left:0; width:9999px; height:0;'/>");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<a.w?a.mw:a.w;return a.w}function h(){a.h=a.h||l.height();a.h=a.mh&&a.mh<a.h?a.mh:a.h;return a.h}function f(G){e.position(G,function(){if(B){if(x){A&&l.fadeIn(100);k[0].style.removeAttribute("filter")}if(a.iframe)l.append("<iframe id='cboxIframe'"+ (a.scrolling?" ":"scrolling='no'")+" name='iframe_"+(new Date).getTime()+"' frameborder=0 src='"+a.href+"' "+(x?"allowtransparency='true'":"")+" />");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('<div id="cboxLoadedContent"/>').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<g.length-1?g[j+1]:g[0];o=c(o).data(q).href||o.href;b=c(b).data(q).href||b.href;M(o)&&c("<img />").attr("src",o);M(b)&&c("<img />").attr("src",b)}}else setTimeout(function(){var G=l.wrapInner("<div style='overflow:auto'></div>").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<a.mw?a.w:a.mw}if(a.maxHeight){a.mh=r(a.maxHeight,"y")-v-y;a.mh=a.h&&a.h<a.mh?a.h:a.mh}b=a.href;J.show();K.show();if(a.inline){c('<div id="cboxInlineTemp" />').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("<div />").appendTo(I).load(b,function(o,A){A==="success"?f(this):f(c("<p>Request unsuccessful.</p>"))})};e.next=function(){if(!C){j=j<g.length-1?j+1:0;e.load()}};e.prev=function(){if(!C){j=j>0?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); 1 // ColorBox v1.3.14 - a full featured, light-weight, customizable lightbox based on jQuery 1.3+ 2 // Copyright (c) 2010 Jack Moore - jack@colorpowered.com 3 // Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php 4 (function(b,ib){var t="none",M="LoadedContent",c=false,v="resize.",o="y",q="auto",e=true,L="nofollow",m="x";function f(a,c){a=a?' id="'+i+a+'"':"";c=c?' style="'+c+'"':"";return b("<div"+a+c+"/>")}function p(a,b){b=b===m?n.width():n.height();return typeof a==="string"?Math.round(/%/.test(a)?b/100*parseInt(a,10):parseInt(a,10)):a}function U(b){return a.photo||/\.(gif|png|jpg|jpeg|bmp)(?:\?([^#]*))?(?:#(\.*))?$/i.test(b)}function cb(a){for(var c in a)if(b.isFunction(a[c])&&c.substring(0,2)!=="on")a[c]=a[c].call(l);a.rel=a.rel||l.rel||L;a.href=a.href||b(l).attr("href");a.title=a.title||l.title;return a}function w(c,a){a&&a.call(l);b.event.trigger(c)}function jb(){var b,e=i+"Slideshow_",c="click."+i,f,k;if(a.slideshow&&h[1]){f=function(){F.text(a.slideshowStop).unbind(c).bind(V,function(){if(g<h.length-1||a.loop)b=setTimeout(d.next,a.slideshowSpeed)}).bind(W,function(){clearTimeout(b)}).one(c+" "+N,k);j.removeClass(e+"off").addClass(e+"on");b=setTimeout(d.next,a.slideshowSpeed)};k=function(){clearTimeout(b);F.text(a.slideshowStart).unbind([V,W,N,c].join(" ")).one(c,f);j.removeClass(e+"on").addClass(e+"off")};a.slideshowAuto?f():k()}}function db(c){if(!O){l=c;a=cb(b.extend({},b.data(l,r)));h=b(l);g=0;if(a.rel!==L){h=b("."+G).filter(function(){return (b.data(this,r).rel||this.rel)===a.rel});g=h.index(l);if(g===-1){h=h.add(l);g=h.length-1}}if(!u){u=E=e;j.show();if(a.returnFocus)try{l.blur();b(l).one(eb,function(){try{this.focus()}catch(a){}})}catch(f){}x.css({opacity:+a.opacity,cursor:a.overlayClose?"pointer":q}).show();a.w=p(a.initialWidth,m);a.h=p(a.initialHeight,o);d.position(0);X&&n.bind(v+P+" scroll."+P,function(){x.css({width:n.width(),height:n.height(),top:n.scrollTop(),left:n.scrollLeft()})}).trigger("scroll."+P);w(fb,a.onOpen);Y.add(H).add(I).add(F).add(Z).hide();ab.html(a.close).show()}d.load(e)}}var gb={transition:"elastic",speed:300,width:c,initialWidth:"600",innerWidth:c,maxWidth:c,height:c,initialHeight:"450",innerHeight:c,maxHeight:c,scalePhotos:e,scrolling:e,inline:c,html:c,iframe:c,photo:c,href:c,title:c,rel:c,opacity:.9,preloading:e,current:"image {current} of {total}",previous:"previous",next:"next",close:"close",open:c,returnFocus:e,loop:e,slideshow:c,slideshowAuto:e,slideshowSpeed:2500,slideshowStart:"start slideshow",slideshowStop:"stop slideshow",onOpen:c,onLoad:c,onComplete:c,onCleanup:c,onClosed:c,overlayClose:e,escKey:e,arrowKey:e},r="colorbox",i="cbox",fb=i+"_open",W=i+"_load",V=i+"_complete",N=i+"_cleanup",eb=i+"_closed",Q=i+"_purge",hb=i+"_loaded",A=b.browser.msie&&!b.support.opacity,X=A&&b.browser.version<7,P=i+"_IE6",x,j,B,s,bb,T,R,S,h,n,k,J,K,Z,Y,F,I,H,ab,C,D,y,z,l,g,a,u,E,O=c,d,G=i+"Element";d=b.fn[r]=b[r]=function(c,f){var a=this,d;if(!a[0]&&a.selector)return a;c=c||{};if(f)c.onComplete=f;if(!a[0]||a.selector===undefined){a=b("<a/>");c.open=e}a.each(function(){b.data(this,r,b.extend({},b.data(this,r)||gb,c));b(this).addClass(G)});d=c.open;if(b.isFunction(d))d=d.call(a);d&&db(a[0]);return a};d.init=function(){var l="hover",m="clear:left";n=b(ib);j=f().attr({id:r,"class":A?i+"IE":""});x=f("Overlay",X?"position:absolute":"").hide();B=f("Wrapper");s=f("Content").append(k=f(M,"width:0; height:0; overflow:hidden"),K=f("LoadingOverlay").add(f("LoadingGraphic")),Z=f("Title"),Y=f("Current"),I=f("Next"),H=f("Previous"),F=f("Slideshow").bind(fb,jb),ab=f("Close"));B.append(f().append(f("TopLeft"),bb=f("TopCenter"),f("TopRight")),f(c,m).append(T=f("MiddleLeft"),s,R=f("MiddleRight")),f(c,m).append(f("BottomLeft"),S=f("BottomCenter"),f("BottomRight"))).children().children().css({"float":"left"});J=f(c,"position:absolute; width:9999px; visibility:hidden; display:none");b("body").prepend(x,j.append(B,J));s.children().hover(function(){b(this).addClass(l)},function(){b(this).removeClass(l)}).addClass(l);C=bb.height()+S.height()+s.outerHeight(e)-s.height();D=T.width()+R.width()+s.outerWidth(e)-s.width();y=k.outerHeight(e);z=k.outerWidth(e);j.css({"padding-bottom":C,"padding-right":D}).hide();I.click(d.next);H.click(d.prev);ab.click(d.close);s.children().removeClass(l);b("."+G).live("click",function(a){if(!(a.button!==0&&typeof a.button!=="undefined"||a.ctrlKey||a.shiftKey||a.altKey)){a.preventDefault();db(this)}});x.click(function(){a.overlayClose&&d.close()});b(document).bind("keydown",function(b){if(u&&a.escKey&&b.keyCode===27){b.preventDefault();d.close()}if(u&&a.arrowKey&&!E&&h[1])if(b.keyCode===37&&(g||a.loop)){b.preventDefault();H.click()}else if(b.keyCode===39&&(g<h.length-1||a.loop)){b.preventDefault();I.click()}})};d.remove=function(){j.add(x).remove();b("."+G).die("click").removeData(r).removeClass(G)};d.position=function(f,d){function b(a){bb[0].style.width=S[0].style.width=s[0].style.width=a.style.width;K[0].style.height=K[1].style.height=s[0].style.height=T[0].style.height=R[0].style.height=a.style.height}var e,h=Math.max(document.documentElement.clientHeight-a.h-y-C,0)/2+n.scrollTop(),g=Math.max(n.width()-a.w-z-D,0)/2+n.scrollLeft();e=j.width()===a.w+z&&j.height()===a.h+y?0:f;B[0].style.width=B[0].style.height="9999px";j.dequeue().animate({width:a.w+z,height:a.h+y,top:h,left:g},{duration:e,complete:function(){b(this);E=c;B[0].style.width=a.w+z+D+"px";B[0].style.height=a.h+y+C+"px";d&&d()},step:function(){b(this)}})};d.resize=function(b){if(u){b=b||{};if(b.width)a.w=p(b.width,m)-z-D;if(b.innerWidth)a.w=p(b.innerWidth,m);k.css({width:a.w});if(b.height)a.h=p(b.height,o)-y-C;if(b.innerHeight)a.h=p(b.innerHeight,o);if(!b.innerHeight&&!b.height){b=k.wrapInner("<div style='overflow:auto'></div>").children();a.h=b.height();b.replaceWith(b.children())}k.css({height:a.h});d.position(a.transition===t?0:a.speed)}};d.prep=function(o){var e="hidden";function m(t){var q,f,o,e,m=h.length,s=a.loop;d.position(t,function(){if(u){A&&p&&k.fadeIn(100);k.show();w(hb);Z.show().html(a.title);if(m>1){typeof a.current==="string"&&Y.html(a.current.replace(/\{current\}/,g+1).replace(/\{total\}/,m)).show();I[s||g<m-1?"show":"hide"]().html(a.next);H[s||g?"show":"hide"]().html(a.previous);q=g?h[g-1]:h[m-1];o=g<m-1?h[g+1]:h[0];a.slideshow&&F.show();if(a.preloading){e=b.data(o,r).href||o.href;f=b.data(q,r).href||q.href;e=b.isFunction(e)?e.call(o):e;f=b.isFunction(f)?f.call(q):f;if(U(e))b("<img/>")[0].src=e;if(U(f))b("<img/>")[0].src=f}}K.hide();if(a.transition==="fade")j.fadeTo(l,1,function(){if(A)j[0].style.filter=c});else if(A)j[0].style.filter=c;n.bind(v+i,function(){d.position(0)});w(V,a.onComplete)}})}if(u){var p,l=a.transition===t?0:a.speed;n.unbind(v+i);k.remove();k=f(M).html(o);k.hide().appendTo(J.show()).css({width:function(){a.w=a.w||k.width();a.w=a.mw&&a.mw<a.w?a.mw:a.w;return a.w}(),overflow:a.scrolling?q:e}).css({height:function(){a.h=a.h||k.height();a.h=a.mh&&a.mh<a.h?a.mh:a.h;return a.h}()}).prependTo(s);J.hide();b("#"+i+"Photo").css({cssFloat:t,marginLeft:q,marginRight:q});X&&b("select").not(j.find("select")).filter(function(){return this.style.visibility!==e}).css({visibility:e}).one(N,function(){this.style.visibility="inherit"});a.transition==="fade"?j.fadeTo(l,0,function(){m(0)}):m(l)}};d.load=function(u){var n,c,s,q=d.prep;E=e;l=h[g];u||(a=cb(b.extend({},b.data(l,r))));w(Q);w(W,a.onLoad);a.h=a.height?p(a.height,o)-y-C:a.innerHeight&&p(a.innerHeight,o);a.w=a.width?p(a.width,m)-z-D:a.innerWidth&&p(a.innerWidth,m);a.mw=a.w;a.mh=a.h;if(a.maxWidth){a.mw=p(a.maxWidth,m)-z-D;a.mw=a.w&&a.w<a.mw?a.w:a.mw}if(a.maxHeight){a.mh=p(a.maxHeight,o)-y-C;a.mh=a.h&&a.h<a.mh?a.h:a.mh}n=a.href;K.show();if(a.inline){f().hide().insertBefore(b(n)[0]).one(Q,function(){b(this).replaceWith(k.children())});q(b(n))}else if(a.iframe){j.one(hb,function(){var c=b("<iframe name='"+(new Date).getTime()+"' frameborder=0"+(a.scrolling?"":" scrolling='no'")+(A?" allowtransparency='true'":"")+" style='width:100%; height:100%; border:0; display:block;'/>");c[0].src=a.href;c.appendTo(k).one(Q,function(){c[0].src='//about:blank'})});q(" ")}else if(a.html)q(a.html);else if(U(n)){c=new Image;c.onload=function(){var e;c.onload=null;c.id=i+"Photo";b(c).css({border:t,display:"block",cssFloat:"left"});if(a.scalePhotos){s=function(){c.height-=c.height*e;c.width-=c.width*e};if(a.mw&&c.width>a.mw){e=(c.width-a.mw)/c.width;s()}if(a.mh&&c.height>a.mh){e=(c.height-a.mh)/c.height;s()}}if(a.h)c.style.marginTop=Math.max(a.h-c.height,0)/2+"px";h[1]&&(g<h.length-1||a.loop)&&b(c).css({cursor:"pointer"}).click(d.next);if(A)c.style.msInterpolationMode="bicubic";setTimeout(function(){q(c)},1)};setTimeout(function(){c.src=n},1)}else n&&J.load(n,function(d,c,a){q(c==="error"?"Request unsuccessful: "+a.statusText:b(this).children())})};d.next=function(){if(!E){g=g<h.length-1?g+1:0;d.load()}};d.prev=function(){if(!E){g=g?g-1:h.length-1;d.load()}};d.close=function(){if(u&&!O){O=e;u=c;w(N,a.onCleanup);n.unbind("."+i+" ."+P);x.fadeTo("fast",0);j.stop().fadeTo("fast",0,function(){w(Q);k.remove();j.add(x).css({opacity:1,cursor:q}).hide();setTimeout(function(){O=c;w(eb,a.onClosed)},1)})}};d.element=function(){return b(l)};d.settings=gb;b(d.init)})(jQuery,this) -
extensions/lightbox/js/jquery.colorbox.js
r6373 r7949 1 // ColorBox v1.3. 6 - a full featured, light-weight, customizable lightbox based on jQuery 1.32 // c) 2009 Jack Moore - www.colorpowered.com- jack@colorpowered.com1 // ColorBox v1.3.14 - a full featured, light-weight, customizable lightbox based on jQuery 1.3+ 2 // Copyright (c) 2010 Jack Moore - jack@colorpowered.com 3 3 // Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php 4 5 (function ($) { 6 // Shortcuts (to increase compression) 7 var colorbox = 'colorbox', 8 hover = 'hover', 9 TRUE = true, 10 FALSE = false, 11 cboxPublic, 12 isIE = $.browser.msie && !$.support.opacity, // feature detection alone gave false positives in some browsers 4 (function ($, window) { 5 6 var 7 // ColorBox Default Settings. 8 // See http://colorpowered.com/colorbox for details. 9 defaults = { 10 transition: "elastic", 11 speed: 300, 12 width: false, 13 initialWidth: "600", 14 innerWidth: false, 15 maxWidth: false, 16 height: false, 17 initialHeight: "450", 18 innerHeight: false, 19 maxHeight: false, 20 scalePhotos: true, 21 scrolling: true, 22 inline: false, 23 html: false, 24 iframe: false, 25 photo: false, 26 href: false, 27 title: false, 28 rel: false, 29 opacity: 0.9, 30 preloading: true, 31 current: "image {current} of {total}", 32 previous: "previous", 33 next: "next", 34 close: "close", 35 open: false, 36 returnFocus: true, 37 loop: true, 38 slideshow: false, 39 slideshowAuto: true, 40 slideshowSpeed: 2500, 41 slideshowStart: "start slideshow", 42 slideshowStop: "stop slideshow", 43 onOpen: false, 44 onLoad: false, 45 onComplete: false, 46 onCleanup: false, 47 onClosed: false, 48 overlayClose: true, 49 escKey: true, 50 arrowKey: true 51 }, 52 53 // Abstracting the HTML and event identifiers for easy rebranding 54 colorbox = 'colorbox', 55 prefix = 'cbox', 56 57 // Events 58 event_open = prefix + '_open', 59 event_load = prefix + '_load', 60 event_complete = prefix + '_complete', 61 event_cleanup = prefix + '_cleanup', 62 event_closed = prefix + '_closed', 63 event_purge = prefix + '_purge', 64 event_loaded = prefix + '_loaded', 65 66 // Special Handling for IE 67 isIE = $.browser.msie && !$.support.opacity, // feature detection alone gave a false positive on at least one phone browser and on some development versions of Chrome. 13 68 isIE6 = isIE && $.browser.version < 7, 14 15 // Event Strings (to increase compression) 16 cbox_open = 'cbox_open', 17 cbox_load = 'cbox_load', 18 cbox_complete = 'cbox_complete', 19 cbox_cleanup = 'cbox_cleanup', 20 cbox_closed = 'cbox_closed', 21 cbox_resize = 'resize.cbox_resize', 69 event_ie6 = prefix + '_IE6', 22 70 23 71 // Cached jQuery Object Variables 24 72 $overlay, 25 $ cbox,73 $box, 26 74 $wrap, 27 75 $content, … … 35 83 $loadingBay, 36 84 $loadingOverlay, 37 $loadingGraphic,38 85 $title, 39 86 $current, … … 49 96 loadedWidth, 50 97 element, 51 bookmark,52 98 index, 53 99 settings, 54 100 open, 55 101 active, 56 57 // ColorBox Default Settings. 58 // See http://colorpowered.com/colorbox for details. 59 defaults = { 60 transition: "elastic", 61 speed: 350, 62 width: FALSE, 63 height: FALSE, 64 innerWidth: FALSE, 65 innerHeight: FALSE, 66 initialWidth: "400", 67 initialHeight: "400", 68 maxWidth: FALSE, 69 maxHeight: FALSE, 70 scalePhotos: TRUE, 71 scrolling: TRUE, 72 inline: FALSE, 73 html: FALSE, 74 iframe: FALSE, 75 photo: FALSE, 76 href: FALSE, 77 title: FALSE, 78 rel: FALSE, 79 opacity: 0.9, 80 preloading: TRUE, 81 current: "image {current} of {total}", 82 previous: "previous", 83 next: "next", 84 close: "close", 85 open: FALSE, 86 overlayClose: TRUE, 87 88 slideshow: FALSE, 89 slideshowAuto: TRUE, 90 slideshowSpeed: 2500, 91 slideshowStart: "start slideshow", 92 slideshowStop: "stop slideshow", 93 94 onOpen: FALSE, 95 onLoad: FALSE, 96 onComplete: FALSE, 97 onCleanup: FALSE, 98 onClosed: FALSE 99 }; 102 closing = false, 103 104 publicMethod, 105 boxElement = prefix + 'Element'; 100 106 101 107 // **************** 102 108 // HELPER FUNCTIONS 103 109 // **************** 104 110 111 // jQuery object generator to reduce code size 112 function $div(id, css) { 113 id = id ? ' id="' + prefix + id + '"' : ''; 114 css = css ? ' style="' + css + '"' : ''; 115 return $('<div' + id + css + '/>'); 116 } 117 105 118 // Convert % values to pixels 106 119 function setSize(size, dimension) { 107 dimension = dimension === 'x' ? $window.width() : $window.height(); //document.documentElement.clientWidth : document.documentElement.clientHeight;108 return (typeof size === 'string') ? Math.round(( size.match(/%/) ? (dimension / 100) * parseInt(size, 10) : parseInt(size, 10))) : size;120 dimension = dimension === 'x' ? $window.width() : $window.height(); 121 return (typeof size === 'string') ? Math.round((/%/.test(size) ? (dimension / 100) * parseInt(size, 10) : parseInt(size, 10))) : size; 109 122 } 110 123 111 124 // Checks an href to see if it is a photo. 112 125 // There is a force photo option (photo: true) for hrefs that cannot be matched by this regex. 113 126 function isImage(url) { 114 url = $.isFunction(url) ? url.call(element) : url; 115 return settings.photo || url.match(/\.(gif|png|jpg|jpeg|bmp)(?:\?([^#]*))?(?:#(\.*))?$/i); 127 return settings.photo || /\.(gif|png|jpg|jpeg|bmp)(?:\?([^#]*))?(?:#(\.*))?$/i.test(url); 116 128 } 117 129 118 // Assigns function s results to their respective settings. This allows functions to be used to set ColorBox options.119 function process( ) {130 // Assigns function results to their respective settings. This allows functions to be used as values. 131 function process(settings) { 120 132 for (var i in settings) { 121 133 if ($.isFunction(settings[i]) && i.substring(0, 2) !== 'on') { // checks to make sure the function isn't one of the callbacks, they will be handled at the appropriate time. … … 123 135 } 124 136 } 125 settings.rel = settings.rel || element.rel ;126 settings.href = settings.href || element.href;137 settings.rel = settings.rel || element.rel || 'nofollow'; 138 settings.href = settings.href || $(element).attr('href'); 127 139 settings.title = settings.title || element.title; 140 return settings; 128 141 } 129 142 143 function trigger(event, callback) { 144 if (callback) { 145 callback.call(element); 146 } 147 $.event.trigger(event); 148 } 149 150 // Slideshow functionality 151 function slideshow() { 152 var 153 timeOut, 154 className = prefix + "Slideshow_", 155 click = "click." + prefix, 156 start, 157 stop, 158 clear; 159 160 if (settings.slideshow && $related[1]) { 161 start = function () { 162 $slideshow 163 .text(settings.slideshowStop) 164 .unbind(click) 165 .bind(event_complete, function () { 166 if (index < $related.length - 1 || settings.loop) { 167 timeOut = setTimeout(publicMethod.next, settings.slideshowSpeed); 168 } 169 }) 170 .bind(event_load, function () { 171 clearTimeout(timeOut); 172 }) 173 .one(click + ' ' + event_cleanup, stop); 174 $box.removeClass(className + "off").addClass(className + "on"); 175 timeOut = setTimeout(publicMethod.next, settings.slideshowSpeed); 176 }; 177 178 stop = function () { 179 clearTimeout(timeOut); 180 $slideshow 181 .text(settings.slideshowStart) 182 .unbind([event_complete, event_load, event_cleanup, click].join(' ')) 183 .one(click, start); 184 $box.removeClass(className + "on").addClass(className + "off"); 185 }; 186 187 if (settings.slideshowAuto) { 188 start(); 189 } else { 190 stop(); 191 } 192 } 193 } 194 130 195 function launch(elem) { 131 132 element = elem; 133 134 settings = $(element).data(colorbox); 135 136 process(); // Convert functions to their returned values. 137 138 if (settings.rel && settings.rel !== 'nofollow') { 139 $related = $('.cboxElement').filter(function () { 140 var relRelated = $(this).data(colorbox).rel || this.rel; 141 return (relRelated === settings.rel); 142 }); 143 index = $related.index(element); 144 145 // Check direct calls to ColorBox. 146 if (index < 0) { 147 $related = $related.add(element); 148 index = $related.length - 1; 149 } 150 } else { 196 if (!closing) { 197 198 element = elem; 199 200 settings = process($.extend({}, $.data(element, colorbox))); 201 151 202 $related = $(element); 203 152 204 index = 0; 153 } 154 155 if (!open) { 156 open = TRUE; 157 158 active = TRUE; // Prevents the page-change action from queuing up if the visitor holds down the left or right keys. 159 160 bookmark = element; 161 162 bookmark.blur(); // Remove the focus from the calling element. 163 164 // Set Navigation Key Bindings 165 $(document).bind("keydown.cbox_close", function (e) { 166 if (e.keyCode === 27) { 167 e.preventDefault(); 168 cboxPublic.close(); 169 } 170 }).bind("keydown.cbox_arrows", function (e) { 171 if ($related.length > 1) { 172 if (e.keyCode === 37) { 173 e.preventDefault(); 174 $prev.click(); 175 } else if (e.keyCode === 39) { 176 e.preventDefault(); 177 $next.click(); 205 206 if (settings.rel !== 'nofollow') { 207 $related = $('.' + boxElement).filter(function () { 208 var relRelated = $.data(this, colorbox).rel || this.rel; 209 return (relRelated === settings.rel); 210 }); 211 index = $related.index(element); 212 213 // Check direct calls to ColorBox. 214 if (index === -1) { 215 $related = $related.add(element); 216 index = $related.length - 1; 217 } 218 } 219 220 if (!open) { 221 open = active = true; // Prevents the page-change action from queuing up if the visitor holds down the left or right keys. 222 223 $box.show(); 224 225 if (settings.returnFocus) { 226 try { 227 element.blur(); 228 $(element).one(event_closed, function () { 229 try { 230 this.focus(); 231 } catch (e) { 232 // do nothing 233 } 234 }); 235 } catch (e) { 236 // do nothing 178 237 } 179 238 } 180 }); 181 182 if (settings.overlayClose) { 183 $overlay.css({"cursor": "pointer"}).one('click', cboxPublic.close); 184 } 185 186 $.event.trigger(cbox_open); 187 if (settings.onOpen) { 188 settings.onOpen.call(element); 189 } 190 191 $overlay.css({"opacity": settings.opacity}).show(); 192 193 // Opens inital empty ColorBox prior to content being loaded. 194 settings.w = setSize(settings.initialWidth, 'x'); 195 settings.h = setSize(settings.initialHeight, 'y'); 196 cboxPublic.position(0); 197 198 if (isIE6) { 199 $window.bind('resize.cboxie6 scroll.cboxie6', function () { 200 $overlay.css({width: $window.width(), height: $window.height(), top: $window.scrollTop(), left: $window.scrollLeft()}); 201 }).trigger("scroll.cboxie6"); 202 } 203 } 204 205 $current.add($prev).add($next).add($slideshow).add($title).hide(); 206 207 $close.html(settings.close).show(); 208 209 cboxPublic.slideshow(); 210 211 cboxPublic.load(); 239 240 // +settings.opacity avoids a problem in IE when using non-zero-prefixed-string-values, like '.5' 241 $overlay.css({"opacity": +settings.opacity, "cursor": settings.overlayClose ? "pointer" : "auto"}).show(); 242 243 // Opens inital empty ColorBox prior to content being loaded. 244 settings.w = setSize(settings.initialWidth, 'x'); 245 settings.h = setSize(settings.initialHeight, 'y'); 246 publicMethod.position(0); 247 248 if (isIE6) { 249 $window.bind('resize.' + event_ie6 + ' scroll.' + event_ie6, function () { 250 $overlay.css({width: $window.width(), height: $window.height(), top: $window.scrollTop(), left: $window.scrollLeft()}); 251 }).trigger('scroll.' + event_ie6); 252 } 253 254 trigger(event_open, settings.onOpen); 255 256 $current.add($prev).add($next).add($slideshow).add($title).hide(); 257 258 $close.html(settings.close).show(); 259 } 260 261 publicMethod.load(true); 262 } 212 263 } 213 264 … … 218 269 // **************** 219 270 220 cboxPublic = $.fn.colorbox = function (options, callback) { 221 var $this = this; 222 223 if (!$this.length) { 224 if ($this.selector === '') { // empty selector means a direct call, ie: $.fn.colorbox(); 225 $this = $('<a/>'); 226 options.open = TRUE; 227 } else { // else the selector didn't match anything, and colorbox should go ahead and return. 228 return this; 229 } 271 publicMethod = $.fn[colorbox] = $[colorbox] = function (options, callback) { 272 var $this = this, autoOpen; 273 274 if (!$this[0] && $this.selector) { // if a selector was given and it didn't match any elements, go ahead and exit. 275 return $this; 276 } 277 278 options = options || {}; 279 280 if (callback) { 281 options.onComplete = callback; 282 } 283 284 if (!$this[0] || $this.selector === undefined) { // detects $.colorbox() and $.fn.colorbox() 285 $this = $('<a/>'); 286 options.open = true; // assume an immediate open 230 287 } 231 288 232 289 $this.each(function () { 233 var data = $.extend({}, $(this).data(colorbox) ? $(this).data(colorbox) : defaults, options); 234 235 $(this).data(colorbox, data).addClass("cboxElement"); 236 237 if (callback) { 238 $(this).data(colorbox).onComplete = callback; 239 } 290 $.data(this, colorbox, $.extend({}, $.data(this, colorbox) || defaults, options)); 291 $(this).addClass(boxElement); 240 292 }); 241 293 242 if (options && options.open) { 243 launch($this); 244 } 245 246 return this; 294 autoOpen = options.open; 295 296 if ($.isFunction(autoOpen)) { 297 autoOpen = autoOpen.call($this); 298 } 299 300 if (autoOpen) { 301 launch($this[0]); 302 } 303 304 return $this; 247 305 }; 248 306 … … 250 308 // This preps colorbox for a speedy open when clicked, and lightens the burdon on the browser by only 251 309 // having to run once, instead of each time colorbox is opened. 252 cboxPublic.init = function () { 253 254 // jQuery object generator to save a bit of space 255 function $div(id) { 256 return $('<div id="cbox' + id + '"/>'); 257 } 258 310 publicMethod.init = function () { 259 311 // Create & Append jQuery Objects 260 312 $window = $(window); 261 $cbox = $('<div id="colorbox"/>'); 262 $overlay = $div("Overlay").hide(); 313 $box = $div().attr({id: colorbox, 'class': isIE ? prefix + 'IE' : ''}); 314 $overlay = $div("Overlay", isIE6 ? 'position:absolute' : '').hide(); 315 263 316 $wrap = $div("Wrapper"); 264 317 $content = $div("Content").append( 265 $loaded = $div("LoadedContent").css({width: 0, height: 0}), 266 $loadingOverlay = $div("LoadingOverlay"), 267 $loadingGraphic = $div("LoadingGraphic"), 318 $loaded = $div("LoadedContent", 'width:0; height:0; overflow:hidden'), 319 $loadingOverlay = $div("LoadingOverlay").add($div("LoadingGraphic")), 268 320 $title = $div("Title"), 269 321 $current = $div("Current"), 270 $slideshow = $div("Slideshow"),271 322 $next = $div("Next"), 272 323 $prev = $div("Previous"), 324 $slideshow = $div("Slideshow").bind(event_open, slideshow), 273 325 $close = $div("Close") 274 326 ); 275 327 $wrap.append( // The 3x3 Grid that makes up ColorBox 276 $ ('<div/>').append(328 $div().append( 277 329 $div("TopLeft"), 278 330 $topBorder = $div("TopCenter"), 279 331 $div("TopRight") 280 332 ), 281 $ ('<div/>').append(333 $div(false, 'clear:left').append( 282 334 $leftBorder = $div("MiddleLeft"), 283 335 $content, 284 336 $rightBorder = $div("MiddleRight") 285 337 ), 286 $ ('<div/>').append(338 $div(false, 'clear:left').append( 287 339 $div("BottomLeft"), 288 340 $bottomBorder = $div("BottomCenter"), … … 291 343 ).children().children().css({'float': 'left'}); 292 344 293 $loadingBay = $("<div style='position:absolute; top:0; left:0; width:9999px; height:0;'/>"); 294 295 $('body').prepend($overlay, $cbox.append($wrap, $loadingBay)); 296 297 if (isIE) { 298 $cbox.addClass('cboxIE'); 299 if (isIE6) { 300 $overlay.css('position', 'absolute'); 301 } 302 } 303 304 // Add rollover event to navigation elements 345 $loadingBay = $div(false, 'position:absolute; width:9999px; visibility:hidden; display:none'); 346 347 $('body').prepend($overlay, $box.append($wrap, $loadingBay)); 348 305 349 $content.children() 306 .bind('mouseover mouseout', function(){ 307 $(this).toggleClass(hover); 308 }).addClass(hover); 350 .hover(function () { 351 $(this).addClass('hover'); 352 }, function () { 353 $(this).removeClass('hover'); 354 }).addClass('hover'); 309 355 310 356 // Cache values needed for size calculations 311 interfaceHeight = $topBorder.height() + $bottomBorder.height() + $content.outerHeight( TRUE) - $content.height();//Subtraction needed for IE6312 interfaceWidth = $leftBorder.width() + $rightBorder.width() + $content.outerWidth( TRUE) - $content.width();313 loadedHeight = $loaded.outerHeight( TRUE);314 loadedWidth = $loaded.outerWidth( TRUE);357 interfaceHeight = $topBorder.height() + $bottomBorder.height() + $content.outerHeight(true) - $content.height();//Subtraction needed for IE6 358 interfaceWidth = $leftBorder.width() + $rightBorder.width() + $content.outerWidth(true) - $content.width(); 359 loadedHeight = $loaded.outerHeight(true); 360 loadedWidth = $loaded.outerWidth(true); 315 361 316 362 // Setting padding to remove the need to do size conversions during the animation step. 317 $ cbox.css({"padding-bottom": interfaceHeight, "padding-right": interfaceWidth}).hide();318 319 // Setup button & keyevents.320 $next.click( cboxPublic.next);321 $prev.click( cboxPublic.prev);322 $close.click( cboxPublic.close);363 $box.css({"padding-bottom": interfaceHeight, "padding-right": interfaceWidth}).hide(); 364 365 // Setup button events. 366 $next.click(publicMethod.next); 367 $prev.click(publicMethod.prev); 368 $close.click(publicMethod.close); 323 369 324 370 // Adding the 'hover' class allowed the browser to load the hover-state 325 371 // background graphics. The class can now can be removed. 326 $content.children().removeClass(hover); 327 328 $('.cboxElement').live('click', function (e) { 329 if (e.button !== 0 && typeof e.button !== 'undefined') {// checks to see if it was a non-left mouse-click. 330 return TRUE; 331 } else { 332 launch(this); 333 return FALSE; 372 $content.children().removeClass('hover'); 373 374 $('.' + boxElement).live('click', function (e) { 375 // checks to see if it was a non-left mouse-click and for clicks modified with ctrl, shift, or alt. 376 if (!((e.button !== 0 && typeof e.button !== 'undefined') || e.ctrlKey || e.shiftKey || e.altKey)) { 377 e.preventDefault(); 378 launch(this); 334 379 } 335 380 }); 336 }; 337 338 cboxPublic.position = function (speed, loadedCallback) { 381 382 $overlay.click(function () { 383 if (settings.overlayClose) { 384 publicMethod.close(); 385 } 386 }); 387 388 // Set Navigation Key Bindings 389 $(document).bind("keydown", function (e) { 390 if (open && settings.escKey && e.keyCode === 27) { 391 e.preventDefault(); 392 publicMethod.close(); 393 } 394 if (open && settings.arrowKey && !active && $related[1]) { 395 if (e.keyCode === 37 && (index || settings.loop)) { 396 e.preventDefault(); 397 $prev.click(); 398 } else if (e.keyCode === 39 && (index < $related.length - 1 || settings.loop)) { 399 e.preventDefault(); 400 $next.click(); 401 } 402 } 403 }); 404 }; 405 406 publicMethod.remove = function () { 407 $box.add($overlay).remove(); 408 $('.' + boxElement).die('click').removeData(colorbox).removeClass(boxElement); 409 }; 410 411 publicMethod.position = function (speed, loadedCallback) { 339 412 var 340 413 animate_speed, 341 winHeight = $window.height(),342 414 // keeps the top and left positions within the browser's viewport. 343 posTop = Math.max( winHeight - settings.h - loadedHeight - interfaceHeight,0)/2 + $window.scrollTop(),344 posLeft = Math.max( document.documentElement.clientWidth - settings.w - loadedWidth - interfaceWidth,0)/2 + $window.scrollLeft();415 posTop = Math.max(document.documentElement.clientHeight - settings.h - loadedHeight - interfaceHeight, 0) / 2 + $window.scrollTop(), 416 posLeft = Math.max($window.width() - settings.w - loadedWidth - interfaceWidth, 0) / 2 + $window.scrollLeft(); 345 417 346 418 // setting the speed to 0 to reduce the delay between same-sized content. 347 animate_speed = ($ cbox.width() === settings.w+loadedWidth && $cbox.height() === settings.h+loadedHeight) ? 0 : speed;419 animate_speed = ($box.width() === settings.w + loadedWidth && $box.height() === settings.h + loadedHeight) ? 0 : speed; 348 420 349 421 // this gives the wrapper plenty of breathing room so it's floated contents can move around smoothly, … … 352 424 $wrap[0].style.width = $wrap[0].style.height = "9999px"; 353 425 354 function modalDimensions 355 // loading overlay size has to be sure that IE6 uses the correct height.426 function modalDimensions(that) { 427 // loading overlay height has to be explicitly set for IE6. 356 428 $topBorder[0].style.width = $bottomBorder[0].style.width = $content[0].style.width = that.style.width; 357 $loadingGraphic[0].style.height = $loadingOverlay[0].style.height = $content[0].style.height = $leftBorder[0].style.height = $rightBorder[0].style.height = that.style.height; 358 } 359 360 $cbox.dequeue().animate({width:settings.w+loadedWidth, height:settings.h+loadedHeight, top:posTop, left:posLeft}, {duration: animate_speed, 361 complete: function(){ 429 $loadingOverlay[0].style.height = $loadingOverlay[1].style.height = $content[0].style.height = $leftBorder[0].style.height = $rightBorder[0].style.height = that.style.height; 430 } 431 432 $box.dequeue().animate({width: settings.w + loadedWidth, height: settings.h + loadedHeight, top: posTop, left: posLeft}, { 433 duration: animate_speed, 434 complete: function () { 362 435 modalDimensions(this); 363 436 364 active = FALSE;437 active = false; 365 438 366 439 // shrink the wrapper down to exactly the size of colorbox to avoid a bug in IE's iframe implementation. 367 $wrap[0].style.width = (settings.w+loadedWidth+interfaceWidth) + "px"; 368 $wrap[0].style.height = (settings.h+loadedHeight+interfaceHeight) + "px"; 369 370 if (loadedCallback) {loadedCallback();} 440 $wrap[0].style.width = (settings.w + loadedWidth + interfaceWidth) + "px"; 441 $wrap[0].style.height = (settings.h + loadedHeight + interfaceHeight) + "px"; 442 443 if (loadedCallback) { 444 loadedCallback(); 445 } 371 446 }, 372 step: function (){447 step: function () { 373 448 modalDimensions(this); 374 449 } … … 376 451 }; 377 452 378 cboxPublic.resize = function (object) { 379 if(!open){ return; } 380 381 var topMargin, 382 prev, 383 prevSrc, 384 next, 385 nextSrc, 386 photo, 387 timeout, 388 speed = settings.transition==="none" ? 0 : settings.speed; 389 390 $window.unbind(cbox_resize); 391 392 if(!object){ 393 timeout = setTimeout(function(){ // timer allows IE to render the dimensions before attempting to calculate the height 453 publicMethod.resize = function (options) { 454 if (open) { 455 options = options || {}; 456 457 if (options.width) { 458 settings.w = setSize(options.width, 'x') - loadedWidth - interfaceWidth; 459 } 460 if (options.innerWidth) { 461 settings.w = setSize(options.innerWidth, 'x'); 462 } 463 $loaded.css({width: settings.w}); 464 465 if (options.height) { 466 settings.h = setSize(options.height, 'y') - loadedHeight - interfaceHeight; 467 } 468 if (options.innerHeight) { 469 settings.h = setSize(options.innerHeight, 'y'); 470 } 471 if (!options.innerHeight && !options.height) { 394 472 var $child = $loaded.wrapInner("<div style='overflow:auto'></div>").children(); // temporary wrapper to get an accurate estimate of just how high the total content should be. 395 473 settings.h = $child.height(); 396 $loaded.css({height:settings.h});397 474 $child.replaceWith($child.children()); // ditch the temporary wrapper div used in height calculation 398 cboxPublic.position(speed); 399 }, 1); 475 } 476 $loaded.css({height: settings.h}); 477 478 publicMethod.position(settings.transition === "none" ? 0 : settings.speed); 479 } 480 }; 481 482 publicMethod.prep = function (object) { 483 if (!open) { 400 484 return; 401 485 } 402 486 487 var photo, 488 speed = settings.transition === "none" ? 0 : settings.speed; 489 490 $window.unbind('resize.' + prefix); 403 491 $loaded.remove(); 404 $loaded = $ ('<div id="cboxLoadedContent"/>').html(object);405 406 function getWidth() {492 $loaded = $div('LoadedContent').html(object); 493 494 function getWidth() { 407 495 settings.w = settings.w || $loaded.width(); 408 496 settings.w = settings.mw && settings.mw < settings.w ? settings.mw : settings.w; 409 497 return settings.w; 410 498 } 411 function getHeight() {499 function getHeight() { 412 500 settings.h = settings.h || $loaded.height(); 413 501 settings.h = settings.mh && settings.mh < settings.h ? settings.mh : settings.h; … … 416 504 417 505 $loaded.hide() 418 .appendTo($loadingBay )// content has to be appended to the DOM for accurate size calculations. Appended to an absolutely positioned element, rather than BODY, which avoids an extremely brief display of the vertical scrollbar in Firefox that can occur for a small minority of websites.419 .css({width: getWidth(), overflow:settings.scrolling ? 'auto' : 'hidden'})420 .css({height: getHeight()})// sets the height independently from the width in case the new width influences the value of height.506 .appendTo($loadingBay.show())// content has to be appended to the DOM for accurate size calculations. 507 .css({width: getWidth(), overflow: settings.scrolling ? 'auto' : 'hidden'}) 508 .css({height: getHeight()})// sets the height independently from the width in case the new width influences the value of height. 421 509 .prependTo($content); 422 510 423 $('#cboxPhoto').css({cssFloat:'none'});// floating the IMG removes the bottom line-height and fixed a problem where IE miscalculates the width of the parent element as 100% of the document width. 511 $loadingBay.hide(); 512 513 // floating the IMG removes the bottom line-height and fixed a problem where IE miscalculates the width of the parent element as 100% of the document width. 514 $('#' + prefix + 'Photo').css({cssFloat: 'none', marginLeft: 'auto', marginRight: 'auto'}); 424 515 425 516 // Hides SELECT elements in IE6 because they would otherwise sit on top of the overlay. 426 517 if (isIE6) { 427 $('select :not(#colorbox select)').filter(function(){518 $('select').not($box.find('select')).filter(function () { 428 519 return this.style.visibility !== 'hidden'; 429 }).css({'visibility': 'hidden'}).one(cbox_cleanup, function(){520 }).css({'visibility': 'hidden'}).one(event_cleanup, function () { 430 521 this.style.visibility = 'inherit'; 431 522 }); 432 523 } 433 524 434 function setPosition (s) { 435 cboxPublic.position(s, function(){ 436 if (!open) { return; } 525 function setPosition(s) { 526 var prev, prevSrc, next, nextSrc, total = $related.length, loop = settings.loop; 527 publicMethod.position(s, function () { 528 function defilter() { 529 if (isIE) { 530 //IE adds a filter when ColorBox fades in and out that can cause problems if the loaded content contains transparent pngs. 531 $box[0].style.filter = false; 532 } 533 } 534 535 if (!open) { 536 return; 537 } 437 538 438 539 if (isIE) { 439 540 //This fadeIn helps the bicubic resampling to kick-in. 440 if( photo ){$loaded.fadeIn(100);} 441 //IE adds a filter when ColorBox fades in and out that can cause problems if the loaded content contains transparent pngs. 442 $cbox[0].style.removeAttribute("filter"); 443 } 444 445 //Waited until the iframe is added to the DOM & it is visible before setting the src. 446 //This increases compatability with pages using DOM dependent JavaScript. 447 if(settings.iframe){ 448 $loaded.append("<iframe id='cboxIframe'" + (settings.scrolling ? " " : "scrolling='no'") + " name='iframe_"+new Date().getTime()+"' frameborder=0 src='"+settings.href+"' " + (isIE ? "allowtransparency='true'" : '') + " />"); 541 if (photo) { 542 $loaded.fadeIn(100); 543 } 449 544 } 450 545 451 546 $loaded.show(); 452 547 548 trigger(event_loaded); 549 453 550 $title.show().html(settings.title); 454 551 455 if ( $related.length>1) {456 $current.html(settings.current.replace(/\{current\}/, index+1).replace(/\{total\}/, $related.length)).show();457 $next.html(settings.next).show();458 $prev.html(settings.previous).show();552 if (total > 1) { // handle grouping 553 if (typeof settings.current === "string") { 554 $current.html(settings.current.replace(/\{current\}/, index + 1).replace(/\{total\}/, total)).show(); 555 } 459 556 460 if(settings.slideshow){ 557 $next[(loop || index < total - 1) ? "show" : "hide"]().html(settings.next); 558 $prev[(loop || index) ? "show" : "hide"]().html(settings.previous); 559 560 prev = index ? $related[index - 1] : $related[total - 1]; 561 next = index < total - 1 ? $related[index + 1] : $related[0]; 562 563 if (settings.slideshow) { 461 564 $slideshow.show(); 462 565 } 566 567 // Preloads images within a rel group 568 if (settings.preloading) { 569 nextSrc = $.data(next, colorbox).href || next.href; 570 prevSrc = $.data(prev, colorbox).href || prev.href; 571 572 nextSrc = $.isFunction(nextSrc) ? nextSrc.call(next) : nextSrc; 573 prevSrc = $.isFunction(prevSrc) ? prevSrc.call(prev) : prevSrc; 574 575 if (isImage(nextSrc)) { 576 $('<img/>')[0].src = nextSrc; 577 } 578 579 if (isImage(prevSrc)) { 580 $('<img/>')[0].src = prevSrc; 581 } 582 } 463 583 } 464 584 465 585 $loadingOverlay.hide(); 466 $loadingGraphic.hide(); 467 468 $.event.trigger(cbox_complete); 469 if (settings.onComplete) { 470 settings.onComplete.call(element); 471 } 472 473 if (settings.transition === 'fade'){ 474 $cbox.fadeTo(speed, 1, function(){ 475 if(isIE){$cbox[0].style.removeAttribute("filter");} 586 587 if (settings.transition === 'fade') { 588 $box.fadeTo(speed, 1, function () { 589 defilter(); 476 590 }); 477 } 478 479 $window.bind(cbox_resize, function(){ 480 cboxPublic.position(0); 591 } else { 592 defilter(); 593 } 594 595 $window.bind('resize.' + prefix, function () { 596 publicMethod.position(0); 481 597 }); 598 599 trigger(event_complete, settings.onComplete); 482 600 }); 483 601 } 484 602 485 if((settings.transition === 'fade' && $cbox.fadeTo(speed, 0, function(){setPosition(0);})) || setPosition(speed)){} 486 487 // Preloads images within a rel group 488 if (settings.preloading && $related.length>1) { 489 prev = index > 0 ? $related[index-1] : $related[$related.length-1]; 490 next = index < $related.length-1 ? $related[index+1] : $related[0]; 491 nextSrc = $(next).data(colorbox).href || next.href; 492 prevSrc = $(prev).data(colorbox).href || prev.href; 493 494 if(isImage(nextSrc)){ 495 $('<img />').attr('src', nextSrc); 496 } 497 498 if(isImage(prevSrc)){ 499 $('<img />').attr('src', prevSrc); 500 } 501 } 502 }; 503 504 cboxPublic.load = function () { 505 var href, img, setResize, resize = cboxPublic.resize; 506 507 active = TRUE; 508 509 /* 510 511 // I decided to comment this out because I can see it causing problems as users 512 // really should just set the dimensions on their IMG elements instead, 513 // but I'm leaving the code in as it may be useful to someone. 514 // To use, uncomment the function and change 'if(textStatus === "success"){ resize(this); }' 515 // to 'if(textStatus === "success"){ preload(this); }' 516 517 // Preload loops through the HTML to find IMG elements and loads their sources. 518 // This allows the resize method to accurately estimate the dimensions of the new content. 519 function preload(html){ 520 var 521 $ajax = $(html), 522 $imgs = $ajax.find('img'), 523 x = $imgs.length; 524 525 function loadloop(){ 526 var img = new Image(); 527 x = x-1; 528 if(x >= 0){ 529 img.onload = loadloop; 530 img.src = $imgs[x].src; 531 } else { 532 resize($ajax); 533 } 534 } 535 536 loadloop(); 537 } 538 */ 539 603 if (settings.transition === 'fade') { 604 $box.fadeTo(speed, 0, function () { 605 setPosition(0); 606 }); 607 } else { 608 setPosition(speed); 609 } 610 }; 611 612 publicMethod.load = function (launched) { 613 var href, img, setResize, prep = publicMethod.prep; 614 615 active = true; 540 616 element = $related[index]; 541 617 542 settings = $(element).data(colorbox); 543 544 //convert functions to static values 545 process(); 546 547 $.event.trigger(cbox_load); 548 if (settings.onLoad) { 549 settings.onLoad.call(element); 550 } 551 552 // Evaluate the height based on the optional height and width settings. 618 if (!launched) { 619 settings = process($.extend({}, $.data(element, colorbox))); 620 } 621 622 trigger(event_purge); 623 624 trigger(event_load, settings.onLoad); 625 553 626 settings.h = settings.height ? 554 627 setSize(settings.height, 'y') - loadedHeight - interfaceHeight : 555 settings.innerHeight ? 556 setSize(settings.innerHeight, 'y') : 557 FALSE; 628 settings.innerHeight && setSize(settings.innerHeight, 'y'); 629 558 630 settings.w = settings.width ? 559 631 setSize(settings.width, 'x') - loadedWidth - interfaceWidth : 560 settings.innerWidth ? 561 setSize(settings.innerWidth, 'x') : 562 FALSE; 632 settings.innerWidth && setSize(settings.innerWidth, 'x'); 563 633 564 634 // Sets the minimum dimensions for use in image scaling … … 568 638 // Re-evaluate the minimum width and height based on maxWidth and maxHeight values. 569 639 // If the width or height exceed the maxWidth or maxHeight, use the maximum values instead. 570 if (settings.maxWidth){640 if (settings.maxWidth) { 571 641 settings.mw = setSize(settings.maxWidth, 'x') - loadedWidth - interfaceWidth; 572 642 settings.mw = settings.w && settings.w < settings.mw ? settings.w : settings.mw; 573 643 } 574 if (settings.maxHeight){644 if (settings.maxHeight) { 575 645 settings.mh = setSize(settings.maxHeight, 'y') - loadedHeight - interfaceHeight; 576 646 settings.mh = settings.h && settings.h < settings.mh ? settings.h : settings.mh; … … 580 650 581 651 $loadingOverlay.show(); 582 $loadingGraphic.show(); 583 652 584 653 if (settings.inline) { 585 654 // Inserts an empty placeholder where inline content is being pulled from. 586 655 // An event is bound to put inline content back when ColorBox closes or loads new content. 587 $ ('<div id="cboxInlineTemp" />').hide().insertBefore($(href)[0]).bind(cbox_load+' '+cbox_cleanup, function(){656 $div().hide().insertBefore($(href)[0]).one(event_purge, function () { 588 657 $(this).replaceWith($loaded.children()); 589 658 }); 590 resize($(href));659 prep($(href)); 591 660 } else if (settings.iframe) { 592 661 // IFrame element won't be added to the DOM until it is ready to be displayed, 593 662 // to avoid problems with DOM-ready JS that might be trying to run in that iframe. 594 resize(" "); 663 $box.one(event_loaded, function () { 664 var $iframe = $("<iframe name='" + new Date().getTime() + "' frameborder=0" + (settings.scrolling ? "" : " scrolling='no'") + (isIE ? " allowtransparency='true'" : '') + " style='width:100%; height:100%; border:0; display:block;'/>"); 665 $iframe[0].src = settings.href; 666 $iframe.appendTo($loaded).one(event_purge, function () { 667 $iframe[0].src = '//about:blank'; 668 }); 669 }); 670 671 prep(" "); 595 672 } else if (settings.html) { 596 resize(settings.html);597 } else if (isImage(href)) {673 prep(settings.html); 674 } else if (isImage(href)) { 598 675 img = new Image(); 599 img.onload = function (){676 img.onload = function () { 600 677 var percent; 601 602 678 img.onload = null; 603 604 img.id = 'cboxPhoto'; 605 606 $(img).css({margin:'auto', border:'none', display:'block', cssFloat:'left'}); 607 608 if(settings.scalePhotos){ 609 setResize = function(){ 679 img.id = prefix + 'Photo'; 680 $(img).css({border: 'none', display: 'block', cssFloat: 'left'}); 681 if (settings.scalePhotos) { 682 setResize = function () { 610 683 img.height -= img.height * percent; 611 684 img.width -= img.width * percent; 612 685 }; 613 if (settings.mw && img.width > settings.mw){686 if (settings.mw && img.width > settings.mw) { 614 687 percent = (img.width - settings.mw) / img.width; 615 688 setResize(); 616 689 } 617 if (settings.mh && img.height > settings.mh){690 if (settings.mh && img.height > settings.mh) { 618 691 percent = (img.height - settings.mh) / img.height; 619 692 setResize(); … … 622 695 623 696 if (settings.h) { 624 img.style.marginTop = Math.max(settings.h - img.height,0)/2 + 'px'; 625 } 626 627 resize(img); 628 629 if($related.length > 1){ 630 $(img).css({cursor:'pointer'}).click(cboxPublic.next); 631 } 632 633 if(isIE){ 634 img.style.msInterpolationMode='bicubic'; 635 } 697 img.style.marginTop = Math.max(settings.h - img.height, 0) / 2 + 'px'; 698 } 699 700 if ($related[1] && (index < $related.length - 1 || settings.loop)) { 701 $(img).css({cursor: 'pointer'}).click(publicMethod.next); 702 } 703 704 if (isIE) { 705 img.style.msInterpolationMode = 'bicubic'; 706 } 707 708 setTimeout(function () { // Chrome will sometimes report a 0 by 0 size if there isn't pause in execution 709 prep(img); 710 }, 1); 636 711 }; 637 img.src = href; 638 } else { 639 $('<div />').appendTo($loadingBay).load(href, function(data, textStatus){ 640 if(textStatus === "success"){ 641 resize(this); 642 } else { 643 resize($("<p>Request unsuccessful.</p>")); 644 } 712 713 setTimeout(function () { // Opera 10.6+ will sometimes load the src before the onload function is set 714 img.src = href; 715 }, 1); 716 } else if (href) { 717 $loadingBay.load(href, function (data, status, xhr) { 718 prep(status === 'error' ? 'Request unsuccessful: ' + xhr.statusText : $(this).children()); 645 719 }); 646 720 } … … 648 722 649 723 // Navigates to the next page/image in a set. 650 cboxPublic.next = function () { 651 if(!active){ 652 index = index < $related.length-1 ? index+1 : 0; 653 cboxPublic.load(); 654 } 655 }; 656 657 cboxPublic.prev = function () { 658 if(!active){ 659 index = index > 0 ? index-1 : $related.length-1; 660 cboxPublic.load(); 661 } 662 }; 663 664 cboxPublic.slideshow = function () { 665 var stop, timeOut, className = 'cboxSlideshow_'; 666 667 $slideshow.bind(cbox_closed, function(){ 668 $slideshow.unbind(); 669 clearTimeout(timeOut); 670 $cbox.removeClass(className+"off"+" "+className+"on"); 671 }); 672 673 function start(){ 674 $slideshow 675 .text(settings.slideshowStop) 676 .bind(cbox_complete, function(){ 677 timeOut = setTimeout(cboxPublic.next, settings.slideshowSpeed); 678 }) 679 .bind(cbox_load, function(){ 680 clearTimeout(timeOut); 681 }).one("click", function(){ 682 stop(); 683 $(this).removeClass(hover); 724 publicMethod.next = function () { 725 if (!active) { 726 index = index < $related.length - 1 ? index + 1 : 0; 727 publicMethod.load(); 728 } 729 }; 730 731 publicMethod.prev = function () { 732 if (!active) { 733 index = index ? index - 1 : $related.length - 1; 734 publicMethod.load(); 735 } 736 }; 737 738 // Note: to use this within an iframe use the following format: parent.$.fn.colorbox.close(); 739 publicMethod.close = function () { 740 if (open && !closing) { 741 closing = true; 742 743 open = false; 744 745 trigger(event_cleanup, settings.onCleanup); 746 747 $window.unbind('.' + prefix + ' .' + event_ie6); 748 749 $overlay.fadeTo('fast', 0); 750 751 $box.stop().fadeTo('fast', 0, function () { 752 753 trigger(event_purge); 754 755 $loaded.remove(); 756 757 $box.add($overlay).css({'opacity': 1, cursor: 'auto'}).hide(); 758 759 setTimeout(function () { 760 closing = false; 761 trigger(event_closed, settings.onClosed); 762 }, 1); 684 763 }); 685 $cbox.removeClass(className+"off").addClass(className+"on"); 686 } 687 688 stop = function(){ 689 clearTimeout(timeOut); 690 $slideshow 691 .text(settings.slideshowStart) 692 .unbind(cbox_complete+' '+cbox_load) 693 .one("click", function(){ 694 start(); 695 timeOut = setTimeout(cboxPublic.next, settings.slideshowSpeed); 696 $(this).removeClass(hover); 697 }); 698 $cbox.removeClass(className+"on").addClass(className+"off"); 699 }; 700 701 if(settings.slideshow && $related.length>1){ 702 if(settings.slideshowAuto){ 703 start(); 704 } else { 705 stop(); 706 } 707 } 708 }; 709 710 // Note: to use this within an iframe use the following format: parent.$.fn.colorbox.close(); 711 cboxPublic.close = function () { 712 713 $.event.trigger(cbox_cleanup); 714 if (settings.onCleanup) { 715 settings.onCleanup.call(element); 716 } 717 718 open = FALSE; 719 $(document).unbind("keydown.cbox_close keydown.cbox_arrows"); 720 $window.unbind(cbox_resize+' resize.cboxie6 scroll.cboxie6'); 721 $overlay.css({cursor: 'auto'}).fadeOut('fast'); 722 723 $cbox 724 .stop(TRUE, FALSE) 725 .fadeOut('fast', function () { 726 $('#colorbox iframe').attr('src', 'about:blank'); 727 $loaded.remove(); 728 $cbox.css({'opacity': 1}); 729 730 try{ 731 bookmark.focus(); 732 } catch (er){ 733 // do nothing 734 } 735 736 $.event.trigger(cbox_closed); 737 if (settings.onClosed) { 738 settings.onClosed.call(element); 739 } 740 }); 764 } 741 765 }; 742 766 743 767 // A method for fetching the current element ColorBox is referencing. 744 768 // returns a jQuery object. 745 cboxPublic.element = function(){ return $(element); }; 746 747 cboxPublic.settings = defaults; 769 publicMethod.element = function () { 770 return $(element); 771 }; 772 773 publicMethod.settings = defaults; 748 774 749 775 // Initializes ColorBox when the DOM has loaded 750 $( cboxPublic.init);751 752 }(jQuery ));776 $(publicMethod.init); 777 778 }(jQuery, this)); -
extensions/lightbox/lightbox.php
r7252 r7949 13 13 <link rel="stylesheet" href="'.get_root_url().'plugins/lightbox/theme/'.$params['theme'].'/colorbox.css" type="text/css" media="screen"> 14 14 <script type="text/javascript"> 15 $(document).ready(function(){16 $("'.$selector.'").attr("href", function () {15 jQuery(document).ready(function(){ 16 jQuery("'.$selector.'").attr("href", function () { 17 17 return this.name; 18 18 }); 19 $("'.$selector.'").colorbox({19 jQuery("'.$selector.'").colorbox({ 20 20 current: "", 21 21 transition: "'.$params['transition'].'", … … 27 27 }, 28 28 function() { 29 $.post("'.get_root_url().'plugins/lightbox/save_history.php", {29 jQuery.post("'.get_root_url().'plugins/lightbox/save_history.php", { 30 30 imgid: this.id, 31 31 catid: "'.@$page['category']['id'].'",
Note: See TracChangeset
for help on using the changeset viewer.