diff --git a/js/gdrive.js b/js/gdrive.js index ec3c35fd..b95e13be 100644 --- a/js/gdrive.js +++ b/js/gdrive.js @@ -60,8 +60,11 @@ var gdrive = (function() { + boundary + '"', }, 'body' : multipartRequestBody, }); request.execute(function(file) { unsetWorkingIndicator(FLAG_GDRIVE_UPLOAD); - var fileSyncIndex = SYNC_PROVIDER_GDRIVE + file.id; - localStorage[fileSyncIndex + ".etag"] = file.etag; + var fileSyncIndex = undefined; + if(file.id) { + fileSyncIndex = SYNC_PROVIDER_GDRIVE + file.id; + localStorage[fileSyncIndex + ".etag"] = file.etag; + } if (callback) { callback(fileSyncIndex); } diff --git a/js/main.js b/js/main.js index 3ccbd9c4..0227e623 100644 --- a/js/main.js +++ b/js/main.js @@ -59,7 +59,10 @@ var synchronizer = (function($) { // Try to find the provider if(fileSyncIndex.indexOf(SYNC_PROVIDER_GDRIVE) === 0) { var id = fileSyncIndex.substring(SYNC_PROVIDER_GDRIVE.length); - gdrive.updateFile(id, title, content, function() { + gdrive.updateFile(id, title, content, function(result) { + if(!result) { + showError("Error while uploading file on Google Drive"); + } sync(fileSyncIndexList, content, title); }); } else { @@ -140,13 +143,15 @@ var fileManager = (function($) { var title = localStorage[fileIndex + ".title"]; (function(fileIndex) { gdrive.createFile(title, content, function(fileSyncIndex) { - localStorage[fileIndex + ".sync"] += fileSyncIndex + ";"; + if(fileSyncIndex) { + localStorage[fileIndex + ".sync"] += fileSyncIndex + ";"; + } + else { + showError("Error while creating file on Google Drive"); + } }); })(fileIndex); }); - $("#wmd-input").keyup(function() { - save = true; - }); }; fileManager.selectFile = function() { @@ -169,7 +174,9 @@ var fileManager = (function($) { // Update the editor and the file title var fileIndex = localStorage["file.current"]; $("#wmd-input").val(localStorage[fileIndex + ".content"]); - core.createEditor(); + core.createEditor(function() { + save = true; + }); this.updateFileTitleUI(); }; @@ -326,9 +333,13 @@ var core = (function($) { }); }; - core.createEditor = function() { + core.createEditor = function(textChangeCallback) { $("#wmd-button-bar").empty(); var converter = Markdown.getSanitizingConverter(); + converter.hooks.chain("preConversion", function (text) { + textChangeCallback(); + return text; + }); var editor = new Markdown.Editor(converter); editor.run();