Refactor sharing links

This commit is contained in:
benweet 2014-10-12 18:57:58 +01:00
parent af05cb3a75
commit 10addd0acc
22 changed files with 185 additions and 114 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

View File

@ -7,7 +7,7 @@ define([
"text!html/buttonHtmlCodeSettingsBlock.html"
], function($, _, utils, Extension, buttonHtmlCodeHTML, buttonHtmlCodeSettingsBlockHTML) {
var buttonHtmlCode = new Extension("buttonHtmlCode", 'Button "HTML code"', true, true);
var buttonHtmlCode = new Extension("buttonHtmlCode", 'Button "HTML code"', true);
buttonHtmlCode.settingsBlock = buttonHtmlCodeSettingsBlockHTML;
buttonHtmlCode.defaultConfig = {
template: "<%= documentHTML %>"

View File

@ -7,7 +7,7 @@ define([
"text!html/buttonStatSettingsBlock.html"
], function($, _, utils, Extension, buttonStatHTML, buttonStatSettingsBlockHTML) {
var buttonStat = new Extension("buttonStat", 'Button "Statistics"', true, true);
var buttonStat = new Extension("buttonStat", 'Button "Statistics"', true);
buttonStat.settingsBlock = buttonStatSettingsBlockHTML;
buttonStat.defaultConfig = {
name1: "Characters",

View File

@ -18,29 +18,40 @@ define([
};
var fileDesc;
var shareListElt;
var $msgShareListElt;
var $msgNoShareElt;
var shareEditorListElt;
var shareViewerListElt;
var $msgNoShareEditorElt;
var $msgNoShareViewerElt;
var refreshDocumentSharing = function(fileDescParameter) {
if(fileDescParameter !== undefined && fileDescParameter !== fileDesc) {
return;
}
var linkListHtml = _.reduce(fileDesc.publishLocations, function(result, attributes) {
var params = sharing.getViewerParams(attributes);
var editorLinkListHtml = _.reduce(fileDesc.syncLocations, function(result, attributes) {
var params = sharing.getEditorParams(attributes);
if(params) {
var link = constants.MAIN_URL + 'viewer?' + $.param(params);
var link = constants.MAIN_URL + 'editor#!' + $.param(params);
result += _.template(dialogManageSharingLocationHTML, {
link: link,
title: fileDesc.title
link: link
});
}
return result;
}, '');
shareListElt.innerHTML = linkListHtml;
shareEditorListElt.innerHTML = editorLinkListHtml;
$msgNoShareEditorElt.toggleClass('hide', editorLinkListHtml.length !== 0);
$msgShareListElt.toggleClass('hide', linkListHtml.length === 0);
$msgNoShareElt.toggleClass('hide', linkListHtml.length !== 0);
var viewerLinkListHtml = _.reduce(fileDesc.publishLocations, function(result, attributes) {
var params = sharing.getViewerParams(attributes);
if(params) {
var link = constants.MAIN_URL + 'viewer#!' + $.param(params);
result += _.template(dialogManageSharingLocationHTML, {
link: link
});
}
return result;
}, '');
shareViewerListElt.innerHTML = viewerLinkListHtml;
$msgNoShareViewerElt.toggleClass('hide', viewerLinkListHtml.length !== 0);
};
dialogManageSharing.onFileSelected = function(fileDescParameter) {
@ -48,21 +59,22 @@ define([
refreshDocumentSharing(fileDescParameter);
};
dialogManageSharing.onNewPublishSuccess = function(fileDescParameter, publishAttributes) {
refreshDocumentSharing(fileDescParameter);
if(sharing.getViewerParams(publishAttributes)) {
$('.modal').modal('hide');
$('.modal-manage-sharing').modal('show');
}
};
dialogManageSharing.onSyncExportSuccess = refreshDocumentSharing;
dialogManageSharing.onSyncRemoved = refreshDocumentSharing;
dialogManageSharing.onNewPublishSuccess = refreshDocumentSharing;
dialogManageSharing.onPublishRemoved = refreshDocumentSharing;
dialogManageSharing.onReady = function() {
var modalElt = document.querySelector('.modal-manage-sharing');
shareListElt = modalElt.querySelector('.share-list');
$msgShareListElt = $(modalElt.querySelectorAll('.msg-share-list'));
$msgNoShareElt = $(modalElt.querySelectorAll('.msg-no-share'));
shareEditorListElt = modalElt.querySelector('.share-editor-list');
shareViewerListElt = modalElt.querySelector('.share-viewer-list');
$msgNoShareEditorElt = $(modalElt.querySelectorAll('.msg-no-share-editor'));
$msgNoShareViewerElt = $(modalElt.querySelectorAll('.msg-no-share-viewer'));
$(modalElt).on('show.bs.modal', function() {
$(modalElt.querySelector('input')).each(function() {
this.value = $(this).data('value');
});
});
};
return dialogManageSharing;

View File

@ -33,6 +33,9 @@ define([
var eventMgr;
userCustom.onEventMgrCreated = function(eventMgrParameter) {
eventMgr = eventMgrParameter;
eventMgr.addListener('onReady', function() {
utils.createTooltip(".tooltip-usercustom-extension", tooltipUserCustomExtensionHTML);
});
};
userCustom.onLoadSettings = function() {
@ -62,9 +65,5 @@ define([
}
};
userCustom.onReady = function() {
utils.createTooltip(".tooltip-usercustom-extension", tooltipUserCustomExtensionHTML);
};
return userCustom;
});

View File

@ -49,6 +49,14 @@ define([
this.getUserId = function() {
return userId;
};
var authUser = parseInt(storage[accountId + '.authUser'] || 0);
this.setAuthUser = function(value) {
authUser = value;
storage[accountId + '.authUser'] = authUser;
};
this.getAuthUser = function() {
return authUser;
};
}
var googleHelper = {};
@ -190,7 +198,7 @@ define([
}
else {
// Success but we need to check the user id
authorizationMgr.authuser = authuser;
authorizationMgr.setAuthUser(authuser);
immediate === true && authuser++;
task.chain(getTokenInfo);
}

View File

@ -382,7 +382,7 @@
Are you sure you want to delete "<span class="file-title"></span>"?
</p>
<blockquote>
<b>Note:</b> It won't delete the file on synchronized locations.
<p><b>Note:</b> It won't delete the file on synchronized locations.</p>
</blockquote>
</div>
<div class="modal-footer">
@ -656,10 +656,10 @@
This will save "<span class="file-title"></span>" to CouchDB and keep it synchronized.
</p>
<blockquote>
<b>Tip:</b> You can use a
<p><b>Tip:</b> You can use a
<a href="http://jekyllrb.com/docs/frontmatter/"
target="_blank">YAML front matter</a> to specify tags for your document.
Alternatively, you can place comma separated tags in squared brackets at the beginning of the document title.
target="_blank">YAML front matter</a> to specify tags for your document.</p>
<p>Alternatively, you can place comma separated tags in squared brackets at the beginning of the document title.</p>
</blockquote>
</div>
<div class="modal-footer">
@ -688,8 +688,8 @@
</p>
<div class="sync-list"></div>
<blockquote>
<b>Note:</b> Removing a synchronized location will not delete any
file.
<p><b>Note:</b> Removing a synchronized location will not delete any
file.</p>
</blockquote>
</div>
<div class="modal-footer">
@ -962,7 +962,7 @@
</p>
<div class="publish-list"></div>
<blockquote>
<b>Note:</b> Removing a publish location will not delete the actual publication.
<p><b>Note:</b> Removing a publish location will not delete the actual publication.</p>
</blockquote>
</div>
<div class="modal-footer">
@ -983,23 +983,28 @@
<h2 class="modal-title">Sharing</h2>
</div>
<div class="modal-body">
<p class="msg-share-list hide">
"<span class="file-title"></span>" can be shared using the following link(s):
</p>
<div class="msg-share-list share-list hide"></div>
<p class="msg-no-share hide alert alert-danger"><b>No sharing link yet!</b>
</p>
<p class="msg-no-share hide">To collaborate on this document, use <i class="icon-provider-gdrive"></i> <b>Google Drive</b>
or <i class="icon-provider-dropbox"></i> <b>Dropbox</b> synchronization from the <i class="icon-provider-stackedit"></i> menu.
</p>
<p class="msg-no-share hide">To share a frozen version of this document within StackEdit, just <a
href="#" class="action-publish-gist" data-dismiss="modal">publish it as a Gist</a> in
Markdown format from the <i class="icon-provider-stackedit"></i> menu.
<p>Collaborate on "<span class="file-title"></span>" using the following link(s):</p>
<p class="msg-no-share-editor"><b>No sharing link yet!</b>
</p>
<div class="share-editor-list"></div>
<blockquote>
<b>Tip:</b> You can open any URL within StackEdit using <a
<p><b>Note:</b> To collaborate on this document, just <a
href="#" class="action-sync-export-dialog-couchdb" data-dismiss="modal">save it on CouchDB</a>.
To collaborate via Google Drive or Dropbox, you have to share the file manually from Google Drive/Dropbox websites.</p>
</blockquote>
<p>Share a read-only version of "<span class="file-title"></span>" using the following link(s):</p>
<p class="msg-no-share-viewer"><b>No sharing link yet!</b>
</p>
<div class="share-viewer-list"></div>
<blockquote>
<p><b>Note:</b> To share a read-only version of this document, just <a
href="#" class="action-publish-gist" data-dismiss="modal">publish it as a Gist</a> in
Markdown format.</p>
</blockquote>
<blockquote>
<p><b>Tip:</b> You can open any markdown URL within StackEdit Viewer using <a
href="viewer#!url=https://raw.github.com/benweet/stackedit/master/README.md"
title="Sharing example"><code>viewer#!url=</code></a>.
title="Sharing example"><code>viewer#!url=</code></a>.</p>
</blockquote>
</div>
<div class="modal-footer">
@ -1334,8 +1339,10 @@
<div class="modal-body">
<p>StackEdit has stopped because another instance was running in
the same browser.</p>
<blockquote>If you want to reopen StackEdit, click on
"Reload".</blockquote>
<blockquote>
<p>If you want to reopen StackEdit, click on
"Reload".</p>
</blockquote>
</div>
<div class="modal-footer">
<a href="javascript:window.location.reload();"
@ -1355,7 +1362,9 @@
</div>
<div class="modal-body">
<p class="redirect-msg"></p>
<blockquote>Please click <b>OK</b> to proceed.</blockquote>
<blockquote>
<p>Please click <b>OK</b> to proceed.</p>
</blockquote>
</div>
<div class="modal-footer">
<a class="btn btn-default" data-dismiss="modal">Cancel</a>
@ -1417,7 +1426,7 @@
</div>
<div class="modal-body">
<p>To perform this request, you need to configure another Google Drive account in StackEdit.</p>
<blockquote>Do you want to proceed?</blockquote>
<blockquote><b>Do you want to proceed?</b></blockquote>
</div>
<div class="modal-footer">
<a href="#" class="btn btn-default action-remove-google-drive-state"
@ -1441,7 +1450,9 @@
<p>This feature is restricted to sponsor users as it's a web service hosted on Amazon EC2.
Note that sponsoring StackEdit would cost you only $5/year.</p>
<p>To see how a PDF looks <a target="_blank" href="/Welcome%20document.pdf">click here</a>.</p>
<blockquote><b>Tip:</b> PDFs are fully customizable via Settings>Advanced>PDF template/options.</blockquote>
<blockquote>
<p><b>Tip:</b> PDFs are fully customizable via Settings>Advanced>PDF template/options.</p>
</blockquote>
</div>
<div class="modal-footer">
<a href="#" class="btn btn-primary"

View File

@ -97,8 +97,10 @@
<div class="modal-body">
<p>StackEdit has stopped because another instance was running in
the same browser.</p>
<blockquote>If you want to reopen StackEdit, click on
"Reload".</blockquote>
<blockquote>
<p>If you want to reopen StackEdit, click on
"Reload".</p>
</blockquote>
</div>
<div class="modal-footer">
<a href="javascript:window.location.reload();"

View File

@ -58,8 +58,8 @@
</div>
</div>
<blockquote>
<b>Note:</b> Removing a local document will not delete the linked file on Google
Drive.
<p><b>Note:</b> Removing a local document will not delete the linked file on Google
Drive.</p>
</blockquote>
</div>
<div class="modal-footer">

View File

@ -48,8 +48,8 @@
</a>
</p>
<blockquote>
<b>Tip:</b> You can move or rename the file afterwards within Google
Drive.
<p><b>Tip:</b> You can move or rename the file afterwards within Google
Drive.</p>
</blockquote>
</div>
<div class="modal-footer">

View File

@ -1,5 +1,7 @@
<div class="entry">
<div class="input-group">
<a href="<%= link %>" class="input-group-addon" title="Sharing location"><i
class="icon-link"></i></a> <input class="form-control" type="text"
value="<%= link %>" disabled />
data-value="<%= link %>">
</div>
</div>

View File

@ -1,5 +1,5 @@
<p>Renders modified sections only.</p>
<blockquote>
<b>Note:</b> Document sections are based on title elements (h1, h2...). Therefore if
your document does not contain any title, performance will not be increased.
<p><b>Note:</b> Document sections are based on title elements (h1, h2...). Therefore if
your document does not contain any title, performance will not be increased.</p>
</blockquote>

View File

@ -1,7 +1,7 @@
<p>Binds together editor and preview scrollbars.</p>
<blockquote>
<b>Note:</b> The mapping between Markdown and HTML is based on the
<p><b>Note:</b> The mapping between Markdown and HTML is based on the
position of the title elements (h1, h2...) in the page. Therefore if
your document does not contain any title, the mapping will be linear and
consequently less accurate.
consequently less accurate.</p>
</blockquote>

View File

@ -19,6 +19,6 @@ cond(no)->op
```</code>
</pre>
<blockquote>
<b>Note:</b> Markdown Extra extension has to be enabled with GFM fenced code blocks option.
<p><b>Note:</b> Markdown Extra extension has to be enabled with GFM fenced code blocks option.</p>
</blockquote>

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

View File

@ -22,6 +22,9 @@ define([
couchdbProvider.importPreferencesInputIds = [
PROVIDER_COUCHDB + "-tag"
];
couchdbProvider.editorSharingAttributes = [
"id"
];
couchdbProvider.getSyncLocationLink = function(attributes) {
return [
@ -57,14 +60,26 @@ define([
return syncAttributes;
}
function importFilesFromIds(ids) {
couchdbHelper.downloadContent(ids.map(function(id) {
function importFilesFromIds(ids, cb) {
var importIds = [];
_.each(ids, function(id) {
var syncIndex = createSyncIndex(id);
var fileDesc = fileMgr.getFileFromSyncIndex(syncIndex);
if(fileDesc !== undefined) {
return eventMgr.onError('"' + fileDesc.title + '" is already in your local documents.');
}
importIds.push(id);
});
if(ids.length === 0) {
return cb && cb();
}
couchdbHelper.downloadContent(importIds.map(function(id) {
return {
_id: id
};
}), function(error, result) {
if(error) {
return;
return cb && cb(error);
}
var fileDescList = [];
var fileDesc;
@ -82,6 +97,7 @@ define([
eventMgr.onSyncImportSuccess(fileDescList, couchdbProvider);
fileMgr.selectFile(fileDesc);
}
cb && cb();
});
}
@ -93,16 +109,7 @@ define([
.compact()
.unique()
.value();
var importIds = [];
_.each(ids, function(id) {
var syncIndex = createSyncIndex(id);
var fileDesc = fileMgr.getFileFromSyncIndex(syncIndex);
if(fileDesc !== undefined) {
return eventMgr.onError('"' + fileDesc.title + '" is already in your local documents.');
}
importIds.push(id);
});
importFilesFromIds(importIds);
importFilesFromIds(ids);
}
};
@ -228,6 +235,10 @@ define([
});
};
couchdbProvider.importPrivate = function(importParameters, callback) {
importFilesFromIds([importParameters.id], callback);
};
eventMgr.addListener("onReady", function() {
if(constants.COUCHDB_URL == settings.couchdbUrl) {
$('.msg-default-couchdb').removeClass('hide');

View File

@ -25,7 +25,7 @@ define([
];
gdriveProvider.getSyncLocationLink = gdriveProvider.getPublishLocationLink = function(attributes) {
var authuser = googleHelper.getAuthorizationMgr(accountId).authuser;
var authuser = googleHelper.getAuthorizationMgr(accountId).getAuthUser();
return [
'https://docs.google.com/file/d/',
attributes.id,
@ -59,14 +59,14 @@ define([
return syncAttributes;
}
function importFilesFromIds(ids) {
function importFilesFromIds(ids, cb) {
googleHelper.downloadMetadata(ids, accountId, function(error, result) {
if(error) {
return;
return cb && cb(error);
}
googleHelper.downloadContent(result, accountId, function(error, result) {
if(error) {
return;
return cb && cb(error);
}
var fileDescList = [];
var fileDesc;
@ -88,6 +88,7 @@ define([
eventMgr.onSyncImportSuccess(fileDescList, gdriveProvider);
fileMgr.selectFile(fileDesc);
}
cb && cb();
});
});
}
@ -369,8 +370,7 @@ define([
storage.removeItem('gdrive.state');
if(state.action == "create") {
eventMgr.onMessage('Please wait while creating your document on ' + providerName);
googleHelper.upload(undefined, state.folderId, constants.GDRIVE_DEFAULT_FILE_TITLE, settings.defaultContent, undefined, undefined, accountId, function(error, file) {
googleHelper.upload(undefined, state.folderId, constants.GDRIVE_DEFAULT_FILE_TITLE, settings.defaultContent, undefined, undefined, accountId, utils.lockUI(function(error, file) {
if(error) {
return;
}
@ -380,7 +380,7 @@ define([
var fileDesc = fileMgr.createFile(file.title, file.content, undefined, syncLocations);
fileMgr.selectFile(fileDesc);
eventMgr.onMessage('"' + file.title + '" created successfully on ' + providerName + '.');
});
}));
}
else if(state.action == "open") {
var importIds = [];
@ -394,8 +394,7 @@ define([
importIds.push(id);
}
});
eventMgr.onMessage('Please wait while loading your document from ' + providerName);
importFilesFromIds(importIds);
importFilesFromIds(importIds, utils.lockUI());
}
});

View File

@ -7,6 +7,7 @@ define([
"fileMgr",
"classes/AsyncTask",
"classes/Provider",
"providers/couchdbProvider",
"providers/downloadProvider",
"providers/gistProvider"
], function($, _, constants, utils, eventMgr, fileMgr, AsyncTask, Provider) {
@ -61,36 +62,49 @@ define([
eventMgr.addListener("onReady", function() {
// Check parameters to see if we have to download a shared document
var providerId = utils.getURLParameter("provider");
var importParameters, provider, providerId = utils.getURLParameter("provider");
if(window.viewerMode) {
if(providerId === undefined) {
providerId = "download";
}
var provider = providerMap[providerId];
provider = providerMap[providerId];
if(provider === undefined) {
return;
}
var importParameters = {};
_.each(provider.viewerSharingAttributes, function(attributeName) {
importParameters = {};
if(_.some(provider.viewerSharingAttributes, function(attributeName) {
var parameter = utils.getURLParameter(attributeName);
if(!parameter) {
importParameters = undefined;
return;
return 1;
}
importParameters[attributeName] = parameter;
});
if(importParameters === undefined) {
})) {
return;
}
$("#preview-contents, .navbar .file-title-navbar").hide();
provider.importPublic(importParameters, function(error, title, content) {
$("#preview-contents, .navbar .file-title-navbar").show();
provider.importPublic(importParameters, utils.lockUI(function(error, title, content) {
if(error) {
return;
}
var fileDesc = fileMgr.createFile(title, content, undefined, undefined, true);
fileMgr.selectFile(fileDesc);
});
}));
}
else if(providerId) {
provider = providerMap[providerId];
if(provider === undefined) {
return;
}
importParameters = {};
if(_.some(provider.editorSharingAttributes, function(attributeName) {
var parameter = utils.getURLParameter(attributeName);
if(!parameter) {
return 1;
}
importParameters[attributeName] = parameter;
})) {
return;
}
provider.importPrivate(importParameters, utils.lockUI());
}
});

View File

@ -1014,17 +1014,14 @@ a {
.modal-manage-sync .sync-list,
.modal-manage-publish .publish-list,
.modal-manage-sharing .share-list {
.modal-manage-sharing .share-editor-list,
.modal-manage-sharing .share-viewer-list {
margin-bottom: 20px;
.entry {
margin-bottom: 10px;
}
}
.share-list .form-control {
width: 280px
}
.publish-custom-template-collapse {
margin-bottom: 0;
textarea {

View File

@ -418,6 +418,21 @@ define([
});
};
utils.lockUI = function(cb) {
var eltsToHide = $([
'#wmd-input',
'#preview-contents',
'.navbar .file-title-navbar',
'.navbar .left-buttons',
'.navbar .right-buttons',
'.navbar .buttons-dropdown'
].join(',')).hide();
return function() {
eltsToHide.show();
cb && cb.apply(null, arguments);
};
};
var entityMap = {
"&": "&amp;",
"<": "&lt;",

View File

@ -5,16 +5,17 @@
<title>StackEdit Editor</title>
<link rel="canonical" href="https://stackedit.io/editor">
<link rel="icon" href="res-min/img/stackedit-32.ico" type="image/x-icon">
<link rel="icon" sizes="192x192" href="res-min/img/logo-highres.png">
<link rel="shortcut icon" href="res-min/img/stackedit-32.ico" type="image/x-icon">
<link rel="shortcut icon" sizes="196x196" href="res-min/img/nice-highres.png">
<link rel="shortcut icon" sizes="192x192" href="res-min/img/logo-highres.png">
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="res-min/img/logo-ipad-retina.png">
<meta name="description" content="Full-featured, 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="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="msvalidate.01" content="5E47EE6F67B069C17E3CDD418351A612">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="/res-min/img/logo-ipad-retina.png"/>
<script>
// Use ?debug to serve original JavaScript files instead of minified
window.baseDir = 'res';