From 5657338f8f57e07eeabedf20ad3cb818d482cd5c Mon Sep 17 00:00:00 2001 From: Damian Krzeminski Date: Mon, 1 Jun 2015 19:23:28 -0400 Subject: [PATCH 1/4] upgrade overlay dependency --- component.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/component.json b/component.json index 84bece9..260bf59 100644 --- a/component.json +++ b/component.json @@ -9,7 +9,7 @@ ], "dependencies": { "component/emitter": "1.1.3", - "component/overlay": "0.3.1", + "component/overlay": "0.3.5", "component/domify": "1.3.1", "component/event": "0.1.4", "component/classes": "1.2.1", diff --git a/package.json b/package.json index 164d627..88bbf36 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "component-event": "^0.1.0", "component-emitter": "^1.1.1", "domify": "^1.1.1", - "overlay-component": "^0.3.0", + "overlay-component": "^0.3.5", "component-classes": "^1.1.3", "stringify": "^3.1.0" }, From a69b5c63f08497691ae42d37e153f670be537689 Mon Sep 17 00:00:00 2001 From: Damian Krzeminski Date: Mon, 1 Jun 2015 14:42:17 -0400 Subject: [PATCH 2/4] add support reusing dialog with overlay handle closing dialog from overlay properly: don't call overlay.hide() if we are hiding dialog as a result of overlay being hidden fixes #21 --- index.js | 12 ++++++++---- test/index.html | 7 +++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 3a6448b..048ba35 100644 --- a/index.js +++ b/index.js @@ -183,10 +183,12 @@ Dialog.prototype.modal = function(){ Dialog.prototype.overlay = function(opts){ var self = this; + opts = opts || { closable: true }; var o = overlay(opts); o.on('hide', function(){ - self._overlay = null; + if (self._hideTrigger === 'dialog') return; + self._hideTrigger = 'overlay'; self.hide(); }); this._overlay = o; @@ -236,6 +238,7 @@ Dialog.prototype.show = function(){ var overlay = this._overlay; var self = this; + self._hideTrigger = null; // overlay if (overlay) { overlay.show(); @@ -260,8 +263,9 @@ Dialog.prototype.show = function(){ Dialog.prototype.hideOverlay = function(){ if (!this._overlay) return; - this._overlay.remove(); - this._overlay = null; + if (this._hideTrigger === 'overlay') return; + this._hideTrigger = 'dialog'; + this._overlay.hide(); }; /** @@ -282,7 +286,7 @@ Dialog.prototype.hide = function(ms){ events.unbind(document, 'keydown', self._escKeyCallback); } - // prevent thrashing - this isn't used + // prevent thrashing self.hiding = true; // duration diff --git a/test/index.html b/test/index.html index e9e422a..dd33745 100644 --- a/test/index.html +++ b/test/index.html @@ -63,11 +63,11 @@ .on('hide', function(){ console.log('closed fourth'); - dialog('Click the overlay to close') + var overlayDialog = dialog('Click the overlay to close') .effect('slide') .overlay() .show() - .on('hide', function(){ + .once('hide', function(){ console.log('closed fifth'); dialog('Modal') @@ -93,6 +93,9 @@ .show() .on('hide', function(){ console.log('closed eight'); + + //test overlay once again (#21) + overlayDialog.show(); }); }); From 8af86c1f67cb8c7e8f704664a2c5bd4418d6d52b Mon Sep 17 00:00:00 2001 From: Damian Krzeminski Date: Tue, 2 Jun 2015 10:03:52 -0400 Subject: [PATCH 3/4] add test for reusing closeable dialog --- test/reuse.html | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 test/reuse.html diff --git a/test/reuse.html b/test/reuse.html new file mode 100644 index 0000000..62e61bb --- /dev/null +++ b/test/reuse.html @@ -0,0 +1,47 @@ + + + + Dialog + + + + + + Dialog + + + + From 868bba3d4abd08aa6357a176aaab5160b9062f8f Mon Sep 17 00:00:00 2001 From: Damian Krzeminski Date: Tue, 2 Jun 2015 10:32:07 -0400 Subject: [PATCH 4/4] yet another implemenation for overlay/reuse add showOverlay method (since we already had hideOverlay method) hide/showOverlay are responsible for making sure that overlay is only shown/hiddent once per cycle regardless of how we close the dialog --- index.js | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/index.js b/index.js index 048ba35..3be023b 100644 --- a/index.js +++ b/index.js @@ -170,7 +170,7 @@ Dialog.prototype.effect = function(type){ */ Dialog.prototype.modal = function(){ - this._overlay = overlay(); + this.overlay(); return this; }; @@ -182,16 +182,7 @@ Dialog.prototype.modal = function(){ */ Dialog.prototype.overlay = function(opts){ - var self = this; - - opts = opts || { closable: true }; - var o = overlay(opts); - o.on('hide', function(){ - if (self._hideTrigger === 'dialog') return; - self._hideTrigger = 'overlay'; - self.hide(); - }); - this._overlay = o; + this._overlayOptions = opts || { closable: true }; return this; }; @@ -236,14 +227,9 @@ Dialog.prototype.fixed = function(){ Dialog.prototype.show = function(){ var overlay = this._overlay; - var self = this; - self._hideTrigger = null; // overlay - if (overlay) { - overlay.show(); - this._classes.add('modal'); - } + this.showOverlay(); // escape if (!overlay || overlay.closable) this.escapable(); @@ -263,9 +249,28 @@ Dialog.prototype.show = function(){ Dialog.prototype.hideOverlay = function(){ if (!this._overlay) return; - if (this._hideTrigger === 'overlay') return; - this._hideTrigger = 'dialog'; + this._overlay.off('hide'); this._overlay.hide(); + this._overlay = null; +}; + +/** + * Show the overlay. + * + * @api private + */ + +Dialog.prototype.showOverlay = function(){ + var self = this; + + if (!self._overlayOptions) return; + self._overlay = overlay(self._overlayOptions) + .once('hide', function(){ + self._overlay = null; + self.hide(); + }) + .show(); + self._classes.add('modal'); }; /**