Use of underscore.js
This commit is contained in:
parent
ff7e08b2bc
commit
98cc144b0a
@ -1,7 +1,7 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<script src="lib/dropbox.js"></script>
|
<script src="lib/dropbox.min.js"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
Dropbox.Drivers.Popup.oauthReceiver();
|
Dropbox.Drivers.Popup.oauthReceiver();
|
||||||
</script>
|
</script>
|
||||||
|
@ -476,6 +476,9 @@
|
|||||||
<dd>
|
<dd>
|
||||||
<a target="_blank" href="http://requirejs.org/">RequireJS</a>
|
<a target="_blank" href="http://requirejs.org/">RequireJS</a>
|
||||||
</dd>
|
</dd>
|
||||||
|
<dd>
|
||||||
|
<a target="_blank" href="http://underscorejs.org/">Underscore.js</a>
|
||||||
|
</dd>
|
||||||
<dd>
|
<dd>
|
||||||
<a target="_blank" href="http://layout.jquery-dev.net/">UI Layout</a>
|
<a target="_blank" href="http://layout.jquery-dev.net/">UI Layout</a>
|
||||||
</dd>
|
</dd>
|
||||||
|
@ -2,7 +2,7 @@ define(
|
|||||||
[ "jquery", "file-manager", "google-helper", "dropbox-helper",
|
[ "jquery", "file-manager", "google-helper", "dropbox-helper",
|
||||||
"github-helper", "synchronizer", "publisher", "async-runner",
|
"github-helper", "synchronizer", "publisher", "async-runner",
|
||||||
"bootstrap", "jgrowl", "layout", "Markdown.Editor", "config",
|
"bootstrap", "jgrowl", "layout", "Markdown.Editor", "config",
|
||||||
"underscore-min" ],
|
"underscore" ],
|
||||||
function($, fileManager, googleHelper, dropboxHelper, githubHelper,
|
function($, fileManager, googleHelper, dropboxHelper, githubHelper,
|
||||||
synchronizer, publisher, asyncTaskRunner) {
|
synchronizer, publisher, asyncTaskRunner) {
|
||||||
|
|
||||||
@ -117,7 +117,7 @@ define(
|
|||||||
core.showMessage = function(msg, iconClass, options) {
|
core.showMessage = function(msg, iconClass, options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
iconClass = iconClass || "icon-info-sign";
|
iconClass = iconClass || "icon-info-sign";
|
||||||
$.jGrowl("<i class='icon-white " + iconClass + "'></i> " + $("<div>").text(msg).html(), options);
|
$.jGrowl("<i class='icon-white " + iconClass + "'></i> " + _.escape(msg), options);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Used to show an error message
|
// Used to show an error message
|
||||||
@ -429,7 +429,7 @@ define(
|
|||||||
|
|
||||||
// Generates a random string
|
// Generates a random string
|
||||||
core.randomString = function() {
|
core.randomString = function() {
|
||||||
return Math.ceil(Math.random() * 4294967296).toString(36);
|
return _.random(4294967296).toString(36);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Used to setup an empty localStorage
|
// Used to setup an empty localStorage
|
||||||
|
@ -280,6 +280,7 @@ define(["jquery", "async-runner"], function($, asyncTaskRunner) {
|
|||||||
callback();
|
callback();
|
||||||
};
|
};
|
||||||
if (error) {
|
if (error) {
|
||||||
|
console.error(error);
|
||||||
// Try to analyze the error
|
// Try to analyze the error
|
||||||
if (typeof error === "string") {
|
if (typeof error === "string") {
|
||||||
errorMsg = error;
|
errorMsg = error;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
define(["jquery", "google-helper", "dropbox-helper", "github-helper", "synchronizer", "publisher"],
|
define(["jquery", "google-helper", "dropbox-helper", "github-helper", "synchronizer", "publisher", "underscore"],
|
||||||
function($, googleHelper, dropboxHelper, githubHelper, synchronizer, publisher) {
|
function($, googleHelper, dropboxHelper, githubHelper, synchronizer, publisher) {
|
||||||
|
|
||||||
var fileManager = {};
|
var fileManager = {};
|
||||||
@ -6,6 +6,26 @@ define(["jquery", "google-helper", "dropbox-helper", "github-helper", "synchroni
|
|||||||
// Dependencies
|
// Dependencies
|
||||||
var core = undefined;
|
var core = undefined;
|
||||||
|
|
||||||
|
// Defines the current file
|
||||||
|
var currentFileIndex = localStorage["file.current"];
|
||||||
|
fileManager.getCurrentFileIndex = function() {
|
||||||
|
return currentFileIndex;
|
||||||
|
};
|
||||||
|
fileManager.isCurrentFileIndex = function(fileIndex) {
|
||||||
|
return fileIndex == currentFileIndex;
|
||||||
|
};
|
||||||
|
fileManager.setCurrentFileIndex = function(fileIndex) {
|
||||||
|
currentFileIndex = fileIndex;
|
||||||
|
// Sanity check since we are going to modify current file in localStorage
|
||||||
|
core.checkWindowUnique();
|
||||||
|
if(fileIndex === undefined) {
|
||||||
|
localStorage.removeItem("file.current");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
localStorage["file.current"] = fileIndex;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Caution: this function recreate the editor (reset undo operations)
|
// Caution: this function recreate the editor (reset undo operations)
|
||||||
var fileDescList = [];
|
var fileDescList = [];
|
||||||
fileManager.selectFile = function(fileIndex) {
|
fileManager.selectFile = function(fileIndex) {
|
||||||
@ -15,19 +35,17 @@ define(["jquery", "google-helper", "dropbox-helper", "github-helper", "synchroni
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(fileIndex !== undefined) {
|
if(fileIndex !== undefined) {
|
||||||
// Since we are going to modify current file
|
fileManager.setCurrentFileIndex(fileIndex);
|
||||||
core.checkWindowUnique();
|
|
||||||
localStorage["file.current"] = fileIndex;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the file titles
|
// Update the file titles
|
||||||
fileManager.updateFileTitles();
|
fileManager.updateFileTitles();
|
||||||
refreshManageSync();
|
refreshManageSync();
|
||||||
refreshManagePublish();
|
refreshManagePublish();
|
||||||
publisher.notifyCurrentFile(localStorage["file.current"]);
|
publisher.notifyCurrentFile();
|
||||||
|
|
||||||
// Recreate the editor
|
// Recreate the editor
|
||||||
fileIndex = localStorage["file.current"];
|
fileIndex = fileManager.getCurrentFileIndex();
|
||||||
$("#wmd-input").val(localStorage[fileIndex + ".content"]);
|
$("#wmd-input").val(localStorage[fileIndex + ".content"]);
|
||||||
core.createEditor(function() {
|
core.createEditor(function() {
|
||||||
fileManager.saveFile();
|
fileManager.saveFile();
|
||||||
@ -40,15 +58,10 @@ define(["jquery", "google-helper", "dropbox-helper", "github-helper", "synchroni
|
|||||||
if (!title) {
|
if (!title) {
|
||||||
// Create a file title
|
// Create a file title
|
||||||
title = DEFAULT_FILE_TITLE;
|
title = DEFAULT_FILE_TITLE;
|
||||||
function exists(title) {
|
|
||||||
for ( var i = 0; i < fileDescList.length; i++) {
|
|
||||||
if(fileDescList[i].title == title) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var indicator = 2;
|
var indicator = 2;
|
||||||
while(exists(title)) {
|
while(_.some(fileDescList, function(fileDesc) {
|
||||||
|
return fileDesc.title == title;
|
||||||
|
})) {
|
||||||
title = DEFAULT_FILE_TITLE + indicator++;
|
title = DEFAULT_FILE_TITLE + indicator++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -57,15 +70,14 @@ define(["jquery", "google-helper", "dropbox-helper", "github-helper", "synchroni
|
|||||||
var fileIndex = undefined;
|
var fileIndex = undefined;
|
||||||
do {
|
do {
|
||||||
fileIndex = "file." + core.randomString();
|
fileIndex = "file." + core.randomString();
|
||||||
} while(localStorage[fileIndex + ".title"] !== undefined);
|
} while(_.has(localStorage, fileIndex + ".title"));
|
||||||
|
|
||||||
// Create the file in the localStorage
|
// Create the file in the localStorage
|
||||||
localStorage[fileIndex + ".content"] = content;
|
localStorage[fileIndex + ".content"] = content;
|
||||||
localStorage[fileIndex + ".title"] = title;
|
localStorage[fileIndex + ".title"] = title;
|
||||||
var sync = ";";
|
var sync = _.reduce(syncIndexes, function(sync, syncIndex) {
|
||||||
for(var i=0; i<syncIndexes.length; i++) {
|
return sync + syncIndex + ";";
|
||||||
sync += syncIndexes[i] + ";";
|
}, ";");
|
||||||
}
|
|
||||||
localStorage[fileIndex + ".sync"] = sync;
|
localStorage[fileIndex + ".sync"] = sync;
|
||||||
localStorage[fileIndex + ".publish"] = ";";
|
localStorage[fileIndex + ".publish"] = ";";
|
||||||
localStorage["file.list"] += fileIndex + ";";
|
localStorage["file.list"] += fileIndex + ";";
|
||||||
@ -73,29 +85,25 @@ define(["jquery", "google-helper", "dropbox-helper", "github-helper", "synchroni
|
|||||||
};
|
};
|
||||||
|
|
||||||
fileManager.deleteFile = function(fileIndex) {
|
fileManager.deleteFile = function(fileIndex) {
|
||||||
var fileIndexCurrent = localStorage["file.current"];
|
fileIndex = fileIndex || fileManager.getCurrentFileIndex();
|
||||||
fileIndex = fileIndex || fileIndexCurrent;
|
if(fileManager.isCurrentFileIndex(fileIndex)) {
|
||||||
if(fileIndex == fileIndexCurrent) {
|
// Unset the current fileIndex
|
||||||
// Since we are going to modify current file
|
fileManager.setCurrentFileIndex();
|
||||||
core.checkWindowUnique();
|
|
||||||
localStorage.removeItem("file.current");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove synchronized locations
|
// Remove synchronized locations
|
||||||
var fileSyncIndexList = localStorage[fileIndex + ".sync"].split(";");
|
var syncIndexList = _.compact(localStorage[fileIndex + ".sync"].split(";"));
|
||||||
for ( var i = 1; i < fileSyncIndexList.length - 1; i++) {
|
|
||||||
var fileSyncIndex = fileSyncIndexList[i];
|
|
||||||
fileManager.removeSync(fileSyncIndex);
|
|
||||||
}
|
|
||||||
localStorage.removeItem(fileIndex + ".sync");
|
localStorage.removeItem(fileIndex + ".sync");
|
||||||
|
_.each(syncIndexList, function(syncIndex) {
|
||||||
|
fileManager.removeSync(syncIndex);
|
||||||
|
});
|
||||||
|
|
||||||
// Remove publish locations
|
// Remove publish locations
|
||||||
var publishIndexList = localStorage[fileIndex + ".publish"].split(";");
|
var publishIndexList = _.compact(localStorage[fileIndex + ".publish"].split(";"));
|
||||||
for ( var i = 1; i < publishIndexList.length - 1; i++) {
|
localStorage.removeItem(fileIndex + ".publish");
|
||||||
var publishIndex = publishIndexList[i];
|
_.each(publishIndexList, function(publishIndex) {
|
||||||
fileManager.removePublish(publishIndex);
|
fileManager.removePublish(publishIndex);
|
||||||
}
|
});
|
||||||
localStorage.removeItem(fileIndex + ".sync");
|
|
||||||
|
|
||||||
localStorage["file.list"] = localStorage["file.list"].replace(";"
|
localStorage["file.list"] = localStorage["file.list"].replace(";"
|
||||||
+ fileIndex + ";", ";");
|
+ fileIndex + ";", ";");
|
||||||
@ -105,35 +113,29 @@ define(["jquery", "google-helper", "dropbox-helper", "github-helper", "synchroni
|
|||||||
|
|
||||||
fileManager.saveFile = function() {
|
fileManager.saveFile = function() {
|
||||||
var content = $("#wmd-input").val();
|
var content = $("#wmd-input").val();
|
||||||
var fileIndex = localStorage["file.current"];
|
var fileIndex = fileManager.getCurrentFileIndex();
|
||||||
localStorage[fileIndex + ".content"] = content;
|
localStorage[fileIndex + ".content"] = content;
|
||||||
synchronizer.notifyChange(fileIndex);
|
synchronizer.notifyChange(fileIndex);
|
||||||
};
|
};
|
||||||
|
|
||||||
fileManager.updateFileTitles = function() {
|
fileManager.updateFileTitles = function() {
|
||||||
fileDescList = [];
|
|
||||||
$("#file-selector").empty();
|
$("#file-selector").empty();
|
||||||
var fileIndexList = localStorage["file.list"].split(";");
|
fileDescList = _.chain(localStorage["file.list"].split(";"))
|
||||||
for ( var i = 1; i < fileIndexList.length - 1; i++) {
|
.compact()
|
||||||
var fileIndex = fileIndexList[i];
|
.reduce(function(fileDescList, fileIndex) {
|
||||||
var title = localStorage[fileIndex + ".title"];
|
var title = localStorage[fileIndex + ".title"];
|
||||||
fileDescList.push({ index : fileIndex, title : title });
|
fileDescList.push({ index : fileIndex, title : title });
|
||||||
}
|
return fileDescList;
|
||||||
fileDescList.sort(function(a, b) {
|
}, [])
|
||||||
if (a.title.toLowerCase() < b.title.toLowerCase())
|
.sortBy(function(fileDesc) {
|
||||||
return -1;
|
return fileDesc.title.toLowerCase();
|
||||||
if (a.title.toLowerCase() > b.title.toLowerCase())
|
}).value();
|
||||||
return 1;
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
|
|
||||||
var fileIndex = localStorage["file.current"];
|
var fileIndex = fileManager.getCurrentFileIndex();
|
||||||
// If no default file take first one
|
// If no default file take first one
|
||||||
if (!fileIndex) {
|
if (fileIndex === undefined) {
|
||||||
// Since we are going to modify current file
|
|
||||||
core.checkWindowUnique();
|
|
||||||
fileIndex = fileDescList[0].index;
|
fileIndex = fileDescList[0].index;
|
||||||
localStorage["file.current"] = fileIndex;
|
fileManager.setCurrentFileIndex(fileIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
var useGoogleDrive = false;
|
var useGoogleDrive = false;
|
||||||
@ -170,10 +172,7 @@ define(["jquery", "google-helper", "dropbox-helper", "github-helper", "synchroni
|
|||||||
} else {
|
} else {
|
||||||
a.prop("href", "#").click((function(fileIndex) {
|
a.prop("href", "#").click((function(fileIndex) {
|
||||||
return function() {
|
return function() {
|
||||||
// Since we are going to modify current file
|
fileManager.selectFile(fileIndex);
|
||||||
core.checkWindowUnique();
|
|
||||||
localStorage["file.current"] = fileIndex;
|
|
||||||
fileManager.selectFile();
|
|
||||||
};
|
};
|
||||||
})(fileDesc.index));
|
})(fileDesc.index));
|
||||||
}
|
}
|
||||||
@ -184,30 +183,30 @@ define(["jquery", "google-helper", "dropbox-helper", "github-helper", "synchroni
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Remove a synchronized location
|
// Remove a synchronized location
|
||||||
fileManager.removeSync = function(fileSyncIndex) {
|
fileManager.removeSync = function(syncIndex) {
|
||||||
var fileIndexCurrent = localStorage["file.current"];
|
var currentFileIndex = fileManager.getCurrentFileIndex();
|
||||||
var fileIndex = this.getFileIndexFromSync(fileSyncIndex);
|
var fileIndex = this.getFileIndexFromSync(syncIndex);
|
||||||
if(fileIndex !== undefined) {
|
if(fileIndex !== undefined) {
|
||||||
localStorage[fileIndex + ".sync"] = localStorage[fileIndex + ".sync"].replace(";"
|
localStorage[fileIndex + ".sync"] = localStorage[fileIndex + ".sync"].replace(";"
|
||||||
+ fileSyncIndex + ";", ";");
|
+ syncIndex + ";", ";");
|
||||||
if(fileIndex == fileIndexCurrent) {
|
if(fileIndex == currentFileIndex) {
|
||||||
refreshManageSync();
|
refreshManageSync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Remove ETAG, version, CRCs (if any)
|
// Remove ETAG, version, CRCs (if any)
|
||||||
localStorage.removeItem(fileSyncIndex + ".etag");
|
localStorage.removeItem(syncIndex + ".etag");
|
||||||
localStorage.removeItem(fileSyncIndex + ".version");
|
localStorage.removeItem(syncIndex + ".version");
|
||||||
localStorage.removeItem(fileSyncIndex + ".contentCRC");
|
localStorage.removeItem(syncIndex + ".contentCRC");
|
||||||
localStorage.removeItem(fileSyncIndex + ".titleCRC");
|
localStorage.removeItem(syncIndex + ".titleCRC");
|
||||||
};
|
};
|
||||||
|
|
||||||
// Look for local file associated to a synchronized location
|
// Look for local file associated to a synchronized location
|
||||||
fileManager.getFileIndexFromSync = function(fileSyncIndex) {
|
fileManager.getFileIndexFromSync = function(syncIndex) {
|
||||||
var fileIndexList = localStorage["file.list"].split(";");
|
var fileIndexList = localStorage["file.list"].split(";");
|
||||||
for ( var i = 1; i < fileIndexList.length - 1; i++) {
|
for ( var i = 1; i < fileIndexList.length - 1; i++) {
|
||||||
var fileIndex = fileIndexList[i];
|
var fileIndex = fileIndexList[i];
|
||||||
var sync = localStorage[fileIndex + ".sync"];
|
var sync = localStorage[fileIndex + ".sync"];
|
||||||
if (sync.indexOf(";" + fileSyncIndex + ";") !== -1) {
|
if (sync.indexOf(";" + syncIndex + ";") !== -1) {
|
||||||
return fileIndex;
|
return fileIndex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -216,18 +215,18 @@ define(["jquery", "google-helper", "dropbox-helper", "github-helper", "synchroni
|
|||||||
|
|
||||||
// Remove a publish location
|
// Remove a publish location
|
||||||
fileManager.removePublish = function(publishIndex) {
|
fileManager.removePublish = function(publishIndex) {
|
||||||
var fileIndexCurrent = localStorage["file.current"];
|
var currentFileIndex = fileManager.getCurrentFileIndex();
|
||||||
var fileIndex = this.getFileIndexFromPublish(publishIndex);
|
var fileIndex = this.getFileIndexFromPublish(publishIndex);
|
||||||
if(fileIndex !== undefined) {
|
if(fileIndex !== undefined) {
|
||||||
localStorage[fileIndex + ".publish"] = localStorage[fileIndex + ".publish"].replace(";"
|
localStorage[fileIndex + ".publish"] = localStorage[fileIndex + ".publish"].replace(";"
|
||||||
+ publishIndex + ";", ";");
|
+ publishIndex + ";", ";");
|
||||||
if(fileIndex == fileIndexCurrent) {
|
if(fileIndex == currentFileIndex) {
|
||||||
refreshManagePublish();
|
refreshManagePublish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Remove publish object
|
// Remove publish object
|
||||||
localStorage.removeItem(publishIndex);
|
localStorage.removeItem(publishIndex);
|
||||||
publisher.notifyCurrentFile(localStorage["file.current"]);
|
publisher.notifyCurrentFile();
|
||||||
};
|
};
|
||||||
|
|
||||||
// Look for local file associated to a publish location
|
// Look for local file associated to a publish location
|
||||||
@ -244,18 +243,18 @@ define(["jquery", "google-helper", "dropbox-helper", "github-helper", "synchroni
|
|||||||
};
|
};
|
||||||
|
|
||||||
function uploadGdrive(fileId, folderId) {
|
function uploadGdrive(fileId, folderId) {
|
||||||
var fileIndex = localStorage["file.current"];
|
var fileIndex = fileManager.getCurrentFileIndex();
|
||||||
var content = localStorage[fileIndex + ".content"];
|
var content = localStorage[fileIndex + ".content"];
|
||||||
var title = localStorage[fileIndex + ".title"];
|
var title = localStorage[fileIndex + ".title"];
|
||||||
googleHelper.upload(fileId, folderId, title, content, function(fileSyncIndex) {
|
googleHelper.upload(fileId, folderId, title, content, function(syncIndex) {
|
||||||
if (fileSyncIndex === undefined) {
|
if (syncIndex === undefined) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var contentCRC = core.crc32(content);
|
var contentCRC = core.crc32(content);
|
||||||
localStorage[fileSyncIndex + ".contentCRC"] = contentCRC;
|
localStorage[syncIndex + ".contentCRC"] = contentCRC;
|
||||||
var titleCRC = core.crc32(title);
|
var titleCRC = core.crc32(title);
|
||||||
localStorage[fileSyncIndex + ".titleCRC"] = titleCRC;
|
localStorage[syncIndex + ".titleCRC"] = titleCRC;
|
||||||
localStorage[fileIndex + ".sync"] += fileSyncIndex + ";";
|
localStorage[fileIndex + ".sync"] += syncIndex + ";";
|
||||||
refreshManageSync();
|
refreshManageSync();
|
||||||
fileManager.updateFileTitles();
|
fileManager.updateFileTitles();
|
||||||
core.showMessage('"' + title
|
core.showMessage('"' + title
|
||||||
@ -268,8 +267,8 @@ define(["jquery", "google-helper", "dropbox-helper", "github-helper", "synchroni
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Check that file is not synchronized with an other one
|
// Check that file is not synchronized with an other one
|
||||||
var fileSyncIndex = SYNC_PROVIDER_GDRIVE + fileId;
|
var syncIndex = SYNC_PROVIDER_GDRIVE + fileId;
|
||||||
var fileIndex = fileManager.getFileIndexFromSync(fileSyncIndex);
|
var fileIndex = fileManager.getFileIndexFromSync(syncIndex);
|
||||||
if(fileIndex !== undefined) {
|
if(fileIndex !== undefined) {
|
||||||
var title = localStorage[fileIndex + ".title"];
|
var title = localStorage[fileIndex + ".title"];
|
||||||
core.showError('File ID is already synchronized with "' + title + '"');
|
core.showError('File ID is already synchronized with "' + title + '"');
|
||||||
@ -285,8 +284,8 @@ define(["jquery", "google-helper", "dropbox-helper", "github-helper", "synchroni
|
|||||||
var importIds = [];
|
var importIds = [];
|
||||||
for(var i=0; i<ids.length; i++) {
|
for(var i=0; i<ids.length; i++) {
|
||||||
var fileId = ids[i];
|
var fileId = ids[i];
|
||||||
var fileSyncIndex = SYNC_PROVIDER_GDRIVE + fileId;
|
var syncIndex = SYNC_PROVIDER_GDRIVE + fileId;
|
||||||
var fileIndex = fileManager.getFileIndexFromSync(fileSyncIndex);
|
var fileIndex = fileManager.getFileIndexFromSync(syncIndex);
|
||||||
if(fileIndex !== undefined) {
|
if(fileIndex !== undefined) {
|
||||||
var title = localStorage[fileIndex + ".title"];
|
var title = localStorage[fileIndex + ".title"];
|
||||||
core.showError('"' + title + '" was already imported');
|
core.showError('"' + title + '" was already imported');
|
||||||
@ -306,23 +305,23 @@ define(["jquery", "google-helper", "dropbox-helper", "github-helper", "synchroni
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Check that file is not synchronized with an other one
|
// Check that file is not synchronized with an other one
|
||||||
var fileSyncIndex = SYNC_PROVIDER_DROPBOX + encodeURIComponent(path.toLowerCase());
|
var syncIndex = SYNC_PROVIDER_DROPBOX + encodeURIComponent(path.toLowerCase());
|
||||||
var fileIndex = fileManager.getFileIndexFromSync(fileSyncIndex);
|
var fileIndex = fileManager.getFileIndexFromSync(syncIndex);
|
||||||
if(fileIndex !== undefined) {
|
if(fileIndex !== undefined) {
|
||||||
var title = localStorage[fileIndex + ".title"];
|
var title = localStorage[fileIndex + ".title"];
|
||||||
core.showError('Path "' + path + '" is already synchronized with "' + title + '"');
|
core.showError('Path "' + path + '" is already synchronized with "' + title + '"');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var fileIndex = localStorage["file.current"];
|
var fileIndex = fileManager.getCurrentFileIndex();
|
||||||
var content = localStorage[fileIndex + ".content"];
|
var content = localStorage[fileIndex + ".content"];
|
||||||
var title = localStorage[fileIndex + ".title"];
|
var title = localStorage[fileIndex + ".title"];
|
||||||
dropboxHelper.upload(path, content, function(fileSyncIndex) {
|
dropboxHelper.upload(path, content, function(syncIndex) {
|
||||||
if (fileSyncIndex === undefined) {
|
if (syncIndex === undefined) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var contentCRC = core.crc32(content);
|
var contentCRC = core.crc32(content);
|
||||||
localStorage[fileSyncIndex + ".contentCRC"] = contentCRC;
|
localStorage[syncIndex + ".contentCRC"] = contentCRC;
|
||||||
localStorage[fileIndex + ".sync"] += fileSyncIndex + ";";
|
localStorage[fileIndex + ".sync"] += syncIndex + ";";
|
||||||
refreshManageSync();
|
refreshManageSync();
|
||||||
fileManager.updateFileTitles();
|
fileManager.updateFileTitles();
|
||||||
core.showMessage('"' + title
|
core.showMessage('"' + title
|
||||||
@ -337,8 +336,8 @@ define(["jquery", "google-helper", "dropbox-helper", "github-helper", "synchroni
|
|||||||
var importPaths = [];
|
var importPaths = [];
|
||||||
for(var i=0; i<paths.length; i++) {
|
for(var i=0; i<paths.length; i++) {
|
||||||
var filePath = paths[i];
|
var filePath = paths[i];
|
||||||
var fileSyncIndex = SYNC_PROVIDER_DROPBOX + encodeURIComponent(filePath.toLowerCase());
|
var syncIndex = SYNC_PROVIDER_DROPBOX + encodeURIComponent(filePath.toLowerCase());
|
||||||
var fileIndex = fileManager.getFileIndexFromSync(fileSyncIndex);
|
var fileIndex = fileManager.getFileIndexFromSync(syncIndex);
|
||||||
if(fileIndex !== undefined) {
|
if(fileIndex !== undefined) {
|
||||||
var title = localStorage[fileIndex + ".title"];
|
var title = localStorage[fileIndex + ".title"];
|
||||||
core.showError('"' + title + '" was already imported');
|
core.showError('"' + title + '" was already imported');
|
||||||
@ -350,46 +349,46 @@ define(["jquery", "google-helper", "dropbox-helper", "github-helper", "synchroni
|
|||||||
}
|
}
|
||||||
|
|
||||||
function refreshManageSync() {
|
function refreshManageSync() {
|
||||||
var fileIndex = localStorage["file.current"];
|
var fileIndex = fileManager.getCurrentFileIndex();
|
||||||
var fileSyncIndexList = localStorage[fileIndex + ".sync"].split(";");
|
var syncIndexList = localStorage[fileIndex + ".sync"].split(";");
|
||||||
$(".msg-no-sync, .msg-sync-list").addClass("hide");
|
$(".msg-no-sync, .msg-sync-list").addClass("hide");
|
||||||
$("#manage-sync-list .input-append").remove();
|
$("#manage-sync-list .input-append").remove();
|
||||||
if (fileSyncIndexList.length > 2) {
|
if (syncIndexList.length > 2) {
|
||||||
$(".msg-sync-list").removeClass("hide");
|
$(".msg-sync-list").removeClass("hide");
|
||||||
} else {
|
} else {
|
||||||
$(".msg-no-sync").removeClass("hide");
|
$(".msg-no-sync").removeClass("hide");
|
||||||
}
|
}
|
||||||
for ( var i = 1; i < fileSyncIndexList.length - 1; i++) {
|
for ( var i = 1; i < syncIndexList.length - 1; i++) {
|
||||||
var fileSyncIndex = fileSyncIndexList[i];
|
var syncIndex = syncIndexList[i];
|
||||||
(function(fileSyncIndex) {
|
(function(syncIndex) {
|
||||||
var line = $("<div>").addClass("input-prepend input-append");
|
var line = $("<div>").addClass("input-prepend input-append");
|
||||||
if (fileSyncIndex.indexOf(SYNC_PROVIDER_GDRIVE) === 0) {
|
if (syncIndex.indexOf(SYNC_PROVIDER_GDRIVE) === 0) {
|
||||||
line.append($("<span>").addClass("add-on").prop("title", "Google Drive").html(
|
line.append($("<span>").addClass("add-on").prop("title", "Google Drive").html(
|
||||||
'<i class="icon-gdrive"></i>'));
|
'<i class="icon-gdrive"></i>'));
|
||||||
line.append($("<input>").prop("type", "text").prop(
|
line.append($("<input>").prop("type", "text").prop(
|
||||||
"disabled", true).addClass("span5").val(
|
"disabled", true).addClass("span5").val(
|
||||||
fileSyncIndex.substring(SYNC_PROVIDER_GDRIVE.length)));
|
syncIndex.substring(SYNC_PROVIDER_GDRIVE.length)));
|
||||||
}
|
}
|
||||||
else if (fileSyncIndex.indexOf(SYNC_PROVIDER_DROPBOX) === 0) {
|
else if (syncIndex.indexOf(SYNC_PROVIDER_DROPBOX) === 0) {
|
||||||
line.append($("<span>").addClass("add-on").prop("title", "Dropbox").html(
|
line.append($("<span>").addClass("add-on").prop("title", "Dropbox").html(
|
||||||
'<i class="icon-dropbox"></i>'));
|
'<i class="icon-dropbox"></i>'));
|
||||||
line.append($("<input>").prop("type", "text").prop(
|
line.append($("<input>").prop("type", "text").prop(
|
||||||
"disabled", true).addClass("span5").val(
|
"disabled", true).addClass("span5").val(
|
||||||
decodeURIComponent(fileSyncIndex.substring(SYNC_PROVIDER_DROPBOX.length))));
|
decodeURIComponent(syncIndex.substring(SYNC_PROVIDER_DROPBOX.length))));
|
||||||
}
|
}
|
||||||
line.append($("<a>").addClass("btn").html(
|
line.append($("<a>").addClass("btn").html(
|
||||||
'<i class="icon-trash"></i>').prop("title",
|
'<i class="icon-trash"></i>').prop("title",
|
||||||
"Remove this location").click(function() {
|
"Remove this location").click(function() {
|
||||||
fileManager.removeSync(fileSyncIndex);
|
fileManager.removeSync(syncIndex);
|
||||||
fileManager.updateFileTitles();
|
fileManager.updateFileTitles();
|
||||||
}));
|
}));
|
||||||
$("#manage-sync-list").append(line);
|
$("#manage-sync-list").append(line);
|
||||||
})(fileSyncIndex);
|
})(syncIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function refreshManagePublish() {
|
function refreshManagePublish() {
|
||||||
var fileIndex = localStorage["file.current"];
|
var fileIndex = fileManager.getCurrentFileIndex();
|
||||||
var publishIndexList = localStorage[fileIndex + ".publish"].split(";");
|
var publishIndexList = localStorage[fileIndex + ".publish"].split(";");
|
||||||
$(".msg-no-publish, .msg-publish-list").addClass("hide");
|
$(".msg-no-publish, .msg-publish-list").addClass("hide");
|
||||||
$("#manage-publish-list .input-append").remove();
|
$("#manage-publish-list .input-append").remove();
|
||||||
@ -465,7 +464,7 @@ define(["jquery", "google-helper", "dropbox-helper", "github-helper", "synchroni
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var fileIndex = localStorage["file.current"];
|
var fileIndex = fileManager.getCurrentFileIndex();
|
||||||
var title = localStorage[fileIndex + ".title"];
|
var title = localStorage[fileIndex + ".title"];
|
||||||
var content = publisher.getPublishContent(publishObject);
|
var content = publisher.getPublishContent(publishObject);
|
||||||
var commitMsg = core.settings.commitMsg;
|
var commitMsg = core.settings.commitMsg;
|
||||||
@ -475,7 +474,7 @@ define(["jquery", "google-helper", "dropbox-helper", "github-helper", "synchroni
|
|||||||
if(error === undefined) {
|
if(error === undefined) {
|
||||||
createPublishIndex(publishObject, fileIndex);
|
createPublishIndex(publishObject, fileIndex);
|
||||||
refreshManagePublish();
|
refreshManagePublish();
|
||||||
publisher.notifyCurrentFile(localStorage["file.current"]);
|
publisher.notifyCurrentFile();
|
||||||
core.showMessage('"' + title
|
core.showMessage('"' + title
|
||||||
+ '" will now be published on GitHub.');
|
+ '" will now be published on GitHub.');
|
||||||
}
|
}
|
||||||
@ -516,7 +515,7 @@ define(["jquery", "google-helper", "dropbox-helper", "github-helper", "synchroni
|
|||||||
$("#file-title-input").blur(function() {
|
$("#file-title-input").blur(function() {
|
||||||
var title = $.trim($(this).val());
|
var title = $.trim($(this).val());
|
||||||
if (title) {
|
if (title) {
|
||||||
var fileIndexTitle = localStorage["file.current"] + ".title";
|
var fileIndexTitle = fileManager.getCurrentFileIndex() + ".title";
|
||||||
if (title != localStorage[fileIndexTitle]) {
|
if (title != localStorage[fileIndexTitle]) {
|
||||||
localStorage[fileIndexTitle] = title;
|
localStorage[fileIndexTitle] = title;
|
||||||
fileManager.updateFileTitles();
|
fileManager.updateFileTitles();
|
||||||
|
@ -161,6 +161,7 @@ define(["jquery", "async-runner"], function($, asyncTaskRunner) {
|
|||||||
callback(error);
|
callback(error);
|
||||||
};
|
};
|
||||||
asyncTask.onError = function() {
|
asyncTask.onError = function() {
|
||||||
|
console.error(error);
|
||||||
var errorMsg = "Could not publish on GitHub.";
|
var errorMsg = "Could not publish on GitHub.";
|
||||||
if(error === 401 || error === 403) {
|
if(error === 401 || error === 403) {
|
||||||
github = undefined;
|
github = undefined;
|
||||||
|
@ -364,6 +364,7 @@ define(["jquery", "async-runner"], function($, asyncTaskRunner) {
|
|||||||
callback();
|
callback();
|
||||||
};
|
};
|
||||||
if (error) {
|
if (error) {
|
||||||
|
console.error(error);
|
||||||
// Try to analyze the error
|
// Try to analyze the error
|
||||||
if (typeof error === "string") {
|
if (typeof error === "string") {
|
||||||
errorMsg = error;
|
errorMsg = error;
|
||||||
|
9
js/main-min.js
vendored
9
js/main-min.js
vendored
File diff suppressed because one or more lines are too long
@ -1,4 +1,4 @@
|
|||||||
define(["jquery", "google-helper", "github-helper"], function($, googleHelper, githubHelper) {
|
define(["jquery", "google-helper", "github-helper", "publish-github", "underscore"], function($, googleHelper, githubHelper) {
|
||||||
|
|
||||||
// Dependencies
|
// Dependencies
|
||||||
var core = undefined;
|
var core = undefined;
|
||||||
@ -6,11 +6,15 @@ define(["jquery", "google-helper", "github-helper"], function($, googleHelper, g
|
|||||||
|
|
||||||
var publisher = {};
|
var publisher = {};
|
||||||
|
|
||||||
|
// Providers
|
||||||
|
var providerMap = {};
|
||||||
|
|
||||||
// Used to know if the current file has publications
|
// Used to know if the current file has publications
|
||||||
var hasPublications = false;
|
var hasPublications = false;
|
||||||
|
|
||||||
// Allows external modules to update hasPublications flag
|
// Allows external modules to update hasPublications flag
|
||||||
publisher.notifyCurrentFile = function(fileIndex) {
|
publisher.notifyCurrentFile = function() {
|
||||||
|
var fileIndex = fileManager.getCurrentFileIndex();
|
||||||
|
|
||||||
// Check that file has publications
|
// Check that file has publications
|
||||||
if(localStorage[fileIndex + ".publish"].length === 1) {
|
if(localStorage[fileIndex + ".publish"].length === 1) {
|
||||||
@ -33,7 +37,7 @@ define(["jquery", "google-helper", "github-helper"], function($, googleHelper, g
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Used to get content to publish
|
// Used to get content to publish
|
||||||
publisher.getPublishContent = function(publishObject) {
|
function getPublishContent(publishObject) {
|
||||||
if(publishObject.format === undefined) {
|
if(publishObject.format === undefined) {
|
||||||
publishObject.format = $("input:radio[name=radio-publish-format]:checked").prop("value");
|
publishObject.format = $("input:radio[name=radio-publish-format]:checked").prop("value");
|
||||||
}
|
}
|
||||||
@ -41,7 +45,7 @@ define(["jquery", "google-helper", "github-helper"], function($, googleHelper, g
|
|||||||
return $("#wmd-input").val();
|
return $("#wmd-input").val();
|
||||||
}
|
}
|
||||||
return $("#wmd-preview").html();
|
return $("#wmd-preview").html();
|
||||||
};
|
}
|
||||||
|
|
||||||
// Recursive function to publish a file on multiple locations
|
// Recursive function to publish a file on multiple locations
|
||||||
var publishIndexList = [];
|
var publishIndexList = [];
|
||||||
@ -61,7 +65,7 @@ define(["jquery", "google-helper", "github-helper"], function($, googleHelper, g
|
|||||||
}
|
}
|
||||||
|
|
||||||
var publishObject = JSON.parse(localStorage[publishIndex]);
|
var publishObject = JSON.parse(localStorage[publishIndex]);
|
||||||
var content = publisher.getPublishContent(publishObject);
|
var content = getPublishContent(publishObject);
|
||||||
var commitMsg = core.settings.commitMsg;
|
var commitMsg = core.settings.commitMsg;
|
||||||
|
|
||||||
// Try to find the provider
|
// Try to find the provider
|
||||||
@ -82,7 +86,7 @@ define(["jquery", "google-helper", "github-helper"], function($, googleHelper, g
|
|||||||
|
|
||||||
publishRunning = true;
|
publishRunning = true;
|
||||||
publisher.updatePublishButton();
|
publisher.updatePublishButton();
|
||||||
var fileIndex = localStorage["file.current"];
|
var fileIndex = fileManager.getCurrentFileIndex();
|
||||||
var title = localStorage[fileIndex + ".title"];
|
var title = localStorage[fileIndex + ".title"];
|
||||||
publishIndexList = localStorage[fileIndex + ".publish"].split(";");;
|
publishIndexList = localStorage[fileIndex + ".publish"].split(";");;
|
||||||
publishLocation(function(error) {
|
publishLocation(function(error) {
|
||||||
@ -93,10 +97,32 @@ define(["jquery", "google-helper", "github-helper"], function($, googleHelper, g
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Add a new publish location to a local document
|
||||||
|
publisher.newLocation = function(publishObject, callback) {
|
||||||
|
var fileIndex = fileManager.getCurrentFileIndex();
|
||||||
|
var title = localStorage[fileIndex + ".title"];
|
||||||
|
var content = getPublishContent(publishObject);
|
||||||
|
var provider = providerMap[publishObject.provider];
|
||||||
|
provider.publishNew(publishObject, title, content);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Associate publish provider to publisher
|
||||||
|
_.each(arguments, function(argument) {
|
||||||
|
if(argument !== undefined && argument.publishProvider !== undefined) {
|
||||||
|
providerMap[argument.publishProvider] = argument;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
publisher.init = function(coreModule, fileManagerModule) {
|
publisher.init = function(coreModule, fileManagerModule) {
|
||||||
core = coreModule;
|
core = coreModule;
|
||||||
fileManager = fileManagerModule;
|
fileManager = fileManagerModule;
|
||||||
|
|
||||||
|
// Init providers
|
||||||
|
_.each(providerMap, function(provider) {
|
||||||
|
provider.init();
|
||||||
|
});
|
||||||
|
|
||||||
$(".action-force-publish").click(function() {
|
$(".action-force-publish").click(function() {
|
||||||
if(!$(this).hasClass("disabled")) {
|
if(!$(this).hasClass("disabled")) {
|
||||||
publisher.publish();
|
publisher.publish();
|
||||||
|
@ -209,7 +209,7 @@ define(["jquery", "google-helper", "dropbox-helper"], function($, googleHelper,
|
|||||||
if(fileContentChanged) {
|
if(fileContentChanged) {
|
||||||
localStorage[fileIndex + ".content"] = file.content;
|
localStorage[fileIndex + ".content"] = file.content;
|
||||||
core.showMessage('"' + file.title + '" has been updated from Google Drive.');
|
core.showMessage('"' + file.title + '" has been updated from Google Drive.');
|
||||||
if(fileIndex == localStorage["file.current"]) {
|
if(fileManager.isCurrentFileIndex(fileIndex)) {
|
||||||
updateFileTitles = false; // Done by next function
|
updateFileTitles = false; // Done by next function
|
||||||
fileManager.selectFile(); // Refresh editor
|
fileManager.selectFile(); // Refresh editor
|
||||||
}
|
}
|
||||||
@ -278,7 +278,7 @@ define(["jquery", "google-helper", "dropbox-helper"], function($, googleHelper,
|
|||||||
if(fileContentChanged) {
|
if(fileContentChanged) {
|
||||||
localStorage[fileIndex + ".content"] = file.content;
|
localStorage[fileIndex + ".content"] = file.content;
|
||||||
core.showMessage('"' + localTitle + '" has been updated from Dropbox.');
|
core.showMessage('"' + localTitle + '" has been updated from Dropbox.');
|
||||||
if(fileIndex == localStorage["file.current"]) {
|
if(fileManager.isCurrentFileIndex(fileIndex)) {
|
||||||
updateFileTitles = false; // Done by next function
|
updateFileTitles = false; // Done by next function
|
||||||
fileManager.selectFile(); // Refresh editor
|
fileManager.selectFile(); // Refresh editor
|
||||||
}
|
}
|
||||||
|
5
js/underscore-min.js
vendored
5
js/underscore-min.js
vendored
File diff suppressed because one or more lines are too long
1227
js/underscore.js
Normal file
1227
js/underscore.js
Normal file
File diff suppressed because it is too large
Load Diff
3399
lib/dropbox.js
3399
lib/dropbox.js
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user