@beradrian/ngx-auto-scroll
Version:
Angular 2+ directive to automatically scroll html container content to the bottom.
98 lines (97 loc) • 2.96 kB
JavaScript
import { Directive, ElementRef, HostListener, Input, NgModule } from '@angular/core';
var NgxAutoScroll = (function () {
/**
* @param {?} element
*/
function NgxAutoScroll(element) {
this.lockYOffset = 10;
this.observeAttributes = "false";
this.isLocked = false;
this.nativeElement = element.nativeElement;
}
/**
* @return {?}
*/
NgxAutoScroll.prototype.getObserveAttributes = function () {
return this.observeAttributes !== "" && this.observeAttributes.toLowerCase() !== "false";
};
/**
* @return {?}
*/
NgxAutoScroll.prototype.ngAfterContentInit = function () {
var _this = this;
this.mutationObserver = new MutationObserver(function () {
if (!_this.isLocked) {
_this.scrollDown();
}
});
this.mutationObserver.observe(this.nativeElement, {
childList: true,
subtree: true,
attributes: this.getObserveAttributes(),
});
};
/**
* @return {?}
*/
NgxAutoScroll.prototype.ngOnDestroy = function () {
this.mutationObserver.disconnect();
};
/**
* @return {?}
*/
NgxAutoScroll.prototype.forceScrollDown = function () {
this.scrollDown();
};
/**
* @return {?}
*/
NgxAutoScroll.prototype.scrollDown = function () {
this.nativeElement.scrollTop = this.nativeElement.scrollHeight;
};
/**
* @return {?}
*/
NgxAutoScroll.prototype.scrollHandler = function () {
var /** @type {?} */ scrollFromBottom = this.nativeElement.scrollHeight - this.nativeElement.scrollTop - this.nativeElement.clientHeight;
this.isLocked = scrollFromBottom > this.lockYOffset;
};
return NgxAutoScroll;
}());
NgxAutoScroll.decorators = [
{ type: Directive, args: [{
selector: "[ngx-auto-scroll]",
},] },
];
/**
* @nocollapse
*/
NgxAutoScroll.ctorParameters = function () { return [
{ type: ElementRef, },
]; };
NgxAutoScroll.propDecorators = {
'lockYOffset': [{ type: Input, args: ["lock-y-offset",] },],
'observeAttributes': [{ type: Input, args: ["observe-attributes",] },],
'scrollHandler': [{ type: HostListener, args: ["scroll",] },],
};
var NgxAutoScrollModule = (function () {
function NgxAutoScrollModule() {
}
return NgxAutoScrollModule;
}());
NgxAutoScrollModule.decorators = [
{ type: NgModule, args: [{
declarations: [NgxAutoScroll],
imports: [],
exports: [NgxAutoScroll]
},] },
];
/**
* @nocollapse
*/
NgxAutoScrollModule.ctorParameters = function () { return []; };
/**
* Generated bundle index. Do not edit.
*/
export { NgxAutoScroll, NgxAutoScrollModule };
//# sourceMappingURL=ngx-auto-scroll.es5.js.map