UNPKG

ng-zorro-antd

Version:

An enterprise-class UI components based on Ant Design and Angular

2 lines 6.48 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/cdk/platform"),require("@angular/common"),require("@angular/core"),require("ng-zorro-antd/core")):"function"==typeof define&&define.amd?define("ng-zorro-antd/affix",["exports","@angular/cdk/platform","@angular/common","@angular/core","ng-zorro-antd/core"],e):e((t["ng-zorro-antd"]=t["ng-zorro-antd"]||{},t["ng-zorro-antd"].affix={}),t.ng.cdk.platform,t.ng.common,t.ng.core,t["ng-zorro-antd"].core)}(this,function(t,e,o,n,f){"use strict";var d=function(){return(d=Object.assign||function(t){for(var e,o=1,i=arguments.length;o<i;o++)for(var n in e=arguments[o])Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t}).apply(this,arguments)};function i(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}var r=function(){function t(t,e,o,i){this.scrollSrv=e,this.doc=o,this.platform=i,this.nzChange=new n.EventEmitter,this.events=["resize","scroll","touchstart","touchmove","touchend","pageshow","load"],this._target=null,this.placeholderNode=t.nativeElement,this.platform.isBrowser&&(this._target=window)}return Object.defineProperty(t.prototype,"nzTarget",{set:function(t){this.platform.isBrowser&&(this.clearEventListeners(),this._target="string"==typeof t?this.doc.querySelector(t):t||window,this.setTargetEventListeners(),this.updatePosition({}))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"nzOffsetTop",{get:function(){return this._offsetTop},set:function(t){t!==undefined&&null!==t&&(this._offsetTop=f.toNumber(t,null),this.updatePosition({}))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"nzOffsetBottom",{set:function(t){void 0!==t&&(this._offsetBottom=f.toNumber(t,null),this.updatePosition({}))},enumerable:!0,configurable:!0}),t.prototype.ngOnInit=function(){var t=this;this.timeout=setTimeout(function(){t.setTargetEventListeners(),t.updatePosition({})})},t.prototype.ngOnDestroy=function(){this.clearEventListeners(),clearTimeout(this.timeout),this.updatePosition.cancel()},t.prototype.getOffset=function(t,e){var o=t.getBoundingClientRect(),i=this.getTargetRect(e),n=this.scrollSrv.getScroll(e,!0),r=this.scrollSrv.getScroll(e,!1),s=this.doc.body,f=s.clientTop||0,l=s.clientLeft||0;return{top:o.top-i.top+n-f,left:o.left-i.left+r-l,width:o.width,height:o.height}},t.prototype.setTargetEventListeners=function(){var e=this;this.clearEventListeners(),this.platform.isBrowser&&this.events.forEach(function(t){e._target.addEventListener(t,e.updatePosition,!1)})},t.prototype.clearEventListeners=function(){var e=this;this.platform.isBrowser&&this.events.forEach(function(t){e._target.removeEventListener(t,e.updatePosition,!1)})},t.prototype.getTargetRect=function(t){return t!==window?t.getBoundingClientRect():{top:0,left:0,bottom:0}},t.prototype.genStyle=function(o){return o?Object.keys(o).map(function(t){var e=o[t];return t+":"+("string"==typeof e?e:e+"px")}).join(";"):""},t.prototype.setAffixStyle=function(t,e){var o=this.affixStyle,i=this._target===window;if(!("scroll"===t.type&&o&&e&&i||f.shallowEqual(o,e))){var n=!!e,r=this.fixedEl.nativeElement;r.style.cssText=this.genStyle(e),this.affixStyle=e;var s="ant-affix";n?r.classList.add(s):r.classList.remove(s),(e&&!o||!e&&o)&&this.nzChange.emit(n)}},t.prototype.setPlaceholderStyle=function(t){var e=this.placeholderStyle;f.shallowEqual(t,e)||(this.placeholderNode.style.cssText=this.genStyle(t),this.placeholderStyle=t)},t.prototype.syncPlaceholderStyle=function(t){if(this.affixStyle){this.placeholderNode.style.cssText="",this.placeholderStyle=undefined;var e={width:this.placeholderNode.offsetWidth,height:this.fixedEl.nativeElement.offsetHeight};this.setAffixStyle(t,d({},this.affixStyle,e)),this.setPlaceholderStyle(e)}},t.prototype.updatePosition=function(t){if(this.platform.isBrowser){var e=this._target,o=this.nzOffsetTop,i=this.scrollSrv.getScroll(e,!0),n=this.getOffset(this.placeholderNode,e),r=this.fixedEl.nativeElement,s={width:r.offsetWidth,height:r.offsetHeight},f={top:!1,bottom:!1};"number"!=typeof o&&"number"!=typeof this._offsetBottom?(f.top=!0,o=0):(f.top="number"==typeof o,f.bottom="number"==typeof this._offsetBottom);var l=this.getTargetRect(e),a=e.innerHeight||e.clientHeight;if(i>=n.top-o&&f.top){var h=n.width,c=l.top+o;this.setAffixStyle(t,{position:"fixed",top:c,left:l.left+n.left,maxHeight:"calc(100vh - "+c+"px)",width:h}),this.setPlaceholderStyle({width:h,height:s.height})}else if(i<=n.top+s.height+this._offsetBottom-a&&f.bottom){var p=e===window?0:window.innerHeight-l.bottom;h=n.width;this.setAffixStyle(t,{position:"fixed",bottom:p+this._offsetBottom,left:l.left+n.left,width:h}),this.setPlaceholderStyle({width:h,height:n.height})}else"resize"===t.type&&this.affixStyle&&"fixed"===this.affixStyle.position&&this.placeholderNode.offsetWidth?this.setAffixStyle(t,d({},this.affixStyle,{width:this.placeholderNode.offsetWidth})):this.setAffixStyle(t),this.setPlaceholderStyle();"resize"===t.type&&this.syncPlaceholderStyle(t)}},t.decorators=[{type:n.Component,args:[{selector:"nz-affix",exportAs:"nzAffix",template:"<div #fixedEl>\n <ng-content></ng-content>\n</div>",changeDetection:n.ChangeDetectionStrategy.OnPush,encapsulation:n.ViewEncapsulation.None,styles:["\n nz-affix {\n display: block;\n }\n "]}]}],t.ctorParameters=function(){return[{type:n.ElementRef},{type:f.NzScrollService},{type:undefined,decorators:[{type:n.Inject,args:[o.DOCUMENT]}]},{type:e.Platform}]},t.propDecorators={nzTarget:[{type:n.Input}],nzOffsetTop:[{type:n.Input}],nzOffsetBottom:[{type:n.Input}],nzChange:[{type:n.Output}],fixedEl:[{type:n.ViewChild,args:["fixedEl"]}]},function(t,e,o,i){var n,r=arguments.length,s=r<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,o):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,o,i);else for(var f=t.length-1;0<=f;f--)(n=t[f])&&(s=(r<3?n(s):3<r?n(e,o,s):n(e,o))||s);3<r&&s&&Object.defineProperty(e,o,s)}([f.throttleByAnimationFrameDecorator(),i("design:type",Function),i("design:paramtypes",[Event]),i("design:returntype",void 0)],t.prototype,"updatePosition",null),t}(),s=function(){function t(){}return t.decorators=[{type:n.NgModule,args:[{declarations:[r],exports:[r],imports:[o.CommonModule],providers:[f.SCROLL_SERVICE_PROVIDER]}]}],t}();t.NzAffixComponent=r,t.NzAffixModule=s,Object.defineProperty(t,"__esModule",{value:!0})}); //# sourceMappingURL=ng-zorro-antd-affix.umd.min.js.map