ng-zorro-antd-yj
Version:
An enterprise-class UI components based on Ant Design and Angular
204 lines • 13.1 kB
JavaScript
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
import { DOCUMENT } from '@angular/common';
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, Inject, Input, Output, TemplateRef, ViewEncapsulation } from '@angular/core';
import { fromEvent } from 'rxjs';
import { distinctUntilChanged, throttleTime } from 'rxjs/operators';
import { fadeMotion } from '../core/animation/fade';
import { NzScrollService } from '../core/scroll/nz-scroll.service';
import { toNumber } from '../core/util/convert';
var NzBackTopComponent = /** @class */ (function () {
// tslint:disable-next-line:no-any
function NzBackTopComponent(scrollSrv, doc, cd) {
this.scrollSrv = scrollSrv;
this.doc = doc;
this.cd = cd;
this.scroll$ = null;
this.target = null;
this.visible = false;
this._visibilityHeight = 400;
this.nzClick = new EventEmitter();
}
Object.defineProperty(NzBackTopComponent.prototype, "nzVisibilityHeight", {
get: /**
* @return {?}
*/
function () {
return this._visibilityHeight;
},
set: /**
* @param {?} value
* @return {?}
*/
function (value) {
this._visibilityHeight = toNumber(value, 400);
},
enumerable: true,
configurable: true
});
Object.defineProperty(NzBackTopComponent.prototype, "nzTarget", {
set: /**
* @param {?} el
* @return {?}
*/
function (el) {
this.target = typeof el === 'string' ? this.doc.querySelector(el) : el;
this.registerScrollEvent();
},
enumerable: true,
configurable: true
});
/**
* @return {?}
*/
NzBackTopComponent.prototype.ngOnInit = /**
* @return {?}
*/
function () {
if (!this.scroll$) {
this.registerScrollEvent();
}
};
/**
* @return {?}
*/
NzBackTopComponent.prototype.clickBackTop = /**
* @return {?}
*/
function () {
this.scrollSrv.scrollTo(this.getTarget(), 0);
this.nzClick.emit(true);
};
/**
* @private
* @return {?}
*/
NzBackTopComponent.prototype.getTarget = /**
* @private
* @return {?}
*/
function () {
return this.target || window;
};
/**
* @private
* @return {?}
*/
NzBackTopComponent.prototype.handleScroll = /**
* @private
* @return {?}
*/
function () {
if (this.visible === this.scrollSrv.getScroll(this.getTarget()) > this.nzVisibilityHeight) {
return;
}
this.visible = !this.visible;
this.cd.markForCheck();
};
/**
* @private
* @return {?}
*/
NzBackTopComponent.prototype.removeListen = /**
* @private
* @return {?}
*/
function () {
if (this.scroll$) {
this.scroll$.unsubscribe();
}
};
/**
* @private
* @return {?}
*/
NzBackTopComponent.prototype.registerScrollEvent = /**
* @private
* @return {?}
*/
function () {
var _this = this;
this.removeListen();
this.handleScroll();
this.scroll$ = fromEvent(this.getTarget(), 'scroll')
.pipe(throttleTime(50), distinctUntilChanged())
.subscribe((/**
* @return {?}
*/
function () { return _this.handleScroll(); }));
};
/**
* @return {?}
*/
NzBackTopComponent.prototype.ngOnDestroy = /**
* @return {?}
*/
function () {
this.removeListen();
};
NzBackTopComponent.decorators = [
{ type: Component, args: [{
selector: 'nz-back-top',
animations: [fadeMotion],
template: "<div class=\"ant-back-top\" (click)=\"clickBackTop()\" @fadeMotion *ngIf=\"visible\">\n <ng-template #defaultContent>\n <div class=\"ant-back-top-content\">\n <div class=\"ant-back-top-icon\"></div>\n </div>\n </ng-template>\n <ng-template [ngTemplateOutlet]=\"nzTemplate || defaultContent\"></ng-template>\n</div>",
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
preserveWhitespaces: false
}] }
];
/** @nocollapse */
NzBackTopComponent.ctorParameters = function () { return [
{ type: NzScrollService },
{ type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] }] },
{ type: ChangeDetectorRef }
]; };
NzBackTopComponent.propDecorators = {
nzTemplate: [{ type: Input }],
nzVisibilityHeight: [{ type: Input }],
nzTarget: [{ type: Input }],
nzClick: [{ type: Output }]
};
return NzBackTopComponent;
}());
export { NzBackTopComponent };
if (false) {
/**
* @type {?}
* @private
*/
NzBackTopComponent.prototype.scroll$;
/**
* @type {?}
* @private
*/
NzBackTopComponent.prototype.target;
/** @type {?} */
NzBackTopComponent.prototype.visible;
/** @type {?} */
NzBackTopComponent.prototype.nzTemplate;
/**
* @type {?}
* @private
*/
NzBackTopComponent.prototype._visibilityHeight;
/** @type {?} */
NzBackTopComponent.prototype.nzClick;
/**
* @type {?}
* @private
*/
NzBackTopComponent.prototype.scrollSrv;
/**
* @type {?}
* @private
*/
NzBackTopComponent.prototype.doc;
/**
* @type {?}
* @private
*/
NzBackTopComponent.prototype.cd;
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnotYmFjay10b3AuY29tcG9uZW50LmpzIiwic291cmNlUm9vdCI6Im5nOi8vbmctem9ycm8tYW50ZC15ai8iLCJzb3VyY2VzIjpbImJhY2stdG9wL256LWJhY2stdG9wLmNvbXBvbmVudC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7O0FBQUEsT0FBTyxFQUFFLFFBQVEsRUFBRSxNQUFNLGlCQUFpQixDQUFDO0FBQzNDLE9BQU8sRUFDTCx1QkFBdUIsRUFDdkIsaUJBQWlCLEVBQ2pCLFNBQVMsRUFDVCxZQUFZLEVBQ1osTUFBTSxFQUNOLEtBQUssRUFHTCxNQUFNLEVBQ04sV0FBVyxFQUNYLGlCQUFpQixFQUNsQixNQUFNLGVBQWUsQ0FBQztBQUV2QixPQUFPLEVBQUUsU0FBUyxFQUFnQixNQUFNLE1BQU0sQ0FBQztBQUMvQyxPQUFPLEVBQUUsb0JBQW9CLEVBQUUsWUFBWSxFQUFFLE1BQU0sZ0JBQWdCLENBQUM7QUFDcEUsT0FBTyxFQUFFLFVBQVUsRUFBRSxNQUFNLHdCQUF3QixDQUFDO0FBRXBELE9BQU8sRUFBRSxlQUFlLEVBQUUsTUFBTSxrQ0FBa0MsQ0FBQztBQUNuRSxPQUFPLEVBQUUsUUFBUSxFQUFFLE1BQU0sc0JBQXNCLENBQUM7QUFFaEQ7SUFtQ0Usa0NBQWtDO0lBQ2xDLDRCQUFvQixTQUEwQixFQUE0QixHQUFRL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