UNPKG

ngx-scroll-lock

Version:
179 lines (173 loc) 5.93 kB
import { __assign } from 'tslib'; import { isDevMode, Component, ViewEncapsulation, Input, NgModule } from '@angular/core'; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var NgxScrollLockComponent = /** @class */ (function () { function NgxScrollLockComponent() { this.target = ''; this.lock = false; this.listenerOptions = { capture: false, passive: false, }; } /** * @return {?} */ NgxScrollLockComponent.prototype.ngOnInit = /** * @return {?} */ function () { this.targetElement = this.target ? document.querySelector(this.target) : document.body; // Shows error message only in Development if (!this.targetElement && isDevMode()) { console.error( // tslint:disable-next-line: max-line-length "`NgxScrollLockComponent` need to receive \"target\" as an element, but it received \"" + (this.target || 'body') + "\". Please check if the element is unique and it's available in your DOM."); } if (this.lock && this.targetElement) { this.disableLock(this.targetElement); } }; /** * @return {?} */ NgxScrollLockComponent.prototype.ngOnDestroy = /** * @return {?} */ function () { if (this.targetElement) { this.enableLock(this.targetElement); } }; /** * @param {?} changes * @return {?} */ NgxScrollLockComponent.prototype.ngOnChanges = /** * @param {?} changes * @return {?} */ function (changes) { if (changes.target && !changes.target.firstChange && changes.target.previousValue !== changes.target.currentValue) { this.enableLock(this.targetElement); this.targetElement = this.target ? document.querySelector(this.target) : document.body; if (this.lock && this.targetElement) { this.disableLock(this.targetElement); } } if (changes.lock && !changes.lock.firstChange && changes.lock.previousValue !== changes.lock.currentValue && this.targetElement) { changes.lock.currentValue ? this.disableLock(this.targetElement) : this.enableLock(this.targetElement); } }; /** * @param {?} target * @return {?} */ NgxScrollLockComponent.prototype.disableLock = /** * @param {?} target * @return {?} */ function (target) { this.targetElement.classList.add('ngx-scroll-lock'); // Mobile Safari ignores { overflow: hidden } declaration on the body. if (this.isTouchDevice()) { this.targetElement.addEventListener('touchmove', this.preventTouchMove, this.listenerOptions); } }; /** * @param {?} target * @return {?} */ NgxScrollLockComponent.prototype.enableLock = /** * @param {?} target * @return {?} */ function (target) { this.targetElement.classList.remove('ngx-scroll-lock'); if (this.isTouchDevice()) { this.targetElement.removeEventListener('touchmove', this.preventTouchMove, this.listenerOptions); } }; /** * @return {?} */ NgxScrollLockComponent.prototype.isTouchDevice = /** * @return {?} */ function () { return !!window && ('ontouchstart' in window || navigator.maxTouchPoints); }; /** * @param {?} rawEvent * @return {?} */ NgxScrollLockComponent.prototype.preventTouchMove = /** * @param {?} rawEvent * @return {?} */ function (rawEvent) { /** @type {?} */ var e = rawEvent || __assign({}, ((/** @type {?} */ (window))).event, { touches: [] }); // // Do not prevent if the event has more than one touch // (usually meaning this is a single or multi touch gesture like pinch to zoom) if (e.touches && e.touches.length >= 1) { return true; } if (e.preventDefault) { e.preventDefault(); } return false; }; NgxScrollLockComponent.decorators = [ { type: Component, args: [{ selector: 'ngx-scroll-lock', template: "\n <style>\n .ngx-scroll-lock {\n box-sizing: border-box !important;\n overflow: hidden !important;\n position: inherit !important;\n }\n </style>\n <ng-content></ng-content>\n ", encapsulation: ViewEncapsulation.None }] } ]; NgxScrollLockComponent.propDecorators = { target: [{ type: Input }], lock: [{ type: Input }] }; return NgxScrollLockComponent; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var NgxScrollLockModule = /** @class */ (function () { function NgxScrollLockModule() { } NgxScrollLockModule.decorators = [ { type: NgModule, args: [{ declarations: [NgxScrollLockComponent], imports: [], exports: [NgxScrollLockComponent] },] } ]; return NgxScrollLockModule; }()); /** * @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 { NgxScrollLockComponent, NgxScrollLockModule }; //# sourceMappingURL=ngx-scroll-lock.js.map