ngx-tempusdominus-bootstrap
Version:
Angular2+ directive for tempus dominus bootstrap library.
249 lines (244 loc) • 9.98 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/forms'), require('moment'), require('@angular/common')) :
typeof define === 'function' && define.amd ? define('ngx-tempusdominus-bootstrap', ['exports', '@angular/core', '@angular/forms', 'moment', '@angular/common'], factory) :
(factory((global['ngx-tempusdominus-bootstrap'] = {}),global.ng.core,global.ng.forms,global.moment,global.ng.common));
}(this, (function (exports,core,forms,moment,common) { 'use strict';
var _moment = moment;
var NgTempusdominusBootstrapInputDirective = /** @class */ (function () {
function NgTempusdominusBootstrapInputDirective(changeDetector, el, differs) {
this.changeDetector = changeDetector;
this.el = el;
this.differs = differs;
this._options = {};
this.click = new core.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) {
if (event) {
var targetElement = event.target;
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 && e.date !== _this.value) {
_this.value = e.date || null;
}
else {
var date = _moment(e.target.value, _this.options.format);
if (date.isValid()) {
_this.value = date;
}
}
});
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: core.Directive, args: [{
selector: '[NgTempusdominusBootstrapInput]',
exportAs: 'NgTempusdominusBootstrapInput',
providers: [
{ provide: forms.NG_VALUE_ACCESSOR, useExisting: core.forwardRef(function () { return NgTempusdominusBootstrapInputDirective; }), multi: true }
]
},] },
];
NgTempusdominusBootstrapInputDirective.ctorParameters = function () { return [
{ type: core.ChangeDetectorRef },
{ type: core.ElementRef },
{ type: core.KeyValueDiffers }
]; };
NgTempusdominusBootstrapInputDirective.propDecorators = {
options: [{ type: core.Input }],
click: [{ type: core.Output }],
onBlur: [{ type: core.HostListener, args: ['blur',] }],
onFocus: [{ type: core.HostListener, args: ['focus',] }],
outsideClick: [{ type: core.HostListener, args: ['document:click', ['$event'],] }]
};
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: core.Directive, args: [{
selector: '[NgTempusdominusBootstrapToggle]'
},] },
];
NgTempusdominusBootstrapToggleDirective.ctorParameters = function () { return [
{ type: undefined, decorators: [{ type: core.Inject, args: [core.forwardRef(function () { return NgTempusdominusBootstrapDirective; }),] }] },
{ type: core.ElementRef }
]; };
NgTempusdominusBootstrapToggleDirective.propDecorators = {
cursor: [{ type: core.HostBinding, args: ['style.cursor',] }],
click: [{ type: core.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: core.Directive, args: [{
selector: '[NgTempusdominusBootstrap]'
},] },
];
NgTempusdominusBootstrapDirective.ctorParameters = function () { return [
{ type: core.ElementRef }
]; };
NgTempusdominusBootstrapDirective.propDecorators = {
_input: [{ type: core.ContentChild, args: [NgTempusdominusBootstrapInputDirective,] }],
outsideClick: [{ type: core.HostListener, args: ['document:click', ['$event', '$event.target'],] }]
};
var NgTempusdominusBootstrapModule = /** @class */ (function () {
function NgTempusdominusBootstrapModule() {
}
return NgTempusdominusBootstrapModule;
}());
NgTempusdominusBootstrapModule.decorators = [
{ type: core.NgModule, args: [{
imports: [
common.CommonModule,
forms.FormsModule
],
declarations: [
NgTempusdominusBootstrapDirective,
NgTempusdominusBootstrapToggleDirective,
NgTempusdominusBootstrapInputDirective,
],
exports: [
NgTempusdominusBootstrapDirective,
NgTempusdominusBootstrapToggleDirective,
NgTempusdominusBootstrapInputDirective
]
},] },
];
exports.NgTempusdominusBootstrapModule = NgTempusdominusBootstrapModule;
exports.NgTempusdominusBootstrapToggleDirective = NgTempusdominusBootstrapToggleDirective;
exports.NgTempusdominusBootstrapDirective = NgTempusdominusBootstrapDirective;
exports.NgTempusdominusBootstrapInputDirective = NgTempusdominusBootstrapInputDirective;
Object.defineProperty(exports, '__esModule', { value: true });
})));
//# sourceMappingURL=ngx-tempusdominus-bootstrap.umd.js.map