| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354 |
- "use strict";
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- var __metadata = (this && this.__metadata) || function (k, v) {
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var core_1 = require("@angular/core");
- var common_1 = require("@angular/common");
- var inputtext_1 = require("../inputtext/inputtext");
- var forms_1 = require("@angular/forms");
- exports.SPINNER_VALUE_ACCESSOR = {
- provide: forms_1.NG_VALUE_ACCESSOR,
- useExisting: core_1.forwardRef(function () { return Spinner; }),
- multi: true
- };
- var Spinner = /** @class */ (function () {
- function Spinner(el, cd) {
- this.el = el;
- this.cd = cd;
- this.onChange = new core_1.EventEmitter();
- this.onFocus = new core_1.EventEmitter();
- this.onBlur = new core_1.EventEmitter();
- this.step = 1;
- this.onModelChange = function () { };
- this.onModelTouched = function () { };
- this.keyPattern = /[0-9\+\-]/;
- this.negativeSeparator = '-';
- }
- Object.defineProperty(Spinner.prototype, "type", {
- set: function (value) {
- console.warn("type property is removed as Spinner does not format the value anymore");
- },
- enumerable: true,
- configurable: true
- });
- Spinner.prototype.ngAfterViewInit = function () {
- if (this.value && this.value.toString().indexOf('.') > 0) {
- this.precision = this.value.toString().split(/[.]/)[1].length;
- }
- else if (this.step % 1 !== 0) {
- // If step is not an integer then extract the length of the decimal part
- this.precision = this.step.toString().split(/[,]|[.]/)[1].length;
- }
- if (this.formatInput) {
- this.localeDecimalSeparator = (1.1).toLocaleString().substring(1, 2);
- this.localeThousandSeparator = (1000).toLocaleString().substring(1, 2);
- this.thousandRegExp = new RegExp("[" + (this.thousandSeparator || this.localeThousandSeparator) + "]", 'gim');
- if (this.decimalSeparator && this.thousandSeparator && this.decimalSeparator === this.thousandSeparator) {
- console.warn("thousandSeparator and decimalSeparator cannot have the same value.");
- }
- }
- };
- Spinner.prototype.repeat = function (event, interval, dir) {
- var _this = this;
- var i = interval || 500;
- this.clearTimer();
- this.timer = setTimeout(function () {
- _this.repeat(event, 40, dir);
- }, i);
- this.spin(event, dir);
- };
- Spinner.prototype.spin = function (event, dir) {
- var step = this.step * dir;
- var currentValue;
- if (this.value)
- currentValue = (typeof this.value === 'string') ? this.parseValue(this.value) : this.value;
- else
- currentValue = 0;
- if (this.precision)
- this.value = parseFloat(this.toFixed(currentValue + step, this.precision));
- else
- this.value = currentValue + step;
- if (this.maxlength !== undefined && this.value.toString().length > this.maxlength) {
- this.value = currentValue;
- }
- if (this.min !== undefined && this.value < this.min) {
- this.value = this.min;
- }
- if (this.max !== undefined && this.value > this.max) {
- this.value = this.max;
- }
- this.formatValue();
- this.onModelChange(this.value);
- this.onChange.emit(event);
- };
- Spinner.prototype.toFixed = function (value, precision) {
- var power = Math.pow(10, precision || 0);
- return String(Math.round(value * power) / power);
- };
- Spinner.prototype.onUpButtonMousedown = function (event) {
- if (!this.disabled) {
- this.inputfieldViewChild.nativeElement.focus();
- this.repeat(event, null, 1);
- this.updateFilledState();
- event.preventDefault();
- }
- };
- Spinner.prototype.onUpButtonMouseup = function (event) {
- if (!this.disabled) {
- this.clearTimer();
- }
- };
- Spinner.prototype.onUpButtonMouseleave = function (event) {
- if (!this.disabled) {
- this.clearTimer();
- }
- };
- Spinner.prototype.onDownButtonMousedown = function (event) {
- if (!this.disabled) {
- this.inputfieldViewChild.nativeElement.focus();
- this.repeat(event, null, -1);
- this.updateFilledState();
- event.preventDefault();
- }
- };
- Spinner.prototype.onDownButtonMouseup = function (event) {
- if (!this.disabled) {
- this.clearTimer();
- }
- };
- Spinner.prototype.onDownButtonMouseleave = function (event) {
- if (!this.disabled) {
- this.clearTimer();
- }
- };
- Spinner.prototype.onInputKeydown = function (event) {
- if (event.which == 38) {
- this.spin(event, 1);
- event.preventDefault();
- }
- else if (event.which == 40) {
- this.spin(event, -1);
- event.preventDefault();
- }
- };
- Spinner.prototype.onInputChange = function (event) {
- this.onChange.emit(event);
- };
- Spinner.prototype.onInput = function (event) {
- this.value = this.parseValue(event.target.value);
- this.onModelChange(this.value);
- this.updateFilledState();
- };
- Spinner.prototype.onInputBlur = function (event) {
- this.focus = false;
- this.formatValue();
- this.onModelTouched();
- this.onBlur.emit(event);
- };
- Spinner.prototype.onInputFocus = function (event) {
- this.focus = true;
- this.onFocus.emit(event);
- };
- Spinner.prototype.parseValue = function (val) {
- var value;
- if (val.trim() === '') {
- value = null;
- }
- else {
- if (this.formatInput) {
- val = val.replace(this.thousandRegExp, '');
- }
- if (this.precision) {
- val = this.formatInput ? val.replace(this.decimalSeparator || this.localeDecimalSeparator, '.') : val.replace(',', '.');
- value = parseFloat(val);
- }
- else {
- value = parseInt(val, 10);
- }
- if (!isNaN(value)) {
- if (this.max !== null && value > this.max) {
- value = this.max;
- }
- if (this.min !== null && value < this.min) {
- value = this.min;
- }
- }
- else {
- value = null;
- }
- }
- return value;
- };
- Spinner.prototype.formatValue = function () {
- var value = this.value;
- if (value != null) {
- if (this.formatInput) {
- value = value.toLocaleString(undefined, { maximumFractionDigits: 20 });
- if (this.decimalSeparator && this.thousandSeparator) {
- value = value.split(this.localeDecimalSeparator);
- if (this.precision && value[1]) {
- value[1] = (this.decimalSeparator || this.localeDecimalSeparator) + value[1];
- }
- if (this.thousandSeparator && value[0].length > 3) {
- value[0] = value[0].replace(new RegExp("[" + this.localeThousandSeparator + "]", 'gim'), this.thousandSeparator);
- }
- value = value.join('');
- }
- }
- this.formattedValue = value.toString();
- }
- else {
- this.formattedValue = null;
- }
- if (this.inputfieldViewChild && this.inputfieldViewChild.nativeElement) {
- this.inputfieldViewChild.nativeElement.value = this.formattedValue;
- }
- };
- Spinner.prototype.clearTimer = function () {
- if (this.timer) {
- clearInterval(this.timer);
- }
- };
- Spinner.prototype.writeValue = function (value) {
- this.value = value;
- this.formatValue();
- this.updateFilledState();
- this.cd.markForCheck();
- };
- Spinner.prototype.registerOnChange = function (fn) {
- this.onModelChange = fn;
- };
- Spinner.prototype.registerOnTouched = function (fn) {
- this.onModelTouched = fn;
- };
- Spinner.prototype.setDisabledState = function (val) {
- this.disabled = val;
- };
- Spinner.prototype.updateFilledState = function () {
- this.filled = (this.value !== undefined && this.value != null);
- };
- __decorate([
- core_1.Output(),
- __metadata("design:type", core_1.EventEmitter)
- ], Spinner.prototype, "onChange", void 0);
- __decorate([
- core_1.Output(),
- __metadata("design:type", core_1.EventEmitter)
- ], Spinner.prototype, "onFocus", void 0);
- __decorate([
- core_1.Output(),
- __metadata("design:type", core_1.EventEmitter)
- ], Spinner.prototype, "onBlur", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Number)
- ], Spinner.prototype, "step", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Number)
- ], Spinner.prototype, "min", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Number)
- ], Spinner.prototype, "max", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Number)
- ], Spinner.prototype, "maxlength", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Number)
- ], Spinner.prototype, "size", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], Spinner.prototype, "placeholder", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], Spinner.prototype, "inputId", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Boolean)
- ], Spinner.prototype, "disabled", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Boolean)
- ], Spinner.prototype, "readonly", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Number)
- ], Spinner.prototype, "tabindex", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Boolean)
- ], Spinner.prototype, "required", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], Spinner.prototype, "name", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Object)
- ], Spinner.prototype, "inputStyle", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], Spinner.prototype, "inputStyleClass", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Boolean)
- ], Spinner.prototype, "formatInput", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], Spinner.prototype, "decimalSeparator", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], Spinner.prototype, "thousandSeparator", void 0);
- __decorate([
- core_1.ViewChild('inputfield', { static: false }),
- __metadata("design:type", core_1.ElementRef)
- ], Spinner.prototype, "inputfieldViewChild", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String),
- __metadata("design:paramtypes", [String])
- ], Spinner.prototype, "type", null);
- Spinner = __decorate([
- core_1.Component({
- selector: 'p-spinner',
- template: "\n <span class=\"ui-spinner ui-widget ui-corner-all\">\n <input #inputfield type=\"text\" [attr.id]=\"inputId\" [value]=\"formattedValue||null\" [attr.name]=\"name\"\n [attr.size]=\"size\" [attr.maxlength]=\"maxlength\" [attr.tabindex]=\"tabindex\" [attr.placeholder]=\"placeholder\" [disabled]=\"disabled\" [readonly]=\"readonly\" [attr.required]=\"required\"\n (keydown)=\"onInputKeydown($event)\" (blur)=\"onInputBlur($event)\" (input)=\"onInput($event)\" (change)=\"onInputChange($event)\" (focus)=\"onInputFocus($event)\"\n [ngStyle]=\"inputStyle\" [class]=\"inputStyleClass\" [ngClass]=\"'ui-spinner-input ui-inputtext ui-widget ui-state-default ui-corner-all'\">\n <button type=\"button\" [ngClass]=\"{'ui-spinner-button ui-spinner-up ui-corner-tr ui-button ui-widget ui-state-default':true,'ui-state-disabled':disabled}\" [disabled]=\"disabled||readonly\" [attr.tabindex]=\"tabindex\" [attr.readonly]=\"readonly\"\n (mouseleave)=\"onUpButtonMouseleave($event)\" (mousedown)=\"onUpButtonMousedown($event)\" (mouseup)=\"onUpButtonMouseup($event)\">\n <span class=\"ui-spinner-button-icon pi pi-caret-up ui-clickable\"></span>\n </button>\n <button type=\"button\" [ngClass]=\"{'ui-spinner-button ui-spinner-down ui-corner-br ui-button ui-widget ui-state-default':true,'ui-state-disabled':disabled}\" [disabled]=\"disabled||readonly\" [attr.tabindex]=\"tabindex\" [attr.readonly]=\"readonly\"\n (mouseleave)=\"onDownButtonMouseleave($event)\" (mousedown)=\"onDownButtonMousedown($event)\" (mouseup)=\"onDownButtonMouseup($event)\">\n <span class=\"ui-spinner-button-icon pi pi-caret-down ui-clickable\"></span>\n </button>\n </span>\n ",
- host: {
- '[class.ui-inputwrapper-filled]': 'filled',
- '[class.ui-inputwrapper-focus]': 'focus'
- },
- providers: [exports.SPINNER_VALUE_ACCESSOR]
- }),
- __metadata("design:paramtypes", [core_1.ElementRef, core_1.ChangeDetectorRef])
- ], Spinner);
- return Spinner;
- }());
- exports.Spinner = Spinner;
- var SpinnerModule = /** @class */ (function () {
- function SpinnerModule() {
- }
- SpinnerModule = __decorate([
- core_1.NgModule({
- imports: [common_1.CommonModule, inputtext_1.InputTextModule],
- exports: [Spinner],
- declarations: [Spinner]
- })
- ], SpinnerModule);
- return SpinnerModule;
- }());
- exports.SpinnerModule = SpinnerModule;
- //# sourceMappingURL=spinner.js.map
|