MCPcopy Create free account
hub / github.com/hoothin/UserScripts / keepSI

Function keepSI

Picviewer CE+/Picviewer CE+.user.js:22427–22479  ·  view source on GitHub ↗
(obj,offsetDirection,defaultValue, out)

Source from the content-addressed store, hash-verified

22425 var windowSize=getWindowSize();
22426
22427 function keepSI(obj,offsetDirection,defaultValue, out){
22428 var objRect=obj.getBoundingClientRect();
22429 var objStyle=obj.style;
22430 var insert=false;
22431
22432 while(offsetDirection.length){
22433 var oD=offsetDirection[0];
22434 var oDV=defaultValue[0];
22435 var outV=0;
22436 if(out)outV=out.shift();
22437 offsetDirection.shift();
22438 defaultValue.shift();
22439 var oValue=parseFloat(objStyle[oD]);
22440 var newValue;
22441 switch(oD){
22442 case 'top':
22443 newValue=oValue - objRect.top - outV;
22444 if(objRect.top-outV<=0){
22445 newValue=Math.min(newValue,imgWindowFullSize.h);
22446 }else{
22447 newValue=Math.max(newValue,oDV);
22448 };
22449 break;
22450 case 'right':
22451 newValue=oValue + (objRect.right - windowSize.w) + outV;
22452 if(objRect.right+outV >= windowSize.w){//屏幕外
22453 newValue=Math.min(newValue,imgWindowFullSize.w);
22454 }else{
22455 newValue=Math.max(newValue,oDV);
22456 };
22457 break;
22458 case 'bottom':
22459 newValue=oValue + (objRect.bottom - windowSize.h) + outV;
22460 if(objRect.bottom+outV >= windowSize.h){//屏幕外
22461 newValue=Math.min(newValue,imgWindowFullSize.h);
22462 }else{
22463 newValue=Math.max(newValue,oDV);
22464 };
22465 break;
22466 case 'left':
22467 newValue=oValue - objRect.left - outV;
22468 if(objRect.left-outV<=0){
22469 newValue=Math.min(newValue,imgWindowFullSize.w);
22470 }else{
22471 newValue=Math.max(newValue,oDV);
22472 }
22473 break;
22474 }
22475 insert=insert||newValue!==oDV;
22476 objStyle[oD]=newValue + 'px';
22477 }
22478 insert ? obj.classList.add("insert") : obj.classList.remove("insert");
22479 }
22480
22481 keepSI(this.closeButton,['top','right'],[-22,0]);
22482 keepSI(this.maxButton,['top','right'],[-22,46],[0,46]);

Callers 1

initFunction · 0.70

Calls 1

removeMethod · 0.80

Tested by

no test coverage detected