-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphoto.min.js
1 lines (1 loc) · 11.8 KB
/
photo.min.js
1
$(function(){var e,t,i,s,o,a,n,l,r,c,p,d,h,f,v,m,x,g,u,b,w,k,C,E,y,A,z,F,M,O,T,q,S,D,I,P,Y=document.documentElement,B=$(".xl-photo li"),R=xltoolbar=xlhandletab="",X=ismove=iszoom=isrotate=isdrag=isshowimglist=!1,L=xlicon=xlicontitle=[];$(".xl-backtotop").css("margin-left","720px");var U=function(){return Y.requestFullscreen||Y.webkitRequestFullscreen||Y.mozRequestFullScreen||Y.msRequestFullscreen},j=function(){return document.fullscreenElement||document.webkitFullscreenElement||document.mozFullScreenElement||document.msFullscreenElement},G=function(){return document.exitFullscreen||document.webkitExitFullscreen||document.mozCancelFullScreen||document.msExitFullscreen};xlicon=["remove","leftrotate","rightrotate","rerotate","zoomin","zoomout","original","fullscreen","like","comment","keep","download"],xlicontitle=["当前图片位置已居中","向左旋转90° (L)","向右旋转90° (R)","当前已显示实际方向","放大 (↑)","缩小 (↓)","当前已显示实际大小","全屏浏览","点赞","评论","收藏","保存原图到电脑"];for(var H=0;H<B.length;H++){var J=B.eq(H);b=J.find("h1"),w=J.find("a"),L[H]=[b.prev().find("img")[0].src,b.text(),b.next().text(),w.parent().prev()[0].src,w.text(),w.parent().next().text()],R+='<li><a><img src="'+L[H][0]+'" title="'+L[H][1]+'" /></a></li>'}for(H=0;H<xlicon.length;H++)H<8?xltoolbar+='<a class="xl-photospage-icon xl-ps-icon-'+xlicon[H]+'"></a>':xlhandletab+='<li title="'+xlicontitle[H]+'"><a class="xl-photospage-tab-btn xl-photospage-'+xlicon[H]+'-btn"><i class="xl-photospage-icon xl-ps-icon-'+xlicon[H]+'"></i></a></li>';B.on("click",".xl-photo-img",function(){html.css("overflow","hidden").not("html").append('<div id="xl-mask" class="xl-mask"></div><div id="xl-photospage" class="xl-photospage"><div class="xl-photospage-main"></div></div>'),O=$(this).parent().index(),q=0,C=L.length,T="xl-photospage-imgdisabled",t=$("#xl-mask"),i=t.next(),s=i.find("div.xl-photospage-main");var b=function(e){return e.length<=18?e+"<em> - "+(O+1)+" / "+C+"</em>":e.substring(0,18)+"<em>… - "+(O+1)+" / "+C+"</em>"};s.prepend('<div class="xl-photospage-imgarea"><div class="xl-photospage-state"></div><a class="xl-photospage-icon xl-ps-icon-fullscreenclose" title="退出全屏"></a><div class="xl-photospage-img"><img /></div><div class="xl-photospage-imgsee"><a class="xl-photospage-icon xl-ps-icon-prevphoto" title="上一张 (←)"><!--[if IE 6]> <![endif]--></a><a class="xl-photospage-icon xl-ps-icon-nextphoto" title="下一张 (→)"><!--[if IE 6]> <![endif]--></a><div class="xl-photospage-imgbar"><a class="xl-photospage-showimglist" title="隐藏图片列表">隐藏图片列表</a><span class="xl-photospage-imgtit"></span><div class="xl-photospage-tool">'+xltoolbar+'</div></div></div><div class="xl-photospage-imglist"><a class="xl-photospage-icon xl-ps-icon-listprve"></a><div class="xl-photospage-imglist-list clearfix" ><ul>'+R+'</ul></div><a class="xl-photospage-icon xl-ps-icon-listnext"></a></div><div class="xl-photospage-fullscreen-ious"><div></div></div></div>'),o=s.find("div.xl-photospage-imgarea"),a=o.find("div.xl-photospage-state"),n=o.find("div.xl-photospage-img img"),r=o.find("a.xl-ps-icon-prevphoto"),c=r.next(),x=o.find("div.xl-photospage-imglist-list ul"),g=o.find("a.xl-ps-icon-listprve"),u=x.find("li"),o.after('<div class="xl-photospage-intro"><div class="xl-photospage-content"><h1></h1><div class="xl-photospage-handle-tab"><ul class="clearfix">'+xlhandletab+'</ul></div><div class="xl-photospage-userinfo clearfix"><div class="xl-photospage-user-avatar" onselectstart="return false;"><img alt="上传者头像" /></div><div class="xl-photospage-section"><div class="xl-photospage-user-info"><a href="#"></a></div><div class="xl-photospage-timestamp"></div></div></div><p></p></div></div><div class="xl-photospage-vanish"><a class="xl-photospage-icon xl-ps-icon-close" title="关闭"></a></div>'),$(".xl-photospage-download-btn").attr("download",""),p=s.find("div.xl-photospage-content"),d=o.find("span.xl-photospage-imgtit"),l=s.find("a.xl-ps-icon-close"),h=o.find("a.xl-ps-icon-"+xlicon[1]),f=h.next().next(),v=o.find("a.xl-ps-icon-"+xlicon[6]),m=p.find("div.xl-photospage-timestamp"),k=o.find("a.xl-photospage-showimglist"),$.browser.msie&&"10.0"!==$.browser.version&&$.browser.version<="9.0"&&(h.prev().hide().nextAll().hide(),v.show().prevUntil(f).show(),"9.0"===$.browser.version&&h.prev().show(),$.browser.version<="7.0"&&(k.hide(),x.parent().parent().hide())),U()||v.next().hide();var w=function(){var e;if(z=win.width()-500,F=win.height()-50,E=n.width(),A=n.height(),!ismove&&A>F&&(e=F/A,A=F-34,E=E*e-34),!ismove&&E>z&&(e=z/E,E=z,A*=e),z+300<=1250?d.next().hide():d.next().show(),s.css({width:z+300,height:F}).parent().fadeTo(300,1),o.removeAttr("style").width(z),!ismove&&i.hasClass("xl-imgarea-fullscreen")&&(z+=500),n.css({width:E,height:A,top:(F-A-34)/2,left:(z-E)/2}).stop().fadeTo(500,1),$.browser.msie&&"6.0"===$.browser.version&&(p.parent().css("margin-left",z+15),i.css("top",dom.scrollTop()+25),d.next().hide().parent().width(z)),/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)?(i.addClass("xl-photospage-mobile"),o.width(win.width()).height(win.height()).parent().width(win.width()),n.css({top:(F-A)/2,left:(z+500-E)/2}),i.hasClass("xl-imgarea-fullscreen")&&v.next().click()):i.removeClass("xl-photospage-mobile"),I=Math.round((z-60)/61),D=Math.round((C-I)/7+1),D<1&&(D=1),!X){for(X=!0,S=1,P=0;O+1>=I+P&&S!==D&&O+1>I;)S++,P+=7;S!==D?Y(S):B(),u.removeAttr("class").eq(O).addClass("xl-photospage-current").parent().width(61*C)}ee(D,S),dom.off("mousemove mouseup")},Y=function(e){x.stop().animate({marginLeft:-7*(e-1)*61})},B=function(){1!==D&&(x.stop().animate({marginLeft:-(61*(C-I)+30)}),S=D,P=7*(D-1))},H=function(e){a.text(e).css("left",z/2-a.width()/2-20).stop().show().delay(1500).hide(0),/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)&&a.css("left",z+25-a.width()/2-20)},J=function(e){O+=e,O===C&&(O=0),-1===O&&(O=C-1),N(),V()},K=function(e){q+=e,n.css({transition:"transform .2s linear",transform:"rotate("+q+"deg)"}),isrotate=q/90%4!=0,W()},N=function(){isrotate=!1,q=0,W(),n.css({transform:"",transition:""})},Q=function(){iszoom=!1,n.css({width:y,height:M,top:(F-M-34)/2,left:(z-y)/2}),W()},V=function(){ismove=!1,$(".xl-photospage-download-btn").attr("href",L[O][0]),n.attr("src",L[O][0]).css({opacity:"",width:"",height:""}).parent().removeAttr("style"),p.find("h1").text(L[O][1]).end().find("p").text(L[O][2]),d.html(b(L[O][1])).attr("title",L[O][1]),m.text(L[O][5]).prev().find("a").text(L[O][4]).attr("title",L[O][4]).end().parent().prev().find("img").attr("src",L[O][3]),u.removeAttr("class").eq(O).addClass("xl-photospage-current"),w(),W(),y=E,M=A},W=function(){ismove?Z(ismove,h.prev(),"del","图片居中"):Z(ismove,h.prev(),xlicontitle[0]),iszoom?Z(iszoom,v,"实际大小"):Z(iszoom,v,xlicontitle[3]),isrotate?Z(isrotate,f,"还原方向"):Z(isrotate,f,xlicontitle[3])},Z=function(e,t,i){e?$(t).removeClass(T).attr("title",i):$(t).addClass(T).attr("title",i)},_=function(e){iszoom=!0,E=n.width(),A=n.height(),n.parent().css("background","#000");var t=e*E,i=e*A;if(e>1){if(t>10*y)return!H("已放到最大")}else if(t<y/10)return!H("已缩到最小");n.css({width:t,height:i}).offset({top:n.offset().top-(i-A)/2,left:n.offset().left-(t-E)/2}),H(Math.round(t/y*100)+"%"),W()},ee=function(e,t){e===t?g.next().next().addClass(T):g.next().next().removeClass(T),e>=t&&1!==t?g.removeClass(T):g.addClass(T)},te=function(e){if("next"===e){if(S===D)return S=D,x.is(":animated")||H("已是最后一页啦"),!1;S+1===D?B():(P+=7,S++,Y(S))}else{if(1===S)return x.is(":animated")||H("已是第一页啦"),P=0,!1;S<=0?S=1:(P-=7,S--,Y(S))}ee(D,S)},ie=function(){I+P===O+1&&O+1>=I&&S!==D&&te("next"),(P-7+8===O+1&&1!==S&&S!==D||C-I+1===O+1&&S===D)&&te("prev")};V(),n.on("mousedown",function(e){var t,i;1===e.which&&(isdrag=!isdrag,q/90%4==0?(t=e.originalEvent.pageX-n.position().left,i=e.originalEvent.pageY-n.position().top):(t=e.originalEvent.pageX-n.offset().left,i=e.originalEvent.pageY-n.offset().top),dom.on("mousemove",function(e){ismove=!0,W(),q/90%4==0?n.css({top:e.originalEvent.pageY-i,left:e.originalEvent.pageX-t}):n.offset({top:e.originalEvent.pageY-i,left:e.originalEvent.pageX-t})}).on("mouseup",function(){var e=n.position().left,t=n.position().top;if(t<50-A||e<40-E&&q/90%4==0||e>z-40||t>F-110||e<40-A&&q/90%4!=0)return!1;isdrag=!isdrag,dom.off("mousemove mouseup")}));return!1}).parent().on("dblclick",function(){U()&&v.next().click()}).on("mousewheel DOMMouseScroll",function(e){if($.browser.msie&&"6.0"===$.browser.version)return!1;if(!isdrag){var t=e.originalEvent.wheelDelta&&(e.originalEvent.wheelDelta>0?1:-1)||e.originalEvent.detail&&(e.originalEvent.detail>0?-1:1);t>0?f.next().click():v.prev().click()}}),i.on("click",function(e){var s=e.target;switch(s){case l[0]:X=!X,$.browser.msie&&($.browser.version<"9.0"||"10.0"===$.browser.version)?(t.detach(),i.detach()):t.fadeTo(300,0,function(){$(this).detach()}).next().fadeTo(250,0,function(){$(this).detach()}),html.removeAttr("style").not("html").css("background-color","#f4f4f4"),dom.off("keyup");break;case r[0]:0===O?B():ie(),J(-1);break;case c[0]:O+1===C&&(P=0,S=1,Y(S)),S===D?B():ie(),J(1);break;case h.prev()[0]:if(h.prev().hasClass(T)){H("图片已居中");break}ismove=!1,w(),W();break;case h[0]:K(-90);break;case h.next()[0]:K(90);break;case f[0]:if(f.hasClass(T)){H("已显示实际方向");break}N();break;case f.next()[0]:_(1.1);break;case v.prev()[0]:_(.9);break;case v[0]:if(v.hasClass(T)){H("已显示实际大小");break}Q(),H("100%");break;case v.next()[0]:U()?(j()?G().call(document):U().call(o[0]),h.prev().hasClass(T)||(ismove=!1,W())):H("浏览器不支持全屏");break;case a.next()[0]:v.next().click();break;case g[0]:te("prev");break;case g.next().next()[0]:te("next");break;case k[0]:isshowimglist?(k.text("隐藏图片列表").attr("title","隐藏图片列表").parent().removeClass("hide-imglist"),x.parent().parent().removeAttr("style")):(k.text("显示图片列表").attr("title","显示图片列表").parent().addClass("hide-imglist"),x.parent().parent().css("height","0")),isshowimglist=!isshowimglist}}),t.on("dblclick",function(){l.click()}),x.on("click","a",function(){return O=$(this).parent().index(),ie(),N(),!V()}).on("mousewheel DOMMouseScroll",function(e){if($.browser.msie&&"6.0"===$.browser.version)return!1;if(!isdrag){var t=e.originalEvent.wheelDelta&&(e.originalEvent.wheelDelta>0?1:-1)||e.originalEvent.detail&&(e.originalEvent.detail>0?-1:1);t>0?g.click():g.next().next().click()}}),dom.on("keyup",function(e){var t=e.keyCode||e.which||e.charCode;switch(t){case 27:if(i.hasClass("xl-imgarea-fullscreen"))break;l.click();break;case 37:0!==O&&r.click();break;case 38:f.next().click();break;case 39:c.click();break;case 40:v.prev().click();break;case 76:h.click();break;case 82:h.next().click()}return!1}),win.on("resize",function(){e&&e&&clearTimeout(e),e=setTimeout(function(){var e=$(".xl-photospage-fullscreen-ious"),t=[r[0],c[0]];if(j()){isshowimglist?e.prev().removeAttr("style"):(o.addClass("above"),setTimeout(function(){o.removeClass("above")},1750));var s,a=function(){var e;if(j())if(o.hasClass("above"))r.is(":animated")||$(t).fadeOut();else{for(var i=0;i<t.length;i++)if($(t[i]).is(":hover")){$(t).not($(t[i])).fadeOut(),e=!0;break}e||(c.next().fadeOut(),$(t).fadeOut(),e=!e)}};o.on("mouseenter",function(){a()}).on("mousemove",function(i){e.on("mouseover",function(){isdrag||o.addClass("above")}),win.height()-130>i.originalEvent.pageY&&o.removeClass("above"),c.next().is(":animated")||(c.next().fadeIn(),$(t).fadeIn()),s&&clearTimeout(s),s=setTimeout(a,1750)}),i.addClass("xl-imgarea-fullscreen")}else isshowimglist&&k.click(),e.off("mouseover").prev().prev().find("div,a").removeAttr("style"),o.off("mouseenter").off("mousemove").parent().parent().removeClass("xl-imgarea-fullscreen");n.css({width:y,height:M}),w()},200)})})});