-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsg.min.js
1 lines (1 loc) · 3.29 KB
/
sg.min.js
1
var sg=function(){var k,p,f,v=document.getElementById("sgBg"),q=document.getElementById("sgLayer"),d=document.getElementById("sgImg"),r=document.getElementById("sgNav"),s=document.getElementById("sgAct"),c,l=!0,w=!0,h="auto",j="auto",m=!0,t=!0,n,x,u,y=!1,z="block",no="none",da="data-";return{init:function(){for(var a=document.getElementsByTagName("a"),b=a.length;b--;){var c=this.gD(a[b],"sg"),d=a[b].className;c&&(a[b].onclick=sg.show,a[b].className=d+" "+c)}q.onclick=sg.close},show:function(){w&&sg.preLoad({});k=document.getElementsByClassName(sg.gD(this,"sg"));var a=p=k.length;if(1<a){for(sg.sD(this,"sGo","true");a--;)sg.gD(k[a],"sGo")&&(f=a);sg.rD(this,"sGo");r.style.display=z}else r.style.display=no;v.style.display=q.style.display=z;sg.load(this.href);return!1},preLoad:function(a){n=a.LoadImg?a.LoadImg:"//cdn.34n.de/sg/load.gif";a.max_width_all&&(h=a.max_width_all);a.max_height_all&&(j=a.max_height_all);void 0!==a.ratio&&(m=!0===a.ratio?!0:!1);void 0!==a.smart_control&&(t=!0===a.smart_control?!0:!1);a=document.createElement("img");a.src=n;a.onclick=function(){l=!1};d.appendChild(a);a=new Image;a.onload=function(){x=this.width;u=this.height;y||sg.showLoad()};a.src=n;window.document.addEventListener?window.document.addEventListener("keydown",sg.kE,!1):window.document.attachEvent("onkeydown",sg.kE);c=s.getElementsByTagName("a");w=!1;return!0},showLoad:function(){d.style.width=d.lastElementChild.style.width=x+"px";d.style.height=d.lastElementChild.style.height=u+"px";d.lastElementChild.src=n;d.style.marginTop=Math.floor(sg.gH()/2)-u/2+"px";d.style.display=z;s.style.display=no;!0===t&&(c[0].style.top=c[0].style.right=c[1].style.bottom=c[1].style.left="6px",c[0].style.width=c[1].style.width="5%",c[0].style.minWidth=c[1].style.minWidth="64px");return!0},go:function(a){l=!1;sg.showLoad()&&(f+=a,p===f?f=0:0>f&&(f=-1+p),sg.load(k[f]));return!1},load:function(a){var b=new Image;b.onload=function(){y=!0;var a=this.width,b=this.height,f=sg.gH(),e=Math.max(document.documentElement.clientWidth,document.body.offsetWidth,document.documentElement.offsetWidth),e=Math.floor(0.6*e),g=Math.floor(0.8*f);"auto"!==j&&"auto"!==h&&!0===m?h<j?(g=Math.floor(g/(e/h)),e=h):(e=Math.floor(e/(g/j)),g=j):("auto"!==h&&e>h&&(e=h),"auto"!==j&&g>j&&(g=j));if(a>e||b>g)a>e&&(!0===m&&(b=Math.floor(b/(a/e))),a=e),b>g&&(!0===m&&(a=Math.floor(a/(b/g))),b=g);d.lastElementChild.src=c[1].href=this.src;d.style.marginTop=Math.floor(f/2)-Math.floor(b/2)+"px";1<k.length&&(r.style.display=z);d.lastElementChild.style.width=d.style.width=a+"px";d.lastElementChild.style.height=d.style.height=b+"px";if(!0===t&&(300>=b||300>=a))c[0].style.width=c[1].style.width=a+12+"px",c[1].style.bottom=c[0].style.top="-64px",c[1].style.left=c[0].style.right="0";s.style.display=z;d.style.display=z};b.src=a},close:function(){l&&(v.style.display=q.style.display=no,sg.showLoad());l=!0},kE:function(a){ev=a?a:event;if(27===ev.keyCode)return sg.close(),!0;1<k.length&&(37===ev.keyCode?sg.go(-1):39===ev.keyCode&&sg.go(1));return!0},gH:function(){return Math.min(document.documentElement.clientHeight,document.body.offsetHeight,document.documentElement.offsetHeight)},gD:function(a,b){return a.dataset?a.dataset[b]:a.getAttribute(da+b)},sD:function(a,b,c){a.dataset?a.dataset[b]=c:a.setAttribute(da+b,c)},rD:function(a,b){a.dataset?delete a.dataset[b]:a.removeAttribute(da+b)}}}();sg.init();