UNPKG

@newbiz/common-libs

Version:

신사업개발실 서비스/어드민 프론트엔드 공통 라이브러리

1 lines 2.96 kB
"use strict";var r=this&&this.__assign||function(){return(r=Object.assign||function(e){for(var o,t=1,n=arguments.length;t<n;t++)for(var r in o=arguments[t])Object.prototype.hasOwnProperty.call(o,r)&&(e[r]=o[r]);return e}).apply(this,arguments)},t=(Object.defineProperty(exports,"__esModule",{value:!0}),exports.openWindow=exports.scroll=exports.unfreezeBody=exports.freezeBody=exports.getImageSize=exports.getScrollOffsetY=exports.getScrollOffsetX=exports.documentBody=void 0,"ui-frozen-body-style"),e=function(){return document.documentElement||document.body.parentNode||document.body};function getScrollOffsetX(){return window.pageXOffset||e().scrollLeft||document.body.scrollLeft}function getScrollOffsetY(){return window.pageYOffset||e().scrollTop||document.body.scrollTop}exports.documentBody="undefined"!=typeof window?e():null,exports.getScrollOffsetX=getScrollOffsetX,exports.getScrollOffsetY=getScrollOffsetY,exports.getImageSize=function getImageSize(n){return new Promise(function(e,o){var t=new Image;try{t.src=n,t.onload=function(){return e({url:n,width:t.width,height:t.height})}}catch(e){o(e)}})},exports.freezeBody=function freezeBody(){document.getElementById(t)||((e=document.createElement("style")).id=t,e.innerText=".__ui-frozen-body__{position:fixed;overflow:hidden;top:auto;left:0;right:0;margin-top:0;height:auto;min-height:100%;-webkit-backface-visibility:hidden;-moz-backface-visibility:hidden;backface-visibility:hidden;}",document.head.append(e));var e=getScrollOffsetX(),o=getScrollOffsetY();document.body.style.marginLeft="".concat(-e,"px"),document.body.style.marginTop="".concat(-o,"px"),document.body.classList?document.body.classList.add("__ui-frozen-body__"):document.body.className+="__ui-frozen-body__"},exports.unfreezeBody=function unfreezeBody(){var e=Math.abs(parseInt(document.body.style.marginLeft,10)),o=Math.abs(parseInt(document.body.style.marginTop,10));document.body.style.marginLeft="",document.body.style.marginTop="",document.body.classList?document.body.classList.remove("__ui-frozen-body__"):(document.body.className=document.body.className.replace("__ui-frozen-body__",""),document.body.className||document.body.removeAttribute("class")),window.scrollTo(e,o)},exports.scroll=function scroll(e){var o,t,n=r(r({},{el:null,marginTop:0,marginLeft:0}),e);null!=(e=n.el)&&e.getClientRects&&(e=n.el.getClientRects()[0]||{top:0,left:0},o=e.top+window.scrollY,t=e.left+window.scrollX,setTimeout(function(){var e;window.scroll({top:o+(null!=(e=n.marginTop)?e:0),left:t+(null!=(e=n.marginLeft)?e:0),behavior:"smooth"})},0))},exports.openWindow=function openWindow(e){var o=e.url,t=e.id,n=e.features,r=e.onFocus,l=e.onBlur,s=e.onClose,d=window.open(o,null!=t?t:"_blank",n);return d&&(r&&(d.onfocus=r),l&&(d.onblur=l),s&&(d.onbeforeunload=function onBeforeUnload(e){var o=this;setTimeout(function(){d&&(d.closed?(d=null,s.bind(o,e)()):(r&&(d.onfocus=r),l&&(d.onblur=l),d.onbeforeunload=onBeforeUnload))},100)}),d.focus()),d};