UNPKG

ng-zorro-antd

Version:

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

10 lines 6.87 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/cdk/platform"),require("@angular/common"),require("@angular/core"),require("rxjs"),require("rxjs/operators"),require("ng-zorro-antd/core")):"function"==typeof define&&define.amd?define("ng-zorro-antd/affix",["exports","@angular/cdk/platform","@angular/common","@angular/core","rxjs","rxjs/operators","ng-zorro-antd/core"],e):e(((t=t||self)["ng-zorro-antd"]=t["ng-zorro-antd"]||{},t["ng-zorro-antd"].affix={}),t.ng.cdk.platform,t.ng.common,t.ng.core,t.rxjs,t.rxjs.operators,t["ng-zorro-antd"].core)}(this,function(t,e,o,i,r,n,s){"use strict";var f=function(){return(f=Object.assign||function(t){for(var e,o=1,i=arguments.length;o<i;o++)for(var r in e=arguments[o])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t}).apply(this,arguments)};function l(t,e,o,i){var r,n=arguments.length,s=n<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;f>=0;f--)(r=t[f])&&(s=(n<3?r(s):n>3?r(e,o,s):r(e,o))||s);return n>3&&s&&Object.defineProperty(e,o,s),s}function a(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}function c(t,e){var o="function"==typeof Symbol&&t[Symbol.iterator];if(!o)return t;var i,r,n=o.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(i=n.next()).done;)s.push(i.value)}catch(t){r={error:t}}finally{try{i&&!i.done&&(o=n.return)&&o.call(n)}finally{if(r)throw r.error}}return s}var h=["resize","scroll","touchstart","touchmove","touchend","pageshow","load"],p=function(){function t(t,e,o,n,s,f){this.nzConfigService=o,this.scrollSrv=n,this.ngZone=s,this.platform=f,this.nzChange=new i.EventEmitter,this.scroll$=r.Subscription.EMPTY,this.placeholderNode=t.nativeElement,this.document=e}return Object.defineProperty(t.prototype,"target",{get:function(){var t=this.nzTarget;return("string"==typeof t?this.document.querySelector(t):t)||window},enumerable:!0,configurable:!0}),t.prototype.ngOnChanges=function(t){var e=t.nzOffsetBottom,o=t.nzOffsetTop,i=t.nzTarget;(e||o)&&this.updatePosition({}),i&&this.registerListeners()},t.prototype.ngAfterViewInit=function(){this.registerListeners()},t.prototype.ngOnDestroy=function(){this.removeListeners()},t.prototype.registerListeners=function(){var t=this;this.removeListeners(),this.scroll$=this.ngZone.runOutsideAngular(function(){return r.merge.apply(void 0,function(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(c(arguments[e]));return t}(h.map(function(e){return r.fromEvent(t.target,e)}))).pipe(n.auditTime(20)).subscribe(function(e){return t.updatePosition(e)})}),this.timeout=setTimeout(function(){return t.updatePosition({})})},t.prototype.removeListeners=function(){clearTimeout(this.timeout),this.scroll$.unsubscribe()},t.prototype.getOffset=function(t,e){var o=t.getBoundingClientRect(),i=this.getTargetRect(e),r=this.scrollSrv.getScroll(e,!0),n=this.scrollSrv.getScroll(e,!1),s=this.document.body,f=s.clientTop||0,l=s.clientLeft||0;return{top:o.top-i.top+r-f,left:o.left-i.left+n-l,width:o.width,height:o.height}},t.prototype.getTargetRect=function(t){ /** * @license * Copyright Alibaba.com All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE */ return function(t){return"undefined"!=typeof window&&t===window}(t)?{top:0,left:0,bottom:0}:t.getBoundingClientRect()},t.prototype.setAffixStyle=function(t,e){var o=this.affixStyle,i=this.target===window;if(!("scroll"===t.type&&o&&e&&i||s.shallowEqual(o,e))){var r=!!e,n=this.fixedEl.nativeElement;n.style.cssText=s.getStyleAsText(e),this.affixStyle=e,r?n.classList.add("ant-affix"):n.classList.remove("ant-affix"),(e&&!o||!e&&o)&&this.nzChange.emit(r)}},t.prototype.setPlaceholderStyle=function(t){var e=this.placeholderStyle;s.shallowEqual(t,e)||(this.placeholderNode.style.cssText=s.getStyleAsText(t),this.placeholderStyle=t)},t.prototype.syncPlaceholderStyle=function(t){if(this.affixStyle){this.placeholderNode.style.cssText="",this.placeholderStyle=void 0;var e={width:this.placeholderNode.offsetWidth,height:this.fixedEl.nativeElement.offsetHeight};this.setAffixStyle(t,f({},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),r=this.getOffset(this.placeholderNode,e),n=this.fixedEl.nativeElement,s={width:n.offsetWidth,height:n.offsetHeight},l={top:!1,bottom:!1};"number"!=typeof o&&"number"!=typeof this.nzOffsetBottom?(l.top=!0,o=0):(l.top="number"==typeof o,l.bottom="number"==typeof this.nzOffsetBottom);var a=this.getTargetRect(e),c=e.innerHeight||e.clientHeight;if(i>=r.top-o&&l.top){var h=r.width,p=a.top+o;this.setAffixStyle(t,{position:"fixed",top:p,left:a.left+r.left,maxHeight:"calc(100vh - "+p+"px)",width:h}),this.setPlaceholderStyle({width:h,height:s.height})}else if(i<=r.top+s.height+this.nzOffsetBottom-c&&l.bottom){var u=e===window?0:window.innerHeight-a.bottom;h=r.width;this.setAffixStyle(t,{position:"fixed",bottom:u+this.nzOffsetBottom,left:a.left+r.left,width:h}),this.setPlaceholderStyle({width:h,height:r.height})}else"resize"===t.type&&this.affixStyle&&"fixed"===this.affixStyle.position&&this.placeholderNode.offsetWidth?this.setAffixStyle(t,f({},this.affixStyle,{width:this.placeholderNode.offsetWidth})):this.setAffixStyle(t),this.setPlaceholderStyle();"resize"===t.type&&this.syncPlaceholderStyle(t)}},t.decorators=[{type:i.Component,args:[{selector:"nz-affix",exportAs:"nzAffix",template:"<div #fixedEl>\n <ng-content></ng-content>\n</div>\n",changeDetection:i.ChangeDetectionStrategy.OnPush,encapsulation:i.ViewEncapsulation.None,styles:["\n nz-affix {\n display: block;\n }\n "]}]}],t.ctorParameters=function(){return[{type:i.ElementRef},{type:void 0,decorators:[{type:i.Inject,args:[o.DOCUMENT]}]},{type:s.NzConfigService},{type:s.NzScrollService},{type:i.NgZone},{type:e.Platform}]},t.propDecorators={fixedEl:[{type:i.ViewChild,args:["fixedEl",{static:!0}]}],nzTarget:[{type:i.Input}],nzOffsetTop:[{type:i.Input}],nzOffsetBottom:[{type:i.Input}],nzChange:[{type:i.Output}]},l([s.WithConfig(0),s.InputNumber(),a("design:type",Object)],t.prototype,"nzOffsetTop",void 0),l([s.WithConfig(null),s.InputNumber(),a("design:type",Object)],t.prototype,"nzOffsetBottom",void 0),t}();var u=function(){function t(){}return t.decorators=[{type:i.NgModule,args:[{declarations:[p],exports:[p],imports:[o.CommonModule,e.PlatformModule],providers:[s.SCROLL_SERVICE_PROVIDER]}]}],t}();t.NzAffixComponent=p,t.NzAffixModule=u,Object.defineProperty(t,"__esModule",{value:!0})}); //# sourceMappingURL=ng-zorro-antd-affix.umd.min.js.map