Added sharing links
This commit is contained in:
parent
8c1430e5d6
commit
d98d872e98
@ -2,12 +2,3 @@ StackEdit - The Markdown editor powered by PageDown.
|
|||||||
|
|
||||||
Copyright 2013 Benoit Schweblin (http://www.benoitschweblin.com)
|
Copyright 2013 Benoit Schweblin (http://www.benoitschweblin.com)
|
||||||
Licensed under an Apache License (http://www.apache.org/licenses/LICENSE-2.0)
|
Licensed under an Apache License (http://www.apache.org/licenses/LICENSE-2.0)
|
||||||
|
|
||||||
Includes:
|
|
||||||
jQuery - http://jquery.com/
|
|
||||||
Bootstrap - http://twitter.github.com/bootstrap/
|
|
||||||
RequireJS - http://requirejs.org/
|
|
||||||
PageDown - https://code.google.com/p/pagedown/
|
|
||||||
UI Layout - http://layout.jquery-dev.net/
|
|
||||||
jGrowl - https://github.com/stanlemon/jGrowl/
|
|
||||||
GLYPHICONS - http://glyphicons.com/
|
|
31
css/main.css
31
css/main.css
@ -80,6 +80,15 @@ textarea,
|
|||||||
background-color: #eee;
|
background-color: #eee;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.nav .dropdown-toggle .caret {
|
||||||
|
border-top-color: #000;
|
||||||
|
border-bottom-color: #000;
|
||||||
|
}
|
||||||
|
|
||||||
|
.navbar .nav.hide {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
.navbar-inner .btn.disabled,
|
.navbar-inner .btn.disabled,
|
||||||
.navbar-inner .btn[disabled] {
|
.navbar-inner .btn[disabled] {
|
||||||
color: #333333;
|
color: #333333;
|
||||||
@ -102,10 +111,15 @@ textarea,
|
|||||||
background-color: #777;
|
background-color: #777;
|
||||||
}
|
}
|
||||||
|
|
||||||
input[disabled], select[disabled], textarea[disabled], input[readonly], select[readonly], textarea[readonly], .input-append .add-on {
|
input[disabled], select[disabled], textarea[disabled], .input-prepend .add-on {
|
||||||
background-color: #f5f5f5;
|
background-color: #f5f5f5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input[readonly], select[readonly], textarea[readonly] {
|
||||||
|
background-color: transparent;
|
||||||
|
cursor: text;
|
||||||
|
}
|
||||||
|
|
||||||
.btn-primary:hover,
|
.btn-primary:hover,
|
||||||
.btn-primary:focus,
|
.btn-primary:focus,
|
||||||
.btn-primary:active,
|
.btn-primary:active,
|
||||||
@ -232,7 +246,6 @@ hr {
|
|||||||
|
|
||||||
div.dropdown-menu {
|
div.dropdown-menu {
|
||||||
padding: 5px 20px;
|
padding: 5px 20px;
|
||||||
width: 300px;
|
|
||||||
white-space: normal;
|
white-space: normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -241,6 +254,20 @@ div.dropdown-menu blockquote {
|
|||||||
margin: 10px 0;
|
margin: 10px 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
div.dropdown-menu i {
|
||||||
|
margin-right: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.internal-link {
|
||||||
|
text-decoration: underline;
|
||||||
|
font-weight: 600;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
#link-container .link-list {
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
.icon-link {
|
.icon-link {
|
||||||
background-position: -72px -168px;
|
background-position: -72px -168px;
|
||||||
}
|
}
|
||||||
|
19
index.html
19
index.html
@ -1,12 +1,10 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html manifest="cache.manifest">
|
<html manifest="cache.manifest">
|
||||||
<head>
|
<head>
|
||||||
<title>StackEdit</title>
|
<title>StackEdit - Markdown editor</title>
|
||||||
<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="description"
|
<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="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">
|
||||||
@ -32,7 +30,7 @@
|
|||||||
<ul class="nav">
|
<ul class="nav">
|
||||||
<li><div id="wmd-button-bar"></div></li>
|
<li><div id="wmd-button-bar"></div></li>
|
||||||
</ul>
|
</ul>
|
||||||
<ul class="pull-right hide" id="menu-bar">
|
<ul class="nav pull-right hide" id="menu-bar">
|
||||||
<li class="btn-group">
|
<li class="btn-group">
|
||||||
<button class="btn action-force-sync" title="Synchronize">
|
<button class="btn action-force-sync" title="Synchronize">
|
||||||
<i class="icon-refresh"></i>
|
<i class="icon-refresh"></i>
|
||||||
@ -46,11 +44,10 @@
|
|||||||
</button>
|
</button>
|
||||||
<div id="link-container" class="dropdown-menu">
|
<div id="link-container" class="dropdown-menu">
|
||||||
<div class="link-list"></div>
|
<div class="link-list"></div>
|
||||||
<p class="no-link">
|
<p class="no-link">To share this document you need first to <span
|
||||||
To share this document you need first to synchronize it or to publish it in Markdown format on
|
class="internal-link action-publish-gist">publish it as a
|
||||||
<a href="#" class="action-publish-gist">Gist</a>.
|
Gist</span> in Markdown format.
|
||||||
</p>
|
</p>
|
||||||
<blockquote class="muted">Please make sure the document is public.</blockquote>
|
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
<li class="btn-group"><button class="btn action-create-file"
|
<li class="btn-group"><button class="btn action-create-file"
|
||||||
@ -67,9 +64,9 @@
|
|||||||
</button>
|
</button>
|
||||||
<ul id="file-selector" class="dropdown-menu">
|
<ul id="file-selector" class="dropdown-menu">
|
||||||
</ul></li>
|
</ul></li>
|
||||||
<li class="btn-group"><a class="btn dropdown-toggle"
|
<li class="btn-group"><button class="btn dropdown-toggle"
|
||||||
data-toggle="dropdown" href="#" title="Menu"><i
|
data-toggle="dropdown" title="Menu"><i
|
||||||
class="icon-stackedit"></i> <b class="caret"></b></a>
|
class="icon-stackedit"></i> <b class="caret"></b></button>
|
||||||
<ul class="dropdown-menu">
|
<ul class="dropdown-menu">
|
||||||
<li><a href="viewer.html"><i class="icon-fullscreen"></i>
|
<li><a href="viewer.html"><i class="icon-fullscreen"></i>
|
||||||
Open in viewer</a></li>
|
Open in viewer</a></li>
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
define(["jquery", "core", "google-helper"], function($, core, googleHelper) {
|
define(["jquery", "core", "google-helper"], function($, core, googleHelper) {
|
||||||
|
|
||||||
|
var PROVIDER_BLOGGER = "blogger";
|
||||||
|
|
||||||
var bloggerProvider = {
|
var bloggerProvider = {
|
||||||
providerId: PROVIDER_BLOGGER,
|
providerId: PROVIDER_BLOGGER,
|
||||||
providerName: "Blogger",
|
providerName: "Blogger",
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
var MAIN_URL = "http://benweet.github.io/stackedit/";
|
var MAIN_URL = "http://benweet.github.io/stackedit/";
|
||||||
|
var GOOGLE_API_KEY = "AIzaSyAeCU8CGcSkn0z9js6iocHuPBX4f_mMWkw";
|
||||||
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" ];
|
"https://www.googleapis.com/auth/blogger" ];
|
||||||
@ -14,12 +15,6 @@ var ASYNC_TASK_DEFAULT_TIMEOUT = 30000;
|
|||||||
var ASYNC_TASK_LONG_TIMEOUT = 90000;
|
var ASYNC_TASK_LONG_TIMEOUT = 90000;
|
||||||
var SYNC_PERIOD = 180000;
|
var SYNC_PERIOD = 180000;
|
||||||
var USER_IDLE_THRESHOLD = 300000;
|
var USER_IDLE_THRESHOLD = 300000;
|
||||||
var PROVIDER_BLOGGER = "blogger";
|
|
||||||
var PROVIDER_DROPBOX = "dropbox";
|
|
||||||
var PROVIDER_GDRIVE = "gdrive";
|
|
||||||
var PROVIDER_GIST = "gist";
|
|
||||||
var PROVIDER_GITHUB = "github";
|
|
||||||
var PROVIDER_TUMBLR = "tumblr";
|
|
||||||
var WELCOME_DOCUMENT_TITLE = "Welcome document";
|
var WELCOME_DOCUMENT_TITLE = "Welcome document";
|
||||||
|
|
||||||
// Use by Google's client.js
|
// Use by Google's client.js
|
||||||
@ -32,7 +27,6 @@ function runDelayedFunction() {
|
|||||||
|
|
||||||
// Site dependent
|
// Site dependent
|
||||||
var BASE_URL = "http://localhost/";
|
var BASE_URL = "http://localhost/";
|
||||||
var GOOGLE_KEY = "AIzaSyAeCU8CGcSkn0z9js6iocHuPBX4f_mMWkw";
|
|
||||||
var GOOGLE_CLIENT_ID = '241271498917-lev37kef013q85avc91am1gccg5g8lrb.apps.googleusercontent.com';
|
var GOOGLE_CLIENT_ID = '241271498917-lev37kef013q85avc91am1gccg5g8lrb.apps.googleusercontent.com';
|
||||||
var GITHUB_CLIENT_ID = 'e47fef6055344579799d';
|
var GITHUB_CLIENT_ID = 'e47fef6055344579799d';
|
||||||
var GATEKEEPER_URL = "http://stackedit-gatekeeper-localhost.herokuapp.com/";
|
var GATEKEEPER_URL = "http://stackedit-gatekeeper-localhost.herokuapp.com/";
|
||||||
@ -40,7 +34,6 @@ var TUMBLR_PROXY_URL = "http://stackedit-tumblr-proxy-local.herokuapp.com/";
|
|||||||
|
|
||||||
if(location.hostname.indexOf("benweet.github.io") === 0) {
|
if(location.hostname.indexOf("benweet.github.io") === 0) {
|
||||||
BASE_URL = MAIN_URL;
|
BASE_URL = MAIN_URL;
|
||||||
GOOGLE_KEY = "AIzaSyB1Bc1wI_YUWkkOR-5Gri5BFuypgZl0Sxc";
|
|
||||||
GOOGLE_CLIENT_ID = '241271498917-jpto9lls9fqnem1e4h6ppds9uob8rpvu.apps.googleusercontent.com';
|
GOOGLE_CLIENT_ID = '241271498917-jpto9lls9fqnem1e4h6ppds9uob8rpvu.apps.googleusercontent.com';
|
||||||
GITHUB_CLIENT_ID = 'fa0d09514da8377ee32e';
|
GITHUB_CLIENT_ID = 'fa0d09514da8377ee32e';
|
||||||
GATEKEEPER_URL = "http://stackedit-gatekeeper.herokuapp.com/";
|
GATEKEEPER_URL = "http://stackedit-gatekeeper.herokuapp.com/";
|
||||||
|
12
js/core.js
12
js/core.js
@ -672,6 +672,16 @@ define(
|
|||||||
return _.random(4294967296).toString(36);
|
return _.random(4294967296).toString(36);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Access a URL parameter
|
||||||
|
core.getURLParameter = function(name) {
|
||||||
|
var regex = new RegExp(name + "=(.+?)(&|$)");
|
||||||
|
try {
|
||||||
|
return decodeURIComponent(regex.exec(location.search)[1]);
|
||||||
|
} catch (e) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Create an centered popup window
|
// Create an centered popup window
|
||||||
core.popupWindow = function(url, title, w, h) {
|
core.popupWindow = function(url, title, w, h) {
|
||||||
var left = (screen.width / 2) - (w / 2);
|
var left = (screen.width / 2) - (w / 2);
|
||||||
@ -859,7 +869,7 @@ define(
|
|||||||
intervalId = window.setInterval(function() {
|
intervalId = window.setInterval(function() {
|
||||||
updateCurrentTime();
|
updateCurrentTime();
|
||||||
core.checkWindowUnique();
|
core.checkWindowUnique();
|
||||||
if(viewerMode === false && isUserActive() === true) {
|
if(isUserActive() === true || viewerMode === true) {
|
||||||
_.each(periodicCallbacks, function(callback) {
|
_.each(periodicCallbacks, function(callback) {
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
|
@ -154,10 +154,11 @@ define(["jquery", "core", "async-runner"], function($, core, asyncRunner) {
|
|||||||
task.chain();
|
task.chain();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var path = paths.pop();
|
var path = paths[0];
|
||||||
client.stat(path, function(error, stat) {
|
client.stat(path, function(error, stat) {
|
||||||
if(stat) {
|
if(stat) {
|
||||||
result.push(stat);
|
result.push(stat);
|
||||||
|
paths.shift();
|
||||||
task.chain(recursiveDownloadMetadata);
|
task.chain(recursiveDownloadMetadata);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -187,7 +188,7 @@ define(["jquery", "core", "async-runner"], function($, core, asyncRunner) {
|
|||||||
task.chain();
|
task.chain();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var object = objects.pop();
|
var object = objects[0];
|
||||||
result.push(object);
|
result.push(object);
|
||||||
var file = undefined;
|
var file = undefined;
|
||||||
// object may be a file
|
// object may be a file
|
||||||
@ -199,13 +200,15 @@ define(["jquery", "core", "async-runner"], function($, core, asyncRunner) {
|
|||||||
file = object.stat;
|
file = object.stat;
|
||||||
}
|
}
|
||||||
if(!file) {
|
if(!file) {
|
||||||
|
objects.shift();
|
||||||
task.chain(recursiveDownloadContent);
|
task.chain(recursiveDownloadContent);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
client.readFile(file.path, function(error, data) {
|
client.readFile(file.path, function(error, data) {
|
||||||
if(data) {
|
if(data) {
|
||||||
file.content = data;
|
file.content = data;
|
||||||
recursiveDownloadContent();
|
objects.shift();
|
||||||
|
task.chain(recursiveDownloadContent);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
handleError(error, task);
|
handleError(error, task);
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
define(["jquery", "core", "dropbox-helper"], function($, core, dropboxHelper) {
|
define(["jquery", "core", "dropbox-helper"], function($, core, dropboxHelper) {
|
||||||
|
|
||||||
|
var PROVIDER_DROPBOX = "dropbox";
|
||||||
|
|
||||||
var dropboxProvider = {
|
var dropboxProvider = {
|
||||||
providerId: PROVIDER_DROPBOX,
|
providerId: PROVIDER_DROPBOX,
|
||||||
providerName: "Dropbox",
|
providerName: "Dropbox",
|
||||||
@ -27,9 +29,11 @@ define(["jquery", "core", "dropbox-helper"], function($, core, dropboxHelper) {
|
|||||||
syncAttributes.path = path;
|
syncAttributes.path = path;
|
||||||
syncAttributes.version = versionTag;
|
syncAttributes.version = versionTag;
|
||||||
syncAttributes.contentCRC = core.crc32(content);
|
syncAttributes.contentCRC = core.crc32(content);
|
||||||
var syncIndex = "sync." + PROVIDER_DROPBOX + "." + encodeURIComponent(path.toLowerCase());
|
return syncAttributes;
|
||||||
localStorage[syncIndex] = JSON.stringify(syncAttributes);
|
}
|
||||||
return syncIndex;
|
|
||||||
|
function createSyncIndex(path) {
|
||||||
|
return "sync." + PROVIDER_DROPBOX + "." + encodeURIComponent(path.toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
function importFilesFromPaths(paths) {
|
function importFilesFromPaths(paths) {
|
||||||
@ -41,12 +45,16 @@ define(["jquery", "core", "dropbox-helper"], function($, core, dropboxHelper) {
|
|||||||
if(error) {
|
if(error) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
var titleList = [];
|
||||||
_.each(result, function(file) {
|
_.each(result, function(file) {
|
||||||
var syncIndex = createSyncAttributes(file.path, file.versionTag, file.content);
|
var syncAttributes = createSyncAttributes(file.path, file.versionTag, file.content);
|
||||||
|
var syncIndex = createSyncIndex(syncAttributes.path);
|
||||||
|
localStorage[syncIndex] = JSON.stringify(syncAttributes);
|
||||||
var fileIndex = core.fileManager.createFile(file.name, file.content, [syncIndex]);
|
var fileIndex = core.fileManager.createFile(file.name, file.content, [syncIndex]);
|
||||||
core.fileManager.selectFile(fileIndex);
|
core.fileManager.selectFile(fileIndex);
|
||||||
core.showMessage('"' + file.name + '" imported successfully from Dropbox.');
|
titleList.push('"' + file.name + '"');
|
||||||
});
|
});
|
||||||
|
core.showMessage(titleList.join(", ") + ' imported successfully from Dropbox.');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -58,7 +66,7 @@ define(["jquery", "core", "dropbox-helper"], function($, core, dropboxHelper) {
|
|||||||
}
|
}
|
||||||
var importPaths = [];
|
var importPaths = [];
|
||||||
_.each(paths, function(path) {
|
_.each(paths, function(path) {
|
||||||
var syncIndex = "sync." + PROVIDER_DROPBOX + "." + encodeURIComponent(path.toLowerCase());
|
var syncIndex = createSyncIndex(path);
|
||||||
var fileIndex = core.fileManager.getFileIndexFromSync(syncIndex);
|
var fileIndex = core.fileManager.getFileIndexFromSync(syncIndex);
|
||||||
if(fileIndex !== undefined) {
|
if(fileIndex !== undefined) {
|
||||||
var title = localStorage[fileIndex + ".title"];
|
var title = localStorage[fileIndex + ".title"];
|
||||||
@ -78,7 +86,7 @@ define(["jquery", "core", "dropbox-helper"], function($, core, dropboxHelper) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Check that file is not synchronized with an other one
|
// Check that file is not synchronized with an other one
|
||||||
var syncIndex = "sync." + PROVIDER_DROPBOX + "." + encodeURIComponent(path.toLowerCase());
|
var syncIndex = createSyncIndex(path);
|
||||||
var fileIndex = core.fileManager.getFileIndexFromSync(syncIndex);
|
var fileIndex = core.fileManager.getFileIndexFromSync(syncIndex);
|
||||||
if(fileIndex !== undefined) {
|
if(fileIndex !== undefined) {
|
||||||
var existingTitle = localStorage[fileIndex + ".title"];
|
var existingTitle = localStorage[fileIndex + ".title"];
|
||||||
@ -91,7 +99,9 @@ define(["jquery", "core", "dropbox-helper"], function($, core, dropboxHelper) {
|
|||||||
callback(error);
|
callback(error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
syncIndex = createSyncAttributes(result.path, result.versionTag, content);
|
var syncAttributes = createSyncAttributes(result.path, result.versionTag, content);
|
||||||
|
var syncIndex = createSyncIndex(syncAttributes.path);
|
||||||
|
localStorage[syncIndex] = JSON.stringify(syncAttributes);
|
||||||
callback(undefined, syncIndex);
|
callback(undefined, syncIndex);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -137,7 +147,7 @@ define(["jquery", "core", "dropbox-helper"], function($, core, dropboxHelper) {
|
|||||||
}
|
}
|
||||||
var interestingChanges = [];
|
var interestingChanges = [];
|
||||||
_.each(changes, function(change) {
|
_.each(changes, function(change) {
|
||||||
var syncIndex = "sync." + PROVIDER_DROPBOX + "." + encodeURIComponent(change.path.toLowerCase());
|
var syncIndex = createSyncIndex(change.path);
|
||||||
var serializedAttributes = localStorage[syncIndex];
|
var serializedAttributes = localStorage[syncIndex];
|
||||||
if(serializedAttributes === undefined) {
|
if(serializedAttributes === undefined) {
|
||||||
return;
|
return;
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
define(["jquery", "core", "synchronizer", "publisher", "sharing", "text!../WELCOME.md", "underscore"],
|
define(["jquery", "core", "synchronizer", "publisher", "sharing", "text!../WELCOME.md", "underscore"],
|
||||||
function($, core, synchronizer, publisher, sharing, welcomeContent) {
|
function($, core, synchronizer, publisher, sharing, welcomeContent) {
|
||||||
|
|
||||||
|
var TEMPORARY_FILE_INDEX = "file.tempIndex";
|
||||||
|
|
||||||
var fileManager = {};
|
var fileManager = {};
|
||||||
|
|
||||||
// Defines the current file
|
// Defines the current file
|
||||||
@ -16,7 +18,7 @@ define(["jquery", "core", "synchronizer", "publisher", "sharing", "text!../WELCO
|
|||||||
if(fileIndex === undefined) {
|
if(fileIndex === undefined) {
|
||||||
localStorage.removeItem("file.current");
|
localStorage.removeItem("file.current");
|
||||||
}
|
}
|
||||||
else {
|
else if(fileIndex != TEMPORARY_FILE_INDEX) {
|
||||||
localStorage["file.current"] = fileIndex;
|
localStorage["file.current"] = fileIndex;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -38,6 +40,14 @@ define(["jquery", "core", "synchronizer", "publisher", "sharing", "text!../WELCO
|
|||||||
synchronizer.refreshManageSync();
|
synchronizer.refreshManageSync();
|
||||||
publisher.notifyPublish();
|
publisher.notifyPublish();
|
||||||
|
|
||||||
|
// Hide the viewer pencil button
|
||||||
|
if(fileIndex == TEMPORARY_FILE_INDEX) {
|
||||||
|
$(".action-edit-document").removeClass("hide");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$(".action-edit-document").addClass("hide");
|
||||||
|
}
|
||||||
|
|
||||||
// Recreate the editor
|
// Recreate the editor
|
||||||
fileIndex = fileManager.getCurrentFileIndex();
|
fileIndex = fileManager.getCurrentFileIndex();
|
||||||
$("#wmd-input").val(localStorage[fileIndex + ".content"]);
|
$("#wmd-input").val(localStorage[fileIndex + ".content"]);
|
||||||
@ -46,7 +56,7 @@ define(["jquery", "core", "synchronizer", "publisher", "sharing", "text!../WELCO
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
fileManager.createFile = function(title, content, syncIndexes) {
|
fileManager.createFile = function(title, content, syncIndexes, isTemporary) {
|
||||||
content = content || core.settings.defaultContent;
|
content = content || core.settings.defaultContent;
|
||||||
syncIndexes = syncIndexes || [];
|
syncIndexes = syncIndexes || [];
|
||||||
if (!title) {
|
if (!title) {
|
||||||
@ -61,10 +71,12 @@ define(["jquery", "core", "synchronizer", "publisher", "sharing", "text!../WELCO
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Generate a unique fileIndex
|
// Generate a unique fileIndex
|
||||||
var fileIndex = undefined;
|
var fileIndex = TEMPORARY_FILE_INDEX;
|
||||||
|
if(!isTemporary) {
|
||||||
do {
|
do {
|
||||||
fileIndex = "file." + core.randomString();
|
fileIndex = "file." + core.randomString();
|
||||||
} while(_.has(localStorage, fileIndex + ".title"));
|
} 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;
|
||||||
@ -74,7 +86,9 @@ define(["jquery", "core", "synchronizer", "publisher", "sharing", "text!../WELCO
|
|||||||
}, ";");
|
}, ";");
|
||||||
localStorage[fileIndex + ".sync"] = sync;
|
localStorage[fileIndex + ".sync"] = sync;
|
||||||
localStorage[fileIndex + ".publish"] = ";";
|
localStorage[fileIndex + ".publish"] = ";";
|
||||||
|
if(!isTemporary) {
|
||||||
localStorage["file.list"] += fileIndex + ";";
|
localStorage["file.list"] += fileIndex + ";";
|
||||||
|
}
|
||||||
return fileIndex;
|
return fileIndex;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -132,22 +146,18 @@ define(["jquery", "core", "synchronizer", "publisher", "sharing", "text!../WELCO
|
|||||||
}
|
}
|
||||||
|
|
||||||
synchronizer.resetSyncFlags();
|
synchronizer.resetSyncFlags();
|
||||||
var links = [];
|
function composeTitle(fileIndex, refreshSharing) {
|
||||||
function composeTitle(fileIndex, generateLinks) {
|
|
||||||
var result = [];
|
var result = [];
|
||||||
var syncAttributesList = synchronizer.getSyncAttributesFromFile(fileIndex);
|
var syncAttributesList = synchronizer.getSyncAttributesFromFile(fileIndex);
|
||||||
var publishAttributesList = publisher.getPublishAttributesFromFile(fileIndex);
|
var publishAttributesList = publisher.getPublishAttributesFromFile(fileIndex);
|
||||||
var attributesList = syncAttributesList.concat(publishAttributesList);
|
var attributesList = syncAttributesList.concat(publishAttributesList);
|
||||||
|
if(refreshSharing === true) {
|
||||||
|
sharing.refreshDocumentSharing(attributesList);
|
||||||
|
}
|
||||||
_.chain(attributesList).sortBy(function(attributes) {
|
_.chain(attributesList).sortBy(function(attributes) {
|
||||||
return attributes.provider;
|
return attributes.provider;
|
||||||
}).each(function(attributes) {
|
}).each(function(attributes) {
|
||||||
result.push('<i class="icon-' + attributes.provider + '"></i>');
|
result.push('<i class="icon-' + attributes.provider + '"></i>');
|
||||||
if(generateLinks === true) {
|
|
||||||
var url = sharing.getLink(attributes);
|
|
||||||
if(url !== undefined) {
|
|
||||||
links.push(url);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
result.push(" ");
|
result.push(" ");
|
||||||
result.push(localStorage[fileIndex + ".title"]);
|
result.push(localStorage[fileIndex + ".title"]);
|
||||||
@ -160,15 +170,6 @@ define(["jquery", "core", "synchronizer", "publisher", "sharing", "text!../WELCO
|
|||||||
$("#file-title").html(composeTitle(fileIndex, true));
|
$("#file-title").html(composeTitle(fileIndex, true));
|
||||||
$(".file-title").text(title);
|
$(".file-title").text(title);
|
||||||
$("#file-title-input").val(title);
|
$("#file-title-input").val(title);
|
||||||
var linkList = $(".link-list").empty();
|
|
||||||
if(links.length > 0) {
|
|
||||||
_.each(links, function(url) {
|
|
||||||
linkList.append($('<div><a href="' + url + '">' + url + '</a></div>'));
|
|
||||||
});
|
|
||||||
$("#link-container no-link").hide();
|
|
||||||
} else {
|
|
||||||
$("#link-container no-link").show();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update the file selector
|
// Update the file selector
|
||||||
$("#file-selector").empty();
|
$("#file-selector").empty();
|
||||||
@ -280,6 +281,16 @@ define(["jquery", "core", "synchronizer", "publisher", "sharing", "text!../WELCO
|
|||||||
applyTitle($(this));
|
applyTitle($(this));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
$(".action-open-stackedit").click(function() {
|
||||||
|
window.location.href = ".";
|
||||||
|
});
|
||||||
|
$(".action-edit-document").click(function() {
|
||||||
|
var content = $("#wmd-input").val();
|
||||||
|
var title = localStorage[fileManager.getCurrentFileIndex() + ".title"];
|
||||||
|
var fileIndex = fileManager.createFile(title, content);
|
||||||
|
fileManager.selectFile(fileIndex);
|
||||||
|
window.location.href = ".";
|
||||||
|
});
|
||||||
$(".action-download-md").click(function() {
|
$(".action-download-md").click(function() {
|
||||||
var content = $("#wmd-input").val();
|
var content = $("#wmd-input").val();
|
||||||
var title = localStorage[fileManager.getCurrentFileIndex() + ".title"];
|
var title = localStorage[fileManager.getCurrentFileIndex() + ".title"];
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
define(["jquery", "core", "google-helper", "underscore"], function($, core, googleHelper) {
|
define(["jquery", "core", "google-helper", "underscore"], function($, core, googleHelper) {
|
||||||
|
|
||||||
|
var PROVIDER_GDRIVE = "gdrive";
|
||||||
|
|
||||||
var gdriveProvider = {
|
var gdriveProvider = {
|
||||||
providerId: PROVIDER_GDRIVE,
|
providerId: PROVIDER_GDRIVE,
|
||||||
providerName: "Google Drive",
|
providerName: "Google Drive",
|
||||||
defaultPublishFormat: "template",
|
defaultPublishFormat: "template",
|
||||||
sharingAttributes: ["id"],
|
|
||||||
useSync: false
|
useSync: false
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -15,9 +16,11 @@ define(["jquery", "core", "google-helper", "underscore"], function($, core, goog
|
|||||||
syncAttributes.etag = etag;
|
syncAttributes.etag = etag;
|
||||||
syncAttributes.contentCRC = core.crc32(content);
|
syncAttributes.contentCRC = core.crc32(content);
|
||||||
syncAttributes.titleCRC = core.crc32(title);
|
syncAttributes.titleCRC = core.crc32(title);
|
||||||
var syncIndex = "sync." + PROVIDER_GDRIVE + "." + id;
|
return syncAttributes;
|
||||||
localStorage[syncIndex] = JSON.stringify(syncAttributes);
|
}
|
||||||
return syncIndex;
|
|
||||||
|
function createSyncIndex(id) {
|
||||||
|
return "sync." + PROVIDER_GDRIVE + "." + id;
|
||||||
}
|
}
|
||||||
|
|
||||||
function importFilesFromIds(ids) {
|
function importFilesFromIds(ids) {
|
||||||
@ -29,12 +32,16 @@ define(["jquery", "core", "google-helper", "underscore"], function($, core, goog
|
|||||||
if(error) {
|
if(error) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
var titleList = [];
|
||||||
_.each(result, function(file) {
|
_.each(result, function(file) {
|
||||||
var syncIndex = createSyncAttributes(file.id, file.etag, file.content, file.title);
|
var syncAttributes = createSyncAttributes(file.id, file.etag, file.content, file.title);
|
||||||
|
var syncIndex = createSyncIndex(syncAttributes.id);
|
||||||
|
localStorage[syncIndex] = JSON.stringify(syncAttributes);
|
||||||
var fileIndex = core.fileManager.createFile(file.title, file.content, [syncIndex]);
|
var fileIndex = core.fileManager.createFile(file.title, file.content, [syncIndex]);
|
||||||
core.fileManager.selectFile(fileIndex);
|
core.fileManager.selectFile(fileIndex);
|
||||||
core.showMessage('"' + file.title + '" imported successfully from Google Drive.');
|
titleList.push('"' + file.title + '"');
|
||||||
});
|
});
|
||||||
|
core.showMessage(titleList.join(", ") + ' imported successfully from Google Drive.');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -46,7 +53,7 @@ define(["jquery", "core", "google-helper", "underscore"], function($, core, goog
|
|||||||
}
|
}
|
||||||
var importIds = [];
|
var importIds = [];
|
||||||
_.each(ids, function(id) {
|
_.each(ids, function(id) {
|
||||||
var syncIndex = "sync." + PROVIDER_GDRIVE + "." + id;
|
var syncIndex = createSyncIndex(id);
|
||||||
var fileIndex = core.fileManager.getFileIndexFromSync(syncIndex);
|
var fileIndex = core.fileManager.getFileIndexFromSync(syncIndex);
|
||||||
if(fileIndex !== undefined) {
|
if(fileIndex !== undefined) {
|
||||||
var title = localStorage[fileIndex + ".title"];
|
var title = localStorage[fileIndex + ".title"];
|
||||||
@ -65,7 +72,9 @@ define(["jquery", "core", "google-helper", "underscore"], function($, core, goog
|
|||||||
callback(error);
|
callback(error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var syncIndex = createSyncAttributes(result.id, result.etag, content, title);
|
var syncAttributes = createSyncAttributes(result.id, result.etag, content, title);
|
||||||
|
var syncIndex = createSyncIndex(syncAttributes.id);
|
||||||
|
localStorage[syncIndex] = JSON.stringify(syncAttributes);
|
||||||
callback(undefined, syncIndex);
|
callback(undefined, syncIndex);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -76,7 +85,7 @@ define(["jquery", "core", "google-helper", "underscore"], function($, core, goog
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Check that file is not synchronized with an other one
|
// Check that file is not synchronized with an other one
|
||||||
var syncIndex = "sync." + PROVIDER_GDRIVE + "." + id;
|
var syncIndex = createSyncIndex(id);
|
||||||
var fileIndex = core.fileManager.getFileIndexFromSync(syncIndex);
|
var fileIndex = core.fileManager.getFileIndexFromSync(syncIndex);
|
||||||
if(fileIndex !== undefined) {
|
if(fileIndex !== undefined) {
|
||||||
var existingTitle = localStorage[fileIndex + ".title"];
|
var existingTitle = localStorage[fileIndex + ".title"];
|
||||||
@ -89,7 +98,9 @@ define(["jquery", "core", "google-helper", "underscore"], function($, core, goog
|
|||||||
callback(error);
|
callback(error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var syncIndex = createSyncAttributes(result.id, result.etag, content, title);
|
var syncAttributes = createSyncAttributes(result.id, result.etag, content, title);
|
||||||
|
var syncIndex = createSyncIndex(syncAttributes.id);
|
||||||
|
localStorage[syncIndex] = JSON.stringify(syncAttributes);
|
||||||
callback(undefined, syncIndex);
|
callback(undefined, syncIndex);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -127,7 +138,7 @@ define(["jquery", "core", "google-helper", "underscore"], function($, core, goog
|
|||||||
}
|
}
|
||||||
var interestingChanges = [];
|
var interestingChanges = [];
|
||||||
_.each(changes, function(change) {
|
_.each(changes, function(change) {
|
||||||
var syncIndex = "sync." + PROVIDER_GDRIVE + "." + change.fileId;
|
var syncIndex = createSyncIndex(change.fileId);
|
||||||
var serializedAttributes = localStorage[syncIndex];
|
var serializedAttributes = localStorage[syncIndex];
|
||||||
if(serializedAttributes === undefined) {
|
if(serializedAttributes === undefined) {
|
||||||
return;
|
return;
|
||||||
@ -263,7 +274,7 @@ define(["jquery", "core", "google-helper", "underscore"], function($, core, goog
|
|||||||
else if (state.action == "open") {
|
else if (state.action == "open") {
|
||||||
var importIds = [];
|
var importIds = [];
|
||||||
_.each(state.ids, function(id) {
|
_.each(state.ids, function(id) {
|
||||||
var syncIndex = "sync." + PROVIDER_GDRIVE + "." + id;
|
var syncIndex = createSyncIndex(id);
|
||||||
var fileIndex = core.fileManager.getFileIndexFromSync(syncIndex);
|
var fileIndex = core.fileManager.getFileIndexFromSync(syncIndex);
|
||||||
if(fileIndex !== undefined) {
|
if(fileIndex !== undefined) {
|
||||||
core.fileManager.selectFile(fileIndex);
|
core.fileManager.selectFile(fileIndex);
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
define(["jquery", "core", "github-helper"], function($, core, githubHelper) {
|
define(["jquery", "core", "github-helper"], function($, core, githubHelper) {
|
||||||
|
|
||||||
|
var PROVIDER_GIST = "gist";
|
||||||
|
|
||||||
var gistProvider = {
|
var gistProvider = {
|
||||||
providerId: PROVIDER_GIST,
|
providerId: PROVIDER_GIST,
|
||||||
providerName: "Gist"
|
providerName: "Gist",
|
||||||
|
sharingAttributes: ["gistId", "filename"]
|
||||||
};
|
};
|
||||||
|
|
||||||
gistProvider.publish = function(publishAttributes, title, content, callback) {
|
gistProvider.publish = function(publishAttributes, title, content, callback) {
|
||||||
githubHelper.gistUpload(publishAttributes.gistId, publishAttributes.filename, publishAttributes.isPublic,
|
githubHelper.uploadGist(publishAttributes.gistId, publishAttributes.filename, publishAttributes.isPublic,
|
||||||
title, content, function(error, gistId) {
|
title, content, function(error, gistId) {
|
||||||
if(error) {
|
if(error) {
|
||||||
callback(error);
|
callback(error);
|
||||||
@ -29,5 +32,9 @@ define(["jquery", "core", "github-helper"], function($, core, githubHelper) {
|
|||||||
return publishAttributes;
|
return publishAttributes;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
gistProvider.importPublic = function(importParameters, callback) {
|
||||||
|
githubHelper.downloadGist(importParameters.gistId, importParameters.filename, callback);
|
||||||
|
};
|
||||||
|
|
||||||
return gistProvider;
|
return gistProvider;
|
||||||
});
|
});
|
@ -144,7 +144,7 @@ define(["jquery", "core", "async-runner"], function($, core, asyncRunner) {
|
|||||||
asyncRunner.addTask(task);
|
asyncRunner.addTask(task);
|
||||||
};
|
};
|
||||||
|
|
||||||
githubHelper.gistUpload = function(gistId, filename, isPublic, title, content, callback) {
|
githubHelper.uploadGist = function(gistId, filename, isPublic, title, content, callback) {
|
||||||
callback = callback || core.doNothing;
|
callback = callback || core.doNothing;
|
||||||
var task = asyncRunner.createTask();
|
var task = asyncRunner.createTask();
|
||||||
connect(task);
|
connect(task);
|
||||||
@ -183,6 +183,41 @@ define(["jquery", "core", "async-runner"], function($, core, asyncRunner) {
|
|||||||
asyncRunner.addTask(task);
|
asyncRunner.addTask(task);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
githubHelper.downloadGist = function(gistId, filename, callback) {
|
||||||
|
callback = callback || core.doNothing;
|
||||||
|
var task = asyncRunner.createTask();
|
||||||
|
connect(task);
|
||||||
|
// No need for authentication
|
||||||
|
var title = undefined;
|
||||||
|
var content = undefined;
|
||||||
|
task.onRun(function() {
|
||||||
|
var github = new Github({});
|
||||||
|
var gist = github.getGist(gistId);
|
||||||
|
gist.read(function(err, gist) {
|
||||||
|
if(err) {
|
||||||
|
// Handle error
|
||||||
|
task.error(new Error('Error trying to access Gist ' + gistId + '.'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
title = gist.description;
|
||||||
|
var file = gist.files[filename];
|
||||||
|
if(file === undefined) {
|
||||||
|
task.error(new Error('Gist ' + gistId + ' does not contain "' + filename + '".'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
content = file.content;
|
||||||
|
task.chain();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
task.onSuccess(function() {
|
||||||
|
callback(undefined, title, content);
|
||||||
|
});
|
||||||
|
task.onError(function(error) {
|
||||||
|
callback(error);
|
||||||
|
});
|
||||||
|
asyncRunner.addTask(task);
|
||||||
|
};
|
||||||
|
|
||||||
function handleError(error, task) {
|
function handleError(error, task) {
|
||||||
var errorMsg = undefined;
|
var errorMsg = undefined;
|
||||||
if (error) {
|
if (error) {
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
define(["jquery", "core", "github-helper"], function($, core, githubHelper) {
|
define(["jquery", "core", "github-helper"], function($, core, githubHelper) {
|
||||||
|
|
||||||
|
var PROVIDER_GITHUB = "github";
|
||||||
|
|
||||||
var githubProvider = {
|
var githubProvider = {
|
||||||
providerId: PROVIDER_GITHUB,
|
providerId: PROVIDER_GITHUB,
|
||||||
providerName: "GitHub"
|
providerName: "GitHub"
|
||||||
|
@ -200,30 +200,35 @@ define(["jquery", "core", "async-runner"], function($, core, asyncRunner) {
|
|||||||
asyncRunner.addTask(task);
|
asyncRunner.addTask(task);
|
||||||
};
|
};
|
||||||
|
|
||||||
googleHelper.downloadMetadata = function(ids, callback) {
|
googleHelper.downloadMetadata = function(ids, callback, skipAuth) {
|
||||||
callback = callback || core.doNothing;
|
callback = callback || core.doNothing;
|
||||||
var result = [];
|
var result = [];
|
||||||
var task = asyncRunner.createTask();
|
var task = asyncRunner.createTask();
|
||||||
connect(task);
|
connect(task);
|
||||||
|
if(!skipAuth) {
|
||||||
authenticate(task);
|
authenticate(task);
|
||||||
|
}
|
||||||
task.onRun(function() {
|
task.onRun(function() {
|
||||||
function recursiveDownloadMetadata() {
|
function recursiveDownloadMetadata() {
|
||||||
if(ids.length === 0) {
|
if(ids.length === 0) {
|
||||||
task.chain();
|
task.chain();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var id = ids.pop();
|
var id = ids[0];
|
||||||
|
var headers = {};
|
||||||
var token = gapi.auth.getToken();
|
var token = gapi.auth.getToken();
|
||||||
var headers = {
|
if(token) {
|
||||||
Authorization : token ? "Bearer " + token.access_token: null
|
headers.Authorization = "Bearer " + token.access_token;
|
||||||
};
|
}
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url : "https://www.googleapis.com/drive/v2/files/" + id,
|
url : "https://www.googleapis.com/drive/v2/files/" + id,
|
||||||
headers : headers,
|
headers : headers,
|
||||||
|
data : {key: GOOGLE_API_KEY},
|
||||||
dataType : "json",
|
dataType : "json",
|
||||||
timeout : AJAX_TIMEOUT
|
timeout : AJAX_TIMEOUT
|
||||||
}).done(function(data, textStatus, jqXHR) {
|
}).done(function(data, textStatus, jqXHR) {
|
||||||
result.push(data);
|
result.push(data);
|
||||||
|
ids.shift();
|
||||||
task.chain(recursiveDownloadMetadata);
|
task.chain(recursiveDownloadMetadata);
|
||||||
}).fail(function(jqXHR) {
|
}).fail(function(jqXHR) {
|
||||||
var error = {
|
var error = {
|
||||||
@ -248,21 +253,23 @@ define(["jquery", "core", "async-runner"], function($, core, asyncRunner) {
|
|||||||
asyncRunner.addTask(task);
|
asyncRunner.addTask(task);
|
||||||
};
|
};
|
||||||
|
|
||||||
googleHelper.downloadContent = function(objects, callback) {
|
googleHelper.downloadContent = function(objects, callback, skipAuth) {
|
||||||
callback = callback || core.doNothing;
|
callback = callback || core.doNothing;
|
||||||
var result = [];
|
var result = [];
|
||||||
var task = asyncRunner.createTask();
|
var task = asyncRunner.createTask();
|
||||||
// Add some time for user to choose his files
|
// Add some time for user to choose his files
|
||||||
task.timeout = ASYNC_TASK_LONG_TIMEOUT;
|
task.timeout = ASYNC_TASK_LONG_TIMEOUT;
|
||||||
connect(task);
|
connect(task);
|
||||||
|
if(!skipAuth) {
|
||||||
authenticate(task);
|
authenticate(task);
|
||||||
|
}
|
||||||
task.onRun(function() {
|
task.onRun(function() {
|
||||||
function recursiveDownloadContent() {
|
function recursiveDownloadContent() {
|
||||||
if(objects.length === 0) {
|
if(objects.length === 0) {
|
||||||
task.chain();
|
task.chain();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var object = objects.pop();
|
var object = objects[0];
|
||||||
result.push(object);
|
result.push(object);
|
||||||
var file = undefined;
|
var file = undefined;
|
||||||
// object may be a file
|
// object may be a file
|
||||||
@ -274,20 +281,24 @@ define(["jquery", "core", "async-runner"], function($, core, asyncRunner) {
|
|||||||
file = object.file;
|
file = object.file;
|
||||||
}
|
}
|
||||||
if(!file) {
|
if(!file) {
|
||||||
|
objects.shift();
|
||||||
task.chain(recursiveDownloadContent);
|
task.chain(recursiveDownloadContent);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
var headers = {};
|
||||||
var token = gapi.auth.getToken();
|
var token = gapi.auth.getToken();
|
||||||
var headers = {
|
if(token) {
|
||||||
Authorization : token ? "Bearer " + token.access_token: null
|
headers.Authorization = "Bearer " + token.access_token;
|
||||||
};
|
}
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url : file.downloadUrl,
|
url : file.downloadUrl,
|
||||||
headers : headers,
|
headers : headers,
|
||||||
|
data : {key: GOOGLE_API_KEY},
|
||||||
dataType : "text",
|
dataType : "text",
|
||||||
timeout : AJAX_TIMEOUT
|
timeout : AJAX_TIMEOUT
|
||||||
}).done(function(data, textStatus, jqXHR) {
|
}).done(function(data, textStatus, jqXHR) {
|
||||||
file.content = data;
|
file.content = data;
|
||||||
|
objects.shift();
|
||||||
task.chain(recursiveDownloadContent);
|
task.chain(recursiveDownloadContent);
|
||||||
}).fail(function(jqXHR) {
|
}).fail(function(jqXHR) {
|
||||||
var error = {
|
var error = {
|
||||||
@ -349,8 +360,9 @@ define(["jquery", "core", "async-runner"], function($, core, asyncRunner) {
|
|||||||
}
|
}
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url : "//www.google.com/jsapi",
|
url : "//www.google.com/jsapi",
|
||||||
data : {key: GOOGLE_KEY},
|
data : {key: GOOGLE_API_KEY},
|
||||||
dataType : "script", timeout : AJAX_TIMEOUT
|
dataType : "script",
|
||||||
|
timeout : AJAX_TIMEOUT
|
||||||
}).done(function() {
|
}).done(function() {
|
||||||
google.load('picker', '1', {callback: task.chain});
|
google.load('picker', '1', {callback: task.chain});
|
||||||
pickerLoaded = true;
|
pickerLoaded = true;
|
||||||
@ -424,10 +436,11 @@ define(["jquery", "core", "async-runner"], function($, core, asyncRunner) {
|
|||||||
connect(task);
|
connect(task);
|
||||||
authenticate(task);
|
authenticate(task);
|
||||||
task.onRun(function() {
|
task.onRun(function() {
|
||||||
|
var headers = {};
|
||||||
var token = gapi.auth.getToken();
|
var token = gapi.auth.getToken();
|
||||||
var headers = {
|
if(token) {
|
||||||
Authorization : token ? "Bearer " + token.access_token: null
|
headers.Authorization = "Bearer " + token.access_token;
|
||||||
};
|
}
|
||||||
function publish() {
|
function publish() {
|
||||||
var url = "https://www.googleapis.com/blogger/v3/blogs/" + blogId + "/posts/";
|
var url = "https://www.googleapis.com/blogger/v3/blogs/" + blogId + "/posts/";
|
||||||
var data = {
|
var data = {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
define(["jquery", "core", "blogger-provider", "dropbox-provider", "gist-provider", "github-provider", "gdrive-provider", "tumblr-provider", "underscore"], function($, core) {
|
define(["jquery", "core", "sharing", "blogger-provider", "dropbox-provider", "gist-provider", "github-provider", "gdrive-provider", "tumblr-provider", "underscore"],
|
||||||
|
function($, core, sharing) {
|
||||||
|
|
||||||
var publisher = {};
|
var publisher = {};
|
||||||
|
|
||||||
@ -167,11 +168,13 @@ define(["jquery", "core", "blogger-provider", "dropbox-provider", "gist-provider
|
|||||||
provider.publish(publishAttributes, title, content, function(error) {
|
provider.publish(publishAttributes, title, content, function(error) {
|
||||||
if(error === undefined) {
|
if(error === undefined) {
|
||||||
publishAttributes.provider = provider.providerId;
|
publishAttributes.provider = provider.providerId;
|
||||||
|
sharing.createLink(publishAttributes, function() {
|
||||||
createPublishIndex(fileIndex, publishAttributes);
|
createPublishIndex(fileIndex, publishAttributes);
|
||||||
publisher.notifyPublish();
|
publisher.notifyPublish();
|
||||||
core.fileManager.updateFileTitles();
|
core.fileManager.updateFileTitles();
|
||||||
core.showMessage('"' + title
|
core.showMessage('"' + title
|
||||||
+ '" is now published on ' + provider.providerName + '.');
|
+ '" is now published on ' + provider.providerName + '.');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -187,7 +190,7 @@ define(["jquery", "core", "blogger-provider", "dropbox-provider", "gist-provider
|
|||||||
var fileIndex = core.fileManager.getCurrentFileIndex();
|
var fileIndex = core.fileManager.getCurrentFileIndex();
|
||||||
var publishIndexList = _.compact(localStorage[fileIndex + ".publish"].split(";"));
|
var publishIndexList = _.compact(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();
|
var publishList = $("#manage-publish-list").empty();
|
||||||
if (publishIndexList.length > 0) {
|
if (publishIndexList.length > 0) {
|
||||||
$(".msg-publish-list").removeClass("hide");
|
$(".msg-publish-list").removeClass("hide");
|
||||||
} else {
|
} else {
|
||||||
@ -196,7 +199,7 @@ define(["jquery", "core", "blogger-provider", "dropbox-provider", "gist-provider
|
|||||||
_.each(publishIndexList, function(publishIndex) {
|
_.each(publishIndexList, function(publishIndex) {
|
||||||
var publishAttributes = JSON.parse(localStorage[publishIndex]);
|
var publishAttributes = JSON.parse(localStorage[publishIndex]);
|
||||||
var publishDesc = JSON.stringify(publishAttributes).replace(/{|}|"/g, "");
|
var publishDesc = JSON.stringify(publishAttributes).replace(/{|}|"/g, "");
|
||||||
lineElement = $(_.template(lineTemplate, {
|
var lineElement = $(_.template(lineTemplate, {
|
||||||
provider: providerMap[publishAttributes.provider],
|
provider: providerMap[publishAttributes.provider],
|
||||||
publishDesc: publishDesc
|
publishDesc: publishDesc
|
||||||
}));
|
}));
|
||||||
@ -204,7 +207,7 @@ define(["jquery", "core", "blogger-provider", "dropbox-provider", "gist-provider
|
|||||||
core.fileManager.removePublish(publishIndex);
|
core.fileManager.removePublish(publishIndex);
|
||||||
core.fileManager.updateFileTitles();
|
core.fileManager.updateFileTitles();
|
||||||
}));
|
}));
|
||||||
$("#manage-publish-list").append(lineElement);
|
publishList.append(lineElement);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
111
js/sharing.js
111
js/sharing.js
@ -1,4 +1,4 @@
|
|||||||
define(["jquery", "core", "async-runner", "gdrive-provider", "underscore"], function($, core, asyncRunner) {
|
define(["jquery", "core", "async-runner", "gist-provider", "underscore"], function($, core, asyncRunner) {
|
||||||
var sharing = {};
|
var sharing = {};
|
||||||
|
|
||||||
// Create a map with providerId: providerObject
|
// Create a map with providerId: providerObject
|
||||||
@ -7,28 +7,34 @@ define(["jquery", "core", "async-runner", "gdrive-provider", "underscore"], func
|
|||||||
return argument && argument.providerId && [argument.providerId, argument];
|
return argument && argument.providerId && [argument.providerId, argument];
|
||||||
}).compact().object().value();
|
}).compact().object().value();
|
||||||
|
|
||||||
sharing.getLink = function(attributes) {
|
// Used to populate the "Sharing" dropdown box
|
||||||
var provider = providerMap[attributes.provider];
|
var lineTemplate = ['<div class="input-prepend">',
|
||||||
if(provider === undefined) {
|
'<a href="<%= link %>" class="add-on" title="Sharing location"><i class="icon-link"></i></a>',
|
||||||
return undefined;
|
'<input class="span2" type="text" value="<%= link %>" readonly />',
|
||||||
}
|
'</div>'].join("");
|
||||||
var url = [BASE_URL, 'viewer.html?provider=', attributes.provider];
|
sharing.refreshDocumentSharing = function(attributesList) {
|
||||||
_.each(provider.sharingAttributes, function(attributeName) {
|
var linkList = $("#link-container .link-list").empty();
|
||||||
url.push('&');
|
$("#link-container .no-link").show();
|
||||||
url.push(attributeName);
|
_.each(attributesList, function(attributes) {
|
||||||
url.push('=');
|
if(attributes.sharingLink) {
|
||||||
url.push(attributes[attributeName]);
|
var lineElement = $(_.template(lineTemplate, {
|
||||||
|
link: attributes.sharingLink
|
||||||
|
}));
|
||||||
|
lineElement.click(function(event) {
|
||||||
|
event.stopPropagation();
|
||||||
|
});
|
||||||
|
linkList.append(lineElement);
|
||||||
|
$("#link-container .no-link").hide();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return url.join("");
|
|
||||||
};
|
};
|
||||||
|
|
||||||
sharing.createLink = function(attributes, callback) {
|
sharing.createLink = function(attributes, callback) {
|
||||||
if(attributes.sharingLink !== undefined) {
|
|
||||||
callback();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var provider = providerMap[attributes.provider];
|
var provider = providerMap[attributes.provider];
|
||||||
if(provider === undefined) {
|
// Don't create link if link already exists or provider is not compatible for sharing
|
||||||
|
if(attributes.sharingLink !== undefined || provider === undefined
|
||||||
|
// Or document is not published in markdown format
|
||||||
|
|| attributes.format != "markdown") {
|
||||||
callback();
|
callback();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -44,7 +50,7 @@ define(["jquery", "core", "async-runner", "gdrive-provider", "underscore"], func
|
|||||||
url.push('&');
|
url.push('&');
|
||||||
url.push(attributeName);
|
url.push(attributeName);
|
||||||
url.push('=');
|
url.push('=');
|
||||||
url.push(attributes[attributeName]);
|
url.push(encodeURIComponent(attributes[attributeName]));
|
||||||
});
|
});
|
||||||
$.getJSON(
|
$.getJSON(
|
||||||
"https://api-ssl.bitly.com/v3/shorten",
|
"https://api-ssl.bitly.com/v3/shorten",
|
||||||
@ -56,29 +62,78 @@ define(["jquery", "core", "async-runner", "gdrive-provider", "underscore"], func
|
|||||||
{
|
{
|
||||||
if(response.data) {
|
if(response.data) {
|
||||||
shortUrl = response.data.url;
|
shortUrl = response.data.url;
|
||||||
|
attributes.sharingLink = shortUrl;
|
||||||
}
|
}
|
||||||
console.log(shortUrl);
|
|
||||||
task.chain();
|
task.chain();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
task.onSuccess(function() {
|
function onFinish() {
|
||||||
|
if(shortUrl === undefined) {
|
||||||
|
localStorage["missingSharingLink"] = true;
|
||||||
|
}
|
||||||
callback(shortUrl);
|
callback(shortUrl);
|
||||||
});
|
}
|
||||||
|
task.onSuccess(onFinish);
|
||||||
|
task.onError(onFinish);
|
||||||
asyncRunner.addTask(task);
|
asyncRunner.addTask(task);
|
||||||
};
|
};
|
||||||
|
|
||||||
core.onReady(function() {
|
// Create the possible missing links
|
||||||
|
function checkMissingLinks() {
|
||||||
|
if(core.isOffline === true) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(!_.has(localStorage, "missingSharingLink")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
localStorage.removeItem("missingSharingLink");
|
||||||
var fileIndexList = _.compact(localStorage["file.list"].split(";"));
|
var fileIndexList = _.compact(localStorage["file.list"].split(";"));
|
||||||
_.each(fileIndexList, function(fileIndex) {
|
_.each(fileIndexList, function(fileIndex) {
|
||||||
var publishIndexList = _.compact(localStorage[fileIndex + ".publish"].split(";"));
|
var syncIndexList = localStorage[fileIndex + ".sync"].split(";");
|
||||||
_.each(publishIndexList, function(publishIndex) {
|
var publishIndexList = localStorage[fileIndex + ".publish"].split(";");
|
||||||
var publishAttributes = JSON.parse(localStorage[publishIndex]);
|
var attributesIndexList = _.compact(syncIndexList.concat(publishIndexList));
|
||||||
sharing.createLink(publishAttributes, function(shortUrl) {
|
_.each(attributesIndexList, function(attributesIndex) {
|
||||||
publishAttributes.sharingLink = shortUrl;
|
var attributes = JSON.parse(localStorage[attributesIndex]);
|
||||||
|
sharing.createLink(attributes, function(shortUrl) {
|
||||||
|
if(shortUrl !== undefined) {
|
||||||
|
localStorage[attributesIndex] = JSON.stringify(attributes);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
// Periodically check that links are not missing
|
||||||
|
if(viewerMode === false) {
|
||||||
|
core.addPeriodicCallback(checkMissingLinks);
|
||||||
|
}
|
||||||
|
|
||||||
|
core.onReady(function() {
|
||||||
|
if(viewerMode === false) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Check parameters to see if we have to download a shared document
|
||||||
|
var providerId = core.getURLParameter("provider");
|
||||||
|
if(providerId === undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var provider = providerMap[providerId];
|
||||||
|
if(provider === undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var importParameters = {};
|
||||||
|
_.each(provider.sharingAttributes, function(attributeName) {
|
||||||
|
importParameters[attributeName] = core.getURLParameter(attributeName);
|
||||||
|
});
|
||||||
|
$("#wmd-preview, #file-title").hide();
|
||||||
|
provider.importPublic(importParameters, function(error, title, content) {
|
||||||
|
$("#wmd-preview, #file-title").show();
|
||||||
|
if(error) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var fileIndex = core.fileManager.createFile(title, content, undefined, true);
|
||||||
|
core.fileManager.selectFile(fileIndex);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return sharing;
|
return sharing;
|
||||||
|
@ -45,6 +45,8 @@ function setupLocalStorage() {
|
|||||||
localStorage.removeItem("sync.dropbox.lastChangeId");
|
localStorage.removeItem("sync.dropbox.lastChangeId");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var PROVIDER_GDRIVE = "gdrive";
|
||||||
|
var PROVIDER_DROPBOX = "dropbox";
|
||||||
var SYNC_PROVIDER_GDRIVE = "sync." + PROVIDER_GDRIVE + ".";
|
var SYNC_PROVIDER_GDRIVE = "sync." + PROVIDER_GDRIVE + ".";
|
||||||
var SYNC_PROVIDER_DROPBOX = "sync." + PROVIDER_DROPBOX + ".";
|
var SYNC_PROVIDER_DROPBOX = "sync." + PROVIDER_DROPBOX + ".";
|
||||||
_.each(fileIndexList, function(fileIndex) {
|
_.each(fileIndexList, function(fileIndex) {
|
||||||
@ -120,6 +122,8 @@ function setupLocalStorage() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
// Force creation of sharing links
|
||||||
|
localStorage["missingSharingLink"] = true;
|
||||||
version = "v6";
|
version = "v6";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,7 +184,9 @@ define(["jquery", "core", "dropbox-provider", "gdrive-provider", "underscore"],
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
// Run sync function periodically
|
// Run sync function periodically
|
||||||
|
if(viewerMode === false) {
|
||||||
core.addPeriodicCallback(synchronizer.sync);
|
core.addPeriodicCallback(synchronizer.sync);
|
||||||
|
}
|
||||||
|
|
||||||
// Used to populate the "Manage synchronization" dialog
|
// Used to populate the "Manage synchronization" dialog
|
||||||
var lineTemplate = ['<div class="input-prepend input-append">',
|
var lineTemplate = ['<div class="input-prepend input-append">',
|
||||||
@ -197,7 +199,7 @@ define(["jquery", "core", "dropbox-provider", "gdrive-provider", "underscore"],
|
|||||||
var fileIndex = core.fileManager.getCurrentFileIndex();
|
var fileIndex = core.fileManager.getCurrentFileIndex();
|
||||||
var syncIndexList = _.compact(localStorage[fileIndex + ".sync"].split(";"));
|
var syncIndexList = _.compact(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();
|
var syncList = $("#manage-sync-list").empty();
|
||||||
if (syncIndexList.length > 0) {
|
if (syncIndexList.length > 0) {
|
||||||
$(".msg-sync-list").removeClass("hide");
|
$(".msg-sync-list").removeClass("hide");
|
||||||
} else {
|
} else {
|
||||||
@ -206,7 +208,7 @@ define(["jquery", "core", "dropbox-provider", "gdrive-provider", "underscore"],
|
|||||||
_.each(syncIndexList, function(syncIndex) {
|
_.each(syncIndexList, function(syncIndex) {
|
||||||
var syncAttributes = JSON.parse(localStorage[syncIndex]);
|
var syncAttributes = JSON.parse(localStorage[syncIndex]);
|
||||||
var syncDesc = syncAttributes.id || syncAttributes.path;
|
var syncDesc = syncAttributes.id || syncAttributes.path;
|
||||||
lineElement = $(_.template(lineTemplate, {
|
var lineElement = $(_.template(lineTemplate, {
|
||||||
provider: providerMap[syncAttributes.provider],
|
provider: providerMap[syncAttributes.provider],
|
||||||
syncDesc: syncDesc
|
syncDesc: syncDesc
|
||||||
}));
|
}));
|
||||||
@ -214,7 +216,7 @@ define(["jquery", "core", "dropbox-provider", "gdrive-provider", "underscore"],
|
|||||||
core.fileManager.removeSync(syncIndex);
|
core.fileManager.removeSync(syncIndex);
|
||||||
core.fileManager.updateFileTitles();
|
core.fileManager.updateFileTitles();
|
||||||
}));
|
}));
|
||||||
$("#manage-sync-list").append(lineElement);
|
syncList.append(lineElement);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
define(["jquery", "core", "tumblr-helper"], function($, core, tumblrHelper) {
|
define(["jquery", "core", "tumblr-helper"], function($, core, tumblrHelper) {
|
||||||
|
|
||||||
|
var PROVIDER_TUMBLR = "tumblr";
|
||||||
|
|
||||||
var tumblrProvider = {
|
var tumblrProvider = {
|
||||||
providerId: PROVIDER_TUMBLR,
|
providerId: PROVIDER_TUMBLR,
|
||||||
providerName: "Tumblr"
|
providerName: "Tumblr"
|
||||||
|
18
viewer.html
18
viewer.html
@ -5,8 +5,6 @@
|
|||||||
<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="description"
|
<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="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">
|
||||||
@ -29,10 +27,16 @@
|
|||||||
<div id="navbar" class="navbar navbar-fixed-top ui-layout-north">
|
<div id="navbar" class="navbar navbar-fixed-top ui-layout-north">
|
||||||
<div class="navbar-inner">
|
<div class="navbar-inner">
|
||||||
|
|
||||||
<ul class="pull-right hide" id="menu-bar">
|
<ul class="nav pull-right hide" id="menu-bar">
|
||||||
|
<li class="btn-group">
|
||||||
|
<button class="btn action-edit-document hide"
|
||||||
|
title="Edit this document">
|
||||||
|
<i class="icon-pencil"></i>
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
<li class="btn-group">
|
<li class="btn-group">
|
||||||
<button class="btn dropdown-toggle" data-toggle="dropdown"
|
<button class="btn dropdown-toggle" data-toggle="dropdown"
|
||||||
title="Save document">
|
title="Save this document">
|
||||||
<i class="icon-download-alt"></i>
|
<i class="icon-download-alt"></i>
|
||||||
</button>
|
</button>
|
||||||
<ul class="dropdown-menu">
|
<ul class="dropdown-menu">
|
||||||
@ -50,9 +54,9 @@
|
|||||||
</button>
|
</button>
|
||||||
<ul id="file-selector" class="dropdown-menu">
|
<ul id="file-selector" class="dropdown-menu">
|
||||||
</ul></li>
|
</ul></li>
|
||||||
<li class="btn-group"><a class="btn"
|
<li class="btn-group"><button class="btn action-open-stackedit"
|
||||||
href="." title="Open StackEdit"><i
|
title="Open StackEdit"><i
|
||||||
class="icon-stackedit"></i></a></li>
|
class="icon-stackedit"></i></button></li>
|
||||||
</ul>
|
</ul>
|
||||||
<ul class="nav pull-right">
|
<ul class="nav pull-right">
|
||||||
<li><i class="working-indicator icon-none"></i></li>
|
<li><i class="working-indicator icon-none"></i></li>
|
||||||
|
Loading…
Reference in New Issue
Block a user