UNPKG

ferngully-aurelia-tools

Version:

Ferngully Tools for Aurelia

146 lines 6.08 kB
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 { customAttribute, bindable, autoinject, BindingEngine } from "aurelia-framework"; import { bindingMode as BindingMode } from "aurelia-binding"; import { LoggingService } from "../../../services/logging-service"; import { DOMService } from "../../../services/dom-service"; import "./editable-inline.css"; var EditableInline = (function () { function EditableInline(el, bindingEngine, logger, domService) { this.bindingEngine = bindingEngine; this.logger = logger; this.domService = domService; this.container = "body"; this.isDirty = false; this.subscription = null; this.editing = false; this.element = $(el); } Object.defineProperty(EditableInline.prototype, "clickElement", { get: function () { return this.element; }, enumerable: true, configurable: true }); EditableInline.prototype.bind = function () { var _this = this; this.subscription = this.bindingEngine.propertyObserver(this, "target") .subscribe(function (newValue, oldValue) { _this.isDirty = (_this.originalValue !== newValue); }); this.element.addClass("editableInline"); this.clickElement.on('click.editable-inline', function (event) { _this.beginEdit(); }); }; EditableInline.prototype.unbind = function () { if (this.subscription) { this.subscription.dispose(); this.subscription = null; } this.clickElement.off('click.editable-inline'); }; EditableInline.prototype.beginEdit = function () { var _this = this; if (!this.originalValue) { this.originalValue = this.target; } if (this.maxLength != undefined) { this.editableInlineEditor.maxLength = this.maxLength; } this.editableInlineEditor.show(this.element, this.editorData, this.target, function (event) { return _this.onKeyPressInEditor(event); }, function () { _this.validateAndSave(); }); this.editing = true; }; EditableInline.prototype.endEdit = function () { this.editing = false; this.editableInlineEditor.hide(); }; EditableInline.prototype.onKeyPressInEditor = function (event) { switch (event.which) { case 13: if (event.shiftKey || event.ctrlKey) { return true; } else { this.validateAndSave(); return false; } case 9: this.validateAndSave(); var nextCell_1 = null; if (event.shiftKey) { nextCell_1 = this.element.prev(".editableInline"); if (nextCell_1.length === 0) { nextCell_1 = this.domService.nextInDOM(".editableInline", this.element, true, this.container); } } else { nextCell_1 = this.element.next(".editableInline"); if (nextCell_1.length === 0) { nextCell_1 = this.domService.nextInDOM(".editableInline", this.element, false, this.container); } } if (nextCell_1) { setTimeout(function () { nextCell_1.click(); }, 10); } return false; case 27: this.target = this.originalValue; this.endEdit(); event.stopPropagation(); return false; default: return true; } ; }; EditableInline.prototype.validateAndSave = function () { if (this.editing) { var currentUneditedValue = (this.target || "") + ""; var newValue = (this.editableInlineEditor.value || "") + ""; if (currentUneditedValue !== newValue) { this.target = this.editableInlineEditor.value; } this.endEdit(); } }; __decorate([ bindable({ defaultBindingMode: BindingMode.twoWay }), __metadata("design:type", Object) ], EditableInline.prototype, "target", void 0); __decorate([ bindable, __metadata("design:type", String) ], EditableInline.prototype, "container", void 0); __decorate([ bindable, __metadata("design:type", Number) ], EditableInline.prototype, "maxLength", void 0); __decorate([ bindable, __metadata("design:type", Object) ], EditableInline.prototype, "editorData", void 0); __decorate([ bindable, __metadata("design:type", Object) ], EditableInline.prototype, "editableInlineEditor", void 0); EditableInline = __decorate([ customAttribute('editable-inline'), autoinject, __metadata("design:paramtypes", [Element, BindingEngine, LoggingService, DOMService]) ], EditableInline); return EditableInline; }()); export { EditableInline }; //# sourceMappingURL=editable-inline.js.map