nakedobjects.spa
Version:
Single Page Application client for a Naked Objects application.
119 lines • 4.88 kB
JavaScript
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);
};
import { Directive, ElementRef, HostListener, Output, EventEmitter, Renderer, Input } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import { safeUnsubscribe } from './helpers-components';
var ClearDirective = (function () {
function ClearDirective(el, renderer) {
this.el = el;
this.renderer = renderer;
this.clear = new EventEmitter();
this.nativeEl = this.el.nativeElement;
}
ClearDirective.prototype.ngOnInit = function () {
var _this = this;
this.onChange();
this.sub = this.subject.subscribe(function (data) { return _this.onChange(); });
};
// not need the ngClass directive on element even though it doesn't do anything
// otherwise we lose all the classes added here
ClearDirective.prototype.onChange = function () {
this.nativeEl.classList.add("ng-clearable");
if (this.subject.getValue()) {
this.nativeEl.classList.add("ng-x");
}
else {
this.nativeEl.classList.remove("ng-x");
}
};
ClearDirective.prototype.onMouseMove = function (event) {
if (this.nativeEl.classList.contains("ng-x")) {
var onX = this.nativeEl.offsetWidth - 18 < event.clientX - this.nativeEl.getBoundingClientRect().left;
if (onX) {
this.nativeEl.classList.add("ng-onX");
}
else {
this.nativeEl.classList.remove("ng-onX");
}
}
};
ClearDirective.prototype.onClick = function (event) {
if (this.nativeEl.classList.contains("ng-onX")) {
event.preventDefault();
this.nativeEl.classList.remove("ng-x");
this.nativeEl.classList.remove("ng-onX");
this.clear.emit("event");
}
};
ClearDirective.prototype.click = function (event) {
this.onClick(event);
};
ClearDirective.prototype.touchstart = function (event) {
this.onClick(event);
};
ClearDirective.prototype.mousemove = function (event) {
this.onMouseMove(event);
};
ClearDirective.prototype.input = function () {
this.onChange();
};
ClearDirective.prototype.change = function () {
this.onChange();
};
ClearDirective.prototype.ngOnDestroy = function () {
safeUnsubscribe(this.sub);
};
return ClearDirective;
}());
__decorate([
Input('nofClear'),
__metadata("design:type", BehaviorSubject)
], ClearDirective.prototype, "subject", void 0);
__decorate([
Output(),
__metadata("design:type", Object)
], ClearDirective.prototype, "clear", void 0);
__decorate([
HostListener("click", ['$event']),
__metadata("design:type", Function),
__metadata("design:paramtypes", [KeyboardEvent]),
__metadata("design:returntype", void 0)
], ClearDirective.prototype, "click", null);
__decorate([
HostListener("touchstart", ['$event']),
__metadata("design:type", Function),
__metadata("design:paramtypes", [KeyboardEvent]),
__metadata("design:returntype", void 0)
], ClearDirective.prototype, "touchstart", null);
__decorate([
HostListener("mousemove", ['$event']),
__metadata("design:type", Function),
__metadata("design:paramtypes", [MouseEvent]),
__metadata("design:returntype", void 0)
], ClearDirective.prototype, "mousemove", null);
__decorate([
HostListener("input"),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], ClearDirective.prototype, "input", null);
__decorate([
HostListener("change"),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], ClearDirective.prototype, "change", null);
ClearDirective = __decorate([
Directive({ selector: '[nofClear]' }),
__metadata("design:paramtypes", [ElementRef,
Renderer])
], ClearDirective);
export { ClearDirective };
//# sourceMappingURL=clear.directive.js.map