Publish support
This commit is contained in:
parent
fb848a9f81
commit
85528c92a9
@ -29,7 +29,7 @@ div, span, a, ul, li, textarea, input, button {
|
|||||||
text-shadow: none !important;
|
text-shadow: none !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.btn, .navbar-inner, .ui-layout-east, .ui-layout-south, textarea, input, .add-on {
|
.btn, .navbar-inner, .ui-layout-east, .ui-layout-south, textarea, .add-on {
|
||||||
border: none !important;
|
border: none !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,10 +38,9 @@ div, span, a, ul, li, textarea, input, button {
|
|||||||
text-align: left;
|
text-align: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
.input-prepend input,
|
input,
|
||||||
.input-prepend .btn,
|
.input-prepend .btn,
|
||||||
.input-prepend .add-on
|
.input-prepend .add-on {
|
||||||
{
|
|
||||||
border: 1px solid #ebebeb !important;
|
border: 1px solid #ebebeb !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
109
index.html
109
index.html
@ -5,8 +5,10 @@
|
|||||||
<link rel="icon" href="img/stackedit-32.ico" type="image/x-icon">
|
<link rel="icon" href="img/stackedit-32.ico" type="image/x-icon">
|
||||||
<link rel="shortcut icon" href="img/stackedit-32.ico"
|
<link rel="shortcut icon" href="img/stackedit-32.ico"
|
||||||
type="image/x-icon">
|
type="image/x-icon">
|
||||||
<meta name="keywords" content="Markdown, Editor, PageDown, Stack Overflow, Stack Exchange">
|
<meta name="keywords"
|
||||||
<meta name="description" content="StackEdit is a free, open-source Markdown editor based on PageDown, the Markdown library used by Stack Overflow and the other Stack Exchange sites.">
|
content="Markdown, Editor, PageDown, Stack Overflow, Stack Exchange">
|
||||||
|
<meta name="description"
|
||||||
|
content="StackEdit is a free, open-source Markdown editor based on PageDown, the Markdown library used by Stack Overflow and the other Stack Exchange sites.">
|
||||||
<meta name="author" content="Benoit Schweblin">
|
<meta name="author" content="Benoit Schweblin">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<link href="css/main.css" rel="stylesheet" media="screen">
|
<link href="css/main.css" rel="stylesheet" media="screen">
|
||||||
@ -23,8 +25,8 @@
|
|||||||
<li class="btn-group"><button class="btn action-force-sync"
|
<li class="btn-group"><button class="btn action-force-sync"
|
||||||
title="Synchronize">
|
title="Synchronize">
|
||||||
<i class="icon-refresh"></i>
|
<i class="icon-refresh"></i>
|
||||||
</button><button class="btn action-publish"
|
</button>
|
||||||
title="Publish">
|
<button class="btn action-publish" title="Publish">
|
||||||
<i class="icon-share"></i>
|
<i class="icon-share"></i>
|
||||||
</button></li>
|
</button></li>
|
||||||
<li class="btn-group"><button class="btn action-create-file"
|
<li class="btn-group"><button class="btn action-create-file"
|
||||||
@ -71,7 +73,7 @@
|
|||||||
Manage synchronization</a></li>
|
Manage synchronization</a></li>
|
||||||
<li class="divider"></li>
|
<li class="divider"></li>
|
||||||
<li class="dropdown-submenu"><a href="#"><i
|
<li class="dropdown-submenu"><a href="#"><i
|
||||||
class="icon-share"></i> Publish</a>
|
class="icon-share"></i> Publish on</a>
|
||||||
<ul class="dropdown-menu">
|
<ul class="dropdown-menu">
|
||||||
<li><a href="#" class="action-publish-github"><i
|
<li><a href="#" class="action-publish-github"><i
|
||||||
class="icon-github"></i> GitHub</a></li>
|
class="icon-github"></i> GitHub</a></li>
|
||||||
@ -256,53 +258,45 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="modal-publish-existing" class="modal hide">
|
<div id="modal-publish" class="modal hide">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
<button type="button" class="close" data-dismiss="modal"
|
<button type="button" class="close" data-dismiss="modal"
|
||||||
aria-hidden="true">×</button>
|
aria-hidden="true">×</button>
|
||||||
<h3>Publish</h3>
|
<h3>Publish</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<dl class="dl-horizontal">
|
<div class="form-horizontal">
|
||||||
<dt>Would you like to:</dt>
|
<div class="control-group control-publish-blogger">
|
||||||
<dd>
|
<label class="control-label" for="input-publish-blogger-url">Blog URL</label>
|
||||||
|
<div class="controls">
|
||||||
|
<input type="text" id="input-publish-blogger-url"
|
||||||
|
placeholder="http://exemple.blogger.com/">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="control-group control-publish-blogger">
|
||||||
|
<label class="control-label" for="input-publish-blogger-postid">Update existing post ID (optional)</label>
|
||||||
|
<div class="controls">
|
||||||
|
<input type="text" id="input-publish-blogger-postid"
|
||||||
|
placeholder="Post ID">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="control-group">
|
||||||
|
<div class="control-label">Publish as</div>
|
||||||
|
<div class="controls">
|
||||||
<label class="radio"> <input type="radio"
|
<label class="radio"> <input type="radio"
|
||||||
name="radio-publish-existing" value="new">
|
name="radio-publish-format" value="markdown"> Markdown
|
||||||
Create a new Post
|
format
|
||||||
</label> <label class="radio"> <input type="radio"
|
|
||||||
name="radio-publish-existing" value="existing"> Edit an existing post
|
|
||||||
</label>
|
|
||||||
</dd>
|
|
||||||
</dl>
|
|
||||||
</div>
|
|
||||||
<div class="modal-footer">
|
|
||||||
<a href="#" class="btn" data-dismiss="modal">Cancel</a> <a href="#"
|
|
||||||
data-dismiss="modal" class="btn btn-primary action-publish-next">Next</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="modal-publish-format" class="modal hide">
|
|
||||||
<div class="modal-header">
|
|
||||||
<button type="button" class="close" data-dismiss="modal"
|
|
||||||
aria-hidden="true">×</button>
|
|
||||||
<h3>Publish</h3>
|
|
||||||
</div>
|
|
||||||
<div class="modal-body">
|
|
||||||
<dl class="dl-horizontal">
|
|
||||||
<dt>Publish as:</dt>
|
|
||||||
<dd>
|
|
||||||
<label class="radio"> <input type="radio"
|
|
||||||
name="radio-publish-format" value="markdown">
|
|
||||||
Markdown format
|
|
||||||
</label> <label class="radio"> <input type="radio"
|
</label> <label class="radio"> <input type="radio"
|
||||||
name="radio-publish-format" value="html"> HTML format
|
name="radio-publish-format" value="html"> HTML format
|
||||||
</label>
|
</label>
|
||||||
</dd>
|
</div>
|
||||||
</dl>
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<a href="#" class="btn" data-dismiss="modal">Cancel</a> <a href="#"
|
<a href="#" class="btn" data-dismiss="modal">Cancel</a>
|
||||||
data-dismiss="modal" class="btn btn-primary action-publish-finish">OK</a>
|
<a href="#" data-dismiss="modal"
|
||||||
|
class="btn btn-primary action-publish-ok">OK</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -313,17 +307,20 @@
|
|||||||
<h3>Settings</h3>
|
<h3>Settings</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<dl class="dl-horizontal">
|
<div class="form-horizontal">
|
||||||
<dt>Layout orientation:</dt>
|
<div class="control-group">
|
||||||
<dd>
|
<div class="control-label">Layout orientation</div>
|
||||||
|
<div class="controls">
|
||||||
<label class="radio"> <input type="radio"
|
<label class="radio"> <input type="radio"
|
||||||
name="radio-layout-orientation" value="horizontal">
|
name="radio-layout-orientation" value="horizontal">
|
||||||
Horizontal
|
Horizontal
|
||||||
</label> <label class="radio"> <input type="radio"
|
</label> <label class="radio"> <input type="radio"
|
||||||
name="radio-layout-orientation" value="vertical"> Vertical
|
name="radio-layout-orientation" value="vertical">
|
||||||
|
Vertical
|
||||||
</label>
|
</label>
|
||||||
</dd>
|
</div>
|
||||||
</dl>
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<a href="#" class="btn" data-dismiss="modal">Cancel</a> <a href="#"
|
<a href="#" class="btn" data-dismiss="modal">Cancel</a> <a href="#"
|
||||||
@ -376,7 +373,7 @@
|
|||||||
<a target="_blank" href="http://twitter.github.com/bootstrap/">Bootstrap</a>
|
<a target="_blank" href="http://twitter.github.com/bootstrap/">Bootstrap</a>
|
||||||
</dd>
|
</dd>
|
||||||
<dd>
|
<dd>
|
||||||
<a target="_blank" href="http://glyphicons.com/">GLYPHICONS</a>
|
<a target="_blank" href="http://glyphicons.com/">Glyphicons</a>
|
||||||
</dd>
|
</dd>
|
||||||
<dd>
|
<dd>
|
||||||
<a target="_blank" href="https://github.com/stanlemon/jGrowl/">jGrowl</a>
|
<a target="_blank" href="https://github.com/stanlemon/jGrowl/">jGrowl</a>
|
||||||
@ -403,8 +400,24 @@
|
|||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<a href="#" class="btn btn-primary" data-dismiss="modal">Close</a>
|
<a href="#" class="btn btn-primary" data-dismiss="modal">Close</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div id="modal-non-unique" class="modal hide">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h3>Stopped...</h3>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<p>StackEdit has stopped because another instance was running on
|
||||||
|
the same browser.</p>
|
||||||
|
<p class="muted">If you want to reopen StackEdit, click on
|
||||||
|
"Reload".</p>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<a href="javascript:window.location.reload();"
|
||||||
|
class="btn btn-primary">Reload</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div id="dropboxjs" data-app-key="x0k2l8puemfvg0o"></div>
|
<div id="dropboxjs" data-app-key="x0k2l8puemfvg0o"></div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -6,17 +6,20 @@
|
|||||||
* - an optional onError() function
|
* - an optional onError() function
|
||||||
* - an optional timeout field (default is 30000)
|
* - an optional timeout field (default is 30000)
|
||||||
*/
|
*/
|
||||||
define(["core"], function(core) {
|
define(function() {
|
||||||
|
|
||||||
var asyncTaskRunner = {};
|
var asyncTaskRunner = {};
|
||||||
|
|
||||||
|
// Dependencies
|
||||||
|
var core = undefined;
|
||||||
|
|
||||||
var asyncTaskQueue = [];
|
var asyncTaskQueue = [];
|
||||||
var currentTask = undefined;
|
var currentTask = undefined;
|
||||||
var currentTaskRunning = false;
|
var currentTaskRunning = false;
|
||||||
var currentTaskStartTime = core.currentTime;
|
var currentTaskStartTime = 0;
|
||||||
|
|
||||||
// Run the next task in the queue if any and no other is running
|
// Run the next task in the queue if any and no other is running
|
||||||
asyncTaskRunner.runTask = function() {
|
function runTask() {
|
||||||
|
|
||||||
// If there is a task currently running
|
// If there is a task currently running
|
||||||
if(currentTaskRunning === true) {
|
if(currentTaskRunning === true) {
|
||||||
@ -42,17 +45,6 @@ define(["core"], function(core) {
|
|||||||
// Set task attributes and functions
|
// Set task attributes and functions
|
||||||
currentTask.finished = false;
|
currentTask.finished = false;
|
||||||
currentTask.retryCounter = 0;
|
currentTask.retryCounter = 0;
|
||||||
currentTask.finish = function() {
|
|
||||||
this.finished = true;
|
|
||||||
currentTask = undefined;
|
|
||||||
currentTaskRunning = false;
|
|
||||||
if(asyncTaskQueue.length === 0) {
|
|
||||||
core.showWorkingIndicator(false);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
asyncTaskRunner.runTask();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
currentTask.success = function() {
|
currentTask.success = function() {
|
||||||
runSafe(this.onSuccess);
|
runSafe(this.onSuccess);
|
||||||
};
|
};
|
||||||
@ -68,8 +60,7 @@ define(["core"], function(core) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Implement an exponential backoff
|
// Implement an exponential backoff
|
||||||
var delay = (Math.pow(2, currentTask.retryCounter++) + Math.random()) * 1000;
|
var delay = Math.pow(2, currentTask.retryCounter++) * 1000;
|
||||||
console.log(delay);
|
|
||||||
currentTaskStartTime = core.currentTime + delay;
|
currentTaskStartTime = core.currentTime + delay;
|
||||||
currentTaskRunning = false;
|
currentTaskRunning = false;
|
||||||
asyncTaskRunner.runTask();
|
asyncTaskRunner.runTask();
|
||||||
@ -81,6 +72,11 @@ define(["core"], function(core) {
|
|||||||
currentTaskRunning = true;
|
currentTaskRunning = true;
|
||||||
currentTask.run();
|
currentTask.run();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
asyncTaskRunner.runTask = function() {
|
||||||
|
// Use setTimeout to avoid stack overflow
|
||||||
|
setTimeout(runTask, 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
function runSafe(func) {
|
function runSafe(func) {
|
||||||
@ -104,12 +100,16 @@ define(["core"], function(core) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a task in the queue
|
// Add a task into the queue
|
||||||
asyncTaskRunner.addTask = function(asyncTask) {
|
asyncTaskRunner.addTask = function(asyncTask) {
|
||||||
asyncTaskQueue.push(asyncTask);
|
asyncTaskQueue.push(asyncTask);
|
||||||
asyncTaskRunner.runTask();
|
asyncTaskRunner.runTask();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
asyncTaskRunner.init = function(coreModule) {
|
||||||
|
core = coreModule;
|
||||||
|
};
|
||||||
|
|
||||||
return asyncTaskRunner;
|
return asyncTaskRunner;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
var GOOGLE_SCOPES = [ 'https://www.googleapis.com/auth/drive.install',
|
var GOOGLE_SCOPES = [ "https://www.googleapis.com/auth/drive.install",
|
||||||
'https://www.googleapis.com/auth/drive' ];
|
"https://www.googleapis.com/auth/drive",
|
||||||
|
"https://www.googleapis.com/auth/blogger" ];
|
||||||
var GOOGLE_DRIVE_APP_ID = "241271498917";
|
var GOOGLE_DRIVE_APP_ID = "241271498917";
|
||||||
var DROPBOX_APP_KEY = "lq6mwopab8wskas";
|
var DROPBOX_APP_KEY = "lq6mwopab8wskas";
|
||||||
var DROPBOX_APP_SECRET = "851fgnucpezy84t";
|
var DROPBOX_APP_SECRET = "851fgnucpezy84t";
|
||||||
@ -10,6 +11,7 @@ var AJAX_TIMEOUT = 10000;
|
|||||||
var ASYNC_TASK_DEFAULT_TIMEOUT = 30000;
|
var ASYNC_TASK_DEFAULT_TIMEOUT = 30000;
|
||||||
var AUTH_POPUP_TIMEOUT = 90000;
|
var AUTH_POPUP_TIMEOUT = 90000;
|
||||||
var SYNC_PERIOD = 180000;
|
var SYNC_PERIOD = 180000;
|
||||||
|
var USER_IDLE_THRESHOLD = 300000;
|
||||||
var SYNC_PROVIDER_GDRIVE = "sync.gdrive.";
|
var SYNC_PROVIDER_GDRIVE = "sync.gdrive.";
|
||||||
var SYNC_PROVIDER_DROPBOX = "sync.dropbox.";
|
var SYNC_PROVIDER_DROPBOX = "sync.dropbox.";
|
||||||
|
|
||||||
|
113
js/core.js
113
js/core.js
@ -1,16 +1,58 @@
|
|||||||
define(["jquery", "bootstrap", "jgrowl", "layout", "Markdown.Editor"], function($) {
|
define(
|
||||||
|
[ "jquery", "file-manager", "google-helper", "dropbox-helper",
|
||||||
|
"synchronizer", "publisher", "async-runner", "bootstrap", "jgrowl",
|
||||||
|
"layout", "Markdown.Editor", "config", "custo" ],
|
||||||
|
function($, fileManager, googleHelper, dropboxHelper, synchronizer,
|
||||||
|
publisher, asyncTaskRunner) {
|
||||||
|
|
||||||
var core = {};
|
var core = {};
|
||||||
|
|
||||||
// Time shared by others modules
|
|
||||||
core.currentTime = new Date().getTime();
|
|
||||||
core.updateCurrentTime = function() {
|
|
||||||
core.currentTime = new Date().getTime();
|
|
||||||
};
|
|
||||||
|
|
||||||
// Usage: callback = callback || core.doNothing;
|
// Usage: callback = callback || core.doNothing;
|
||||||
core.doNothing = function() {};
|
core.doNothing = function() {};
|
||||||
|
|
||||||
|
// Time shared by others modules
|
||||||
|
core.currentTime = new Date().getTime();
|
||||||
|
function updateCurrentTime() {
|
||||||
|
core.currentTime = new Date().getTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Used to detect user activity
|
||||||
|
var userReal = false;
|
||||||
|
var userActive = false;
|
||||||
|
var windowUnique = true;
|
||||||
|
var userLastActivity = 0;
|
||||||
|
function setUserActive() {
|
||||||
|
userReal = true;
|
||||||
|
userActive = true;
|
||||||
|
userLastActivity = core.currentTime;
|
||||||
|
};
|
||||||
|
function isUserActive() {
|
||||||
|
if(userActive === true
|
||||||
|
&& core.currentTime - userLastActivity > USER_IDLE_THRESHOLD) {
|
||||||
|
userActive = false;
|
||||||
|
}
|
||||||
|
return userActive && windowUnique;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Used to only have 1 window of the application in the same browser
|
||||||
|
var windowId = undefined;
|
||||||
|
core.checkWindowUnique = function() {
|
||||||
|
if(userReal === false || windowUnique === false) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(windowId === undefined) {
|
||||||
|
windowId = Math.random().toString(36);
|
||||||
|
localStorage["frontWindowId"] = windowId;
|
||||||
|
}
|
||||||
|
var frontWindowId = localStorage["frontWindowId"];
|
||||||
|
if(frontWindowId != windowId) {
|
||||||
|
windowUnique = false;
|
||||||
|
$('#modal-non-unique').modal({
|
||||||
|
backdrop: "static",
|
||||||
|
keyboard: false
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Useful function
|
// Useful function
|
||||||
core.getInputValue = function(element, event) {
|
core.getInputValue = function(element, event) {
|
||||||
@ -58,10 +100,6 @@ define(["jquery", "bootstrap", "jgrowl", "layout", "Markdown.Editor"], function(
|
|||||||
var offlineTime = core.currentTime;
|
var offlineTime = core.currentTime;
|
||||||
var offlineListeners = [];
|
var offlineListeners = [];
|
||||||
|
|
||||||
core.addOfflineListener = function(listener) {
|
|
||||||
offlineListeners.push(listener);
|
|
||||||
};
|
|
||||||
|
|
||||||
core.setOffline = function() {
|
core.setOffline = function() {
|
||||||
offlineTime = core.currentTime;
|
offlineTime = core.currentTime;
|
||||||
if(core.isOffline === false) {
|
if(core.isOffline === false) {
|
||||||
@ -89,7 +127,7 @@ define(["jquery", "bootstrap", "jgrowl", "layout", "Markdown.Editor"], function(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
core.checkOnline = function() {
|
function checkOnline() {
|
||||||
// Try to reconnect if we are offline but we have some network
|
// Try to reconnect if we are offline but we have some network
|
||||||
if (core.isOffline === true && navigator.onLine === true
|
if (core.isOffline === true && navigator.onLine === true
|
||||||
&& offlineTime + CHECK_ONLINE_PERIOD < core.currentTime) {
|
&& offlineTime + CHECK_ONLINE_PERIOD < core.currentTime) {
|
||||||
@ -102,7 +140,7 @@ define(["jquery", "bootstrap", "jgrowl", "layout", "Markdown.Editor"], function(
|
|||||||
core.setOnline();
|
core.setOnline();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
// Setting management
|
// Setting management
|
||||||
var settings = { layoutOrientation : "horizontal" };
|
var settings = { layoutOrientation : "horizontal" };
|
||||||
@ -338,10 +376,10 @@ define(["jquery", "bootstrap", "jgrowl", "layout", "Markdown.Editor"], function(
|
|||||||
|
|
||||||
// Used to setup an empty localStorage
|
// Used to setup an empty localStorage
|
||||||
function setupLocalStorage() {
|
function setupLocalStorage() {
|
||||||
if (localStorage["file.counter"] === undefined
|
if (localStorage["file.counter"] === undefined) {
|
||||||
|| localStorage["file.list"] === undefined) {
|
|
||||||
localStorage["file.counter"] = "0";
|
localStorage["file.counter"] = "0";
|
||||||
localStorage["file.list"] = ";";
|
localStorage["file.list"] = ";";
|
||||||
|
localStorage["version"] = "v1";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -351,19 +389,22 @@ define(["jquery", "bootstrap", "jgrowl", "layout", "Markdown.Editor"], function(
|
|||||||
|
|
||||||
// from v0 to v1
|
// from v0 to v1
|
||||||
if(version === undefined) {
|
if(version === undefined) {
|
||||||
|
|
||||||
|
// Synchronization queue not used anymore
|
||||||
|
localStorage.removeItem("sync.queue");
|
||||||
|
localStorage.removeItem("sync.current");
|
||||||
|
|
||||||
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];
|
||||||
localStorage[fileIndex + ".publish"] = ";";
|
localStorage[fileIndex + ".publish"] = ";";
|
||||||
var titleCRC = core.crc32(localStorage[fileIndex + ".title"]);
|
|
||||||
var contentCRC = core.crc32(localStorage[fileIndex + ".content"]);
|
|
||||||
var fileSyncIndexList = localStorage[fileIndex + ".sync"].split(";");
|
var fileSyncIndexList = localStorage[fileIndex + ".sync"].split(";");
|
||||||
for ( var j = 1; j < fileSyncIndexList.length - 1; j++) {
|
for ( var j = 1; j < fileSyncIndexList.length - 1; j++) {
|
||||||
var fileSyncIndex = fileSyncIndexList[j];
|
var fileSyncIndex = fileSyncIndexList[j];
|
||||||
localStorage[fileSyncIndex + ".contentCRC"] = contentCRC;
|
localStorage[fileSyncIndex + ".contentCRC"] = "0";
|
||||||
// We store title CRC only for Google Drive synchronization
|
// We store title CRC only for Google Drive synchronization
|
||||||
if(localStorage[fileSyncIndex + ".etag"] !== undefined) {
|
if(localStorage[fileSyncIndex + ".etag"] !== undefined) {
|
||||||
localStorage[fileSyncIndex + ".titleCRC"] = titleCRC;
|
localStorage[fileSyncIndex + ".titleCRC"] = "0";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -389,6 +430,9 @@ define(["jquery", "bootstrap", "jgrowl", "layout", "Markdown.Editor"], function(
|
|||||||
core.setOffline();
|
core.setOffline();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Detect user activity
|
||||||
|
$(document).mousemove(setUserActive).keypress(setUserActive);
|
||||||
|
|
||||||
// Avoid dropdown to close when clicking on submenu
|
// Avoid dropdown to close when clicking on submenu
|
||||||
$('.dropdown-submenu > a').click(function(e) {
|
$('.dropdown-submenu > a').click(function(e) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
@ -421,8 +465,37 @@ define(["jquery", "bootstrap", "jgrowl", "layout", "Markdown.Editor"], function(
|
|||||||
|
|
||||||
$(".action-apply-settings").click(function() {
|
$(".action-apply-settings").click(function() {
|
||||||
core.saveSettings();
|
core.saveSettings();
|
||||||
location.reload();
|
window.location.reload();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Init asyncTaskRunner
|
||||||
|
asyncTaskRunner.init(core);
|
||||||
|
|
||||||
|
// Init helpers
|
||||||
|
googleHelper.init(core, fileManager);
|
||||||
|
dropboxHelper.init(core, fileManager);
|
||||||
|
|
||||||
|
// Init publisher
|
||||||
|
publisher.init(core, fileManager);
|
||||||
|
|
||||||
|
// Init synchronizer
|
||||||
|
synchronizer.init(core, fileManager);
|
||||||
|
offlineListeners.push(synchronizer.updateSyncButton);
|
||||||
|
|
||||||
|
// Init file manager
|
||||||
|
fileManager.init(core);
|
||||||
|
|
||||||
|
// Do periodic tasks
|
||||||
|
window.setInterval(function() {
|
||||||
|
updateCurrentTime();
|
||||||
|
core.checkWindowUnique();
|
||||||
|
if(isUserActive() === false) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
synchronizer.sync();
|
||||||
|
asyncTaskRunner.runTask();
|
||||||
|
checkOnline();
|
||||||
|
}, 1000);
|
||||||
};
|
};
|
||||||
|
|
||||||
return core;
|
return core;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
define(["jquery", "core", "async-runner"], function($, core, asyncTaskRunner) {
|
define(["jquery", "async-runner"], function($, asyncTaskRunner) {
|
||||||
|
|
||||||
// Dependencies
|
// Dependencies
|
||||||
|
var core = undefined;
|
||||||
var fileManager = undefined;
|
var fileManager = undefined;
|
||||||
|
|
||||||
var client = undefined;
|
var client = undefined;
|
||||||
@ -372,7 +373,8 @@ define(["jquery", "core", "async-runner"], function($, core, asyncTaskRunner) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
dropboxHelper.init = function(fileManagerModule) {
|
dropboxHelper.init = function(coreModule, fileManagerModule) {
|
||||||
|
core = coreModule;
|
||||||
fileManager = fileManagerModule;
|
fileManager = fileManagerModule;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,114 +1,10 @@
|
|||||||
define(["jquery", "core", "google-helper", "dropbox-helper", "synchronizer", "publisher", "async-runner"],
|
define(["jquery", "google-helper", "dropbox-helper", "synchronizer", "publisher"],
|
||||||
function($, core, googleHelper, dropboxHelper, synchronizer, publisher, asyncTaskRunner) {
|
function($, googleHelper, dropboxHelper, synchronizer, publisher) {
|
||||||
|
|
||||||
var fileManager = {};
|
var fileManager = {};
|
||||||
|
|
||||||
fileManager.init = function() {
|
// Dependencies
|
||||||
googleHelper.init(fileManager);
|
var core = undefined;
|
||||||
dropboxHelper.init(fileManager);
|
|
||||||
publisher.init(fileManager);
|
|
||||||
|
|
||||||
var changeSyncButtonState = function() {
|
|
||||||
if(synchronizer.isRunning() || synchronizer.isQueueEmpty() || core.isOffline) {
|
|
||||||
$(".action-force-sync").addClass("disabled");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$(".action-force-sync").removeClass("disabled");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
core.addOfflineListener(changeSyncButtonState);
|
|
||||||
synchronizer.init(fileManager, {
|
|
||||||
onSyncBegin : changeSyncButtonState,
|
|
||||||
onSyncEnd : changeSyncButtonState,
|
|
||||||
onQueueChanged : changeSyncButtonState
|
|
||||||
});
|
|
||||||
$(".action-force-sync").click(function() {
|
|
||||||
if(!$(this).hasClass("disabled")) {
|
|
||||||
synchronizer.forceSync();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
fileManager.selectFile();
|
|
||||||
|
|
||||||
// Do periodic tasks
|
|
||||||
window.setInterval(function() {
|
|
||||||
core.updateCurrentTime();
|
|
||||||
synchronizer.sync();
|
|
||||||
asyncTaskRunner.runTask();
|
|
||||||
core.checkOnline();
|
|
||||||
}, 1000);
|
|
||||||
|
|
||||||
$(".action-create-file").click(function() {
|
|
||||||
var fileIndex = fileManager.createFile();
|
|
||||||
fileManager.selectFile(fileIndex);
|
|
||||||
$("#file-title").click();
|
|
||||||
});
|
|
||||||
$(".action-remove-file").click(function() {
|
|
||||||
fileManager.deleteFile();
|
|
||||||
fileManager.selectFile();
|
|
||||||
});
|
|
||||||
$("#file-title").click(function() {
|
|
||||||
$(this).hide();
|
|
||||||
$("#file-title-input").show().focus();
|
|
||||||
});
|
|
||||||
$("#file-title-input").blur(function() {
|
|
||||||
var title = $.trim($(this).val());
|
|
||||||
if (title) {
|
|
||||||
var fileIndexTitle = localStorage["file.current"] + ".title";
|
|
||||||
if (title != localStorage[fileIndexTitle]) {
|
|
||||||
localStorage[fileIndexTitle] = title;
|
|
||||||
fileManager.updateFileTitles();
|
|
||||||
fileManager.saveFile();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$(this).hide();
|
|
||||||
$("#file-title").show();
|
|
||||||
});
|
|
||||||
$(".action-download-md").click(
|
|
||||||
function() {
|
|
||||||
var content = $("#wmd-input").val();
|
|
||||||
var uriContent = "data:application/octet-stream;base64,"
|
|
||||||
+ core.encodeBase64(content);
|
|
||||||
window.open(uriContent, 'file');
|
|
||||||
});
|
|
||||||
$(".action-download-html").click(
|
|
||||||
function() {
|
|
||||||
var content = $("#wmd-preview").html();
|
|
||||||
var uriContent = "data:application/octet-stream;base64,"
|
|
||||||
+ core.encodeBase64(content);
|
|
||||||
window.open(uriContent, 'file');
|
|
||||||
});
|
|
||||||
$(".action-upload-gdrive-root").click(function() {
|
|
||||||
uploadGdrive();
|
|
||||||
});
|
|
||||||
$(".action-upload-gdrive-select").click(function() {
|
|
||||||
// This action is not available because picker does not support
|
|
||||||
// folder selection yet
|
|
||||||
googleHelper.picker(function(ids) {
|
|
||||||
if(ids !== undefined && ids.length !== 0) {
|
|
||||||
uploadGdrive(undefined, ids[0]);
|
|
||||||
}
|
|
||||||
}, true);
|
|
||||||
});
|
|
||||||
$(".action-download-gdrive").click(function() {
|
|
||||||
googleHelper.picker(importGdrive);
|
|
||||||
});
|
|
||||||
$(".action-manual-gdrive").click(function(event) {
|
|
||||||
var fileId = core.getInputValue($("#manual-gdrive-fileid"), event);
|
|
||||||
manualGdrive(fileId);
|
|
||||||
});
|
|
||||||
$(".action-download-dropbox").click(function() {
|
|
||||||
dropboxHelper.picker(importDropbox);
|
|
||||||
});
|
|
||||||
$(".action-upload-dropbox").click(function(event) {
|
|
||||||
var path = core.getInputValue($("#upload-dropbox-path"), event);
|
|
||||||
manualDropbox(path);
|
|
||||||
});
|
|
||||||
$(".action-manual-dropbox").click(function(event) {
|
|
||||||
var path = core.getInputValue($("#manual-dropbox-path"), event);
|
|
||||||
manualDropbox(path);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// Caution: this function recreate the editor (reset undo operations)
|
// Caution: this function recreate the editor (reset undo operations)
|
||||||
var fileDescList = [];
|
var fileDescList = [];
|
||||||
@ -118,8 +14,9 @@ define(["jquery", "core", "google-helper", "dropbox-helper", "synchronizer", "pu
|
|||||||
fileIndex = this.createFile();
|
fileIndex = this.createFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
fileIndex = fileIndex || localStorage["file.current"];
|
|
||||||
if(fileIndex !== undefined) {
|
if(fileIndex !== undefined) {
|
||||||
|
// Since we are going to modify current file
|
||||||
|
core.checkWindowUnique();
|
||||||
localStorage["file.current"] = fileIndex;
|
localStorage["file.current"] = fileIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,7 +25,7 @@ define(["jquery", "core", "google-helper", "dropbox-helper", "synchronizer", "pu
|
|||||||
refreshManageSync();
|
refreshManageSync();
|
||||||
|
|
||||||
// Recreate the editor
|
// Recreate the editor
|
||||||
var fileIndex = localStorage["file.current"];
|
fileIndex = localStorage["file.current"];
|
||||||
$("#wmd-input").val(localStorage[fileIndex + ".content"]);
|
$("#wmd-input").val(localStorage[fileIndex + ".content"]);
|
||||||
core.createEditor(function() {
|
core.createEditor(function() {
|
||||||
fileManager.saveFile();
|
fileManager.saveFile();
|
||||||
@ -174,6 +71,8 @@ define(["jquery", "core", "google-helper", "dropbox-helper", "synchronizer", "pu
|
|||||||
var fileIndexCurrent = localStorage["file.current"];
|
var fileIndexCurrent = localStorage["file.current"];
|
||||||
fileIndex = fileIndex || fileIndexCurrent;
|
fileIndex = fileIndex || fileIndexCurrent;
|
||||||
if(fileIndex == fileIndexCurrent) {
|
if(fileIndex == fileIndexCurrent) {
|
||||||
|
// Since we are going to modify current file
|
||||||
|
core.checkWindowUnique();
|
||||||
localStorage.removeItem("file.current");
|
localStorage.removeItem("file.current");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,7 +94,7 @@ define(["jquery", "core", "google-helper", "dropbox-helper", "synchronizer", "pu
|
|||||||
var content = $("#wmd-input").val();
|
var content = $("#wmd-input").val();
|
||||||
var fileIndex = localStorage["file.current"];
|
var fileIndex = localStorage["file.current"];
|
||||||
localStorage[fileIndex + ".content"] = content;
|
localStorage[fileIndex + ".content"] = content;
|
||||||
synchronizer.addFileForUpload(fileIndex);
|
synchronizer.notifyChange(fileIndex);
|
||||||
};
|
};
|
||||||
|
|
||||||
fileManager.updateFileTitles = function() {
|
fileManager.updateFileTitles = function() {
|
||||||
@ -218,6 +117,8 @@ define(["jquery", "core", "google-helper", "dropbox-helper", "synchronizer", "pu
|
|||||||
var fileIndex = localStorage["file.current"];
|
var fileIndex = localStorage["file.current"];
|
||||||
// If no default file take first one
|
// If no default file take first one
|
||||||
if (!fileIndex) {
|
if (!fileIndex) {
|
||||||
|
// Since we are going to modify current file
|
||||||
|
core.checkWindowUnique();
|
||||||
fileIndex = fileDescList[0].index;
|
fileIndex = fileDescList[0].index;
|
||||||
localStorage["file.current"] = fileIndex;
|
localStorage["file.current"] = fileIndex;
|
||||||
}
|
}
|
||||||
@ -256,6 +157,8 @@ define(["jquery", "core", "google-helper", "dropbox-helper", "synchronizer", "pu
|
|||||||
} 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
|
||||||
|
core.checkWindowUnique();
|
||||||
localStorage["file.current"] = fileIndex;
|
localStorage["file.current"] = fileIndex;
|
||||||
fileManager.selectFile();
|
fileManager.selectFile();
|
||||||
};
|
};
|
||||||
@ -445,5 +348,82 @@ define(["jquery", "core", "google-helper", "dropbox-helper", "synchronizer", "pu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fileManager.init = function(coreModule) {
|
||||||
|
core = coreModule;
|
||||||
|
|
||||||
|
fileManager.selectFile();
|
||||||
|
|
||||||
|
$(".action-create-file").click(function() {
|
||||||
|
var fileIndex = fileManager.createFile();
|
||||||
|
fileManager.selectFile(fileIndex);
|
||||||
|
$("#file-title").click();
|
||||||
|
});
|
||||||
|
$(".action-remove-file").click(function() {
|
||||||
|
fileManager.deleteFile();
|
||||||
|
fileManager.selectFile();
|
||||||
|
});
|
||||||
|
$("#file-title").click(function() {
|
||||||
|
$(this).hide();
|
||||||
|
$("#file-title-input").show().focus();
|
||||||
|
});
|
||||||
|
$("#file-title-input").blur(function() {
|
||||||
|
var title = $.trim($(this).val());
|
||||||
|
if (title) {
|
||||||
|
var fileIndexTitle = localStorage["file.current"] + ".title";
|
||||||
|
if (title != localStorage[fileIndexTitle]) {
|
||||||
|
localStorage[fileIndexTitle] = title;
|
||||||
|
fileManager.updateFileTitles();
|
||||||
|
fileManager.saveFile();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$(this).hide();
|
||||||
|
$("#file-title").show();
|
||||||
|
});
|
||||||
|
$(".action-download-md").click(
|
||||||
|
function() {
|
||||||
|
var content = $("#wmd-input").val();
|
||||||
|
var uriContent = "data:application/octet-stream;base64,"
|
||||||
|
+ core.encodeBase64(content);
|
||||||
|
window.open(uriContent, 'file');
|
||||||
|
});
|
||||||
|
$(".action-download-html").click(
|
||||||
|
function() {
|
||||||
|
var content = $("#wmd-preview").html();
|
||||||
|
var uriContent = "data:application/octet-stream;base64,"
|
||||||
|
+ core.encodeBase64(content);
|
||||||
|
window.open(uriContent, 'file');
|
||||||
|
});
|
||||||
|
$(".action-upload-gdrive-root").click(function() {
|
||||||
|
uploadGdrive();
|
||||||
|
});
|
||||||
|
$(".action-upload-gdrive-select").click(function() {
|
||||||
|
// This action is not available because picker does not support
|
||||||
|
// folder selection
|
||||||
|
googleHelper.picker(function(ids) {
|
||||||
|
if(ids !== undefined && ids.length !== 0) {
|
||||||
|
uploadGdrive(undefined, ids[0]);
|
||||||
|
}
|
||||||
|
}, true);
|
||||||
|
});
|
||||||
|
$(".action-download-gdrive").click(function() {
|
||||||
|
googleHelper.picker(importGdrive);
|
||||||
|
});
|
||||||
|
$(".action-manual-gdrive").click(function(event) {
|
||||||
|
var fileId = core.getInputValue($("#manual-gdrive-fileid"), event);
|
||||||
|
manualGdrive(fileId);
|
||||||
|
});
|
||||||
|
$(".action-download-dropbox").click(function() {
|
||||||
|
dropboxHelper.picker(importDropbox);
|
||||||
|
});
|
||||||
|
$(".action-upload-dropbox").click(function(event) {
|
||||||
|
var path = core.getInputValue($("#upload-dropbox-path"), event);
|
||||||
|
manualDropbox(path);
|
||||||
|
});
|
||||||
|
$(".action-manual-dropbox").click(function(event) {
|
||||||
|
var path = core.getInputValue($("#manual-dropbox-path"), event);
|
||||||
|
manualDropbox(path);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
return fileManager;
|
return fileManager;
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
define(["jquery", "core", "async-runner"], function($, core, asyncTaskRunner) {
|
define(["jquery", "async-runner"], function($, asyncTaskRunner) {
|
||||||
|
|
||||||
// Dependencies
|
// Dependencies
|
||||||
|
var core = undefined;
|
||||||
var fileManager = undefined;
|
var fileManager = undefined;
|
||||||
|
|
||||||
var connected = false;
|
var connected = false;
|
||||||
@ -464,7 +465,8 @@ define(["jquery", "core", "async-runner"], function($, core, asyncTaskRunner) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
googleHelper.init = function(fileManagerModule) {
|
googleHelper.init = function(coreModule, fileManagerModule) {
|
||||||
|
core = coreModule;
|
||||||
fileManager = fileManagerModule;
|
fileManager = fileManagerModule;
|
||||||
var state = localStorage["sync.gdrive.state"];
|
var state = localStorage["sync.gdrive.state"];
|
||||||
if(state === undefined) {
|
if(state === undefined) {
|
||||||
|
@ -18,10 +18,10 @@ requirejs.config({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
require(["jquery", "core", "file-manager", "config", "custo"], function($, core, fileManager) {
|
require(["jquery", "core"], function($, core) {
|
||||||
$(function() {
|
$(function() {
|
||||||
|
|
||||||
// If browser detected a new application cache.
|
// If browser has detected a new application cache.
|
||||||
if (window.applicationCache
|
if (window.applicationCache
|
||||||
&& window.applicationCache.status === window.applicationCache.UPDATEREADY) {
|
&& window.applicationCache.status === window.applicationCache.UPDATEREADY) {
|
||||||
window.applicationCache.swapCache();
|
window.applicationCache.swapCache();
|
||||||
@ -30,6 +30,5 @@ require(["jquery", "core", "file-manager", "config", "custo"], function($, core,
|
|||||||
}
|
}
|
||||||
|
|
||||||
core.init();
|
core.init();
|
||||||
fileManager.init();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,37 +1,44 @@
|
|||||||
define(["jquery", "core", "async-runner"], function($, core, asyncTaskRunner) {
|
define(["jquery"], function($) {
|
||||||
|
|
||||||
// Dependencies
|
// Dependencies
|
||||||
|
var core = undefined;
|
||||||
var fileManager = undefined;
|
var fileManager = undefined;
|
||||||
|
|
||||||
var publisher = {};
|
var publisher = {};
|
||||||
|
|
||||||
var wizardProvider = undefined;
|
var wizardProvider = undefined;
|
||||||
|
|
||||||
function initWizard(provider) {
|
function initWizard(provider, defaultPublishFormat) {
|
||||||
|
defaultPublishFormat = defaultPublishFormat || "markdown";
|
||||||
wizardProvider = provider;
|
wizardProvider = provider;
|
||||||
$("input:radio[name=radio-publish-existing][value=new]").prop("checked", true);
|
|
||||||
$("input:radio[name=radio-publish-format][value=markdown]").prop("checked", true);
|
// Show/hide controls depending on provider
|
||||||
|
$('div[class*=" control-publish-"]').hide().filter(".control-publish-" + provider).show();
|
||||||
|
|
||||||
|
// Reset fields
|
||||||
|
$("#modal-publish input[type=text]").val("");
|
||||||
|
$("input:radio[name=radio-publish-format][value=" + defaultPublishFormat + "]").prop("checked", true);
|
||||||
|
|
||||||
|
// Open dialog box
|
||||||
|
$("#modal-publish").modal();
|
||||||
}
|
}
|
||||||
|
|
||||||
publisher.init = function(fileManagerModule) {
|
publisher.init = function(coreModule, fileManagerModule) {
|
||||||
|
core = coreModule;
|
||||||
fileManager = fileManagerModule;
|
fileManager = fileManagerModule;
|
||||||
$("#action-publish-github").click(function() {
|
$(".action-publish-github").click(function() {
|
||||||
initWizard("github");
|
initWizard("github");
|
||||||
});
|
});
|
||||||
$("#action-publish-blogger").click(function() {
|
$(".action-publish-blogger").click(function() {
|
||||||
initWizard("blogger");
|
initWizard("blogger", "html");
|
||||||
});
|
});
|
||||||
$("#action-publish-wordpress").click(function() {
|
$(".action-publish-wordpress").click(function() {
|
||||||
initWizard("wordpress");
|
initWizard("wordpress");
|
||||||
});
|
});
|
||||||
$("#action-publish-tumblr").click(function() {
|
$(".action-publish-tumblr").click(function() {
|
||||||
initWizard("tumblr");
|
initWizard("tumblr");
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
publisher.initWizard = function() {
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
return publisher;
|
return publisher;
|
||||||
});
|
});
|
@ -1,132 +1,141 @@
|
|||||||
define(["jquery", "core", "google-helper", "dropbox-helper"], function($, core, googleHelper, dropboxHelper) {
|
define(["jquery", "google-helper", "dropbox-helper"], function($, googleHelper, dropboxHelper) {
|
||||||
var synchronizer = {};
|
var synchronizer = {};
|
||||||
|
|
||||||
// Dependencies
|
// Dependencies
|
||||||
|
var core = undefined;
|
||||||
var fileManager = undefined;
|
var fileManager = undefined;
|
||||||
|
|
||||||
// Used to know the providers we are connected to
|
// Used to know the providers we are connected to
|
||||||
synchronizer.useGoogleDrive = false;
|
synchronizer.useGoogleDrive = false;
|
||||||
synchronizer.useDropbox = false;
|
synchronizer.useDropbox = false;
|
||||||
|
|
||||||
var onSyncBegin = undefined;
|
// Used to know if user can force synchronization
|
||||||
var onSyncEnd = undefined;
|
var uploadPending = false;
|
||||||
var onQueueChanged = undefined;
|
|
||||||
|
|
||||||
// A synchronization queue containing fileIndex that has to be synchronized
|
|
||||||
var syncUpQueue = undefined;
|
|
||||||
|
|
||||||
synchronizer.init = function(fileManagerModule, options) {
|
|
||||||
fileManager = fileManagerModule;
|
|
||||||
onSyncBegin = options.onSyncBegin || core.doNothing;
|
|
||||||
onSyncEnd = options.onSyncEnd || core.doNothing;
|
|
||||||
onQueueChanged = options.onQueueChanged || core.doNothing;
|
|
||||||
|
|
||||||
syncUpQueue = ";";
|
|
||||||
// Load the queue from localStorage in case a previous synchronization
|
|
||||||
// was aborted
|
|
||||||
if (localStorage["sync.queue"]) {
|
|
||||||
syncUpQueue = localStorage["sync.queue"];
|
|
||||||
onQueueChanged();
|
|
||||||
}
|
|
||||||
if (localStorage["sync.current"]) {
|
|
||||||
this.addFileForUpload(localStorage["sync.current"]);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Add a file to the synchronization queue
|
// Add a file to the synchronization queue
|
||||||
synchronizer.addFileForUpload = function(fileIndex) {
|
synchronizer.notifyChange = function(fileIndex) {
|
||||||
// Check that file has synchronized locations
|
// Check that file has synchronized locations
|
||||||
if(localStorage[fileIndex + ".sync"].length === 1) {
|
if(localStorage[fileIndex + ".sync"].length === 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Check that file is not in the queue
|
uploadPending = true;
|
||||||
if (syncUpQueue.indexOf(";" + fileIndex + ";") !== -1) {
|
synchronizer.updateSyncButton();
|
||||||
return;
|
|
||||||
}
|
|
||||||
syncUpQueue += fileIndex + ";";
|
|
||||||
localStorage["sync.queue"] = syncUpQueue;
|
|
||||||
onQueueChanged();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Recursive function to upload a single file on multiple locations
|
// Recursive function to upload a single file on multiple locations
|
||||||
function fileUp(fileSyncIndexList, content, contentCRC, title, titleCRC, callback) {
|
var uploadFileSyncIndexList = [];
|
||||||
if (fileSyncIndexList.length === 0) {
|
var uploadContent = undefined;
|
||||||
localStorage.removeItem("sync.current");
|
var uploadContentCRC = undefined;
|
||||||
// run the next file synchronization
|
var uploadTitle = undefined;
|
||||||
syncUp(callback);
|
var uploadTitleCRC = undefined;
|
||||||
|
function locationUp(callback) {
|
||||||
|
|
||||||
|
// No more synchronized location for this document
|
||||||
|
if (uploadFileSyncIndexList.length === 0) {
|
||||||
|
fileUp(callback);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dequeue a synchronized location
|
||||||
|
var fileSyncIndex = uploadFileSyncIndexList.pop();
|
||||||
|
if(!fileSyncIndex) {
|
||||||
|
locationUp(callback);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var fileSyncIndex = fileSyncIndexList.pop();
|
|
||||||
|
|
||||||
// Skip if CRC has not changed
|
// Skip if CRC has not changed
|
||||||
var syncContentCRC = localStorage[fileSyncIndex + ".contentCRC"];
|
var syncContentCRC = localStorage[fileSyncIndex + ".contentCRC"];
|
||||||
var syncTitleCRC = localStorage[fileSyncIndex + ".titleCRC"];
|
var syncTitleCRC = localStorage[fileSyncIndex + ".titleCRC"];
|
||||||
if(contentCRC == syncContentCRC && (syncTitleCRC === undefined || titleCRC == syncTitleCRC)) {
|
if(uploadContentCRC == syncContentCRC && (syncTitleCRC === undefined || uploadTitleCRC == syncTitleCRC)) {
|
||||||
fileUp(fileSyncIndexList, content, contentCRC, title, titleCRC, callback);
|
locationUp(callback);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If upload is going to run, go for an other upload cycle at the end
|
||||||
|
uploadCycle = true;
|
||||||
|
// When page is refreshed, this flag is false but should be true here
|
||||||
|
uploadPending = true;
|
||||||
|
|
||||||
// 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);
|
||||||
googleHelper.upload(id, undefined, title, content, function(result) {
|
googleHelper.upload(id, undefined, uploadTitle, uploadContent, function(result) {
|
||||||
if (result !== undefined) {
|
if (result !== undefined) {
|
||||||
localStorage[fileSyncIndex + ".contentCRC"] = contentCRC;
|
localStorage[fileSyncIndex + ".contentCRC"] = uploadContentCRC;
|
||||||
localStorage[fileSyncIndex + ".titleCRC"] = titleCRC;
|
localStorage[fileSyncIndex + ".titleCRC"] = uploadTitleCRC;
|
||||||
fileUp(fileSyncIndexList, content, contentCRC, title, titleCRC, callback);
|
locationUp(callback);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// If error we put the fileIndex back in the queue
|
|
||||||
synchronizer.addFileForUpload(localStorage["sync.current"]);
|
// If error we abort the synchronization (retry later)
|
||||||
localStorage.removeItem("sync.current");
|
callback("abort");
|
||||||
callback();
|
|
||||||
return;
|
return;
|
||||||
});
|
});
|
||||||
} else if (fileSyncIndex.indexOf(SYNC_PROVIDER_DROPBOX) === 0) {
|
} else if (fileSyncIndex.indexOf(SYNC_PROVIDER_DROPBOX) === 0) {
|
||||||
var path = fileSyncIndex.substring(SYNC_PROVIDER_DROPBOX.length);
|
var path = fileSyncIndex.substring(SYNC_PROVIDER_DROPBOX.length);
|
||||||
path = decodeURIComponent(path);
|
path = decodeURIComponent(path);
|
||||||
dropboxHelper.upload(path, content, function(result) {
|
dropboxHelper.upload(path, uploadContent, function(result) {
|
||||||
if (result !== undefined) {
|
if (result !== undefined) {
|
||||||
localStorage[fileSyncIndex + ".contentCRC"] = contentCRC;
|
localStorage[fileSyncIndex + ".contentCRC"] = uploadContentCRC;
|
||||||
fileUp(fileSyncIndexList, content, contentCRC, title, titleCRC, callback);
|
locationUp(callback);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// If error we put the fileIndex back in the queue
|
|
||||||
synchronizer.addFileForUpload(localStorage["sync.current"]);
|
// If error we abort the synchronization (retry later)
|
||||||
localStorage.removeItem("sync.current");
|
callback("abort");
|
||||||
callback();
|
|
||||||
return;
|
return;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
fileUp(fileSyncIndexList, content, contentCRC, title, titleCRC, callback);
|
// This should never happen
|
||||||
|
console.error("Invalid fileSyncIndex: " + fileSyncIndex);
|
||||||
|
callback("error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function syncUp(callback) {
|
// Recursive function to upload multiple files
|
||||||
// If nothing to synchronize
|
var uploadFileIndexList = [];
|
||||||
if (syncUpQueue.length === 1) {
|
function fileUp(callback) {
|
||||||
callback();
|
|
||||||
|
// No more fileIndex to synchronize
|
||||||
|
if (uploadFileIndexList.length === 0) {
|
||||||
|
syncUp(callback);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dequeue the fileIndex
|
// Dequeue a fileIndex
|
||||||
var separatorPos = syncUpQueue.indexOf(";", 1);
|
var fileIndex = uploadFileIndexList.pop();
|
||||||
var fileIndex = syncUpQueue.substring(1, separatorPos);
|
var fileSyncIndexes = localStorage[fileIndex + ".sync"];
|
||||||
localStorage["sync.current"] = fileIndex;
|
if(!fileIndex || fileSyncIndexes.length === 1) {
|
||||||
syncUpQueue = syncUpQueue.substring(separatorPos);
|
fileUp(callback);
|
||||||
localStorage["sync.queue"] = syncUpQueue;
|
return;
|
||||||
onQueueChanged();
|
}
|
||||||
|
|
||||||
var content = localStorage[fileIndex + ".content"];
|
// Get document title/content
|
||||||
var title = localStorage[fileIndex + ".title"];
|
uploadContent = localStorage[fileIndex + ".content"];
|
||||||
var contentCRC = core.crc32(content);
|
uploadContentCRC = core.crc32(uploadContent);
|
||||||
var titleCRC = core.crc32(title);
|
uploadTitle = localStorage[fileIndex + ".title"];
|
||||||
|
uploadTitleCRC = core.crc32(uploadTitle);
|
||||||
|
|
||||||
// Parse the list of synchronized locations associated to the file
|
// Parse the list of synchronized locations associated to the document
|
||||||
var fileSyncIndexList = localStorage[fileIndex + ".sync"].split(";");
|
uploadFileSyncIndexList = fileSyncIndexes.split(";");
|
||||||
fileUp(fileSyncIndexList, content, contentCRC, title, titleCRC, callback);
|
locationUp(callback);
|
||||||
};
|
}
|
||||||
|
|
||||||
|
// Used to upload document changes from local storage
|
||||||
|
var uploadCycle = false;
|
||||||
|
function syncUp(callback) {
|
||||||
|
if(uploadCycle === true) {
|
||||||
|
// New upload cycle
|
||||||
|
uploadCycle = false;
|
||||||
|
uploadFileIndexList = localStorage["file.list"].split(";");
|
||||||
|
fileUp(callback);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Used to download file changes from Google Drive
|
||||||
function syncDownGdrive(callback) {
|
function syncDownGdrive(callback) {
|
||||||
if (synchronizer.useGoogleDrive === false) {
|
if (synchronizer.useGoogleDrive === false) {
|
||||||
callback();
|
callback();
|
||||||
@ -136,12 +145,12 @@ define(["jquery", "core", "google-helper", "dropbox-helper"], function($, core,
|
|||||||
+ "lastChangeId"]);
|
+ "lastChangeId"]);
|
||||||
googleHelper.checkUpdates(lastChangeId, function(changes, newChangeId) {
|
googleHelper.checkUpdates(lastChangeId, function(changes, newChangeId) {
|
||||||
if (changes === undefined) {
|
if (changes === undefined) {
|
||||||
callback();
|
callback("error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
googleHelper.downloadContent(changes, function(changes) {
|
googleHelper.downloadContent(changes, function(changes) {
|
||||||
if (changes === undefined) {
|
if (changes === undefined) {
|
||||||
callback();
|
callback("error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var updateFileTitles = false;
|
var updateFileTitles = false;
|
||||||
@ -155,32 +164,35 @@ define(["jquery", "core", "google-helper", "dropbox-helper"], function($, core,
|
|||||||
localStorage.removeItem(fileSyncIndex + ".etag");
|
localStorage.removeItem(fileSyncIndex + ".etag");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
var title = localStorage[fileIndex + ".title"];
|
var localTitle = localStorage[fileIndex + ".title"];
|
||||||
// File deleted
|
// File deleted
|
||||||
if (change.deleted === true) {
|
if (change.deleted === true) {
|
||||||
fileManager.removeSync(fileSyncIndex);
|
fileManager.removeSync(fileSyncIndex);
|
||||||
updateFileTitles = true;
|
updateFileTitles = true;
|
||||||
core.showMessage('"' + title + '" has been removed from Google Drive.');
|
core.showMessage('"' + localTitle + '" has been removed from Google Drive.');
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
var content = localStorage[fileIndex + ".content"];
|
var localTitleChanged = localStorage[fileSyncIndex + ".titleCRC"] == core.crc32(localTitle);
|
||||||
|
var localContent = localStorage[fileIndex + ".content"];
|
||||||
|
var localContentChanged = localStorage[fileSyncIndex + ".contentCRC"] == core.crc32(localContent);
|
||||||
var file = change.file;
|
var file = change.file;
|
||||||
var titleChanged = title != file.title;
|
var fileTitleChanged = localTitle != file.title;
|
||||||
var contentChanged = content != file.content;
|
var fileContentChanged = localContent != file.content;
|
||||||
// If file is in the upload queue we have a conflict
|
// Conflict detection
|
||||||
if ((titleChanged || contentChanged) && syncUpQueue.indexOf(";" + fileIndex + ";") !== -1) {
|
if ((fileTitleChanged === true && localTitleChanged === true)
|
||||||
fileManager.createFile(title + " (backup)", content);
|
|| (fileContentChanged === true && localContentChanged === true)) {
|
||||||
|
fileManager.createFile(localTitle + " (backup)", localContent);
|
||||||
updateFileTitles = true;
|
updateFileTitles = true;
|
||||||
core.showMessage('Conflict detected on "' + title + '". A backup has been created locally.');
|
core.showMessage('Conflict detected on "' + localTitle + '". A backup has been created locally.');
|
||||||
}
|
}
|
||||||
// If file title changed
|
// If file title changed
|
||||||
if(titleChanged) {
|
if(fileTitleChanged) {
|
||||||
localStorage[fileIndex + ".title"] = file.title;
|
localStorage[fileIndex + ".title"] = file.title;
|
||||||
updateFileTitles = true;
|
updateFileTitles = true;
|
||||||
core.showMessage('"' + title + '" has been renamed to "' + file.title + '" on Google Drive.');
|
core.showMessage('"' + localTitle + '" has been renamed to "' + file.title + '" on Google Drive.');
|
||||||
}
|
}
|
||||||
// If file content changed
|
// If file content changed
|
||||||
if(contentChanged) {
|
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(fileIndex == localStorage["file.current"]) {
|
||||||
@ -190,13 +202,11 @@ define(["jquery", "core", "google-helper", "dropbox-helper"], function($, core,
|
|||||||
}
|
}
|
||||||
// Update file etag and CRCs
|
// Update file etag and CRCs
|
||||||
localStorage[fileSyncIndex + ".etag"] = file.etag;
|
localStorage[fileSyncIndex + ".etag"] = file.etag;
|
||||||
var contentCRC = core.crc32(file.content);
|
localStorage[fileSyncIndex + ".contentCRC"] = core.crc32(file.content);
|
||||||
localStorage[fileSyncIndex + ".contentCRC"] = contentCRC;
|
localStorage[fileSyncIndex + ".titleCRC"] = core.crc32(file.title);
|
||||||
var titleCRC = core.crc32(file.title);
|
|
||||||
localStorage[fileSyncIndex + ".titleCRC"] = titleCRC;
|
|
||||||
|
|
||||||
// Synchronize file with others locations
|
// Synchronize file with others locations
|
||||||
synchronizer.addFileForUpload(fileIndex);
|
uploadPending = true;
|
||||||
}
|
}
|
||||||
if(updateFileTitles) {
|
if(updateFileTitles) {
|
||||||
fileManager.updateFileTitles();
|
fileManager.updateFileTitles();
|
||||||
@ -208,6 +218,7 @@ define(["jquery", "core", "google-helper", "dropbox-helper"], function($, core,
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Used to download file changes from Dropbox
|
||||||
function syncDownDropbox(callback) {
|
function syncDownDropbox(callback) {
|
||||||
if (synchronizer.useDropbox === false) {
|
if (synchronizer.useDropbox === false) {
|
||||||
callback();
|
callback();
|
||||||
@ -216,12 +227,12 @@ define(["jquery", "core", "google-helper", "dropbox-helper"], function($, core,
|
|||||||
var lastChangeId = localStorage[SYNC_PROVIDER_DROPBOX + "lastChangeId"];
|
var lastChangeId = localStorage[SYNC_PROVIDER_DROPBOX + "lastChangeId"];
|
||||||
dropboxHelper.checkUpdates(lastChangeId, function(changes, newChangeId) {
|
dropboxHelper.checkUpdates(lastChangeId, function(changes, newChangeId) {
|
||||||
if (changes === undefined) {
|
if (changes === undefined) {
|
||||||
callback();
|
callback("error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
dropboxHelper.downloadContent(changes, function(changes) {
|
dropboxHelper.downloadContent(changes, function(changes) {
|
||||||
if (changes === undefined) {
|
if (changes === undefined) {
|
||||||
callback();
|
callback("error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var updateFileTitles = false;
|
var updateFileTitles = false;
|
||||||
@ -235,27 +246,28 @@ define(["jquery", "core", "google-helper", "dropbox-helper"], function($, core,
|
|||||||
localStorage.removeItem(fileSyncIndex + ".version");
|
localStorage.removeItem(fileSyncIndex + ".version");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
var title = localStorage[fileIndex + ".title"];
|
var localTitle = localStorage[fileIndex + ".title"];
|
||||||
// File deleted
|
// File deleted
|
||||||
if (change.wasRemoved === true) {
|
if (change.wasRemoved === true) {
|
||||||
fileManager.removeSync(fileSyncIndex);
|
fileManager.removeSync(fileSyncIndex);
|
||||||
updateFileTitles = true;
|
updateFileTitles = true;
|
||||||
core.showMessage('"' + title + '" has been removed from Dropbox.');
|
core.showMessage('"' + localTitle + '" has been removed from Dropbox.');
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
var content = localStorage[fileIndex + ".content"];
|
var localContent = localStorage[fileIndex + ".content"];
|
||||||
|
var localContentChanged = localStorage[fileSyncIndex + ".contentCRC"] == core.crc32(localContent);
|
||||||
var file = change.stat;
|
var file = change.stat;
|
||||||
var contentChanged = content != file.content;
|
var fileContentChanged = localContent != file.content;
|
||||||
// If file is in the upload queue we have a conflict
|
// Conflict detection
|
||||||
if (contentChanged && syncUpQueue.indexOf(";" + fileIndex + ";") !== -1) {
|
if (fileContentChanged === true && localContentChanged === true) {
|
||||||
fileManager.createFile(title + " (backup)", content);
|
fileManager.createFile(localTitle + " (backup)", localContent);
|
||||||
updateFileTitles = true;
|
updateFileTitles = true;
|
||||||
core.showMessage('Conflict detected on "' + title + '". A backup has been created locally.');
|
core.showMessage('Conflict detected on "' + localTitle + '". A backup has been created locally.');
|
||||||
}
|
}
|
||||||
// If file content changed
|
// If file content changed
|
||||||
if(contentChanged) {
|
if(fileContentChanged) {
|
||||||
localStorage[fileIndex + ".content"] = file.content;
|
localStorage[fileIndex + ".content"] = file.content;
|
||||||
core.showMessage('"' + title + '" has been updated from Dropbox.');
|
core.showMessage('"' + localTitle + '" has been updated from Dropbox.');
|
||||||
if(fileIndex == localStorage["file.current"]) {
|
if(fileIndex == localStorage["file.current"]) {
|
||||||
updateFileTitles = false; // Done by next function
|
updateFileTitles = false; // Done by next function
|
||||||
fileManager.selectFile(); // Refresh editor
|
fileManager.selectFile(); // Refresh editor
|
||||||
@ -263,11 +275,10 @@ define(["jquery", "core", "google-helper", "dropbox-helper"], function($, core,
|
|||||||
}
|
}
|
||||||
// Update file version and CRC
|
// Update file version and CRC
|
||||||
localStorage[fileSyncIndex + ".version"] = file.versionTag;
|
localStorage[fileSyncIndex + ".version"] = file.versionTag;
|
||||||
var contentCRC = core.crc32(file.content);
|
localStorage[fileSyncIndex + ".contentCRC"] = core.crc32(file.content);
|
||||||
localStorage[fileSyncIndex + ".contentCRC"] = contentCRC;
|
|
||||||
|
|
||||||
// Synchronize file with others locations
|
// Synchronize file with others locations
|
||||||
synchronizer.addFileForUpload(fileIndex);
|
uploadPending = true;
|
||||||
}
|
}
|
||||||
if(updateFileTitles) {
|
if(updateFileTitles) {
|
||||||
fileManager.updateFileTitles();
|
fileManager.updateFileTitles();
|
||||||
@ -293,28 +304,57 @@ define(["jquery", "core", "google-helper", "dropbox-helper"], function($, core,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
syncRunning = true;
|
syncRunning = true;
|
||||||
|
uploadCycle = true;
|
||||||
lastSync = core.currentTime;
|
lastSync = core.currentTime;
|
||||||
onSyncBegin();
|
synchronizer.updateSyncButton();
|
||||||
|
|
||||||
syncDown(function() {
|
function isError(error) {
|
||||||
syncUp(function() {
|
if(error !== undefined) {
|
||||||
syncRunning = false;
|
syncRunning = false;
|
||||||
onSyncEnd();
|
synchronizer.updateSyncButton();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
syncDown(function(error) {
|
||||||
|
if(isError(error)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
syncUp(function(error) {
|
||||||
|
if(isError(error)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
syncRunning = false;
|
||||||
|
uploadPending = false;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
synchronizer.forceSync = function() {
|
synchronizer.forceSync = function() {
|
||||||
lastSync = 0;
|
lastSync = 0;
|
||||||
this.sync();
|
synchronizer.sync();
|
||||||
};
|
};
|
||||||
|
|
||||||
synchronizer.isRunning = function() {
|
synchronizer.updateSyncButton = function() {
|
||||||
return syncRunning;
|
if(syncRunning === true || uploadPending === false || core.isOffline) {
|
||||||
|
$(".action-force-sync").addClass("disabled");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$(".action-force-sync").removeClass("disabled");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
synchronizer.isQueueEmpty = function() {
|
synchronizer.init = function(coreModule, fileManagerModule) {
|
||||||
return syncUpQueue.length === 1;
|
core = coreModule;
|
||||||
|
fileManager = fileManagerModule;
|
||||||
|
|
||||||
|
synchronizer.updateSyncButton();
|
||||||
|
$(".action-force-sync").click(function() {
|
||||||
|
if(!$(this).hasClass("disabled")) {
|
||||||
|
synchronizer.forceSync();
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return synchronizer;
|
return synchronizer;
|
||||||
|
Loading…
Reference in New Issue
Block a user