jqwidgets-ng
Version:
[](https://jqwidgets.com/license/)
470 lines (465 loc) • 18.1 kB
JavaScript
import '../jqwidgets/modules/jqxformattedinput';
import * as i0 from '@angular/core';
import { forwardRef, EventEmitter, Component, ChangeDetectionStrategy, Input, Output, NgModule } from '@angular/core';
import * as i1 from '@angular/forms';
import { NG_VALUE_ACCESSOR, FormsModule } from '@angular/forms';
/// <reference path="../../jqwidgets.d.ts" />
const noop = () => { };
const CUSTOM_INPUT_CONTROL_VALUE_ACCESSOR = {
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => jqxFormattedInputComponent),
multi: true
};
class jqxFormattedInputComponent {
constructor(containerElement) {
this.autoCreate = true;
this.properties = ['disabled', 'decimalNotation', 'dropDown', 'dropDownWidth', 'height', 'min', 'max', 'placeHolder', 'popupZIndex', 'roundedCorners', 'rtl', 'radix', 'spinButtons', 'spinButtonsStep', 'template', 'theme', 'upperCase', 'value', 'width'];
this.onTouchedCallback = noop;
this.onChangeCallback = noop;
// jqxFormattedInputComponent events
this.onChange = new EventEmitter();
this.onClose = new EventEmitter();
this.onOpen = new EventEmitter();
this.onRadixChange = new EventEmitter();
this.elementRef = containerElement;
}
ngOnInit() {
if (this.autoCreate) {
this.createComponent();
}
}
;
ngOnChanges(changes) {
if (this.host) {
for (let i = 0; i < this.properties.length; i++) {
let attrName = 'attr' + this.properties[i].substring(0, 1).toUpperCase() + this.properties[i].substring(1);
let areEqual = false;
if (this[attrName] !== undefined) {
if (typeof this[attrName] === 'object') {
if (this[attrName] instanceof Array) {
areEqual = this.arraysEqual(this[attrName], this.host.jqxFormattedInput(this.properties[i]));
}
if (areEqual) {
return false;
}
this.host.jqxFormattedInput(this.properties[i], this[attrName]);
continue;
}
if (this[attrName] !== this.host.jqxFormattedInput(this.properties[i])) {
this.host.jqxFormattedInput(this.properties[i], this[attrName]);
}
}
}
}
}
arraysEqual(attrValue, hostValue) {
if ((attrValue && !hostValue) || (!attrValue && hostValue)) {
return false;
}
if (attrValue.length != hostValue.length) {
return false;
}
for (let i = 0; i < attrValue.length; i++) {
if (attrValue[i] !== hostValue[i]) {
return false;
}
}
return true;
}
manageAttributes() {
let options = {};
for (let i = 0; i < this.properties.length; i++) {
let attrName = 'attr' + this.properties[i].substring(0, 1).toUpperCase() + this.properties[i].substring(1);
if (this[attrName] !== undefined) {
options[this.properties[i]] = this[attrName];
}
}
return options;
}
moveClasses(parentEl, childEl) {
let classes = parentEl.classList;
if (classes.length > 0) {
childEl.classList.add(...classes);
}
parentEl.className = '';
}
moveStyles(parentEl, childEl) {
let style = parentEl.style.cssText;
childEl.style.cssText = style;
parentEl.style.cssText = '';
}
createComponent(options) {
if (this.host) {
return;
}
if (options) {
JQXLite.extend(options, this.manageAttributes());
}
else {
options = this.manageAttributes();
}
this.host = JQXLite(this.elementRef.nativeElement.firstChild);
this.moveClasses(this.elementRef.nativeElement, this.host[0]);
this.moveStyles(this.elementRef.nativeElement, this.host[0]);
if (this.attrRtl !== true) {
if (this.attrSpinButtons === false) {
this.host.children()[1].remove();
}
if (this.attrDropDown !== true) {
this.host.children()[1].remove();
}
}
else if (this.attrRtl === true) {
this.host.children()[1].remove();
this.host.children()[1].remove();
if (this.attrSpinButtons !== false) {
this.host.prepend('<div></div>');
}
if (this.attrDropDown === true) {
this.host.prepend('<div></div>');
}
}
this.__wireEvents__();
this.widgetObject = jqwidgets.createInstance(this.host, 'jqxFormattedInput', options);
}
createWidget(options) {
this.createComponent(options);
}
__updateRect__() {
if (this.host)
this.host.css({ width: this.attrWidth, height: this.attrHeight });
}
get ngValue() {
if (this.widgetObject) {
const value = this.host.val();
return value;
}
return '';
}
set ngValue(value) {
if (this.widgetObject) {
this.onChangeCallback(value);
}
}
writeValue(value) {
if (this.widgetObject) {
this.host.jqxFormattedInput('val', value);
}
if (this.host && (value === null || value === undefined)) {
this.host.jqxFormattedInput('val', '');
}
}
registerOnChange(fn) {
this.onChangeCallback = fn;
}
registerOnTouched(fn) {
this.onTouchedCallback = fn;
}
setOptions(options) {
this.host.jqxFormattedInput('setOptions', options);
}
// jqxFormattedInputComponent properties
disabled(arg) {
if (arg !== undefined) {
this.host.jqxFormattedInput('disabled', arg);
}
else {
return this.host.jqxFormattedInput('disabled');
}
}
decimalNotation(arg) {
if (arg !== undefined) {
this.host.jqxFormattedInput('decimalNotation', arg);
}
else {
return this.host.jqxFormattedInput('decimalNotation');
}
}
dropDown(arg) {
if (arg !== undefined) {
this.host.jqxFormattedInput('dropDown', arg);
}
else {
return this.host.jqxFormattedInput('dropDown');
}
}
dropDownWidth(arg) {
if (arg !== undefined) {
this.host.jqxFormattedInput('dropDownWidth', arg);
}
else {
return this.host.jqxFormattedInput('dropDownWidth');
}
}
height(arg) {
if (arg !== undefined) {
this.host.jqxFormattedInput('height', arg);
}
else {
return this.host.jqxFormattedInput('height');
}
}
min(arg) {
if (arg !== undefined) {
this.host.jqxFormattedInput('min', arg);
}
else {
return this.host.jqxFormattedInput('min');
}
}
max(arg) {
if (arg !== undefined) {
this.host.jqxFormattedInput('max', arg);
}
else {
return this.host.jqxFormattedInput('max');
}
}
placeHolder(arg) {
if (arg !== undefined) {
this.host.jqxFormattedInput('placeHolder', arg);
}
else {
return this.host.jqxFormattedInput('placeHolder');
}
}
popupZIndex(arg) {
if (arg !== undefined) {
this.host.jqxFormattedInput('popupZIndex', arg);
}
else {
return this.host.jqxFormattedInput('popupZIndex');
}
}
roundedCorners(arg) {
if (arg !== undefined) {
this.host.jqxFormattedInput('roundedCorners', arg);
}
else {
return this.host.jqxFormattedInput('roundedCorners');
}
}
rtl(arg) {
if (arg !== undefined) {
this.host.jqxFormattedInput('rtl', arg);
}
else {
return this.host.jqxFormattedInput('rtl');
}
}
radix(arg) {
if (arg !== undefined) {
this.host.jqxFormattedInput('radix', arg);
}
else {
return this.host.jqxFormattedInput('radix');
}
}
spinButtons(arg) {
if (arg !== undefined) {
this.host.jqxFormattedInput('spinButtons', arg);
}
else {
return this.host.jqxFormattedInput('spinButtons');
}
}
spinButtonsStep(arg) {
if (arg !== undefined) {
this.host.jqxFormattedInput('spinButtonsStep', arg);
}
else {
return this.host.jqxFormattedInput('spinButtonsStep');
}
}
template(arg) {
if (arg !== undefined) {
this.host.jqxFormattedInput('template', arg);
}
else {
return this.host.jqxFormattedInput('template');
}
}
theme(arg) {
if (arg !== undefined) {
this.host.jqxFormattedInput('theme', arg);
}
else {
return this.host.jqxFormattedInput('theme');
}
}
upperCase(arg) {
if (arg !== undefined) {
this.host.jqxFormattedInput('upperCase', arg);
}
else {
return this.host.jqxFormattedInput('upperCase');
}
}
value(arg) {
if (arg !== undefined) {
this.host.jqxFormattedInput('value', arg);
}
else {
return this.host.jqxFormattedInput('value');
}
}
width(arg) {
if (arg !== undefined) {
this.host.jqxFormattedInput('width', arg);
}
else {
return this.host.jqxFormattedInput('width');
}
}
// jqxFormattedInputComponent functions
close() {
this.host.jqxFormattedInput('close');
}
destroy() {
this.host.jqxFormattedInput('destroy');
}
focus() {
this.host.jqxFormattedInput('focus');
}
open() {
this.host.jqxFormattedInput('open');
}
render() {
this.host.jqxFormattedInput('render');
}
refresh() {
this.host.jqxFormattedInput('refresh');
}
selectAll() {
this.host.jqxFormattedInput('selectAll');
}
selectFirst() {
this.host.jqxFormattedInput('selectFirst');
}
selectLast() {
this.host.jqxFormattedInput('selectLast');
}
val(value) {
if (value !== undefined) {
return this.host.jqxFormattedInput('val', value);
}
else {
return this.host.jqxFormattedInput('val');
}
}
;
__wireEvents__() {
this.host.on('change', (eventData) => {
this.onChange.emit(eventData);
if (eventData.args)
this.onChangeCallback(eventData.args.value);
});
this.host.on('close', (eventData) => { this.onClose.emit(eventData); });
this.host.on('open', (eventData) => { this.onOpen.emit(eventData); });
this.host.on('radixChange', (eventData) => {
this.onRadixChange.emit(eventData);
if (eventData.args)
this.onChangeCallback(eventData.args.value);
});
}
} //jqxFormattedInputComponent
jqxFormattedInputComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.7", ngImport: i0, type: jqxFormattedInputComponent, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Component });
jqxFormattedInputComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.2.7", type: jqxFormattedInputComponent, selector: "jqxFormattedInput", inputs: { attrDisabled: ["disabled", "attrDisabled"], attrDecimalNotation: ["decimalNotation", "attrDecimalNotation"], attrDropDown: ["dropDown", "attrDropDown"], attrDropDownWidth: ["dropDownWidth", "attrDropDownWidth"], attrMin: ["min", "attrMin"], attrMax: ["max", "attrMax"], attrPlaceHolder: ["placeHolder", "attrPlaceHolder"], attrPopupZIndex: ["popupZIndex", "attrPopupZIndex"], attrRoundedCorners: ["roundedCorners", "attrRoundedCorners"], attrRtl: ["rtl", "attrRtl"], attrRadix: ["radix", "attrRadix"], attrSpinButtons: ["spinButtons", "attrSpinButtons"], attrSpinButtonsStep: ["spinButtonsStep", "attrSpinButtonsStep"], attrTemplate: ["template", "attrTemplate"], attrTheme: ["theme", "attrTheme"], attrUpperCase: ["upperCase", "attrUpperCase"], attrValue: ["value", "attrValue"], attrWidth: ["width", "attrWidth"], attrHeight: ["height", "attrHeight"], autoCreate: ["auto-create", "autoCreate"] }, outputs: { onChange: "onChange", onClose: "onClose", onOpen: "onOpen", onRadixChange: "onRadixChange" }, providers: [CUSTOM_INPUT_CONTROL_VALUE_ACCESSOR], usesOnChanges: true, ngImport: i0, template: '<div><input type="text" [(ngModel)]="ngValue"><div></div><div></div></div>', isInline: true, directives: [{ type: i1.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { type: i1.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.7", ngImport: i0, type: jqxFormattedInputComponent, decorators: [{
type: Component,
args: [{
selector: 'jqxFormattedInput',
template: '<div><input type="text" [(ngModel)]="ngValue"><div></div><div></div></div>',
providers: [CUSTOM_INPUT_CONTROL_VALUE_ACCESSOR],
changeDetection: ChangeDetectionStrategy.OnPush
}]
}], ctorParameters: function () { return [{ type: i0.ElementRef }]; }, propDecorators: { attrDisabled: [{
type: Input,
args: ['disabled']
}], attrDecimalNotation: [{
type: Input,
args: ['decimalNotation']
}], attrDropDown: [{
type: Input,
args: ['dropDown']
}], attrDropDownWidth: [{
type: Input,
args: ['dropDownWidth']
}], attrMin: [{
type: Input,
args: ['min']
}], attrMax: [{
type: Input,
args: ['max']
}], attrPlaceHolder: [{
type: Input,
args: ['placeHolder']
}], attrPopupZIndex: [{
type: Input,
args: ['popupZIndex']
}], attrRoundedCorners: [{
type: Input,
args: ['roundedCorners']
}], attrRtl: [{
type: Input,
args: ['rtl']
}], attrRadix: [{
type: Input,
args: ['radix']
}], attrSpinButtons: [{
type: Input,
args: ['spinButtons']
}], attrSpinButtonsStep: [{
type: Input,
args: ['spinButtonsStep']
}], attrTemplate: [{
type: Input,
args: ['template']
}], attrTheme: [{
type: Input,
args: ['theme']
}], attrUpperCase: [{
type: Input,
args: ['upperCase']
}], attrValue: [{
type: Input,
args: ['value']
}], attrWidth: [{
type: Input,
args: ['width']
}], attrHeight: [{
type: Input,
args: ['height']
}], autoCreate: [{
type: Input,
args: ['auto-create']
}], onChange: [{
type: Output
}], onClose: [{
type: Output
}], onOpen: [{
type: Output
}], onRadixChange: [{
type: Output
}] } });
class jqxFormattedInputModule {
}
jqxFormattedInputModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.7", ngImport: i0, type: jqxFormattedInputModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
jqxFormattedInputModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.2.7", ngImport: i0, type: jqxFormattedInputModule, declarations: [jqxFormattedInputComponent], imports: [FormsModule], exports: [jqxFormattedInputComponent] });
jqxFormattedInputModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.2.7", ngImport: i0, type: jqxFormattedInputModule, imports: [[
FormsModule
]] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.7", ngImport: i0, type: jqxFormattedInputModule, decorators: [{
type: NgModule,
args: [{
imports: [
FormsModule
],
declarations: [jqxFormattedInputComponent],
exports: [jqxFormattedInputComponent]
}]
}] });
/**
* Generated bundle index. Do not edit.
*/
export { jqxFormattedInputComponent, jqxFormattedInputModule };