UNPKG

ng-zorro-antd

Version:

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

31 lines (29 loc) 8.53 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/config"),require("ng-zorro-antd/core/services"),require("ng-zorro-antd/core/util"),require("rxjs"),require("rxjs/operators")):"function"==typeof define&&define.amd?define("ng-zorro-antd/affix",["exports","@angular/cdk/platform","@angular/common","@angular/core","ng-zorro-antd/core/config","ng-zorro-antd/core/services","ng-zorro-antd/core/util","rxjs","rxjs/operators"],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["ng-zorro-antd"].core.config,t["ng-zorro-antd"].core.services,t["ng-zorro-antd"].core.util,t.rxjs,t.rxjs.operators)}(this,(function(t,e,o,r,i,n,s,f,l){"use strict"; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */var a=function(){return(a=Object.assign||function(t){for(var e,o=1,r=arguments.length;o<r;o++)for(var i in e=arguments[o])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function c(t,e,o,r){var i,n=arguments.length,s=n<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,o):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,o,r);else for(var f=t.length-1;f>=0;f--)(i=t[f])&&(s=(n<3?i(s):n>3?i(e,o,s):i(e,o))||s);return n>3&&s&&Object.defineProperty(e,o,s),s}function h(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}function p(t,e){var o="function"==typeof Symbol&&t[Symbol.iterator];if(!o)return t;var r,i,n=o.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=n.next()).done;)s.push(r.value)}catch(t){i={error:t}}finally{try{r&&!r.done&&(o=n.return)&&o.call(n)}finally{if(i)throw i.error}}return s} /** * @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 */ var u={resize:"resize",scroll:"scroll",touchstart:"touchstart",touchmove:"touchmove",touchend:"touchend",pageshow:"pageshow",load:"LOAD"}; /** * @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 */function d(t){return function(t){return"undefined"!=typeof window&&t===window}(t)?{top:0,left:0,bottom:0}:t.getBoundingClientRect()}var g=function(){function t(t,e,o,i,n,s,l){this.nzConfigService=o,this.scrollSrv=i,this.ngZone=n,this.platform=s,this.renderer=l,this.nzChange=new r.EventEmitter,this.positionChangeSubscription=f.Subscription.EMPTY,this.offsetChanged$=new f.ReplaySubject(1),this.destroy$=new f.Subject,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,r=t.nzTarget;(e||o)&&this.offsetChanged$.next(),r&&this.registerListeners()},t.prototype.ngAfterViewInit=function(){this.registerListeners()},t.prototype.ngOnDestroy=function(){this.removeListeners()},t.prototype.registerListeners=function(){var t=this;this.removeListeners(),this.positionChangeSubscription=this.ngZone.runOutsideAngular((function(){return f.merge.apply(void 0,function(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(p(arguments[e]));return t}(Object.keys(u).map((function(e){return f.fromEvent(t.target,e)})),[t.offsetChanged$.pipe(l.takeUntil(t.destroy$),l.map((function(){return{}})))])).pipe(l.auditTime(20)).subscribe((function(e){return t.updatePosition(e)}))})),this.timeout=setTimeout((function(){return t.updatePosition({})}))},t.prototype.removeListeners=function(){clearTimeout(this.timeout),this.positionChangeSubscription.unsubscribe(),this.destroy$.next(),this.destroy$.complete()},t.prototype.getOffset=function(t,e){var o=t.getBoundingClientRect(),r=d(e),i=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-r.top+i-f,left:o.left-r.left+n-l,width:o.width,height:o.height}},t.prototype.setAffixStyle=function(t,e){var o=this.affixStyle,r=this.target===window;if(!("scroll"===t.type&&o&&e&&r||s.shallowEqual(o,e))){var i=!!e,n=this.fixedEl.nativeElement;this.renderer.setStyle(n,"cssText",s.getStyleAsText(e)),this.affixStyle=e,i?n.classList.add("ant-affix"):n.classList.remove("ant-affix"),(e&&!o||!e&&o)&&this.nzChange.emit(i)}},t.prototype.setPlaceholderStyle=function(t){var e=this.placeholderStyle;s.shallowEqual(t,e)||(this.renderer.setStyle(this.placeholderNode,"cssText",s.getStyleAsText(t)),this.placeholderStyle=t)},t.prototype.syncPlaceholderStyle=function(t){if(this.affixStyle){this.renderer.setStyle(this.placeholderNode,"cssText",""),this.placeholderStyle=void 0;var e={width:this.placeholderNode.offsetWidth,height:this.fixedEl.nativeElement.offsetHeight};this.setAffixStyle(t,a(a({},this.affixStyle),e)),this.setPlaceholderStyle(e)}},t.prototype.updatePosition=function(t){if(this.platform.isBrowser){var e=this.target,o=this.nzOffsetTop,r=this.scrollSrv.getScroll(e,!0),i=this.getOffset(this.placeholderNode,e),n=this.fixedEl.nativeElement,s={width:n.offsetWidth,height:n.offsetHeight},f={top:!1,bottom:!1};"number"!=typeof o&&"number"!=typeof this.nzOffsetBottom?(f.top=!0,o=0):(f.top="number"==typeof o,f.bottom="number"==typeof this.nzOffsetBottom);var l=d(e),c=e.innerHeight||e.clientHeight;if(r>=i.top-o&&f.top){var h=i.width,p=l.top+o;this.setAffixStyle(t,{position:"fixed",top:p,left:l.left+i.left,width:h}),this.setPlaceholderStyle({width:h,height:s.height})}else if(r<=i.top+s.height+this.nzOffsetBottom-c&&f.bottom){var g=e===window?0:window.innerHeight-l.bottom;h=i.width;this.setAffixStyle(t,{position:"fixed",bottom:g+this.nzOffsetBottom,left:l.left+i.left,width:h}),this.setPlaceholderStyle({width:h,height:i.height})}else t.type===u.resize&&this.affixStyle&&"fixed"===this.affixStyle.position&&this.placeholderNode.offsetWidth?this.setAffixStyle(t,a(a({},this.affixStyle),{width:this.placeholderNode.offsetWidth})):this.setAffixStyle(t),this.setPlaceholderStyle();"resize"===t.type&&this.syncPlaceholderStyle(t)}},t.decorators=[{type:r.Component,args:[{selector:"nz-affix",exportAs:"nzAffix",template:"\n <div #fixedEl>\n <ng-content></ng-content>\n </div>\n ",changeDetection:r.ChangeDetectionStrategy.OnPush,encapsulation:r.ViewEncapsulation.None}]}],t.ctorParameters=function(){return[{type:r.ElementRef},{type:void 0,decorators:[{type:r.Inject,args:[o.DOCUMENT]}]},{type:i.NzConfigService},{type:n.NzScrollService},{type:r.NgZone},{type:e.Platform},{type:r.Renderer2}]},t.propDecorators={fixedEl:[{type:r.ViewChild,args:["fixedEl",{static:!0}]}],nzTarget:[{type:r.Input}],nzOffsetTop:[{type:r.Input}],nzOffsetBottom:[{type:r.Input}],nzChange:[{type:r.Output}]},c([i.WithConfig("affix",null),s.InputNumber(),h("design:type",Object)],t.prototype,"nzOffsetTop",void 0),c([i.WithConfig("affix",null),s.InputNumber(),h("design:type",Object)],t.prototype,"nzOffsetBottom",void 0),t}();var y=function(){function t(){}return t.decorators=[{type:r.NgModule,args:[{declarations:[g],exports:[g],imports:[o.CommonModule,e.PlatformModule],providers:[n.SCROLL_SERVICE_PROVIDER]}]}],t}();t.NzAffixComponent=g,t.NzAffixModule=y,Object.defineProperty(t,"__esModule",{value:!0})})); //# sourceMappingURL=ng-zorro-antd-affix.umd.min.js.map