Stackedit/js/extensions/button-share.js

72 lines
2.2 KiB
JavaScript
Raw Normal View History

2013-05-27 19:45:33 +00:00
define([
"jquery",
"underscore"
], function($, _) {
2013-05-26 22:59:17 +00:00
2013-05-27 19:45:33 +00:00
var buttonShare = {
extensionId: "buttonShare",
extensionName: 'Button "Share"',
2013-05-26 22:59:17 +00:00
optional: true,
2013-05-27 19:45:33 +00:00
settingsBloc: '<p>Adds a "Share document" button in the navigation bar.</p>'
2013-05-26 22:59:17 +00:00
};
2013-05-28 23:41:09 +00:00
buttonShare.onCreateButton = function() {
return $([
'<button class="btn dropdown-toggle" data-toggle="dropdown" title="Share this document">',
'<i class="icon-link"></i>',
'</button>',
'<div id="link-container" class="dropdown-menu pull-right">',
'<div class="link-list"></div>',
2013-05-29 00:08:25 +00:00
'<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.',
2013-05-28 23:41:09 +00:00
'</p>',
'<blockquote class="muted">',
2013-05-29 00:08:25 +00:00
'<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"',
2013-05-28 23:41:09 +00:00
'title="Sharing example">viewer.html?url=...</a>',
'</blockquote>',
'</div>'].join("")
);
};
2013-05-26 22:59:17 +00:00
var fileDesc = undefined;
var lineTemplate = [
'<div class="input-prepend">',
'<a href="<%= link %>" class="add-on" title="Sharing location"><i class="icon-link"></i></a>',
'<input class="span2" type="text" value="<%= link %>" readonly />',
2013-05-27 19:45:33 +00:00
'</div>'].join("");
2013-05-26 22:59:17 +00:00
var refreshDocumentSharing = function(fileDescParameter) {
if(fileDescParameter !== undefined && fileDescParameter !== fileDesc) {
return;
}
var linkList = $("#link-container .link-list").empty();
$("#link-container .no-link").show();
var attributesList = _.values(fileDesc.publishLocations);
_.each(attributesList, function(attributes) {
if(attributes.sharingLink) {
var lineElement = $(_.template(lineTemplate, {
link: attributes.sharingLink
}));
lineElement.click(function(event) {
event.stopPropagation();
});
linkList.append(lineElement);
$("#link-container .no-link").hide();
}
});
};
2013-05-27 19:45:33 +00:00
buttonShare.onFileSelected = function(fileDescParameter) {
2013-05-26 22:59:17 +00:00
fileDesc = fileDescParameter;
refreshDocumentSharing(fileDescParameter);
};
2013-05-27 19:45:33 +00:00
buttonShare.onNewPublishSuccess = refreshDocumentSharing;
buttonShare.onPublishRemoved = refreshDocumentSharing;
2013-05-26 22:59:17 +00:00
2013-05-27 19:45:33 +00:00
return buttonShare;
2013-05-26 22:59:17 +00:00
});