diff --git a/dist/amd/attach-focus.js b/dist/amd/attach-focus.js index b3deb74..4f792e7 100644 --- a/dist/amd/attach-focus.js +++ b/dist/amd/attach-focus.js @@ -8,24 +8,23 @@ define(['exports', 'aurelia-templating'], function (exports, _aureliaTemplating) function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } var AttachFocus = (function () { + _createClass(AttachFocus, null, [{ + key: 'inject', + value: [Element], + enumerable: true + }]); + function AttachFocus(element) { _classCallCheck(this, _AttachFocus); this.element = element; } - var _AttachFocus = AttachFocus; - - _AttachFocus.prototype.attached = function attached() { + AttachFocus.prototype.attached = function attached() { this.element.focus(); }; - _createClass(_AttachFocus, null, [{ - key: 'inject', - value: [Element], - enumerable: true - }]); - + var _AttachFocus = AttachFocus; AttachFocus = _aureliaTemplating.customAttribute('attach-focus')(AttachFocus) || AttachFocus; return AttachFocus; })(); diff --git a/dist/amd/dialog-controller.js b/dist/amd/dialog-controller.js index 8ffb089..741c202 100644 --- a/dist/amd/dialog-controller.js +++ b/dist/amd/dialog-controller.js @@ -23,27 +23,35 @@ define(['exports', './lifecycle'], function (exports, _lifecycle) { this.close(false, result); }; - DialogController.prototype.close = function close(success, result) { + DialogController.prototype.error = function error(message) { var _this = this; + return _lifecycle.invokeLifecycle(this.viewModel, 'deactivate').then(function () { + return _this._renderer.hideDialog(_this).then(function () { + return _this._renderer.destroyDialogHost(_this).then(function () { + _this.behavior.unbind(); + _this._reject(message); + }); + }); + }); + }; + + DialogController.prototype.close = function close(ok, result) { + var _this2 = this; + return _lifecycle.invokeLifecycle(this.viewModel, 'canDeactivate').then(function (canDeactivate) { if (canDeactivate) { - return _lifecycle.invokeLifecycle(_this.viewModel, 'deactivate').then(function () { - return _this._renderer.hideDialog(_this).then(function () { - return _this._renderer.destroyDialogHost(_this).then(function () { - _this.behavior.unbind(); - - if (success) { - _this._resolve(result); - } else { - _this._reject(result); + return _lifecycle.invokeLifecycle(_this2.viewModel, 'deactivate').then(function () { + return _this2._renderer.hideDialog(_this2).then(function () { + return _this2._renderer.destroyDialogHost(_this2).then(function () { + _this2.behavior.unbind(); + if (ok) { + _this2._resolve(result); } }); }); }); } - - return Promise.reject(); }); }; diff --git a/dist/amd/dialog-footer.js b/dist/amd/dialog-footer.js index 15dd4ea..960ca76 100644 --- a/dist/amd/dialog-footer.js +++ b/dist/amd/dialog-footer.js @@ -12,6 +12,26 @@ define(['exports', 'aurelia-templating', './dialog-controller'], function (expor var DialogFooter = (function () { var _instanceInitializers = {}; + _createDecoratedClass(DialogFooter, [{ + key: 'buttons', + decorators: [_aureliaTemplating.bindable], + initializer: function initializer() { + return []; + }, + enumerable: true + }, { + key: 'useDefaultButtons', + decorators: [_aureliaTemplating.bindable], + initializer: function initializer() { + return false; + }, + enumerable: true + }], [{ + key: 'inject', + value: [_dialogController.DialogController], + enumerable: true + }], _instanceInitializers); + function DialogFooter(controller) { _classCallCheck(this, _DialogFooter); @@ -22,9 +42,7 @@ define(['exports', 'aurelia-templating', './dialog-controller'], function (expor this.controller = controller; } - var _DialogFooter = DialogFooter; - - _DialogFooter.prototype.close = function close(buttonValue) { + DialogFooter.prototype.close = function close(buttonValue) { if (DialogFooter.isCancelButton(buttonValue)) { this.controller.cancel(buttonValue); } else { @@ -32,36 +50,17 @@ define(['exports', 'aurelia-templating', './dialog-controller'], function (expor } }; - _DialogFooter.prototype.useDefaultButtonsChanged = function useDefaultButtonsChanged(newValue) { + DialogFooter.prototype.useDefaultButtonsChanged = function useDefaultButtonsChanged(newValue) { if (newValue) { this.buttons = ['Cancel', 'Ok']; } }; - _DialogFooter.isCancelButton = function isCancelButton(value) { + DialogFooter.isCancelButton = function isCancelButton(value) { return value === 'Cancel'; }; - _createDecoratedClass(_DialogFooter, [{ - key: 'buttons', - decorators: [_aureliaTemplating.bindable], - initializer: function initializer() { - return []; - }, - enumerable: true - }, { - key: 'useDefaultButtons', - decorators: [_aureliaTemplating.bindable], - initializer: function initializer() { - return false; - }, - enumerable: true - }], [{ - key: 'inject', - value: [_dialogController.DialogController], - enumerable: true - }], _instanceInitializers); - + var _DialogFooter = DialogFooter; DialogFooter = _aureliaTemplating.customElement('dialog-footer')(DialogFooter) || DialogFooter; return DialogFooter; })(); diff --git a/dist/amd/dialog-header.js b/dist/amd/dialog-header.js index 3698b69..37d062a 100644 --- a/dist/amd/dialog-header.js +++ b/dist/amd/dialog-header.js @@ -8,6 +8,12 @@ define(['exports', 'aurelia-templating', './dialog-controller'], function (expor function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } var DialogHeader = (function () { + _createClass(DialogHeader, null, [{ + key: 'inject', + value: [_dialogController.DialogController], + enumerable: true + }]); + function DialogHeader(controller) { _classCallCheck(this, _DialogHeader); @@ -15,13 +21,6 @@ define(['exports', 'aurelia-templating', './dialog-controller'], function (expor } var _DialogHeader = DialogHeader; - - _createClass(_DialogHeader, null, [{ - key: 'inject', - value: [_dialogController.DialogController], - enumerable: true - }]); - DialogHeader = _aureliaTemplating.customElement('dialog-header')(DialogHeader) || DialogHeader; return DialogHeader; })(); diff --git a/dist/amd/dialog-renderer.js b/dist/amd/dialog-renderer.js index 6486455..cc6635e 100644 --- a/dist/amd/dialog-renderer.js +++ b/dist/amd/dialog-renderer.js @@ -30,18 +30,34 @@ define(["exports", "aurelia-templating"], function (exports, _aureliaTemplating) var DialogRenderer = (function () { function DialogRenderer() { + var _this = this; + _classCallCheck(this, DialogRenderer); this.defaultSettings = { - lock: true + lock: true, + centerHorizontalOnly: false }; + + this.dialogControllers = []; + + document.addEventListener('keyup', function (e) { + if (e.keyCode === 27) { + var top = _this.dialogControllers[_this.dialogControllers.length - 1]; + if (top && top.settings.lock !== true) { + top.cancel(); + } + } + }); } DialogRenderer.prototype.createDialogHost = function createDialogHost(controller) { + var _this2 = this; + var settings = controller.settings, emptyParameters = {}, - modalOverlay = document.createElement("dialog-overlay"), - modalContainer = document.createElement("dialog-container"); + modalOverlay = document.createElement('dialog-overlay'), + modalContainer = document.createElement('dialog-container'); modalOverlay.style.zIndex = getNextZIndex(); modalContainer.style.zIndex = getNextZIndex(); @@ -53,15 +69,11 @@ define(["exports", "aurelia-templating"], function (exports, _aureliaTemplating) controller.slot.add(controller.view); controller.showDialog = function () { + _this2.dialogControllers.push(controller); + controller.slot.attached(); controller.centerDialog(); - document.onkeypress = function (e) { - if (e.keyCode === 27 && settings.lock !== true) { - controller.cancel(); - } - }; - modalOverlay.onclick = function () { if (!settings.lock) { controller.cancel(); @@ -78,12 +90,17 @@ define(["exports", "aurelia-templating"], function (exports, _aureliaTemplating) resolve(); }; - modalOverlay.classList.add("active"); - modalContainer.classList.add("active"); + modalOverlay.classList.add('active'); + modalContainer.classList.add('active'); }); }; controller.hideDialog = function () { + var i = _this2.dialogControllers.indexOf(controller); + if (i !== -1) { + _this2.dialogControllers.splice(i, 1); + } + return new Promise(function (resolve, reject) { modalContainer.addEventListener(transitionEvent, onTransitionEnd); @@ -92,8 +109,8 @@ define(["exports", "aurelia-templating"], function (exports, _aureliaTemplating) resolve(); }; - modalOverlay.classList.remove("active"); - modalContainer.classList.remove("active"); + modalOverlay.classList.remove('active'); + modalContainer.classList.remove('active'); }); }; @@ -107,11 +124,11 @@ define(["exports", "aurelia-templating"], function (exports, _aureliaTemplating) controller.centerDialog = function () { var child = modalContainer.children[0]; + child.style.marginLeft = -(child.offsetWidth / 2) + 'px'; + if (!settings.centerHorizontalOnly) { - child.style.marginLeft = -(child.offsetWidth / 2) + "px"; + child.style.marginTop = -(child.offsetHeight / 2) + 'px'; } - - child.style.marginTop = -(child.offsetHeight / 2) + "px"; }; return Promise.resolve(); diff --git a/dist/amd/dialog-service.js b/dist/amd/dialog-service.js index 25586df..ef00daf 100644 --- a/dist/amd/dialog-service.js +++ b/dist/amd/dialog-service.js @@ -8,6 +8,12 @@ define(['exports', 'aurelia-metadata', 'aurelia-dependency-injection', 'aurelia- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } var DialogService = (function () { + _createClass(DialogService, null, [{ + key: 'inject', + value: [_aureliaDependencyInjection.Container, _aureliaTemplating.CompositionEngine, _dialogRenderer.DialogRenderer], + enumerable: true + }]); + function DialogService(container, compositionEngine, renderer) { _classCallCheck(this, DialogService); @@ -34,7 +40,6 @@ define(['exports', 'aurelia-metadata', 'aurelia-dependency-injection', 'aurelia- settings = Object.assign({}, this.renderer.defaultSettings, settings); return new Promise(function (resolve, reject) { - console.log('creating'); var childContainer = _this.container.createChild(), controller = new _dialogController.DialogController(_this.renderer, settings, resolve, reject), instruction = { @@ -43,7 +48,6 @@ define(['exports', 'aurelia-metadata', 'aurelia-dependency-injection', 'aurelia- childContainer: childContainer, model: settings.model }; - console.log(controller); childContainer.registerInstance(_dialogController.DialogController, controller); @@ -61,20 +65,12 @@ define(['exports', 'aurelia-metadata', 'aurelia-dependency-injection', 'aurelia- return _this.renderer.showDialog(controller); }); }); - } else { - return Promise.reject(); } }); }); }); }; - _createClass(DialogService, null, [{ - key: 'inject', - value: [_aureliaDependencyInjection.Container, _aureliaTemplating.CompositionEngine, _dialogRenderer.DialogRenderer], - enumerable: true - }]); - return DialogService; })(); diff --git a/dist/amd/examples/common-dialogs.js b/dist/amd/examples/common-dialogs.js index 7f78e4a..fc9f2f4 100644 --- a/dist/amd/examples/common-dialogs.js +++ b/dist/amd/examples/common-dialogs.js @@ -8,6 +8,12 @@ define(['exports', './prompt', '../dialog-service'], function (exports, _prompt, function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } var CommonDialogs = (function () { + _createClass(CommonDialogs, null, [{ + key: 'inject', + value: [_dialogService.DialogService], + enumerable: true + }]); + function CommonDialogs(dialogService) { _classCallCheck(this, CommonDialogs); @@ -18,12 +24,6 @@ define(['exports', './prompt', '../dialog-service'], function (exports, _prompt, return this.dialogService.open({ viewModel: _prompt.Prompt, model: question }); }; - _createClass(CommonDialogs, null, [{ - key: 'inject', - value: [_dialogService.DialogService], - enumerable: true - }]); - return CommonDialogs; })(); diff --git a/dist/amd/examples/prompt.js b/dist/amd/examples/prompt.js index f6adbad..f02a497 100644 --- a/dist/amd/examples/prompt.js +++ b/dist/amd/examples/prompt.js @@ -8,6 +8,12 @@ define(['exports', '../dialog-controller'], function (exports, _dialogController function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } var Prompt = (function () { + _createClass(Prompt, null, [{ + key: 'inject', + value: [_dialogController.DialogController], + enumerable: true + }]); + function Prompt(controller) { _classCallCheck(this, Prompt); @@ -21,12 +27,6 @@ define(['exports', '../dialog-controller'], function (exports, _dialogController this.question = question; }; - _createClass(Prompt, null, [{ - key: 'inject', - value: [_dialogController.DialogController], - enumerable: true - }]); - return Prompt; })(); diff --git a/dist/amd/index.js b/dist/amd/index.js index 22e5e26..4edbb09 100644 --- a/dist/amd/index.js +++ b/dist/amd/index.js @@ -8,8 +8,8 @@ define(['exports', './dialog-service', './dialog-controller', './examples/prompt function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; } - function configure(aurelia) { - aurelia.globalizeResources('./dialog', './dialog-header', './dialog-body', './dialog-footer', './attach-focus', './examples/prompt'); + function configure(config) { + config.globalResources('./dialog', './dialog-header', './dialog-body', './dialog-footer', './attach-focus', './examples/prompt'); } _defaults(exports, _interopRequireWildcard(_dialogService)); diff --git a/dist/commonjs/attach-focus.js b/dist/commonjs/attach-focus.js index 04493b5..0f52bbd 100644 --- a/dist/commonjs/attach-focus.js +++ b/dist/commonjs/attach-focus.js @@ -9,24 +9,23 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons var _aureliaTemplating = require('aurelia-templating'); var AttachFocus = (function () { + _createClass(AttachFocus, null, [{ + key: 'inject', + value: [Element], + enumerable: true + }]); + function AttachFocus(element) { _classCallCheck(this, _AttachFocus); this.element = element; } - var _AttachFocus = AttachFocus; - - _AttachFocus.prototype.attached = function attached() { + AttachFocus.prototype.attached = function attached() { this.element.focus(); }; - _createClass(_AttachFocus, null, [{ - key: 'inject', - value: [Element], - enumerable: true - }]); - + var _AttachFocus = AttachFocus; AttachFocus = _aureliaTemplating.customAttribute('attach-focus')(AttachFocus) || AttachFocus; return AttachFocus; })(); diff --git a/dist/commonjs/dialog-controller.js b/dist/commonjs/dialog-controller.js index d28a260..2518416 100644 --- a/dist/commonjs/dialog-controller.js +++ b/dist/commonjs/dialog-controller.js @@ -24,27 +24,35 @@ var DialogController = (function () { this.close(false, result); }; - DialogController.prototype.close = function close(success, result) { + DialogController.prototype.error = function error(message) { var _this = this; + return _lifecycle.invokeLifecycle(this.viewModel, 'deactivate').then(function () { + return _this._renderer.hideDialog(_this).then(function () { + return _this._renderer.destroyDialogHost(_this).then(function () { + _this.behavior.unbind(); + _this._reject(message); + }); + }); + }); + }; + + DialogController.prototype.close = function close(ok, result) { + var _this2 = this; + return _lifecycle.invokeLifecycle(this.viewModel, 'canDeactivate').then(function (canDeactivate) { if (canDeactivate) { - return _lifecycle.invokeLifecycle(_this.viewModel, 'deactivate').then(function () { - return _this._renderer.hideDialog(_this).then(function () { - return _this._renderer.destroyDialogHost(_this).then(function () { - _this.behavior.unbind(); - - if (success) { - _this._resolve(result); - } else { - _this._reject(result); + return _lifecycle.invokeLifecycle(_this2.viewModel, 'deactivate').then(function () { + return _this2._renderer.hideDialog(_this2).then(function () { + return _this2._renderer.destroyDialogHost(_this2).then(function () { + _this2.behavior.unbind(); + if (ok) { + _this2._resolve(result); } }); }); }); } - - return Promise.reject(); }); }; diff --git a/dist/commonjs/dialog-footer.js b/dist/commonjs/dialog-footer.js index d79ebd7..592d173 100644 --- a/dist/commonjs/dialog-footer.js +++ b/dist/commonjs/dialog-footer.js @@ -15,6 +15,26 @@ var _dialogController = require('./dialog-controller'); var DialogFooter = (function () { var _instanceInitializers = {}; + _createDecoratedClass(DialogFooter, [{ + key: 'buttons', + decorators: [_aureliaTemplating.bindable], + initializer: function initializer() { + return []; + }, + enumerable: true + }, { + key: 'useDefaultButtons', + decorators: [_aureliaTemplating.bindable], + initializer: function initializer() { + return false; + }, + enumerable: true + }], [{ + key: 'inject', + value: [_dialogController.DialogController], + enumerable: true + }], _instanceInitializers); + function DialogFooter(controller) { _classCallCheck(this, _DialogFooter); @@ -25,9 +45,7 @@ var DialogFooter = (function () { this.controller = controller; } - var _DialogFooter = DialogFooter; - - _DialogFooter.prototype.close = function close(buttonValue) { + DialogFooter.prototype.close = function close(buttonValue) { if (DialogFooter.isCancelButton(buttonValue)) { this.controller.cancel(buttonValue); } else { @@ -35,36 +53,17 @@ var DialogFooter = (function () { } }; - _DialogFooter.prototype.useDefaultButtonsChanged = function useDefaultButtonsChanged(newValue) { + DialogFooter.prototype.useDefaultButtonsChanged = function useDefaultButtonsChanged(newValue) { if (newValue) { this.buttons = ['Cancel', 'Ok']; } }; - _DialogFooter.isCancelButton = function isCancelButton(value) { + DialogFooter.isCancelButton = function isCancelButton(value) { return value === 'Cancel'; }; - _createDecoratedClass(_DialogFooter, [{ - key: 'buttons', - decorators: [_aureliaTemplating.bindable], - initializer: function initializer() { - return []; - }, - enumerable: true - }, { - key: 'useDefaultButtons', - decorators: [_aureliaTemplating.bindable], - initializer: function initializer() { - return false; - }, - enumerable: true - }], [{ - key: 'inject', - value: [_dialogController.DialogController], - enumerable: true - }], _instanceInitializers); - + var _DialogFooter = DialogFooter; DialogFooter = _aureliaTemplating.customElement('dialog-footer')(DialogFooter) || DialogFooter; return DialogFooter; })(); diff --git a/dist/commonjs/dialog-header.js b/dist/commonjs/dialog-header.js index c5ad1ee..5b8e061 100644 --- a/dist/commonjs/dialog-header.js +++ b/dist/commonjs/dialog-header.js @@ -11,6 +11,12 @@ var _aureliaTemplating = require('aurelia-templating'); var _dialogController = require('./dialog-controller'); var DialogHeader = (function () { + _createClass(DialogHeader, null, [{ + key: 'inject', + value: [_dialogController.DialogController], + enumerable: true + }]); + function DialogHeader(controller) { _classCallCheck(this, _DialogHeader); @@ -18,13 +24,6 @@ var DialogHeader = (function () { } var _DialogHeader = DialogHeader; - - _createClass(_DialogHeader, null, [{ - key: 'inject', - value: [_dialogController.DialogController], - enumerable: true - }]); - DialogHeader = _aureliaTemplating.customElement('dialog-header')(DialogHeader) || DialogHeader; return DialogHeader; })(); diff --git a/dist/commonjs/dialog-renderer.js b/dist/commonjs/dialog-renderer.js index bab4de3..7248fb2 100644 --- a/dist/commonjs/dialog-renderer.js +++ b/dist/commonjs/dialog-renderer.js @@ -4,7 +4,7 @@ exports.__esModule = true; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } -var _aureliaTemplating = require("aurelia-templating"); +var _aureliaTemplating = require('aurelia-templating'); var currentZIndex = 1000; var transitionEvent = (function () { @@ -31,18 +31,34 @@ function getNextZIndex() { var DialogRenderer = (function () { function DialogRenderer() { + var _this = this; + _classCallCheck(this, DialogRenderer); this.defaultSettings = { - lock: true + lock: true, + centerHorizontalOnly: false }; + + this.dialogControllers = []; + + document.addEventListener('keyup', function (e) { + if (e.keyCode === 27) { + var top = _this.dialogControllers[_this.dialogControllers.length - 1]; + if (top && top.settings.lock !== true) { + top.cancel(); + } + } + }); } DialogRenderer.prototype.createDialogHost = function createDialogHost(controller) { + var _this2 = this; + var settings = controller.settings, emptyParameters = {}, - modalOverlay = document.createElement("dialog-overlay"), - modalContainer = document.createElement("dialog-container"); + modalOverlay = document.createElement('dialog-overlay'), + modalContainer = document.createElement('dialog-container'); modalOverlay.style.zIndex = getNextZIndex(); modalContainer.style.zIndex = getNextZIndex(); @@ -54,15 +70,11 @@ var DialogRenderer = (function () { controller.slot.add(controller.view); controller.showDialog = function () { + _this2.dialogControllers.push(controller); + controller.slot.attached(); controller.centerDialog(); - document.onkeypress = function (e) { - if (e.keyCode === 27 && settings.lock !== true) { - controller.cancel(); - } - }; - modalOverlay.onclick = function () { if (!settings.lock) { controller.cancel(); @@ -79,12 +91,17 @@ var DialogRenderer = (function () { resolve(); }; - modalOverlay.classList.add("active"); - modalContainer.classList.add("active"); + modalOverlay.classList.add('active'); + modalContainer.classList.add('active'); }); }; controller.hideDialog = function () { + var i = _this2.dialogControllers.indexOf(controller); + if (i !== -1) { + _this2.dialogControllers.splice(i, 1); + } + return new Promise(function (resolve, reject) { modalContainer.addEventListener(transitionEvent, onTransitionEnd); @@ -93,8 +110,8 @@ var DialogRenderer = (function () { resolve(); }; - modalOverlay.classList.remove("active"); - modalContainer.classList.remove("active"); + modalOverlay.classList.remove('active'); + modalContainer.classList.remove('active'); }); }; @@ -108,11 +125,11 @@ var DialogRenderer = (function () { controller.centerDialog = function () { var child = modalContainer.children[0]; + child.style.marginLeft = -(child.offsetWidth / 2) + 'px'; + if (!settings.centerHorizontalOnly) { - child.style.marginLeft = -(child.offsetWidth / 2) + "px"; + child.style.marginTop = -(child.offsetHeight / 2) + 'px'; } - - child.style.marginTop = -(child.offsetHeight / 2) + "px"; }; return Promise.resolve(); diff --git a/dist/commonjs/dialog-service.js b/dist/commonjs/dialog-service.js index 724b363..4c4a099 100644 --- a/dist/commonjs/dialog-service.js +++ b/dist/commonjs/dialog-service.js @@ -19,6 +19,12 @@ var _dialogRenderer = require('./dialog-renderer'); var _lifecycle = require('./lifecycle'); var DialogService = (function () { + _createClass(DialogService, null, [{ + key: 'inject', + value: [_aureliaDependencyInjection.Container, _aureliaTemplating.CompositionEngine, _dialogRenderer.DialogRenderer], + enumerable: true + }]); + function DialogService(container, compositionEngine, renderer) { _classCallCheck(this, DialogService); @@ -45,7 +51,6 @@ var DialogService = (function () { settings = Object.assign({}, this.renderer.defaultSettings, settings); return new Promise(function (resolve, reject) { - console.log('creating'); var childContainer = _this.container.createChild(), controller = new _dialogController.DialogController(_this.renderer, settings, resolve, reject), instruction = { @@ -54,7 +59,6 @@ var DialogService = (function () { childContainer: childContainer, model: settings.model }; - console.log(controller); childContainer.registerInstance(_dialogController.DialogController, controller); @@ -72,20 +76,12 @@ var DialogService = (function () { return _this.renderer.showDialog(controller); }); }); - } else { - return Promise.reject(); } }); }); }); }; - _createClass(DialogService, null, [{ - key: 'inject', - value: [_aureliaDependencyInjection.Container, _aureliaTemplating.CompositionEngine, _dialogRenderer.DialogRenderer], - enumerable: true - }]); - return DialogService; })(); diff --git a/dist/commonjs/examples/common-dialogs.js b/dist/commonjs/examples/common-dialogs.js index 78a1bdd..e4e7ccc 100644 --- a/dist/commonjs/examples/common-dialogs.js +++ b/dist/commonjs/examples/common-dialogs.js @@ -11,6 +11,12 @@ var _prompt = require('./prompt'); var _dialogService = require('../dialog-service'); var CommonDialogs = (function () { + _createClass(CommonDialogs, null, [{ + key: 'inject', + value: [_dialogService.DialogService], + enumerable: true + }]); + function CommonDialogs(dialogService) { _classCallCheck(this, CommonDialogs); @@ -21,12 +27,6 @@ var CommonDialogs = (function () { return this.dialogService.open({ viewModel: _prompt.Prompt, model: question }); }; - _createClass(CommonDialogs, null, [{ - key: 'inject', - value: [_dialogService.DialogService], - enumerable: true - }]); - return CommonDialogs; })(); diff --git a/dist/commonjs/examples/prompt.js b/dist/commonjs/examples/prompt.js index f7589ac..425a0c5 100644 --- a/dist/commonjs/examples/prompt.js +++ b/dist/commonjs/examples/prompt.js @@ -9,6 +9,12 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons var _dialogController = require('../dialog-controller'); var Prompt = (function () { + _createClass(Prompt, null, [{ + key: 'inject', + value: [_dialogController.DialogController], + enumerable: true + }]); + function Prompt(controller) { _classCallCheck(this, Prompt); @@ -22,12 +28,6 @@ var Prompt = (function () { this.question = question; }; - _createClass(Prompt, null, [{ - key: 'inject', - value: [_dialogController.DialogController], - enumerable: true - }]); - return Prompt; })(); diff --git a/dist/commonjs/index.js b/dist/commonjs/index.js index b964911..7d90318 100644 --- a/dist/commonjs/index.js +++ b/dist/commonjs/index.js @@ -7,8 +7,8 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; } -function configure(aurelia) { - aurelia.globalizeResources('./dialog', './dialog-header', './dialog-body', './dialog-footer', './attach-focus', './examples/prompt'); +function configure(config) { + config.globalResources('./dialog', './dialog-header', './dialog-body', './dialog-footer', './attach-focus', './examples/prompt'); } var _dialogService = require('./dialog-service'); diff --git a/dist/es6/dialog-controller.js b/dist/es6/dialog-controller.js index 708d5e1..97bc8c3 100644 --- a/dist/es6/dialog-controller.js +++ b/dist/es6/dialog-controller.js @@ -16,25 +16,31 @@ export class DialogController { this.close(false, result); } - close(success, result){ + error(message){ + return invokeLifecycle(this.viewModel, 'deactivate').then(() => { + return this._renderer.hideDialog(this).then(() => { + return this._renderer.destroyDialogHost(this).then(() => { + this.behavior.unbind(); + this._reject(message); + }); + }); + }); + } + + close(ok, result){ return invokeLifecycle(this.viewModel, 'canDeactivate').then(canDeactivate =>{ if(canDeactivate){ return invokeLifecycle(this.viewModel, 'deactivate').then(() => { return this._renderer.hideDialog(this).then(() => { return this._renderer.destroyDialogHost(this).then(() => { this.behavior.unbind(); - - if(success){ + if(ok){ this._resolve(result); - } else{ - this._reject(result); } }); }); }); } - - return Promise.reject(); }); } } diff --git a/dist/es6/dialog-renderer.js b/dist/es6/dialog-renderer.js index acafb5b..0433bff 100644 --- a/dist/es6/dialog-renderer.js +++ b/dist/es6/dialog-renderer.js @@ -25,9 +25,23 @@ function getNextZIndex(){ export class DialogRenderer { defaultSettings = { - lock: true + lock: true, + centerHorizontalOnly: false, }; + constructor(){ + this.dialogControllers = []; + + document.addEventListener('keyup', e => { + if (e.keyCode === 27){ + var top = this.dialogControllers[this.dialogControllers.length-1]; + if(top && top.settings.lock !== true){ + top.cancel(); + } + } + }); + } + createDialogHost(controller){ var settings = controller.settings, emptyParameters = {}, @@ -43,16 +57,12 @@ export class DialogRenderer { controller.slot = new ViewSlot(modalContainer, true); controller.slot.add(controller.view); - controller.showDialog = function(){ + controller.showDialog = () => { + this.dialogControllers.push(controller); + controller.slot.attached(); controller.centerDialog(); - document.onkeypress = function(e) { - if (e.keyCode === 27 && settings.lock !== true) { - controller.cancel(); - } - }; - modalOverlay.onclick = () => { if (!settings.lock) { controller.cancel(); @@ -75,6 +85,11 @@ export class DialogRenderer { }; controller.hideDialog = () => { + let i = this.dialogControllers.indexOf(controller); + if(i !== -1) { + this.dialogControllers.splice(i, 1); + } + return new Promise((resolve, reject) => { modalContainer.addEventListener(transitionEvent, onTransitionEnd); @@ -98,11 +113,11 @@ export class DialogRenderer { controller.centerDialog = () => { var child = modalContainer.children[0]; + child.style.marginLeft = -(child.offsetWidth/2) + 'px'; + if(!settings.centerHorizontalOnly){ - child.style.marginLeft = -(child.offsetWidth/2) + 'px'; + child.style.marginTop = -(child.offsetHeight/2) + 'px'; } - - child.style.marginTop = -(child.offsetHeight/2) + 'px'; }; return Promise.resolve(); diff --git a/dist/es6/dialog-service.js b/dist/es6/dialog-service.js index 87a1802..887582d 100644 --- a/dist/es6/dialog-service.js +++ b/dist/es6/dialog-service.js @@ -30,7 +30,6 @@ export class DialogService { settings = Object.assign({}, this.renderer.defaultSettings, settings); return new Promise((resolve, reject) => { - console.log('creating'); var childContainer = this.container.createChild(), controller = new DialogController(this.renderer, settings, resolve, reject), instruction = { @@ -39,7 +38,6 @@ export class DialogService { childContainer:childContainer, model:settings.model }; - console.log(controller); childContainer.registerInstance(DialogController, controller); @@ -57,8 +55,6 @@ export class DialogService { return this.renderer.showDialog(controller); }); }); - }else{ - return Promise.reject(); } }); }); diff --git a/dist/es6/dialog.css b/dist/es6/dialog.css new file mode 100644 index 0000000..9e47f80 --- /dev/null +++ b/dist/es6/dialog.css @@ -0,0 +1 @@ +dialog-overlay{bottom:0;left:0;position:fixed;top:0;right:0;opacity:0}dialog-overlay.active{opacity:1}dialog-container{display:block;position:fixed;transition:opacity .2s linear;top:50%;left:50%;opacity:0}dialog-container.active{opacity:1}dialog{display:block;min-width:300px;box-shadow:0 5px 15px rgba(0,0,0,.5);border:1px solid rgba(0,0,0,.2);border-radius:5px;padding:0}dialog>dialog-header{display:block;padding:16px;border-bottom:1px solid #e5e5e5}dialog>dialog-header>button{float:right;border:none;background:0 0;font-size:22px;position:relative;top:-4px;margin:0;padding:0;cursor:pointer}dialog>dialog-footer button:focus,dialog>dialog-header>button:focus{outline:0}dialog>dialog-body{display:block;padding:16px}dialog>dialog-footer{display:block;padding:6px;border-top:1px solid #e5e5e5;text-align:right}dialog>dialog-footer button{color:#333;background-color:#fff;padding:6px 12px;font-size:14px;text-align:center;white-space:nowrap;vertical-align:middle;-ms-touch-action:manipulation;touch-action:manipulation;cursor:pointer;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;background-image:none;border:1px solid #ccc;border-radius:4px;margin:5px 0 5px 5px}dialog>dialog-footer button:hover{color:#333;background-color:#e6e6e6;border-color:#adadad} \ No newline at end of file diff --git a/dist/es6/index.js b/dist/es6/index.js index 16c4618..cf7d57c 100644 --- a/dist/es6/index.js +++ b/dist/es6/index.js @@ -1,5 +1,5 @@ -export function configure(aurelia) { - aurelia.globalizeResources( +export function configure(config) { + config.globalResources( './dialog', './dialog-header', './dialog-body', diff --git a/dist/system/attach-focus.js b/dist/system/attach-focus.js index c74c9cc..e2905f6 100644 --- a/dist/system/attach-focus.js +++ b/dist/system/attach-focus.js @@ -13,24 +13,23 @@ System.register(['aurelia-templating'], function (_export) { }], execute: function () { AttachFocus = (function () { + _createClass(AttachFocus, null, [{ + key: 'inject', + value: [Element], + enumerable: true + }]); + function AttachFocus(element) { _classCallCheck(this, _AttachFocus); this.element = element; } - var _AttachFocus = AttachFocus; - - _AttachFocus.prototype.attached = function attached() { + AttachFocus.prototype.attached = function attached() { this.element.focus(); }; - _createClass(_AttachFocus, null, [{ - key: 'inject', - value: [Element], - enumerable: true - }]); - + var _AttachFocus = AttachFocus; AttachFocus = customAttribute('attach-focus')(AttachFocus) || AttachFocus; return AttachFocus; })(); diff --git a/dist/system/dialog-controller.js b/dist/system/dialog-controller.js index b815f04..4062120 100644 --- a/dist/system/dialog-controller.js +++ b/dist/system/dialog-controller.js @@ -28,27 +28,35 @@ System.register(['./lifecycle'], function (_export) { this.close(false, result); }; - DialogController.prototype.close = function close(success, result) { + DialogController.prototype.error = function error(message) { var _this = this; + return invokeLifecycle(this.viewModel, 'deactivate').then(function () { + return _this._renderer.hideDialog(_this).then(function () { + return _this._renderer.destroyDialogHost(_this).then(function () { + _this.behavior.unbind(); + _this._reject(message); + }); + }); + }); + }; + + DialogController.prototype.close = function close(ok, result) { + var _this2 = this; + return invokeLifecycle(this.viewModel, 'canDeactivate').then(function (canDeactivate) { if (canDeactivate) { - return invokeLifecycle(_this.viewModel, 'deactivate').then(function () { - return _this._renderer.hideDialog(_this).then(function () { - return _this._renderer.destroyDialogHost(_this).then(function () { - _this.behavior.unbind(); - - if (success) { - _this._resolve(result); - } else { - _this._reject(result); + return invokeLifecycle(_this2.viewModel, 'deactivate').then(function () { + return _this2._renderer.hideDialog(_this2).then(function () { + return _this2._renderer.destroyDialogHost(_this2).then(function () { + _this2.behavior.unbind(); + if (ok) { + _this2._resolve(result); } }); }); }); } - - return Promise.reject(); }); }; diff --git a/dist/system/dialog-footer.js b/dist/system/dialog-footer.js index 146bcd8..bf7bc0f 100644 --- a/dist/system/dialog-footer.js +++ b/dist/system/dialog-footer.js @@ -20,6 +20,26 @@ System.register(['aurelia-templating', './dialog-controller'], function (_export DialogFooter = (function () { var _instanceInitializers = {}; + _createDecoratedClass(DialogFooter, [{ + key: 'buttons', + decorators: [bindable], + initializer: function initializer() { + return []; + }, + enumerable: true + }, { + key: 'useDefaultButtons', + decorators: [bindable], + initializer: function initializer() { + return false; + }, + enumerable: true + }], [{ + key: 'inject', + value: [DialogController], + enumerable: true + }], _instanceInitializers); + function DialogFooter(controller) { _classCallCheck(this, _DialogFooter); @@ -30,9 +50,7 @@ System.register(['aurelia-templating', './dialog-controller'], function (_export this.controller = controller; } - var _DialogFooter = DialogFooter; - - _DialogFooter.prototype.close = function close(buttonValue) { + DialogFooter.prototype.close = function close(buttonValue) { if (DialogFooter.isCancelButton(buttonValue)) { this.controller.cancel(buttonValue); } else { @@ -40,36 +58,17 @@ System.register(['aurelia-templating', './dialog-controller'], function (_export } }; - _DialogFooter.prototype.useDefaultButtonsChanged = function useDefaultButtonsChanged(newValue) { + DialogFooter.prototype.useDefaultButtonsChanged = function useDefaultButtonsChanged(newValue) { if (newValue) { this.buttons = ['Cancel', 'Ok']; } }; - _DialogFooter.isCancelButton = function isCancelButton(value) { + DialogFooter.isCancelButton = function isCancelButton(value) { return value === 'Cancel'; }; - _createDecoratedClass(_DialogFooter, [{ - key: 'buttons', - decorators: [bindable], - initializer: function initializer() { - return []; - }, - enumerable: true - }, { - key: 'useDefaultButtons', - decorators: [bindable], - initializer: function initializer() { - return false; - }, - enumerable: true - }], [{ - key: 'inject', - value: [DialogController], - enumerable: true - }], _instanceInitializers); - + var _DialogFooter = DialogFooter; DialogFooter = customElement('dialog-footer')(DialogFooter) || DialogFooter; return DialogFooter; })(); diff --git a/dist/system/dialog-header.js b/dist/system/dialog-header.js index 2889fb4..7e348e7 100644 --- a/dist/system/dialog-header.js +++ b/dist/system/dialog-header.js @@ -15,6 +15,12 @@ System.register(['aurelia-templating', './dialog-controller'], function (_export }], execute: function () { DialogHeader = (function () { + _createClass(DialogHeader, null, [{ + key: 'inject', + value: [DialogController], + enumerable: true + }]); + function DialogHeader(controller) { _classCallCheck(this, _DialogHeader); @@ -22,13 +28,6 @@ System.register(['aurelia-templating', './dialog-controller'], function (_export } var _DialogHeader = DialogHeader; - - _createClass(_DialogHeader, null, [{ - key: 'inject', - value: [DialogController], - enumerable: true - }]); - DialogHeader = customElement('dialog-header')(DialogHeader) || DialogHeader; return DialogHeader; })(); diff --git a/dist/system/dialog-renderer.js b/dist/system/dialog-renderer.js index e823202..4c8d631 100644 --- a/dist/system/dialog-renderer.js +++ b/dist/system/dialog-renderer.js @@ -36,18 +36,34 @@ System.register(["aurelia-templating"], function (_export) { DialogRenderer = (function () { function DialogRenderer() { + var _this = this; + _classCallCheck(this, DialogRenderer); this.defaultSettings = { - lock: true + lock: true, + centerHorizontalOnly: false }; + + this.dialogControllers = []; + + document.addEventListener('keyup', function (e) { + if (e.keyCode === 27) { + var top = _this.dialogControllers[_this.dialogControllers.length - 1]; + if (top && top.settings.lock !== true) { + top.cancel(); + } + } + }); } DialogRenderer.prototype.createDialogHost = function createDialogHost(controller) { + var _this2 = this; + var settings = controller.settings, emptyParameters = {}, - modalOverlay = document.createElement("dialog-overlay"), - modalContainer = document.createElement("dialog-container"); + modalOverlay = document.createElement('dialog-overlay'), + modalContainer = document.createElement('dialog-container'); modalOverlay.style.zIndex = getNextZIndex(); modalContainer.style.zIndex = getNextZIndex(); @@ -59,15 +75,11 @@ System.register(["aurelia-templating"], function (_export) { controller.slot.add(controller.view); controller.showDialog = function () { + _this2.dialogControllers.push(controller); + controller.slot.attached(); controller.centerDialog(); - document.onkeypress = function (e) { - if (e.keyCode === 27 && settings.lock !== true) { - controller.cancel(); - } - }; - modalOverlay.onclick = function () { if (!settings.lock) { controller.cancel(); @@ -84,12 +96,17 @@ System.register(["aurelia-templating"], function (_export) { resolve(); }; - modalOverlay.classList.add("active"); - modalContainer.classList.add("active"); + modalOverlay.classList.add('active'); + modalContainer.classList.add('active'); }); }; controller.hideDialog = function () { + var i = _this2.dialogControllers.indexOf(controller); + if (i !== -1) { + _this2.dialogControllers.splice(i, 1); + } + return new Promise(function (resolve, reject) { modalContainer.addEventListener(transitionEvent, onTransitionEnd); @@ -98,8 +115,8 @@ System.register(["aurelia-templating"], function (_export) { resolve(); }; - modalOverlay.classList.remove("active"); - modalContainer.classList.remove("active"); + modalOverlay.classList.remove('active'); + modalContainer.classList.remove('active'); }); }; @@ -113,11 +130,11 @@ System.register(["aurelia-templating"], function (_export) { controller.centerDialog = function () { var child = modalContainer.children[0]; + child.style.marginLeft = -(child.offsetWidth / 2) + 'px'; + if (!settings.centerHorizontalOnly) { - child.style.marginLeft = -(child.offsetWidth / 2) + "px"; + child.style.marginTop = -(child.offsetHeight / 2) + 'px'; } - - child.style.marginTop = -(child.offsetHeight / 2) + "px"; }; return Promise.resolve(); diff --git a/dist/system/dialog-service.js b/dist/system/dialog-service.js index 2f23ab3..1c12e3d 100644 --- a/dist/system/dialog-service.js +++ b/dist/system/dialog-service.js @@ -23,6 +23,12 @@ System.register(['aurelia-metadata', 'aurelia-dependency-injection', 'aurelia-te }], execute: function () { DialogService = (function () { + _createClass(DialogService, null, [{ + key: 'inject', + value: [Container, CompositionEngine, DialogRenderer], + enumerable: true + }]); + function DialogService(container, compositionEngine, renderer) { _classCallCheck(this, DialogService); @@ -49,7 +55,6 @@ System.register(['aurelia-metadata', 'aurelia-dependency-injection', 'aurelia-te settings = Object.assign({}, this.renderer.defaultSettings, settings); return new Promise(function (resolve, reject) { - console.log('creating'); var childContainer = _this.container.createChild(), controller = new DialogController(_this.renderer, settings, resolve, reject), instruction = { @@ -58,7 +63,6 @@ System.register(['aurelia-metadata', 'aurelia-dependency-injection', 'aurelia-te childContainer: childContainer, model: settings.model }; - console.log(controller); childContainer.registerInstance(DialogController, controller); @@ -76,20 +80,12 @@ System.register(['aurelia-metadata', 'aurelia-dependency-injection', 'aurelia-te return _this.renderer.showDialog(controller); }); }); - } else { - return Promise.reject(); } }); }); }); }; - _createClass(DialogService, null, [{ - key: 'inject', - value: [Container, CompositionEngine, DialogRenderer], - enumerable: true - }]); - return DialogService; })(); diff --git a/dist/system/examples/common-dialogs.js b/dist/system/examples/common-dialogs.js index b0b42b9..2cc13c8 100644 --- a/dist/system/examples/common-dialogs.js +++ b/dist/system/examples/common-dialogs.js @@ -15,6 +15,12 @@ System.register(['./prompt', '../dialog-service'], function (_export) { }], execute: function () { CommonDialogs = (function () { + _createClass(CommonDialogs, null, [{ + key: 'inject', + value: [DialogService], + enumerable: true + }]); + function CommonDialogs(dialogService) { _classCallCheck(this, CommonDialogs); @@ -25,12 +31,6 @@ System.register(['./prompt', '../dialog-service'], function (_export) { return this.dialogService.open({ viewModel: Prompt, model: question }); }; - _createClass(CommonDialogs, null, [{ - key: 'inject', - value: [DialogService], - enumerable: true - }]); - return CommonDialogs; })(); diff --git a/dist/system/examples/prompt.js b/dist/system/examples/prompt.js index 857677f..4ff4ad3 100644 --- a/dist/system/examples/prompt.js +++ b/dist/system/examples/prompt.js @@ -13,6 +13,12 @@ System.register(['../dialog-controller'], function (_export) { }], execute: function () { Prompt = (function () { + _createClass(Prompt, null, [{ + key: 'inject', + value: [DialogController], + enumerable: true + }]); + function Prompt(controller) { _classCallCheck(this, Prompt); @@ -26,12 +32,6 @@ System.register(['../dialog-controller'], function (_export) { this.question = question; }; - _createClass(Prompt, null, [{ - key: 'inject', - value: [DialogController], - enumerable: true - }]); - return Prompt; })(); diff --git a/dist/system/index.js b/dist/system/index.js index 57c2057..e13b314 100644 --- a/dist/system/index.js +++ b/dist/system/index.js @@ -3,8 +3,8 @@ System.register(['./dialog-service', './dialog-controller', './examples/prompt'] _export('configure', configure); - function configure(aurelia) { - aurelia.globalizeResources('./dialog', './dialog-header', './dialog-body', './dialog-footer', './attach-focus', './examples/prompt'); + function configure(config) { + config.globalResources('./dialog', './dialog-header', './dialog-body', './dialog-footer', './attach-focus', './examples/prompt'); } return {