Repository: couchdb-fauxton Updated Branches: refs/heads/master 118aea1e7 -> b0f30178d
Fix COUCHDB-2543 by avoiding overlapping callbacks for two editors Project: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/commit/b0f30178 Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/tree/b0f30178 Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/diff/b0f30178 Branch: refs/heads/master Commit: b0f30178ddef8ee0e9b3d31d395de59d181bbfdc Parents: 118aea1 Author: sebastianrothbucher <[email protected]> Authored: Sun Jan 18 17:52:36 2015 +0100 Committer: sebastianrothbucher <[email protected]> Committed: Wed Jan 21 22:17:52 2015 +0100 ---------------------------------------------------------------------- app/addons/documents/views-doceditor.js | 11 +++++++++++ app/addons/fauxton/components.js | 8 ++++---- 2 files changed, 15 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/b0f30178/app/addons/documents/views-doceditor.js ---------------------------------------------------------------------- diff --git a/app/addons/documents/views-doceditor.js b/app/addons/documents/views-doceditor.js index 49e3da7..2a0e969 100644 --- a/app/addons/documents/views-doceditor.js +++ b/app/addons/documents/views-doceditor.js @@ -574,6 +574,17 @@ function (app, FauxtonAPI, Components, Documents, Databases, prettify) { }, afterRender: function () { + var that = this; + this.$('.modal').on('hide', function (e) { + if(that.subEditor.edited){ + if(!confirm("Close without saving changes?")){ + e.preventDefault(); + return; + } + } + /* make sure we don't have save warnings w/out change */ + that.subEditor.editSaved(); + }); /* make sure we init only ONCE */ if (!this.subEditor) { this.subEditor = new Components.Editor({ http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/b0f30178/app/addons/fauxton/components.js ---------------------------------------------------------------------- diff --git a/app/addons/fauxton/components.js b/app/addons/fauxton/components.js index b261c31..b017129 100644 --- a/app/addons/fauxton/components.js +++ b/app/addons/fauxton/components.js @@ -803,13 +803,13 @@ function(app, FauxtonAPI, ace, spin, ZeroClipboard) { that.edited = true; }); - $(window).on('beforeunload.editor', function() { + $(window).on('beforeunload.editor_'+this.editorId, function() { if (that.edited) { return 'Your changes have not been saved. Click cancel to return to the document.'; } }); - FauxtonAPI.beforeUnload("editor", function (deferred) { + FauxtonAPI.beforeUnload("editor_"+this.editorId, function (deferred) { if (that.edited) { return 'Your changes have not been saved. Click cancel to return to the document.'; } @@ -824,8 +824,8 @@ function(app, FauxtonAPI, ace, spin, ZeroClipboard) { }, cleanup: function () { - $(window).off('beforeunload.editor'); - FauxtonAPI.removeBeforeUnload("editor"); + $(window).off('beforeunload.editor_'+this.editorId); + FauxtonAPI.removeBeforeUnload("editor_"+this.editorId); this.editor.destroy(); },
