aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_texteditor
diff options
context:
space:
mode:
authorTom Needham <needham.thomas@gmail.com>2011-10-14 22:56:14 +0100
committerTom Needham <needham.thomas@gmail.com>2011-10-14 22:56:14 +0100
commit9bde002c95e35c84c2c53ddbf5f3d196cff5812d (patch)
tree4e722dfbe6396991c5e4d9fb6e12e5de447d5d9c /apps/files_texteditor
parent3fee961a0a4f33aa4c62964714b1fa5a31cef44b (diff)
downloadnextcloud-server-9bde002c95e35c84c2c53ddbf5f3d196cff5812d.tar.gz
nextcloud-server-9bde002c95e35c84c2c53ddbf5f3d196cff5812d.zip
Fixed issue with opening editor multiple times.
Diffstat (limited to 'apps/files_texteditor')
-rw-r--r--apps/files_texteditor/js/editor.js97
1 files changed, 52 insertions, 45 deletions
diff --git a/apps/files_texteditor/js/editor.js b/apps/files_texteditor/js/editor.js
index 87810702f62..a2581d4143f 100644
--- a/apps/files_texteditor/js/editor.js
+++ b/apps/files_texteditor/js/editor.js
@@ -4,6 +4,7 @@ function setEditorSize(){
}
function getFileExtension(file){
+ // Extracts the file extension from the full filename
var parts=file.split('.');
return parts[parts.length-1];
}
@@ -11,7 +12,6 @@ function getFileExtension(file){
function setSyntaxMode(ext){
// Loads the syntax mode files and tells the editor
var filetype = new Array();
- // Todo finish these
filetype["h"] = "c_cpp";
filetype["c"] = "c_cpp";
filetype["cpp"] = "c_cpp";
@@ -63,17 +63,21 @@ function showControls(filename){
function bindControlEvents(){
$("#editor_save").live('click',function() {
- doFileSave();
+ if(editorIsShown()){
+ doFileSave();
+ }
});
$('#editor_close').live('click',function() {
- hideFileEditor();
+ if(editorIsShown()){
+ hideFileEditor();
+ }
});
}
function editorIsShown(){
// Not working as intended.
- if(window.aceEditor){
+ if($('#editor').attr('editorshown')=='true'){
return true;
} else {
return false;
@@ -91,55 +95,56 @@ function updateSessionFileHash(path){
function doFileSave(){
if(editorIsShown()){
- $('#editor_save').after('<img id="saving_icon" src="'+OC.filePath('core','img','loading.gif')+'"></img>');
- var filecontents = window.aceEditor.getSession().getValue();
- var dir = $('#editor').attr('data-dir');
- var file = $('#editor').attr('data-filename');
- $.post(OC.filePath('files_texteditor','ajax','savefile.php'), { filecontents: filecontents, file: file, dir: dir },function(jsondata){
-
- if(jsondata.status == 'failure'){
- var answer = confirm(jsondata.data.message);
- if(answer){
- $.post(OC.filePath('files_texteditor','ajax','savefile.php'),{ filecontents: filecontents, file: file, dir: dir, force: 'true' },function(jsondata){
- if(jsondata.status =='success'){
- $('#saving_icon').remove();
- $('#editor_save').after('<p id="save_result" style="float: left">Saved!</p>')
- setTimeout(function() {
- $('#save_result').remove();
- }, 2000);
- }
- else {
- // Save error
- $('#saving_icon').remove();
- $('#editor_save').after('<p id="save_result" style="float: left">Failed!</p>');
- setTimeout(function() {
- $('#save_result').fadeOut('slow',function(){ $(this).remove(); });
- }, 2000);
- }
- }, 'json');
+ $('#editor_save').after('<img id="saving_icon" src="'+OC.filePath('core','img','loading.gif')+'"></img>');
+ var filecontents = window.aceEditor.getSession().getValue();
+ var dir = $('#editor').attr('data-dir');
+ var file = $('#editor').attr('data-filename');
+ $.post(OC.filePath('files_texteditor','ajax','savefile.php'), { filecontents: filecontents, file: file, dir: dir },function(jsondata){
+
+ if(jsondata.status == 'failure'){
+ var answer = confirm(jsondata.data.message);
+ if(answer){
+ $.post(OC.filePath('files_texteditor','ajax','savefile.php'),{ filecontents: filecontents, file: file, dir: dir, force: 'true' },function(jsondata){
+ if(jsondata.status =='success'){
+ $('#saving_icon').remove();
+ $('#editor_save').after('<p id="save_result" style="float: left">Saved!</p>')
+ setTimeout(function() {
+ $('#save_result').remove();
+ }, 2000);
+ }
+ else {
+ // Save error
+ $('#saving_icon').remove();
+ $('#editor_save').after('<p id="save_result" style="float: left">Failed!</p>');
+ setTimeout(function() {
+ $('#save_result').fadeOut('slow',function(){ $(this).remove(); });
+ }, 2000);
+ }
+ }, 'json');
+ }
+ else {
+ // Don't save!
+ $('#saving_icon').remove();
+ // Temporary measure until we get a tick icon
+ $('#editor_save').after('<p id="save_result" style="float: left">Saved!</p>');
+ setTimeout(function() {
+ $('#save_result').fadeOut('slow',function(){ $(this).remove(); });
+ }, 2000);
+ }
}
- else {
- // Don't save!
+ else if(jsondata.status == 'success'){
+ // Success
$('#saving_icon').remove();
// Temporary measure until we get a tick icon
$('#editor_save').after('<p id="save_result" style="float: left">Saved!</p>');
setTimeout(function() {
$('#save_result').fadeOut('slow',function(){ $(this).remove(); });
}, 2000);
- }
- }
- else if(jsondata.status == 'success'){
- // Success
- $('#saving_icon').remove();
- // Temporary measure until we get a tick icon
- $('#editor_save').after('<p id="save_result" style="float: left">Saved!</p>');
- setTimeout(function() {
- $('#save_result').fadeOut('slow',function(){ $(this).remove(); });
- }, 2000);
- }
- }, 'json');
- giveEditorFocus();
+ }
+ }, 'json');
+ giveEditorFocus();
} else {
+ $('#editor').data('editor','false');
return;
}
};
@@ -155,6 +160,7 @@ function showFileEditor(dir,filename){
url: OC.filePath('files','ajax','download.php')+'?files='+encodeURIComponent(filename)+'&dir='+encodeURIComponent(dir),
complete: function(data){
// Initialise the editor
+ $('#editor').attr('editorshown','true');
updateSessionFileHash(dir+'/'+filename);
showControls(filename);
$('table').fadeOut('slow', function() {
@@ -178,6 +184,7 @@ function showFileEditor(dir,filename){
}
function hideFileEditor(){
+ $('#editor').attr('editorshown','false');
// Fade out controls
$('#editor_close').fadeOut('slow');
// Fade out the save button