@beradrian/ngx-auto-scroll
Version:
Angular 2+ directive to automatically scroll html container content to the bottom.
106 lines (101 loc) • 3.31 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core')) :
typeof define === 'function' && define.amd ? define(['exports', '@angular/core'], factory) :
(factory((global['ngx-auto-scroll'] = {}),global.ng.core));
}(this, (function (exports,core) { 'use strict';
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: core.Directive, args: [{
selector: "[ngx-auto-scroll]",
},] },
];
/**
* @nocollapse
*/
NgxAutoScroll.ctorParameters = function () { return [
{ type: core.ElementRef, },
]; };
NgxAutoScroll.propDecorators = {
'lockYOffset': [{ type: core.Input, args: ["lock-y-offset",] },],
'observeAttributes': [{ type: core.Input, args: ["observe-attributes",] },],
'scrollHandler': [{ type: core.HostListener, args: ["scroll",] },],
};
var NgxAutoScrollModule = (function () {
function NgxAutoScrollModule() {
}
return NgxAutoScrollModule;
}());
NgxAutoScrollModule.decorators = [
{ type: core.NgModule, args: [{
declarations: [NgxAutoScroll],
imports: [],
exports: [NgxAutoScroll]
},] },
];
/**
* @nocollapse
*/
NgxAutoScrollModule.ctorParameters = function () { return []; };
exports.NgxAutoScroll = NgxAutoScroll;
exports.NgxAutoScrollModule = NgxAutoScrollModule;
Object.defineProperty(exports, '__esModule', { value: true });
})));
//# sourceMappingURL=ngx-auto-scroll.umd.js.map