From adebefad84e06d15a9bc5e1fadb4846c636b3347 Mon Sep 17 00:00:00 2001 From: Tom Needham Date: Sat, 8 Oct 2011 15:46:38 +0100 Subject: [PATCH] Fixed editor loading and file saving issue --- apps/files_texteditor/js/editor.js | 53 ++++++++++++++++-------------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/apps/files_texteditor/js/editor.js b/apps/files_texteditor/js/editor.js index 62a945c6faf..f7b924d494d 100644 --- a/apps/files_texteditor/js/editor.js +++ b/apps/files_texteditor/js/editor.js @@ -55,7 +55,7 @@ function showControls(filename){ var html = ''; $('#controls').append(html); $('#editorbar').fadeIn('slow'); - var breadcrumbhtml = ''; + var breadcrumbhtml = ''; $('.actions').before(breadcrumbhtml); $('.actions').before(savebtnhtml); }); @@ -72,11 +72,12 @@ function bindControlEvents(){ } function editorIsShown(){ - if($('#editor').length!=0){ + // Not working as intended. Always returns true. + if(window.aceEditor){ return true; } else { return false; - } + } } function updateSessionFileHash(path){ @@ -148,30 +149,32 @@ function giveEditorFocus(){ }; function showFileEditor(dir,filename){ - // Loads the file editor and display it. - var data = $.ajax({ - url: OC.filePath('files','ajax','download.php')+'?files='+encodeURIComponent(filename)+'&dir='+encodeURIComponent(dir), - complete: function(data){ - // Initialise the editor - updateSessionFileHash(dir+'/'+filename); - showControls(filename); - $('table').fadeOut('slow', function() { - $('#editor').text(data.responseText); - // encodeURIComponenet? - $('#editor').attr('data-dir', dir); - $('#editor').attr('data-filename', filename); - window.aceEditor = ace.edit("editor"); - aceEditor.setShowPrintMargin(false); - setEditorSize(); - setSyntaxMode(getFileExtension(filename)); - OC.addScript('files_texteditor','aceeditor/theme-clouds', function(){ - window.aceEditor.setTheme("ace/theme/clouds"); + if(!editorIsShown()){ + // Loads the file editor and display it. + var data = $.ajax({ + url: OC.filePath('files','ajax','download.php')+'?files='+encodeURIComponent(filename)+'&dir='+encodeURIComponent(dir), + complete: function(data){ + // Initialise the editor + updateSessionFileHash(dir+'/'+filename); + showControls(filename); + $('table').fadeOut('slow', function() { + $('#editor').text(data.responseText); + // encodeURIComponenet? + $('#editor').attr('data-dir', dir); + $('#editor').attr('data-filename', filename); + window.aceEditor = ace.edit("editor"); + aceEditor.setShowPrintMargin(false); + setEditorSize(); + setSyntaxMode(getFileExtension(filename)); + OC.addScript('files_texteditor','aceeditor/theme-clouds', function(){ + window.aceEditor.setTheme("ace/theme/clouds"); + }); }); + // End success + } + // End ajax }); - // End success - } - // End ajax - }); + } } function hideFileEditor(){ -- 2.39.5