Biomod/2014/VCCRI/easybox.js: Difference between revisions

From OpenWetWare
Jump to navigationJump to search
No edit summary
No edit summary
 
(No difference)

Latest revision as of 05:20, 25 October 2014

/*

       Easybox v1.3 - Lightweight easy to use lightbox clone for jQuery
       Based on Slimbox2 by Christophe Beyls <http://www.digitalia.be>
  • /

/android|iphone|ipod|series60|symbian|windows ce|blackberry|msie 6/i.test(navigator.userAgent)||jQuery(function(a){a("a.lightbox").easybox({/* custom options here */},null,function(a){return this==a||-1!=this.className.indexOf("lightbox")&&this.hasAttribute("data-group")&&this.getAttribute("data-group")==a.getAttribute("data-group")},function(b){var c={};if(a("#easyOptions").length){var f=a.parseJSON(a("#easyOptions").html()),d=b.getAttribute("data-group");a.each(f,function(e,b){if("global"==e||"string"==typeof d&&e==d)c= a.extend(c,b)})}return c})}); /*

       Easybox v1.3 - Lightweight easy to use lightbox clone for jQuery
       Based on Slimbox2 by Christophe Beyls <http://www.digitalia.be>
  • /

(function(a){function A(b){if(s||0>b||b>=e.length)return!1;B();g=b;k=(g||(c.loop?e.length:0))-1;f=(g+1)%e.length||(c.loop?0:-1);c.preloadNext&&(0<=k&&C(k),0<=f&&C(f));e[g].loaded||a(w).show();C(g);return!1}function W(){var b=e[g];a(w).hide();b.error?a(j).addClass("error").width(c.errorSize[0]).height(c.errorSize[1]):(b.caption.length&&a(m).html(b.caption).css({display:""}),a(j).width(b.width).height(b.height));1<e.length&&c.counterText.length&&a(n).html(c.counterText.replace(/{x}/,g+1).replace(/{y}/, e.length)).css({display:""});s=!0;a(j).css({visibility:"hidden",display:""});P([j.offsetWidth,j.offsetHeight],-1,c.resizeDuration);a(h).queue(function(d){a(j).css({visibility:"",display:"none"});b.error||(a(b.obj).appendTo(j),b.handler.show(b),D=!0);Q();a(j).fadeIn(c.fadeDuration,X);s=!1;d()})}function P(b,d,o){i=b.slice();var e={};if(h.offsetHeight!=b[1]||h.offsetWidth!=b[0])e={height:b[1],marginTop:-b[1]/2,width:b[0],marginLeft:-b[0]/2};if(-1<d)e.opacity=d;a(h).animate(e,o,c.resizeEasing)}function X(){if(!c.hideBottom){if((0<= k||0<=f)&&!c.noNavigation&&!c.hideButtons)a(E).css({display:""}),a([m,n]).addClass("nav"),0>k&&a(F).addClass("disabled"),0>f&&a(G).addClass("disabled");c.hideCaption||a([m,n]).show();a(x).fadeIn(c.captionFadeDuration);a(h).animate({height:i[1]+x.offsetHeight},c.captionFadeDuration,c.resizeEasing)}}function B(){null!=l&&(clearTimeout(l),l=null);null!=t&&(clearTimeout(t),t=null);if(0<=g){var b=e[g];!b.error&&D&&b.handler.hide(b)}a([j,m,n]).html("");a(w).hide();a([x,j]).stop(!0,!0).hide();a(h).stop(!0).css({width:i[0], height:i[1],marginLeft:-i[0]/2,marginTop:-i[1]/2,opacity:""});a([E,m,n]).hide();a([j,m,n,F,G]).removeClass();D=s=!1}function H(){if(!p)return!1;B();g=k=f=-1;I();R(0);a(J).stop().fadeOut(c.fadeDuration);P([i[0]/2,i[1]/2],0,c.fadeDuration);a(h).queue(function(b){a(h).css({left:"",top:""}).hide();p=!1;b()});return!1}function u(){q=!0;return A(k)}function v(){q=!1;return A(f)}function K(){return s||c.noClose?!1:H()}function Y(){r=!r;q=!1;a(L).toggleClass("disabled",r);r?null!=l&&(clearTimeout(l),l=null): Q();return!1}function Q(){if(c.slideshow&&!r&&null==l){if(q&&0<=k)return l=setTimeout(u,c.slideshow),!1;if(!q&&0<=f)return l=setTimeout(v,c.slideshow),!1}c.autoClose&&null==t&&(t=setTimeout(H,c.autoClose));return!1}function C(a){var c=e[a];c.loaded&&M(a);if(!c.loading){c.loading=!0;for(var o=y.length-1;0<=o;--o)if(y[o].identify(c)){c.handler=y[o];c.handler.preLoad(c,function(){M(a)});return}c.error=!0;M(a)}}function M(a){var d=e[a];if(!d.loaded&&(d.loaded=!0,!d.error)){if(!d.width||!d.height)d.width= c.defaultContentSize[0],d.height=c.defaultContentSize[1];if(d.height>c.maximumContentSize[1])d.width=Math.round(c.maximumContentSize[1]*d.width/d.height),d.height=c.maximumContentSize[1];if(d.width>c.maximumContentSize[0])d.height=Math.round(c.maximumContentSize[0]/d.width*d.height),d.width=c.maximumContentSize[0];d.handler.postLoad(d)}a==g&&W()}function R(b){b?a("object:visible").add("embed").each(function(a,b){N[a]=[b,b.style.visibility];b.style.visibility="hidden"}):(a.each(N,function(a,b){b[0].style.visibility= b[1]}),N=[]);b=b?"bind":"unbind";a(document)[b]("keydown",Z);if(a.fn.mousewheel)a(window)[b]("mousewheel",$);a(h)[b]("mousedown",aa)[b]("mousemove",S)[b]("mouseup",I);a(window)[b]("mousemove",S)[b]("mouseup",I)}function Z(b){var b=b.keyCode,d=a.inArray;return 0<=d(b,c.closeKeys)?K():0<=d(b,c.nextKeys)&&!c.noNavigation?v():0<=d(b,c.previousKeys)&&!c.noNavigation?u():!c.preventOtherKeys}function $(a,d){return 0<d&&!c.noNavigation?u():0>d&&!c.noNavigation?v():!1}function aa(b){return c.dragDrop?(z=!0, a(h).css({cursor:"pointer"}),T=b.pageX-a(this).position().left,U=b.pageY-a(this).position().top,!1):!0}function S(b){if(c.dragDrop&&z){var d=b.pageX-a(window).scrollLeft()-T,b=b.pageY-a(window).scrollTop()-U;a(h).css({left:d+"px",top:b+"px"});return!1}return!0}function I(){z&&(z=!1,a(h).css({cursor:""}));return!0}var O={loop:!1,preloadNext:!0,dragDrop:!0,hideBottom:!1,hideCaption:!1,hideButtons:!1,noNavigation:!1,noClose:!1,overlayOpacity:0.8,resizeDuration:400,resizeEasing:"easybox",fadeDuration:400,

initCenterSize:[250,250],errorSize:[320,180],defaultContentSize:[960,720],maximumContentSize:[1280,720],captionFadeDuration:200,slideshow:0,autoClose:0,counterText:"{x} of {y}",closeKeys:[27],previousKeys:[37],nextKeys:[39],preventOtherKeys:!0},y=[],c,e,g=-1,k,f,i,N=[],q,r,z=!1,T=0,U=0,p=!1,s,D,l=null,t=null,J,h,j,E,F,G,L,V,x,m,n,w;a(function(){a("body").append(a([J=a('

').click(K)[0],h=a('
').append([j=a('
')[0],w=a('
')[0], x=a('
').append([E=a('
').append([F=a('<a id="easyPrevLink" href="#" />').click(u)[0],G=a('<a id="easyNextLink" href="#" />').click(v)[0]])[0],V=a('<a id="easyCloseLink" href="#" />').click(K)[0],L=a('<a id="easySlideLink" href="#" />').click(Y)[0],m=a('
')[0],n=a('
')[0],a('
')[0]])[0]])[0]]).css("display","none"))});a.fn.easybox=function(b,c,e,h){var c=c||function(a){var b={url:a.href,

caption:a.title};if(a.hasAttribute("data-width"))b.width=a.getAttribute("data-width");if(a.hasAttribute("data-height"))b.height=a.getAttribute("data-height");return b},e=e||function(a){return this==a},h=h||function(){return{}},j=this;return j.unbind("click").click(function(){var g=this,k=0,f,i=0,l;f=a.grep(j,function(a,b){return e.call(g,a,b)});for(l=f.length;i<l;++i)f[i]==g&&(k=i),f[i]=c(f[i],i);return a.easybox(f,k,a.extend({},b,h(g)))})};a.easybox=function(b,d,f){if(p)return!1;c=a.extend({},O, f);var f=0,g;e=[];for(g=b.length;f<g;++f)e.push(a.extend({caption:"",width:0,height:0},b[f],{handler:null,loaded:!1,loading:!1,error:!1,obj:null}));if(e.length)return p=!0,c.loop=c.loop&&1<e.length,c.slideshow=c.slideshow&&1<e.length?c.slideshow:0,a(L).css({display:c.slideshow&&1<e.length&&!c.hideButtons?"":"none"}),q=r=!1,a(V).css({display:!c.hideButtons?"":"none"}),i=c.initCenterSize.slice(),B(),R(1),a(h).show(),a(J).css({opacity:c.overlayOpacity}).fadeIn(c.fadeDuration,function(){A(Math.min(e.length- 1,d||0))}),!1};a.easybox.previous=function(){return 0<=k?!u():!1};a.easybox.next=function(){return 0<=f?!v():!1};a.easybox.close=function(){return p?!H():!1};a.easybox.isOpen=function(){return p};a.easybox.defaults=function(b){O=a.extend(O,b)};a.easybox.resourceHandler=function(b){y.push(a.extend({identify:function(){return!1},preLoad:function(a,b){b()},postLoad:function(){},show:function(){},hide:function(){}},b))};a.easing.easybox=function(a){return 0.7>a?1.2*Math.pow(a/0.7,2):1.2-0.2*Math.sqrt((a- 0.7)/(1-0.7))}})(jQuery); /*

       Easybox v1.3 - Lightweight easy to use lightbox clone for jQuery
       Based on Slimbox2 by Christophe Beyls <http://www.digitalia.be>
  • /
(function(b){b(function(){b.easybox.resourceHandler({identify:function(a){return a.url?!0:!1},postLoad:function(a){a.obj=b('<iframe width="'+a.width+'" height="'+a.height+'" src="'+a.url+'" frameborder="0"></iframe>')[0]}});b.easybox.resourceHandler({identify:function(a){return a.html?!0:!1},postLoad:function(a){a.obj=b('
'+a.html+"
")[0]}});b.easybox.resourceHandler({identify:function(a){if(!a.url)return!1;var c=/^(.*)\#([A-Za-z0-9\-_]*)$/i.exec(a.url);

return null!=c&&b("#"+c[2]).length?(a.id=c[2],!0):!1},preLoad:function(a,c){var d=b("#"+a.id)[0];d?(a.width=a.width||b(d).width(),a.height=a.height||b(d).height(),a.obj=d):a.error=!0;c()},postLoad:function(a){a.parent=b(a.obj).parent()[0];a.display=b(a.obj).css("display")},show:function(a){b(a.obj).css("display","block")},hide:function(a){b(a.parent).append(b(a.obj).css("display",a.display))}});b.easybox.resourceHandler({identify:function(a){return!a.url?!1:/(\.jpg|\.jpeg|\.png|\.gif)$/i.test(a.url)},

preLoad:function(a,b){var d=new Image;d.onload=function(){a.width=a.width||this.width;a.height=a.height||this.height;b()};d.onerror=function(){a.error=!0;b()};d.src=a.url},postLoad:function(a){a.obj=b('<img src="'+a.url+'" style="display:block;width:'+a.width+"px;height:"+a.height+'px" alt="'+a.caption+'" />')[0]}});b.easybox.resourceHandler({identify:function(a){return!a.url?!1:/(\.mpg|\.mpeg|\.mp4|\.ogv|\.webm|\.flv)$/i.test(a.url)},postLoad:function(a){a.obj=b('
')[0]},show:function(a){var c=!!b.fn.flowplayer;b(a.obj).append(b('<video src="'+a.url+'" width="'+a.width+'" height="'+a.height+'"'+(!c?' controls="controls"':"")+" />"));c&&b(a.obj).flowplayer()}});b.easybox.resourceHandler({identify:function(a){if(!a.url)return!1;var b=/^http\:\/\/www\.youtube\.com\/watch\?v=([A-Za-z0-9\-_]*)(&(.*))?$/i.exec(a.url);return null!=b?(a.id=b[1],!0):!1},preLoad:function(a,c){b.ajax("http://gdata.youtube.com/feeds/api/videos/"+a.id+

"?v=2&alt=jsonc",{type:"GET",dataType:"jsonp",timeout:2E3,error:function(b,e){if("abort"!=e)a.error=!0,c()},success:function(b){!b.error&&b.data&&"allowed"==b.data.accessControl.embed?(b="widescreen"==b.data.aspectRatio,a.height=a.height||720,a.width=Math.round(a.height*(b?16/9:4/3))):a.error=!0;c()}})},postLoad:function(a){a.obj=b('<iframe src="http://www.youtube.com/embed/'+a.id+'?version=3&autohide=1&autoplay=1&rel=0" width="'+a.width+'" height="'+a.height+'" frameborder="0"></iframe>')[0]}}); b.easybox.resourceHandler({identify:function(a){if(!a.url)return!1;var b=/^http\:\/\/vimeo\.com\/([0-9]*)(.*)?$/i.exec(a.url);return null!=b?(a.id=b[1],!0):!1},preLoad:function(a,c){b.ajax("http://vimeo.com/api/v2/video/"+a.id+".json",{type:"GET",dataType:"jsonp",timeout:2E3,error:function(b,e){if("abort"!=e)a.error=!0,c()},success:function(b){if(b.length)if("anywhere"==b[0].embed_privacy||"approved"==b[0].embed_privacy){if(b[0].width&&b[0].height)a.width=b[0].width,a.height=b[0].height}else a.error= !0;c()}})},postLoad:function(a){a.obj=b('<iframe src="http://player.vimeo.com/video/'+a.id+'?title=0&byline=0&portrait=0&autoplay=true" width="'+a.width+'" height="'+a.height+'" frameborder="0"></iframe>')[0]}});b.easybox.resourceHandler({identify:function(a){if(!a.url)return!1;var b=/^http\:\/\/www\.dailymotion\.com\/video\/([A-Za-z0-9]*)(.*)?$/i.exec(a.url);return null!=b?(a.id=b[1],!0):!1},preLoad:function(a,c){b.ajax("https://api.dailymotion.com/video/"+a.id+"?fields=allow_embed,aspect_ratio", {type:"GET",dataType:"jsonp",timeout:2E3,error:function(b,e){if("abort"!=e)a.error=!0,c()},success:function(b){b.allow_embed?(b=b.aspect_ratio,a.height=a.height||720,a.width=Math.round(a.height*b)):a.error=!0;c()}})},postLoad:function(a){a.obj=b('<iframe src="http://www.dailymotion.com/embed/video/'+a.id+'?autoplay=1" width="'+a.width+'" height="'+a.height+'" frameborder="0"></iframe>')[0]}})})})(jQuery);