angular-auto-size-input
Version:
Plug and Play directive to automatically scale textareas to their contents. Works while yout type, copy, cut, and paste.
81 lines (74 loc) • 2.85 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common')) :
typeof define === 'function' && define.amd ? define(['exports', '@angular/core', '@angular/common'], factory) :
(factory((global['angular-auto-size-input'] = {}),global.core,global.common));
}(this, (function (exports,core,common) { 'use strict';
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var AutoSizeInputDirective = (function () {
function AutoSizeInputDirective(_elementRef) {
var _this = this;
this._elementRef = _elementRef;
this.resize = function () {
_this._elementRef.nativeElement.style.height = 'auto';
_this._elementRef.nativeElement.style.height = _this._elementRef.nativeElement.scrollHeight + 'px';
};
this.delayedResize = function () {
setTimeout(_this.resize, 0);
};
}
/**
* @return {?}
*/
AutoSizeInputDirective.prototype.ngAfterViewInit = /**
* @return {?}
*/
function () {
this._elementRef.nativeElement.addEventListener('change', this.resize);
this._elementRef.nativeElement.addEventListener('cut', this.delayedResize);
this._elementRef.nativeElement.addEventListener('paste', this.delayedResize);
this._elementRef.nativeElement.addEventListener('drop', this.delayedResize);
this._elementRef.nativeElement.addEventListener('keydown', this.delayedResize);
this.delayedResize();
};
AutoSizeInputDirective.decorators = [
{ type: core.Directive, args: [{
selector: 'textarea[asAutoSizeInput]'
},] },
];
/** @nocollapse */
AutoSizeInputDirective.ctorParameters = function () { return [
{ type: core.ElementRef, },
]; };
AutoSizeInputDirective.propDecorators = {
"true": [{ type: core.HostBinding, args: ['class.as-auto-size-input',] },],
};
return AutoSizeInputDirective;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var AutoSizeInputModule = (function () {
function AutoSizeInputModule() {
}
AutoSizeInputModule.decorators = [
{ type: core.NgModule, args: [{
declarations: [AutoSizeInputDirective],
exports: [AutoSizeInputDirective],
imports: [common.CommonModule]
},] },
];
/** @nocollapse */
AutoSizeInputModule.ctorParameters = function () { return []; };
return AutoSizeInputModule;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
exports.AutoSizeInputModule = AutoSizeInputModule;
Object.defineProperty(exports, '__esModule', { value: true });
})));