diff options
author | Morris Jobke <hey@morrisjobke.de> | 2015-11-25 18:01:03 +0300 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2015-11-25 18:01:03 +0300 |
commit | a2d882594824206ff747f5ff7a868f00e20ecd56 (patch) | |
tree | 0e52502f2b39d106dd297f28d2e531089d40f6fe /js | |
parent | 5daeb66c4fc82344507df9fb794bbd208fad2eda (diff) | |
parent | 171cf42cfebe4969dc87ef1ab58180669991bacb (diff) |
Merge pull request #140 from owncloud/close-on-click-outside
Close editor when clicking outside of the container
Diffstat (limited to 'js')
-rw-r--r-- | js/editor.js | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/js/editor.js b/js/editor.js index 11372e4..ba9404b 100644 --- a/js/editor.js +++ b/js/editor.js @@ -296,6 +296,7 @@ var Files_Texteditor = { // Show the controls _self.loadControlBar(file, _self.currentContext); window.aceEditor.getSession().on('change', _self.setupAutosave); + _self.bindVisibleActions(); window.aceEditor.focus(); if (_self.previewPlugins[file.mime]){ @@ -532,6 +533,7 @@ var Files_Texteditor = { closeEditor: function() { this.$container.html('').show(); this.unloadControlBar(); + this.unBindVisibleActions(); if (this.fileInfoModel) { this.fileInfoModel.set({ // temp dummy, until we can do a PROPFIND @@ -549,6 +551,7 @@ var Files_Texteditor = { hideEditor: function() { this.$container.hide(); document.title = this.oldTitle; + this.unBindVisibleActions(); }, /** @@ -557,7 +560,32 @@ var Files_Texteditor = { setupAutosave: function() { clearTimeout(this.saveTimer); this.saveTimer = setTimeout(OCA.Files_Texteditor._onSaveTrigger, 3000); - } + }, + + /** + * Handles event when clicking outside editor + */ + _onClickDocument: function(event) { + // Check if click was inside the editor or not. + if(!$(event.target).closest('#editor_container').length) { + // Edit the editor + OCA.Files_Texteditor._onCloseTrigger(); + } + }, + + /* + * Binds actions that need to happen whilst the editor is visible + */ + bindVisibleActions: function() { + $(document).bind('click', this._onClickDocument); + }, + + /** + * Unbinds actions that happen whilst the editor is visible + */ + unBindVisibleActions: function() { + $(document).unbind('click', this._onClickDocument); + } }; |