UNPKG

ng-tempusdominus-bootstrap4

Version:

Angular2+ directive for tempus dominus bootstrap 4 library.

230 lines (227 loc) 9.06 kB
import { Directive, ElementRef, Input, EventEmitter, Output, forwardRef, ChangeDetectorRef, KeyValueDiffers, HostListener, HostBinding, Inject, ContentChild, NgModule } from '@angular/core'; import { NG_VALUE_ACCESSOR, FormsModule } from '@angular/forms'; import { CommonModule } from '@angular/common'; var NgTempusdominusBootstrapInputDirective = /** @class */ (function () { function NgTempusdominusBootstrapInputDirective(changeDetector, el, differs) { this.changeDetector = changeDetector; this.el = el; this.differs = differs; this._options = {}; this.click = new EventEmitter(); this._onTouched = function () { }; this._onChange = function () { }; this.dpinitialized = false; var $parent = $(el.nativeElement.parentNode); this.inputOnly = !$parent.hasClass('input-group'); this.dpElement = $parent.hasClass('input-group') ? $parent : $(el.nativeElement); } Object.defineProperty(NgTempusdominusBootstrapInputDirective.prototype, "options", { get: function () { return this._options; }, set: function (value) { if (value !== null) { this._options = value; } }, enumerable: true, configurable: true }); NgTempusdominusBootstrapInputDirective.prototype.onBlur = function () { this._onTouched(); }; NgTempusdominusBootstrapInputDirective.prototype.onFocus = function () { if (this.inputOnly) { this.dpElement.datetimepicker('toggle'); } }; NgTempusdominusBootstrapInputDirective.prototype.outsideClick = function (event, targetElement) { if (!targetElement || !this.inputOnly || this.options.inline) { return; } var clickedInside = this.el.nativeElement.contains(targetElement); if (!clickedInside) { this.dpElement.datetimepicker('hide'); } }; Object.defineProperty(NgTempusdominusBootstrapInputDirective.prototype, "value", { get: function () { return this._value || null; }, set: function (val) { this._value = val; this._onChange(val); if (val) { this._onTouched(); } this.changeDetector.markForCheck(); }, enumerable: true, configurable: true }); NgTempusdominusBootstrapInputDirective.prototype.writeValue = function (value) { if (this._value && !value) { this.value = null; this.dpElement.datetimepicker('clear'); } this.value = value; this.setDpValue(value); }; NgTempusdominusBootstrapInputDirective.prototype.registerOnChange = function (fn) { this._onChange = fn; }; NgTempusdominusBootstrapInputDirective.prototype.registerOnTouched = function (fn) { this._onTouched = fn; }; NgTempusdominusBootstrapInputDirective.prototype.setDpValue = function (val) { if (!this.dpinitialized) { return; } if (val) { this.dpElement.datetimepicker('date', this.value); } }; NgTempusdominusBootstrapInputDirective.prototype.setDisabledState = function (isDisabled) { if (isDisabled) { this.dpElement.datetimepicker('disable'); return; } this.dpElement.datetimepicker('enable'); }; NgTempusdominusBootstrapInputDirective.prototype.ngOnInit = function () { var _this = this; this.dpinitialized = true; this.dpElement.datetimepicker(this.options); this.dpElement.on('change.datetimepicker', function (e) { if (e.date !== _this.value) { _this.value = e.date || null; } }); this.dpElement.on('click', function () { _this.click.emit(); }); this.optionsDiffer = this.differs.find(this.options).create(); }; NgTempusdominusBootstrapInputDirective.prototype.ngDoCheck = function () { var _this = this; if (this.dpinitialized) { var changes = this.optionsDiffer.diff(this.options); if (changes) { $.map(this.options, function (value, key) { _this.dpElement.datetimepicker(key, value); }); } } }; NgTempusdominusBootstrapInputDirective.prototype.ngOnDestroy = function () { this.dpElement.datetimepicker('destroy'); }; NgTempusdominusBootstrapInputDirective.prototype.toggle = function () { this.dpElement.datetimepicker('toggle'); }; return NgTempusdominusBootstrapInputDirective; }()); NgTempusdominusBootstrapInputDirective.decorators = [ { type: Directive, args: [{ selector: '[NgTempusdominusBootstrapInput]', exportAs: 'NgTempusdominusBootstrapInput', providers: [ { provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(function () { return NgTempusdominusBootstrapInputDirective; }), multi: true } ] },] }, ]; NgTempusdominusBootstrapInputDirective.ctorParameters = function () { return [ { type: ChangeDetectorRef, }, { type: ElementRef, }, { type: KeyValueDiffers, }, ]; }; NgTempusdominusBootstrapInputDirective.propDecorators = { "options": [{ type: Input },], "click": [{ type: Output },], "onBlur": [{ type: HostListener, args: ['blur',] },], "onFocus": [{ type: HostListener, args: ['focus',] },], "outsideClick": [{ type: HostListener, args: ['document:click', ['$event', '$event.target'],] },], }; var NgTempusdominusBootstrapToggleDirective = /** @class */ (function () { function NgTempusdominusBootstrapToggleDirective(tempusDominus, elementRef) { this.tempusDominus = tempusDominus; this.cursor = 'pointer'; } NgTempusdominusBootstrapToggleDirective.prototype.click = function () { this.toggleOpen(); }; NgTempusdominusBootstrapToggleDirective.prototype.toggleOpen = function () { this.tempusDominus.toggle(); }; return NgTempusdominusBootstrapToggleDirective; }()); NgTempusdominusBootstrapToggleDirective.decorators = [ { type: Directive, args: [{ selector: '[NgTempusdominusBootstrapToggle]' },] }, ]; NgTempusdominusBootstrapToggleDirective.ctorParameters = function () { return [ { type: undefined, decorators: [{ type: Inject, args: [forwardRef(function () { return NgTempusdominusBootstrapDirective; }),] },] }, { type: ElementRef, }, ]; }; NgTempusdominusBootstrapToggleDirective.propDecorators = { "cursor": [{ type: HostBinding, args: ['style.cursor',] },], "click": [{ type: HostListener, args: ['click',] },], }; var NgTempusdominusBootstrapDirective = /** @class */ (function () { function NgTempusdominusBootstrapDirective(el) { this.el = el; } NgTempusdominusBootstrapDirective.prototype.outsideClick = function (event, targetElement) { if (!targetElement) { return; } var clickedInside = this.el.nativeElement.contains(targetElement); if (!clickedInside) { this._input.dpElement.datetimepicker('hide'); } }; NgTempusdominusBootstrapDirective.prototype.toggle = function () { this._input.toggle(); }; return NgTempusdominusBootstrapDirective; }()); NgTempusdominusBootstrapDirective.decorators = [ { type: Directive, args: [{ selector: '[NgTempusdominusBootstrap]' },] }, ]; NgTempusdominusBootstrapDirective.ctorParameters = function () { return [ { type: ElementRef, }, ]; }; NgTempusdominusBootstrapDirective.propDecorators = { "_input": [{ type: ContentChild, args: [NgTempusdominusBootstrapInputDirective,] },], "outsideClick": [{ type: HostListener, args: ['document:click', ['$event', '$event.target'],] },], }; var NgTempusdominusBootstrapModule = /** @class */ (function () { function NgTempusdominusBootstrapModule() { } return NgTempusdominusBootstrapModule; }()); NgTempusdominusBootstrapModule.decorators = [ { type: NgModule, args: [{ imports: [ CommonModule, FormsModule ], declarations: [ NgTempusdominusBootstrapDirective, NgTempusdominusBootstrapToggleDirective, NgTempusdominusBootstrapInputDirective, ], exports: [ NgTempusdominusBootstrapDirective, NgTempusdominusBootstrapToggleDirective, NgTempusdominusBootstrapInputDirective ] },] }, ]; export { NgTempusdominusBootstrapModule, NgTempusdominusBootstrapToggleDirective, NgTempusdominusBootstrapDirective, NgTempusdominusBootstrapInputDirective }; //# sourceMappingURL=ng-tempusdominus-bootstrap4.js.map