UNPKG

ngx-bootstrap

Version:
2 lines 3.88 kB
!function(t,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports,require("@angular/core")):"function"==typeof define&&define.amd?define("ngx-bootstrap/positioning",["exports","@angular/core"],o):o((t["ngx-bootstrap"]=t["ngx-bootstrap"]||{},t["ngx-bootstrap"].positioning={}),t.ng.core)}(this,function(t,o){"use strict";var e=function(){function t(){}return t.prototype.position=function(t,o){var e;void 0===o&&(o=!0);var i={width:0,height:0,top:0,bottom:0,left:0,right:0};if("fixed"===this.getStyle(t,"position")){var n=t.getBoundingClientRect();e={width:n.width,height:n.height,top:n.top,bottom:n.bottom,left:n.left,right:n.right}}else{var r=this.offsetParent(t);e=this.offset(t,!1),r!==document.documentElement&&(i=this.offset(r,!1)),i.top+=r.clientTop,i.left+=r.clientLeft}return e.top-=i.top,e.bottom-=i.top,e.left-=i.left,e.right-=i.left,o&&(e.top=Math.round(e.top),e.bottom=Math.round(e.bottom),e.left=Math.round(e.left),e.right=Math.round(e.right)),e},t.prototype.offset=function(t,o){void 0===o&&(o=!0);var e=t.getBoundingClientRect(),i=window.pageYOffset-document.documentElement.clientTop,n=window.pageXOffset-document.documentElement.clientLeft,r={height:e.height||t.offsetHeight,width:e.width||t.offsetWidth,top:e.top+i,bottom:e.bottom+i,left:e.left+n,right:e.right+n};return o&&(r.height=Math.round(r.height),r.width=Math.round(r.width),r.top=Math.round(r.top),r.bottom=Math.round(r.bottom),r.left=Math.round(r.left),r.right=Math.round(r.right)),r},t.prototype.positionElements=function(t,o,e,i){var n=i?this.offset(t,!1):this.position(t,!1),r=this.getAllStyles(o),h=o.getBoundingClientRect(),f=e.split(" ")[0]||"top",p=e.split(" ")[1]||"center",s={height:h.height||o.offsetHeight,width:h.width||o.offsetWidth,top:0,bottom:h.height||o.offsetHeight,left:0,right:h.width||o.offsetWidth},l={top:n.top,center:n.top+n.height/2-s.height/2,bottom:n.top+n.height},d={left:n.left,center:n.left+n.width/2-s.width/2,right:n.left+n.width};if("auto"===f){var g=this.autoPosition(s,n,o,p);g||(g=this.autoPosition(s,n,o)),g&&(f=g),o.classList.add(f)}switch(f){case"top":s.top=n.top-(s.height+parseFloat(r.marginBottom)),s.bottom+=n.top-s.height,s.left=d[p],s.right+=d[p];break;case"bottom":s.top=l[f],s.bottom+=l[f],s.left=d[p],s.right+=d[p];break;case"left":s.top=l[p],s.bottom+=l[p],s.left=n.left-(s.width+parseFloat(r.marginRight)),s.right+=n.left-s.width;break;case"right":s.top=l[p],s.bottom+=l[p],s.left=d[f],s.right+=d[f]}return s.top=Math.round(s.top),s.bottom=Math.round(s.bottom),s.left=Math.round(s.left),s.right=Math.round(s.right),s},t.prototype.autoPosition=function(t,o,e,i){return(!i||"right"===i)&&t.left+o.left-t.width<0?"right":(!i||"top"===i)&&t.bottom+o.bottom+t.height>window.innerHeight?"top":(!i||"bottom"===i)&&t.top+o.top-t.height<0?"bottom":(!i||"left"===i)&&t.right+o.right+t.width>window.innerWidth?"left":null},t.prototype.getAllStyles=function(t){return window.getComputedStyle(t)},t.prototype.getStyle=function(t,o){return this.getAllStyles(t)[o]},t.prototype.isStaticPositioned=function(t){return"static"===(this.getStyle(t,"position")||"static")},t.prototype.offsetParent=function(t){for(var o=t.offsetParent||document.documentElement;o&&o!==document.documentElement&&this.isStaticPositioned(o);)o=o.offsetParent;return o||document.documentElement},t}(),r=new e;function h(t,o,e,i){var n=r.positionElements(t,o,e,i);o.style.top=n.top+"px",o.style.left=n.left+"px"}var i=function(){function t(){}return t.prototype.position=function(t){var o=t.element,e=t.target,i=t.attachment,n=t.appendToBody;h(f(e),f(o),i,n)},t.decorators=[{type:o.Injectable}],t}();function f(t){return"string"==typeof t?document.querySelector(t):t instanceof o.ElementRef?t.nativeElement:t}t.positionElements=h,t.Positioning=e,t.PositioningService=i,Object.defineProperty(t,"__esModule",{value:!0})}); //# sourceMappingURL=ngx-bootstrap-positioning.umd.min.js.map