UNPKG

ngx-headroom

Version:

Headroom.js implementation in Angular

236 lines (229 loc) 6.48 kB
import { EventEmitter, Directive, ElementRef, Input, Output, NgModule } from '@angular/core'; import Headroom from 'headroom.js'; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class NgxHeadroomDirective { /** * @param {?} el */ constructor(el) { this.el = el; this.options = { offset: 300, tolerance: 1, classes: { initial: 'animated', pinned: 'flipInX', unpinned: 'flipOutX' } }; // callback when pinned this.pinned = new EventEmitter(); // callback when unpinned this.unpinned = new EventEmitter(); // callback when above offset this.toped = new EventEmitter(); // callback when below offset this.notToped = new EventEmitter(); // callback when at bottom of page this.bottomed = new EventEmitter(); // callback moving away from bottom of page this.notBottomed = new EventEmitter(); this.element = this.el.nativeElement; } /** * @return {?} */ ngOnInit() { this.initalizeEvents(); this.headroom = new Headroom(this.element, this.options); this.headroom.init(); } /** * @return {?} */ initalizeEvents() { this.options.onPin = (/** * @return {?} */ () => { this.pinned.emit(); }); this.options.onUnpin = (/** * @return {?} */ () => { this.unpinned.emit(); }); this.options.onTop = (/** * @return {?} */ () => { this.toped.emit(); }); this.options.onNotTop = (/** * @return {?} */ () => { this.notToped.emit(); }); this.options.onBottom = (/** * @return {?} */ () => { this.bottomed.emit(); }); this.options.onNotBottom = (/** * @return {?} */ () => { this.notBottomed.emit(); }); } /** * \@description destroy the headroom instance, removing event listeners and any classes added * @return {?} */ destroy() { this.headroom.destory(); } /** * \@description forcibly set the headroom instance's state to pinned * @return {?} */ pin() { this.headroom.destory(); } /** * \@description forcibly set the headroom instance's state to unpinned * @return {?} */ unpin() { this.headroom.unpin(); } /** * \@description freeze the headroom instance's state (pinned or unpinned), and no longer respond to scroll events * @return {?} */ freeze() { this.headroom.freeze(); } /** * \@description resume responding to scroll events * @return {?} */ unfreeze() { this.headroom.unfreeze(); } } NgxHeadroomDirective.decorators = [ { type: Directive, args: [{ selector: '[Ngxheadroom]' },] } ]; /** @nocollapse */ NgxHeadroomDirective.ctorParameters = () => [ { type: ElementRef } ]; NgxHeadroomDirective.propDecorators = { options: [{ type: Input }], pinned: [{ type: Output }], unpinned: [{ type: Output }], toped: [{ type: Output }], notToped: [{ type: Output }], bottomed: [{ type: Output }], notBottomed: [{ type: Output }] }; if (false) { /** * @type {?} * @private */ NgxHeadroomDirective.prototype.element; /** @type {?} */ NgxHeadroomDirective.prototype.headroom; /** @type {?} */ NgxHeadroomDirective.prototype.options; /** @type {?} */ NgxHeadroomDirective.prototype.pinned; /** @type {?} */ NgxHeadroomDirective.prototype.unpinned; /** @type {?} */ NgxHeadroomDirective.prototype.toped; /** @type {?} */ NgxHeadroomDirective.prototype.notToped; /** @type {?} */ NgxHeadroomDirective.prototype.bottomed; /** @type {?} */ NgxHeadroomDirective.prototype.notBottomed; /** * @type {?} * @private */ NgxHeadroomDirective.prototype.el; } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class NgxHeadroomModule { } NgxHeadroomModule.decorators = [ { type: NgModule, args: [{ declarations: [NgxHeadroomDirective], imports: [], exports: [NgxHeadroomDirective] },] } ]; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @record */ function ITolerance() { } if (false) { /** @type {?} */ ITolerance.prototype.up; /** @type {?} */ ITolerance.prototype.down; } /** * @record */ function NgxHeadroomOption() { } if (false) { /** @type {?|undefined} */ NgxHeadroomOption.prototype.offset; /** @type {?|undefined} */ NgxHeadroomOption.prototype.tolerance; /** @type {?|undefined} */ NgxHeadroomOption.prototype.classes; /** @type {?|undefined} */ NgxHeadroomOption.prototype.scroller; /** @type {?|undefined} */ NgxHeadroomOption.prototype.onPin; /** @type {?|undefined} */ NgxHeadroomOption.prototype.onUnpin; /** @type {?|undefined} */ NgxHeadroomOption.prototype.onTop; /** @type {?|undefined} */ NgxHeadroomOption.prototype.onNotTop; /** @type {?|undefined} */ NgxHeadroomOption.prototype.onBottom; /** @type {?|undefined} */ NgxHeadroomOption.prototype.onNotBottom; } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ export { NgxHeadroomModule, NgxHeadroomDirective as ɵa }; //# sourceMappingURL=ngx-headroom.js.map