UNPKG

@duoduo-oba/ng-devui

Version:

DevUI components based on Angular

2 lines 3.66 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("ng-devui/window-ref")):"function"==typeof define&&define.amd?define("ng-devui/position",["exports","@angular/core","ng-devui/window-ref"],e):e(((t=t||self)["ng-devui"]=t["ng-devui"]||{},t["ng-devui"].position={}),t.ng.core,t["ng-devui"]["window-ref"])}(this,(function(t,e,o){"use strict";var i=function(){function t(t,e){this.documentRef=t,this.windowRef=e}return t.prototype.position=function(t,e){var o;void 0===e&&(e=!0);var i={width:0,height:0,top:0,bottom:0,left:0,right:0};if("fixed"===this.getStyle(t,"position"))o=t.getBoundingClientRect();else{var n=this.offsetParent(t);o=this.offset(t,!1),n!==this.documentRef.documentElement&&(i=this.offset(n,!1)),i.top+=n.clientTop-n.scrollTop,i.left+=n.clientLeft-n.scrollLeft}return o.top-=i.top,o.bottom-=i.top,o.left-=i.left,o.right-=i.left,e&&(o.top=Math.round(o.top),o.bottom=Math.round(o.bottom),o.left=Math.round(o.left),o.right=Math.round(o.right)),o},t.prototype.offset=function(t,e){void 0===e&&(e=!0);var o=t.getBoundingClientRect(),i=this.windowRef.pageYOffset-this.documentRef.documentElement.clientTop,n=this.windowRef.pageXOffset-this.documentRef.documentElement.clientLeft,f={height:o.height||t.offsetHeight,width:o.width||t.offsetWidth,top:o.top+i,bottom:o.bottom+i,left:o.left+n,right:o.right+n};return e&&(f.height=Math.round(f.height),f.width=Math.round(f.width),f.top=Math.round(f.top),f.bottom=Math.round(f.bottom),f.left=Math.round(f.left),f.right=Math.round(f.right)),f},t.prototype.getScrollParent=function(t){var e=getComputedStyle(t),o="absolute"===e.position,i=/(auto|scroll|hidden)/;if("fixed"===e.position)return this.documentRef.body;for(var n=t;n=n.parentElement;n.parentElement!==this.documentRef.body)if(e=getComputedStyle(n),(!o||"static"!==e.position)&&i.test(e.overflow+e.overflowY+e.overflowX))return n;return this.documentRef.body},t.prototype.positionElements=function(t,e,o,i){var n=i?this.offset(t,!1):this.position(t,!1),f={left:n.left,center:n.left+n.width/2-e.offsetWidth/2,right:n.left+n.width},r={top:n.top,center:n.top+n.height/2-e.offsetHeight/2,bottom:n.top+n.height},h=e.getBoundingClientRect(),d=o.split("-")[0]||"top",s=o.split("-")[1]||"center",u={height:h.height||e.offsetHeight,width:h.width||e.offsetWidth,top:0,bottom:h.height||e.offsetHeight,left:0,right:h.width||e.offsetWidth};switch(d){case"top":u.top=n.top-e.offsetHeight,u.bottom+=n.top-e.offsetHeight,u.left=f[s],u.right+=f[s];break;case"bottom":u.top=r[d],u.bottom+=r[d],u.left=f[s],u.right+=f[s];break;case"left":u.top=r[s],u.bottom+=r[s],u.left=n.left-e.offsetWidth,u.right+=n.left-e.offsetWidth;break;case"right":u.top=r[s],u.bottom+=r[s],u.left=f[d],u.right+=f[d]}return u.top=Math.round(u.top),u.bottom=Math.round(u.bottom),u.left=Math.round(u.left),u.right=Math.round(u.right),u},t.prototype.getStyle=function(t,e){return this.windowRef.getComputedStyle(t)[e]},t.prototype.isStaticPositioned=function(t){return"static"===(this.getStyle(t,"position")||"static")},t.prototype.offsetParent=function(t){for(var e=t.offsetParent||this.documentRef.documentElement;e&&e!==this.documentRef.documentElement&&this.isStaticPositioned(e);)e=e.offsetParent;return e||this.documentRef.documentElement},t.decorators=[{type:e.Injectable}],t.ctorParameters=function(){return[{type:o.DocumentRef},{type:o.WindowRef}]},t}();var n=function(){function t(){}return t.decorators=[{type:e.NgModule,args:[{providers:[i,o.DocumentRef,o.WindowRef]}]}],t}();t.PositionService=i,t.PositioningModule=n,Object.defineProperty(t,"__esModule",{value:!0})})); //# sourceMappingURL=ng-devui-position.umd.min.js.map