forked from YoshikiKozaki/MultiBoxForJQuery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jmultibox.min.js
4 lines (4 loc) · 13.5 KB
/
jmultibox.min.js
1
2
3
4
/**
* MultiBox for jQuery with Vegas Background jQuery Plugin. License Dual licensed under the MIT and GPL licenses. Copyright (C) Yoshiki Kozaki
*/
(function(e){e.fn.jmultibox=function(t){var n={};var r=0;var i=0;var s=0;var o=false;var u=false;var a={};var f={};var l;var c,h,p,d,v,m,g,y,b,w,E,S,x,T,N,C,k,L,A,O,M,_;t=e.extend({initialWidth:250,initialHeight:250,container:document.body,contentColor:"#000",showNumbers:true,showControls:true,descClassName:false,descMinWidth:400,descMaxWidth:600,movieWidth:576,movieHeight:324,offset:{x:0,y:0},fixedTop:false,path:"",openFromLink:true,opac:.7,useOverlay:false,overlaybg:"01.png",onOpen:function(){},onClose:function(){},easing:"swing",useratio:false,ratio:"90"},t);if(t.path.length){if(t.path.indexOf("/")!==0){t.path="/"+t.path}}t.path+="";if(t.useratio){t.ratio=parseInt(t.ratio,10);if(t.ratio<20){t.useratio=false}else{t.ratio=t.ratio/100}}var D=function(n){var r=n.href.substr(n.href.lastIndexOf(".")+1).toLowerCase();var i={};if(!!(n.rel||n.rel===0)){var s=n.rel.split(",");e(s).each(function(e,t){if(t.indexOf(":")>0){var n=t.split(":");i[n[0]]=n[1]}})}if(i.type!==undefined){r=i.type}a={};a.url=n.href;a.src=n.href;a.xH=0;if(i.width){a.width=i.width}else{a.width=t.movieWidth}if(i.height){a.height=i.height}else{a.height=t.movieHeight}if(i.panel){g=i.panel}else{g=t.panel}switch(r){case"jpg":case"image":case"gif":case"png":c="image";break;case"swf":c="flash";break;case"mp4":case"flv":c="flashVideo";a.xH=70;break;case"mov":c="quicktime";break;case"wmv":c="windowsMedia";break;case"rv":case"rm":case"rmvb":c="real";break;case"mp3":c="flashMp3";a.width=320;a.height=70;break;case"element":c="htmlelement";p=n.content;p.css({display:"block",opacity:0});if(i.width){a.width=i.width}else if(p.css("width")!=="auto"){a.width=p.css("width")}if(i.height){a.height=i.height}else{a.height=p.getSize().y}p.css({display:"none",opacity:1});break;default:if(a.url.match(/youtube\.com\/v/i)||a.url.match(/youtu\.be/i)){c="element";u=true;break}if(a.url.match(/youtube\.com\/watch\?v=/)){c="element";u=true;a.url="http://www.youtube.com/v/"+a.url.replace(/.*?youtube\.com\/watch\?v=/,"").replace(/&=.*$/,"");break}c="iframe";if(i.ajax){c="ajax"}break}G()};var P=function(){d.css({opacity:0,display:"none"});v.css({height:0});X();m.removeClass("MultiBoxButtonDisabled");y.removeClass("MultiBoxButtonDisabled");o=false};var H=function(r){var i=parseInt(d.css("border-left-width"),10);if(t.openFromLink){w=r.attr("id");var s=r.children().get(0);if(s){var o=e(s).width()-i*2;if(o<0){o=0}var u=e(s).height()-i*2;if(u<0){u=0}n={width:o,height:u,top:e(s).offset().top,left:e(s).offset().left}}else{var o=r.width()-i*2;if(o<0){o=0}var u=r.height()-i*2;if(u<0){u=0}n={width:o,height:u,top:r.offset().top,left:r.offset().left}}}else{if(t.fixedTop){var a=t.fixedTop}else{var a=e(window).height()/2-t.initialHeight/2-i+t.offset.y+e(window).scrollTop()}n={width:t.initialWidth,height:t.initialHeight,top:a,left:e(window).width()/2-t.initialWidth/2-i+t.offset.x}}return n};var B=function(n,r){t.onOpen(n,r);s=r;var i=parseInt(d.css("border-left-width"),10);var u=parseInt(d.css("opacity"),10);if(!u){o=I();if(o.length){var a=e(o[0]).children(".MultiBoxClose");a.trigger("click");et(function(){return B(n,r)},1100)}else{o=true;if(t.useOverlay){e.vegas("overlay",{src:t.path+"overlays/"+t.overlaybg,opacity:t.opac});e(".vegas-overlay").bind("click",F)}d.css(H(n));d.css({opacity:0,display:"block"});if(t.fixedTop){var f=t.fixedTop}else{var f=e(window).height()/2-t.initialHeight/2-i+t.offset.y+e(window).scrollTop()}R(s)}return false}if(t.showControls){J()}H(e(b[s]));et(W,500);et(function(){R(s)},1100);return false};var j=function(n){D(b[n]);var r=false;if(t.descClassName){E.each(function(t,i){if(e(i).hasClass(w)||e(i).prev()===e(b[n])){r=e(i).clone()}})}i={title:b[n].title||" ",desc:r,number:n+1}};var F=function(){if(t.useOverlay){e(".vegas-overlay").animate({opacity:0},800,t.easing,function(){e.vegas("destroy","overlay")})}if(t.showControls){J()}W();et(q,500);t.onClose()};var I=function(){return e(".MultiBoxContainer").filter(function(){return parseInt(e(this).css("opacity"),10)===1})};var q=function(){C.animate({width:n.width,height:n.height},400,t.easing);d.animate({width:n.width,height:n.height,top:n.top,left:n.left,opacity:0},400,t.easing,function(){et(P,500)})};var R=function(e){x.addClass("MultiBoxLoading");j(e);if(c==="image"){var t=a.xH;a=Y(b[e].href,{onload:U});a.xH=t}else{U()}};var U=function(){if(S!==a.src){var n=parseInt(d.css("border-left-width"),10);if(t.fixedTop){var i=t.fixedTop}else{var i=e(window).height()/2-(parseInt(a.height,10)+a.xH)/2-n+e(window).scrollTop()+t.offset.y}var s=e(window).width()/2-parseInt(a.width,10)/2-n+t.offset.x;if(i<0){i=0}if(s<0){s=0}a.width=parseInt(a.width,10);a.height=parseInt(a.height,10);a.xH=parseInt(a.xH,10);d.animate({width:a.width,height:a.height+a.xH,top:i,left:s,opacity:1},400,t.easing);C.animate({width:a.width+n*2,height:a.height+a.xH+n*2},400,t.easing);r=et(z,500);S=a.src}};var z=function(){S="";x.removeClass("MultiBoxLoading");X();T=e("<div>",{id:"MultiBoxContentContainer"}).css({opacity:0,width:a.width+"px",height:parseInt(a.height,10)+a.xH+"px"}).appendTo(x);if(c==="image"){e(a).appendTo(T)}else if(c==="iframe"){e("<iframe>",{id:"iFrame"+(new Date).getTime(),width:a.width,height:a.height,src:a.url,frameborder:0,scrolling:"auto"}).appendTo(T)}else if(c==="htmlelement"){T.css("overflow","auto");N=p.parent();p.css("display","block").appendTo(T)}else if(c==="ajax"){e.ajax({url:a.url,cache:false,success:function(t){e("#MultiBoxContentContainer").append(t)}})}else{var n=Z().appendTo(T);if(h!==""){e("#MultiBoxMediaObject").html(h)}}T.animate({opacity:1},500,t.easing);O.text(i.title);if(b.length>1){L.text(i.number+" of "+b.length)}else{L.text("")}if(t.descClassName){var s=A.children();if(s.length){e(s[0]).remove()}if(i.desc){e(i.desc).appendTo(A).css({display:"block"})}}if(t.showControls){if(i.title!==" "||b.length>1){r=et(V,800)}}};var W=function(){x.addClass("MultiBoxLoading");T.animate({opacity:0},500,t.easing);et(X,500)};var X=function(){if(e("#MultiBoxMediaObject")){e("#MultiBoxMediaObject").empty();e("#MultiBoxMediaObject").remove()}if(e("#MultiBoxContentContainer")){if(c==="htmlelement"){p.css("display","none").appendTo(N)}e("#MultiBoxContentContainer").remove()}};var V=function(){clicked=false;if(d.css("height")!=="auto"){f.height=d.css("height");f.backgroundColor=t.contentColor}d.css({height:"auto"});if(b.length>1){m.css("visibility","visible");y.css("visibility","visible");O.css("margin-left",_)}else{m.css("visibility","hidden");y.css("visibility","hidden");O.css("margin-left",0)}v.animate({height:k.height()},300,t.easing);C.animate({height:parseInt(C.css("height"),10)+parseInt(k.css("height"),10)},400,t.easing)};var J=function(e){C.animate({height:parseInt(C.css("height"),10)-parseInt(k.css("height"),10)},400,t.easing);v.animate({height:0},300,t.easing,function(){d.css(f)})};var K=function(){s++;if(s>b.length-1){s=0}w=e(b[s]).attr("id");if(t.showControls){J()}H(e(b[s]));et(W,500);et(function(){R(s)},1100)};var Q=function(){s--;if(s<0){s=b.length-1}w=e(b[s]).attr("id");if(t.showControls){J()}H(e(b[s]));et(W,500);et(function(){R(s)},1e3)};var G=function(){if(t.useratio){if(c==="iframe"||u){a.width=parseInt(e(window).width()*t.ratio,10);if(c==="iframe"){a.height=parseInt(e(window).height()*t.ratio,10)}else{a.height=parseInt(a.width*10/16)}}}};var Y=function(t,n){if(!n)n={};var r=new Image,i=e(r);e.each(["load","abort","error"],function(e,t){var s="on"+t,o="on"+t.toLowerCase().replace(/\b[a-z]/g,function(e){return e.toUpperCase()}),u=n[s]||n[o]||function(){};delete n[o];delete n[s];r[s]=function(){if(!i.parentNode){i.width=r.width;i.height=r.height}r.onload=r.onabort=r.onerror=null;et(u,1)}});r.src=i.src=t;return i.attr(n)};var Z=function(n,r){n=a.url;switch(c){case"flash":r=e("<div>",{id:"MultiBoxMediaObject"});h='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" ';h+='width="'+a.width+'" ';h+='height="'+a.height+'" ';h+='title="MultiBoxMedia">';h+='<param name="movie" value="'+n+'" />';h+='<param name="quality" value="high" />';h+='<embed src="'+n+'" ';h+='quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" ';h+='width="'+a.width+'" ';h+='height="'+a.height+'"></embed>';h+="</object>";break;case"flashVideo":r=e("<div>",{id:"MultiBoxMediaObject"});h='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" ';h+='width="'+a.width+'" ';h+='height="'+(parseInt(a.height,10)+a.xH)+'" ';h+='title="MultiBoxMedia">';h+='<param name="movie" value="'+t.path+'files/flvplayer.swf" />';h+='<param name="quality" value="high" />';h+='<param name="salign" value="TL" />';h+='<param name="scale" value="noScale" />';h+='<param name="FlashVars" value="path='+n+'" />';h+='<embed src="'+t.path+'files/flvplayer.swf" ';h+='quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" ';h+='width="'+a.width+'" ';h+='height="'+(parseInt(a.height,10)+a.xH)+'"';h+='salign="TL" ';h+='scale="noScale" ';h+='FlashVars="path='+n+'"';h+="></embed>";h+="</object>";break;case"flashMp3":r=e("<div>",{id:"MultiBoxMediaObject"});h='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" ';h+='width="'+a.width+'" ';h+='height="'+a.height+'" ';h+='title="MultiBoxMedia">';h+='<param name="movie" value="'+t.path+'files/mp3player.swf" />';h+='<param name="quality" value="high" />';h+='<param name="salign" value="TL" />';h+='<param name="scale" value="noScale" />';h+='<param name="FlashVars" value="path='+n+'" />';h+='<embed src="'+t.path+'files/mp3player.swf" ';h+='quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" ';h+='width="'+a.width+'" ';h+='height="'+a.height+'"';h+='salign="TL" ';h+='scale="noScale" ';h+='FlashVars="path='+n+'"';h+="></embed>";h+="</object>";break;case"quicktime":r=e("<div>",{id:"MultiBoxMediaObject"});h='<object type="video/quicktime" classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab"';h+=' width="'+a.width+'" height="'+a.height+'">';h+='<param name="src" value="'+n+'" />';h+='<param name="autoplay" value="true" />';h+='<param name="controller" value="true" />';h+='<param name="enablejavascript" value="true" />';h+='<embed src="'+n+'" autoplay="true" pluginspage="http://www.apple.com/quicktime/download/" width="'+a.width+'" height="'+a.height+'"></embed>';h+="<object/>";break;case"windowsMedia":r=e("<div>",{id:"MultiBoxMediaObject"});h='<object type="application/x-oleobject" classid="CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112"';h+=' width="'+a.width+'" height="'+a.height+'">';h+='<param name="filename" value="'+n+'" />';h+='<param name="Showcontrols" value="true" />';h+='<param name="autoStart" value="true" />';h+='<embed type="application/x-mplayer2" src="'+n+'" Showcontrols="true" autoStart="true" width="'+a.width+'" height="'+a.height+'"></embed>';h+="<object/>";break;case"real":r=e("<div>",{id:"MultiBoxMediaObject"});h='<object classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA"';h+=' width="'+a.width+'" height="'+a.height+'">';h+='<param name="src" value="'+n+'" />';h+='<param name="controls" value="ImageWindow" />';h+='<param name="autostart" value="true" />';h+='<embed src="'+n+'" controls="ImageWindow" autostart="true" width="'+a.width+'" height="'+a.height+'"></embed>';h+="<object/>";break;default:if(u){var i;if(n.match(/youtu\.be/i)){i=n.replace(/.*?youtu\.be\//,"")}else if(n.match(/youtube\.com\/watch\?v=/)){i=n.replace(/.*?youtube\.com\/watch\?v=/,"").replace(/&=.*$/,"")}else if(n.match(/youtube\.com\/v/)){i=n.replace(/.*?youtube\.com\/v\//,"").replace(/&=.*$/,"")}r=e("<iframe>",{id:"MultiBoxMediaObject",width:a.width,height:a.height,src:"http://www.youtube.com/embed/"+i,frameborder:0,allowfullscreen:true})}}return r};var et=function(e,t){if(e){return setTimeout(e,t)}};b=this;if(t.descClassName){E=e("."+t.descClassName);E.each(function(t,n){e(n).css("display","none")})}d=e("<div>").addClass("MultiBoxContainer").appendTo(t.container);C=e("<iframe>",{id:"multiBoxIframe",name:"mulitBoxIframe",src:"javascript:void(0);",frameborder:0,scrolling:"no"}).css({position:"absolute",top:-20,left:-20,filter:"progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)",opacity:0}).appendTo(d);x=e("<div>").addClass("MultiBoxContent").appendTo(d);M=e("<div>").addClass("MultiBoxClose").appendTo(d).bind("click",F);v=e("<div>").addClass("MultiBoxControlsContainer").appendTo(d);k=e("<div>").addClass("MultiBoxControls").appendTo(v);m=e("<div>").addClass("MultiBoxPrevious").appendTo(k).bind("click",Q);y=e("<div>").addClass("MultiBoxNext").appendTo(k).bind("click",K);O=e("<div>").addClass("MultiBoxTitle").appendTo(k);_=O.css("margin-left");L=e("<div>").addClass("MultiBoxNumber").appendTo(k);A=e("<div>").addClass("MultiBoxDescription").appendTo(k);if(b.length===1){O.css({"margin-left":0});A.css({"margin-left":0});m.css("display","none");y.css("display","none");L.css("display","none")}e("<div>").css("clear","both").appendTo(k);b.each(function(t,n){e(n).bind("click",function(r){return B(e(n),t)});if(n.href.indexOf("#")>-1){n.content=e(n.href.substr(n.href.indexOf("#")+1));if(n.content){n.content.css("display","none")}}});P()}})(jQuery)