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, });
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);
}

View File

@ -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();