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 { div.dropdown-menu i {
margin-right: 0; margin-right: 0;
} }
#link-container {
min-width: 210px;
}
#link-container .link-list { #link-container .link-list {
margin-top: 10px; margin-top: 10px;
} }

View File

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

View File

@ -44,10 +44,15 @@
</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">To share this document you need first to <a href="#" <p class="no-link">To share this document you need first to <a
class="action-publish-gist">publish it as a href="#" class="action-publish-gist">publish it as a Gist</a> in
Gist</a> in Markdown format. Markdown format.
</p> </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> </div>
</li> </li>
<li class="btn-group"><button class="btn action-create-file" <li class="btn-group"><button class="btn action-create-file"
@ -65,11 +70,12 @@
<ul id="file-selector" class="dropdown-menu"> <ul id="file-selector" class="dropdown-menu">
</ul></li> </ul></li>
<li class="btn-group"><button class="btn dropdown-toggle" <li class="btn-group"><button class="btn dropdown-toggle"
data-toggle="dropdown" title="Menu"><i data-toggle="dropdown" title="Menu">
class="icon-stackedit"></i>&nbsp;&nbsp;<b class="caret"></b></button> <i class="icon-stackedit"></i>&nbsp;&nbsp;<b class="caret"></b>
</button>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li><a href="viewer.html" title="Viewer"><i class="icon-fullscreen"></i> <li><a href="viewer.html" title="Viewer"><i
Open in viewer</a></li> class="icon-fullscreen"></i> Open in viewer</a></li>
<li><a class="action-download-md" href="#"><i <li><a class="action-download-md" href="#"><i
class="icon-download-alt"></i> Save as Markdown</a></li> class="icon-download-alt"></i> Save as Markdown</a></li>
<li><a class="action-download-html" href="#"><i <li><a class="action-download-html" href="#"><i
@ -596,8 +602,8 @@
</dd> </dd>
<dd> <dd>
<a target="_blank" <a target="_blank"
href="https://plus.google.com/110816046787593496375" rel="publisher">Follow href="https://plus.google.com/110816046787593496375"
on Google+</a> rel="publisher">Follow on Google+</a>
</dd> </dd>
</dl> </dl>
<dl> <dl>

View File

@ -10,12 +10,13 @@ var BITLY_ACCESS_TOKEN = "317e033bfd48cf31155a68a536b1860013b09c4c";
var DEFAULT_FILE_TITLE = "Title"; var DEFAULT_FILE_TITLE = "Title";
var GDRIVE_DEFAULT_FILE_TITLE = "New Markdown document"; var GDRIVE_DEFAULT_FILE_TITLE = "New Markdown document";
var CHECK_ONLINE_PERIOD = 60000; var CHECK_ONLINE_PERIOD = 60000;
var AJAX_TIMEOUT = 10000; var AJAX_TIMEOUT = 15000;
var ASYNC_TASK_DEFAULT_TIMEOUT = 30000; 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 WELCOME_DOCUMENT_TITLE = "Welcome document"; var WELCOME_DOCUMENT_TITLE = "Welcome document";
var DOWNLOAD_PROXY_URL = "http://stackedit-download-proxy.herokuapp.com/";
// Use by Google's client.js // Use by Google's client.js
var delayedFunction = undefined; 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 = {}; var sharing = {};
// Create a map with providerId: providerObject // 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 // Check parameters to see if we have to download a shared document
var providerId = core.getURLParameter("provider"); var providerId = core.getURLParameter("provider");
if(providerId === undefined) { if(providerId === undefined) {
return; providerId = "download";
} }
var provider = providerMap[providerId]; var provider = providerMap[providerId];
if(provider === undefined) { if(provider === undefined) {
@ -123,7 +123,11 @@ define(["jquery", "core", "async-runner", "gist-provider", "underscore"], functi
} }
var importParameters = {}; var importParameters = {};
_.each(provider.sharingAttributes, function(attributeName) { _.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(); $("#wmd-preview, #file-title").hide();
provider.importPublic(importParameters, function(error, title, content) { provider.importPublic(importParameters, function(error, title, content) {