Added any URL sharing support using download-proxy

This commit is contained in:
benweet 2013-05-11 00:49:50 +01:00
parent 47ef49808c
commit 89557f03a7
8 changed files with 77 additions and 15 deletions

View File

@ -1 +1 @@
CACHE MANIFEST # v27 CACHE: index.html viewer.html css/main-min.css js/main-min.js js/require.js img/ajax-loader.gif img/glyphicons-halflings.png img/glyphicons-halflings-white.png img/icons.png img/stackedit-32.ico img/stackedit-promo.png NETWORK: *
CACHE MANIFEST # v28 CACHE: index.html viewer.html css/main-min.css js/main-min.js js/require.js img/ajax-loader.gif img/glyphicons-halflings.png img/glyphicons-halflings-white.png img/icons.png img/stackedit-32.ico img/stackedit-promo.png NETWORK: *

3
css/main-min.css vendored
View File

@ -5556,6 +5556,9 @@ div.dropdown-menu blockquote {
div.dropdown-menu i {
margin-right: 0;
}
#link-container {
min-width: 210px;
}
#link-container .link-list {
margin-top: 10px;
}

View File

@ -264,6 +264,10 @@ div.dropdown-menu i {
margin-right: 0;
}
#link-container {
min-width: 210px;
}
#link-container .link-list {
margin-top: 10px;
}

View File

@ -44,10 +44,15 @@
</button>
<div id="link-container" class="dropdown-menu">
<div class="link-list"></div>
<p class="no-link">To share this document you need first to <a href="#"
class="action-publish-gist">publish it as a
Gist</a> in Markdown format.
<p class="no-link">To share this document you need first to <a
href="#" class="action-publish-gist">publish it as a Gist</a> in
Markdown format.
</p>
<blockquote class="muted">
<b>NOTE:</b> You can open any URL within StackEdit using <a
href="viewer.html?url=https://raw.github.com/benweet/stackedit/master/README.md"
title="Sharing example">viewer.html?url=...</a>
</blockquote>
</div>
</li>
<li class="btn-group"><button class="btn action-create-file"
@ -65,11 +70,12 @@
<ul id="file-selector" class="dropdown-menu">
</ul></li>
<li class="btn-group"><button class="btn dropdown-toggle"
data-toggle="dropdown" title="Menu"><i
class="icon-stackedit"></i>&nbsp;&nbsp;<b class="caret"></b></button>
data-toggle="dropdown" title="Menu">
<i class="icon-stackedit"></i>&nbsp;&nbsp;<b class="caret"></b>
</button>
<ul class="dropdown-menu">
<li><a href="viewer.html" title="Viewer"><i class="icon-fullscreen"></i>
Open in viewer</a></li>
<li><a href="viewer.html" title="Viewer"><i
class="icon-fullscreen"></i> Open in viewer</a></li>
<li><a class="action-download-md" href="#"><i
class="icon-download-alt"></i> Save as Markdown</a></li>
<li><a class="action-download-html" href="#"><i
@ -596,8 +602,8 @@
</dd>
<dd>
<a target="_blank"
href="https://plus.google.com/110816046787593496375" rel="publisher">Follow
on Google+</a>
href="https://plus.google.com/110816046787593496375"
rel="publisher">Follow on Google+</a>
</dd>
</dl>
<dl>

View File

@ -10,12 +10,13 @@ var BITLY_ACCESS_TOKEN = "317e033bfd48cf31155a68a536b1860013b09c4c";
var DEFAULT_FILE_TITLE = "Title";
var GDRIVE_DEFAULT_FILE_TITLE = "New Markdown document";
var CHECK_ONLINE_PERIOD = 60000;
var AJAX_TIMEOUT = 10000;
var AJAX_TIMEOUT = 15000;
var ASYNC_TASK_DEFAULT_TIMEOUT = 30000;
var ASYNC_TASK_LONG_TIMEOUT = 90000;
var SYNC_PERIOD = 180000;
var USER_IDLE_THRESHOLD = 300000;
var WELCOME_DOCUMENT_TITLE = "Welcome document";
var DOWNLOAD_PROXY_URL = "http://stackedit-download-proxy.herokuapp.com/";
// Use by Google's client.js
var delayedFunction = undefined;

44
js/download-provider.js Normal file
View File

@ -0,0 +1,44 @@
define(["jquery", "core", "async-runner"], function($, core, asyncRunner) {
var PROVIDER_DOWNLOAD = "download";
var downloadProvider = {
providerId: PROVIDER_DOWNLOAD,
sharingAttributes: ["url"]
};
downloadProvider.importPublic = function(importParameters, callback) {
var task = asyncRunner.createTask();
var title = undefined;
var content = undefined;
task.onRun(function() {
var url = importParameters.url;
var slashUrl = url.lastIndexOf("/");
if(slashUrl === -1) {
task.error(new Error("Invalid URL parameter."));
return;
}
title = url.substring(slashUrl + 1);
$.ajax({
url : DOWNLOAD_PROXY_URL + "download?url=" + url,
type: "GET",
dataType : "text",
timeout : AJAX_TIMEOUT
}).done(function(result, textStatus, jqXHR) {
content = result;
task.chain();
}).fail(function(jqXHR) {
task.error(new Error("Unable to access URL " + url));
});
});
task.onSuccess(function() {
callback(undefined, title, content);
});
task.onError(function(error) {
callback(error);
});
asyncRunner.addTask(task);
};
return downloadProvider;
});

2
js/main-min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
define(["jquery", "core", "async-runner", "gist-provider", "underscore"], function($, core, asyncRunner) {
define(["jquery", "core", "async-runner", "download-provider", "gist-provider", "underscore"], function($, core, asyncRunner) {
var sharing = {};
// Create a map with providerId: providerObject
@ -115,7 +115,7 @@ define(["jquery", "core", "async-runner", "gist-provider", "underscore"], functi
// Check parameters to see if we have to download a shared document
var providerId = core.getURLParameter("provider");
if(providerId === undefined) {
return;
providerId = "download";
}
var provider = providerMap[providerId];
if(provider === undefined) {
@ -123,7 +123,11 @@ define(["jquery", "core", "async-runner", "gist-provider", "underscore"], functi
}
var importParameters = {};
_.each(provider.sharingAttributes, function(attributeName) {
importParameters[attributeName] = core.getURLParameter(attributeName);
var parameter = core.getURLParameter(attributeName);
if(!parameter) {
return;
}
importParameters[attributeName] = parameter;
});
$("#wmd-preview, #file-title").hide();
provider.importPublic(importParameters, function(error, title, content) {