@q149/angular-scrollspy
Version:
A simple lightweight library for Angular which automatically updates links to indicate the currently active section in the viewport
2 lines • 3.75 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("@q149/angular-inviewport")):"function"==typeof define&&define.amd?define("@q149/angular-scrollspy",["exports","@angular/core","@q149/angular-inviewport"],e):e((t.q149=t.q149||{},t.q149["angular-scrollspy"]={}),t.ng.core,t.angularInviewport)}(this,function(t,e,n){"use strict";var r=function(){function t(t){this.cdRef=t,this.active=!1,this.inViewport=!1}return Object.defineProperty(t.prototype,"section",{get:function(){return this.href.replace("#","")},enumerable:!0,configurable:!0}),t.prototype.detectChanges=function(){this.cdRef.detectChanges()},t.decorators=[{type:e.Directive,args:[{selector:"[snScrollSpyItem]"}]}],t.ctorParameters=function(){return[{type:e.ChangeDetectorRef}]},t.propDecorators={active:[{type:e.HostBinding,args:["class.active"]}],"for":[{type:e.Input}],href:[{type:e.Input}]},t}(),o=function(){function t(){this.spys=[],this.buffer=[]}return t.prototype.addSpy=function(e,t){var n=this;this.spys.push({id:e,items:t});var r=this.buffer.filter(function(t){return t.spyId===e});this.buffer=this.buffer.filter(function(t){return t.spyId!==e}),r.forEach(function(t){return n.setSpySectionStatus(t.sectionId,t.spyId,t.inViewport)})},t.prototype.removeSpy=function(e){var t=this.spys.findIndex(function(t){return t.id===e});this.spys.splice(t,1)},t.prototype.setSpySectionStatus=function(e,n,t){var r=this.spys.find(function(t){return t.id===n});if(r){var o=r.items.find(function(t){return t.section===e});if(o){o.inViewport=t;var i=r.items.filter(function(t){return t.inViewport})[0];r.items.forEach(function(t){return t.active=!1}),i&&(i.active=!0,i.detectChanges())}}else this.buffer.push({sectionId:e,spyId:n,inViewport:t})},t.decorators=[{type:e.Injectable}],t}(),i=function(){function t(t){this.scrollSpySvc=t}return t.prototype.ngAfterViewInit=function(){this.scrollSpySvc.addSpy(this.id,this.items)},t.prototype.ngOnDestroy=function(){this.scrollSpySvc.removeSpy(this.id)},t.decorators=[{type:e.Directive,args:[{selector:"[snScrollSpy]"}]}],t.ctorParameters=function(){return[{type:o}]},t.propDecorators={items:[{type:e.ContentChildren,args:[r]}],id:[{type:e.Input}]},t}(),s=function(){function t(t){this.scrollSpySvc=t,this.debounce=0}return t.prototype.onInViewportChange=function(t){this.scrollSpySvc.setSpySectionStatus(this.id,this["for"],t)},t.decorators=[{type:e.Component,args:[{selector:"sn-scroll-spy-section",template:'<div\n class="sn-hidden"\n snInViewport\n [offsetTop]="500"\n (inViewportChange)="onInViewportChange($event)"\n [debounce]="debounce">\n</div>\n<ng-content></ng-content>\n',styles:[":host{display:block;position:relative}.sn-hidden{bottom:0;left:0;opacity:0;position:absolute;right:0;top:0;z-index:-1}"]}]}],t.ctorParameters=function(){return[{type:o}]},t.propDecorators={id:[{type:e.Input}],"for":[{type:e.Input}],debounce:[{type:e.Input}]},t}();function c(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),s=[];try{for(;(void 0===e||0<e--)&&!(r=i.next()).done;)s.push(r.value)}catch(c){o={error:c}}finally{try{r&&!r.done&&(n=i["return"])&&n.call(i)}finally{if(o)throw o.error}}return s}function p(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(c(arguments[e]));return t}var u=[i,r],a=[s],f=[o],l=function(){function t(){}return t.forRoot=function(){return{ngModule:t,providers:p(f)}},t.decorators=[{type:e.NgModule,args:[{imports:[n.InViewportModule],declarations:p(u,a),exports:p(u,a)}]}],t}();t.ScrollSpyDirective=i,t.ScrollSpyItemDirective=r,t.ScrollSpySectionComponent=s,t.ScrollSpyService=o,t.ScrollSpyModule=l,Object.defineProperty(t,"__esModule",{value:!0})});
//# sourceMappingURL=q149-angular-scrollspy.umd.min.js.map