UNPKG

ng-zorro-antd

Version:

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

24 lines (22 loc) 9.55 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/cdk/platform"),require("@angular/core"),require("@angular/common"),require("ng-zorro-antd/core/config"),require("ng-zorro-antd/core/logger"),require("ng-zorro-antd/core/services"),require("ng-zorro-antd/core/util"),require("rxjs"),require("rxjs/operators"),require("ng-zorro-antd/affix")):"function"==typeof define&&define.amd?define("ng-zorro-antd/anchor",["exports","@angular/cdk/platform","@angular/core","@angular/common","ng-zorro-antd/core/config","ng-zorro-antd/core/logger","ng-zorro-antd/core/services","ng-zorro-antd/core/util","rxjs","rxjs/operators","ng-zorro-antd/affix"],e):e(((t=t||self)["ng-zorro-antd"]=t["ng-zorro-antd"]||{},t["ng-zorro-antd"].anchor={}),t.ng.cdk.platform,t.ng.core,t.ng.common,t["ng-zorro-antd"].core.config,t["ng-zorro-antd"].core.logger,t["ng-zorro-antd"].core.services,t["ng-zorro-antd"].core.util,t.rxjs,t.rxjs.operators,t["ng-zorro-antd"].affix)}(this,(function(t,e,n,r,o,i,s,a,l,c,p){"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. ***************************************************************************** */function h(t,e,n,r){var o,i=arguments.length,s=i<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,n,r);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(s=(i<3?o(s):i>3?o(e,n,s):o(e,n))||s);return i>3&&s&&Object.defineProperty(e,n,s),s}function f(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)} /** * @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 u(t,e){if(!t||!t.getClientRects().length)return 0;var n=t.getBoundingClientRect();if(n.width||n.height){if(e===window){var r=t.ownerDocument.documentElement;return n.top-r.clientTop}return n.top-e.getBoundingClientRect().top}return n.top}var d=/#([^#]+)$/,g=function(){function t(t,e,r,o,i,s,a){this.doc=t,this.nzConfigService=e,this.scrollSrv=r,this.cdr=o,this.platform=i,this.zone=s,this.renderer=a,this.nzAffix=!0,this.nzClick=new n.EventEmitter,this.nzScroll=new n.EventEmitter,this.visible=!1,this.wrapperStyle={"max-height":"100vh"},this.links=[],this.animating=!1,this.destroy$=new l.Subject,this.handleScrollTimeoutID=-1}return t.prototype.registerLink=function(t){this.links.push(t)},t.prototype.unregisterLink=function(t){this.links.splice(this.links.indexOf(t),1)},t.prototype.getContainer=function(){return this.container||window},t.prototype.ngAfterViewInit=function(){this.registerScrollEvent()},t.prototype.ngOnDestroy=function(){clearTimeout(this.handleScrollTimeoutID),this.destroy$.next(),this.destroy$.complete()},t.prototype.registerScrollEvent=function(){var t=this;this.platform.isBrowser&&(this.destroy$.next(),this.zone.runOutsideAngular((function(){l.fromEvent(t.getContainer(),"scroll").pipe(c.throttleTime(50),c.takeUntil(t.destroy$)).subscribe((function(){return t.handleScroll()}))})),this.handleScrollTimeoutID=setTimeout((function(){return t.handleScroll()})))},t.prototype.handleScroll=function(){var t=this;if("undefined"!=typeof document&&!this.animating){var e=[],n=(this.nzOffsetTop||0)+this.nzBounds;if(this.links.forEach((function(r){var o=d.exec(r.nzHref.toString());if(o){var i=t.doc.getElementById(o[1]);if(i){var s=u(i,t.getContainer());s<n&&e.push({top:s,comp:r})}}})),this.visible=!!e.length,this.visible){var r=e.reduce((function(t,e){return e.top>t.top?e:t}));this.handleActive(r.comp)}else this.clearActive(),this.cdr.detectChanges();this.setVisible()}},t.prototype.clearActive=function(){this.links.forEach((function(t){t.unsetActive()}))},t.prototype.handleActive=function(t){this.clearActive(),t.setActive();var e=t.getLinkTitleElement();this.ink.nativeElement.style.top=e.offsetTop+e.clientHeight/2-4.5+"px",this.visible=!0,this.setVisible(),this.nzScroll.emit(t)},t.prototype.setVisible=function(){var t=this.visible;this.ink&&(t?this.renderer.addClass(this.ink.nativeElement,"visible"):this.renderer.removeClass(this.ink.nativeElement,"visible"))},t.prototype.handleScrollTo=function(t){var e=this,n=this.doc.querySelector(t.nzHref);if(n){this.animating=!0;var r=this.scrollSrv.getScroll(this.getContainer())+u(n,this.getContainer())-(this.nzOffsetTop||0);this.scrollSrv.scrollTo(this.getContainer(),r,void 0,(function(){e.animating=!1,e.handleActive(t)})),this.nzClick.emit(t.nzHref)}},t.prototype.ngOnChanges=function(t){var e=t.nzOffsetTop,n=t.nzTarget,r=t.nzContainer;if(e&&(this.wrapperStyle={"max-height":"calc(100vh - "+this.nzOffsetTop+"px)"}),r||n){var o=this.nzContainer||this.nzTarget;this.container="string"==typeof o?this.doc.querySelector(o):o,this.registerScrollEvent(),n&&i.warnDeprecation("'nzTarget' of 'nz-anchor' is deprecated and will be removed in 10.0.0.Please use 'nzContainer' instead.")}},t.decorators=[{type:n.Component,args:[{selector:"nz-anchor",exportAs:"nzAnchor",preserveWhitespaces:!1,template:'\n <nz-affix *ngIf="nzAffix; else content" [nzOffsetTop]="nzOffsetTop" [nzTarget]="container">\n <ng-template [ngTemplateOutlet]="content"></ng-template>\n </nz-affix>\n <ng-template #content>\n <div class="ant-anchor-wrapper" [ngStyle]="wrapperStyle">\n <div class="ant-anchor" [ngClass]="{ fixed: !nzAffix && !nzShowInkInFixed }">\n <div class="ant-anchor-ink">\n <div class="ant-anchor-ink-ball" #ink></div>\n </div>\n <ng-content></ng-content>\n </div>\n </div>\n </ng-template>\n ',encapsulation:n.ViewEncapsulation.None,changeDetection:n.ChangeDetectionStrategy.OnPush}]}],t.ctorParameters=function(){return[{type:void 0,decorators:[{type:n.Inject,args:[r.DOCUMENT]}]},{type:o.NzConfigService},{type:s.NzScrollService},{type:n.ChangeDetectorRef},{type:e.Platform},{type:n.NgZone},{type:n.Renderer2}]},t.propDecorators={ink:[{type:n.ViewChild,args:["ink",{static:!1}]}],nzAffix:[{type:n.Input}],nzShowInkInFixed:[{type:n.Input}],nzBounds:[{type:n.Input}],nzOffsetTop:[{type:n.Input}],nzContainer:[{type:n.Input}],nzTarget:[{type:n.Input}],nzClick:[{type:n.Output}],nzScroll:[{type:n.Output}]},h([a.InputBoolean(),f("design:type",Object)],t.prototype,"nzAffix",void 0),h([o.WithConfig("anchor",!1),a.InputBoolean(),f("design:type",Boolean)],t.prototype,"nzShowInkInFixed",void 0),h([o.WithConfig("anchor",5),a.InputNumber(),f("design:type",Number)],t.prototype,"nzBounds",void 0),h([a.InputNumber(),o.WithConfig("anchor"),f("design:type",Number)],t.prototype,"nzOffsetTop",void 0),t}();var m=function(){function t(t,e,n,r){this.elementRef=t,this.anchorComp=e,this.platform=n,this.renderer=r,this.nzHref="#",this.titleStr="",this.renderer.addClass(t.nativeElement,"ant-anchor-link")}return Object.defineProperty(t.prototype,"nzTitle",{set:function(t){t instanceof n.TemplateRef?(this.titleStr=null,this.titleTpl=t):this.titleStr=t},enumerable:!0,configurable:!0}),t.prototype.ngOnInit=function(){this.anchorComp.registerLink(this)},t.prototype.getLinkTitleElement=function(){return this.linkTitle.nativeElement},t.prototype.setActive=function(){this.renderer.addClass(this.elementRef.nativeElement,"ant-anchor-link-active")},t.prototype.unsetActive=function(){this.renderer.removeClass(this.elementRef.nativeElement,"ant-anchor-link-active")},t.prototype.goToClick=function(t){t.preventDefault(),t.stopPropagation(),this.platform.isBrowser&&this.anchorComp.handleScrollTo(this)},t.prototype.ngOnDestroy=function(){this.anchorComp.unregisterLink(this)},t.decorators=[{type:n.Component,args:[{selector:"nz-link",exportAs:"nzLink",preserveWhitespaces:!1,template:'\n <a #linkTitle (click)="goToClick($event)" href="{{ nzHref }}" class="ant-anchor-link-title" title="{{ titleStr }}">\n <span *ngIf="titleStr; else titleTpl || nzTemplate">{{ titleStr }}</span>\n </a>\n <ng-content></ng-content>\n ',encapsulation:n.ViewEncapsulation.None,changeDetection:n.ChangeDetectionStrategy.OnPush}]}],t.ctorParameters=function(){return[{type:n.ElementRef},{type:g},{type:e.Platform},{type:n.Renderer2}]},t.propDecorators={nzHref:[{type:n.Input}],nzTitle:[{type:n.Input}],nzTemplate:[{type:n.ContentChild,args:["nzTemplate",{static:!1}]}],linkTitle:[{type:n.ViewChild,args:["linkTitle"]}]},t}();var v=function(){function t(){}return t.decorators=[{type:n.NgModule,args:[{declarations:[g,m],exports:[g,m],imports:[r.CommonModule,p.NzAffixModule,e.PlatformModule],providers:[s.SCROLL_SERVICE_PROVIDER]}]}],t}();t.NzAnchorComponent=g,t.NzAnchorLinkComponent=m,t.NzAnchorModule=v,Object.defineProperty(t,"__esModule",{value:!0})})); //# sourceMappingURL=ng-zorro-antd-anchor.umd.min.js.map