gdrive support

This commit is contained in:
benweet 2013-03-28 23:12:15 +00:00
commit 7f783a6430
2 changed files with 23 additions and 9 deletions

View File

@ -60,8 +60,11 @@ var gdrive = (function() {
+ boundary + '"', }, 'body' : multipartRequestBody, }); + boundary + '"', }, 'body' : multipartRequestBody, });
request.execute(function(file) { request.execute(function(file) {
unsetWorkingIndicator(FLAG_GDRIVE_UPLOAD); unsetWorkingIndicator(FLAG_GDRIVE_UPLOAD);
var fileSyncIndex = SYNC_PROVIDER_GDRIVE + file.id; var fileSyncIndex = undefined;
if(file.id) {
fileSyncIndex = SYNC_PROVIDER_GDRIVE + file.id;
localStorage[fileSyncIndex + ".etag"] = file.etag; localStorage[fileSyncIndex + ".etag"] = file.etag;
}
if (callback) { if (callback) {
callback(fileSyncIndex); callback(fileSyncIndex);
} }

View File

@ -59,7 +59,10 @@ var synchronizer = (function($) {
// Try to find the provider // Try to find the provider
if(fileSyncIndex.indexOf(SYNC_PROVIDER_GDRIVE) === 0) { if(fileSyncIndex.indexOf(SYNC_PROVIDER_GDRIVE) === 0) {
var id = fileSyncIndex.substring(SYNC_PROVIDER_GDRIVE.length); 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); sync(fileSyncIndexList, content, title);
}); });
} else { } else {
@ -140,13 +143,15 @@ var fileManager = (function($) {
var title = localStorage[fileIndex + ".title"]; var title = localStorage[fileIndex + ".title"];
(function(fileIndex) { (function(fileIndex) {
gdrive.createFile(title, content, function(fileSyncIndex) { gdrive.createFile(title, content, function(fileSyncIndex) {
if(fileSyncIndex) {
localStorage[fileIndex + ".sync"] += fileSyncIndex + ";"; localStorage[fileIndex + ".sync"] += fileSyncIndex + ";";
}
else {
showError("Error while creating file on Google Drive");
}
}); });
})(fileIndex); })(fileIndex);
}); });
$("#wmd-input").keyup(function() {
save = true;
});
}; };
fileManager.selectFile = function() { fileManager.selectFile = function() {
@ -169,7 +174,9 @@ var fileManager = (function($) {
// Update the editor and the file title // Update the editor and the file title
var fileIndex = localStorage["file.current"]; var fileIndex = localStorage["file.current"];
$("#wmd-input").val(localStorage[fileIndex + ".content"]); $("#wmd-input").val(localStorage[fileIndex + ".content"]);
core.createEditor(); core.createEditor(function() {
save = true;
});
this.updateFileTitleUI(); this.updateFileTitleUI();
}; };
@ -326,9 +333,13 @@ var core = (function($) {
}); });
}; };
core.createEditor = function() { core.createEditor = function(textChangeCallback) {
$("#wmd-button-bar").empty(); $("#wmd-button-bar").empty();
var converter = Markdown.getSanitizingConverter(); var converter = Markdown.getSanitizingConverter();
converter.hooks.chain("preConversion", function (text) {
textChangeCallback();
return text;
});
var editor = new Markdown.Editor(converter); var editor = new Markdown.Editor(converter);
editor.run(); editor.run();