Stackedit/js/extensions/buttonShare.js

53 lines
1.6 KiB
JavaScript
Raw Normal View History

2013-05-27 19:45:33 +00:00
define([
"jquery",
2013-06-10 21:22:32 +00:00
"underscore",
"text!html/buttonShare.html",
"text!html/buttonShareLocation.html",
], function($, _, buttonShareHTML, buttonShareLocationHTML) {
2013-05-29 19:55:23 +00:00
var buttonShare = {
extensionId: "buttonShare",
extensionName: 'Button "Share"',
2013-05-26 22:59:17 +00:00
optional: true,
2013-05-29 19:55:23 +00:00
settingsBloc: '<p>Adds a "Share document" button in the navigation bar.</p>'
};
buttonShare.onCreateButton = function() {
2013-06-10 21:22:32 +00:00
return $(buttonShareHTML);
2013-05-29 19:55:23 +00:00
};
var fileDesc = undefined;
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) {
2013-06-10 21:22:32 +00:00
var lineElement = $(_.template(buttonShareLocationHTML, {
2013-05-29 19:55:23 +00:00
link: attributes.sharingLink
}));
lineElement.click(function(event) {
event.stopPropagation();
});
linkList.append(lineElement);
$("#link-container .no-link").hide();
}
});
};
buttonShare.onFileSelected = function(fileDescParameter) {
fileDesc = fileDescParameter;
refreshDocumentSharing(fileDescParameter);
};
buttonShare.onNewPublishSuccess = refreshDocumentSharing;
buttonShare.onPublishRemoved = refreshDocumentSharing;
return buttonShare;
2013-05-26 22:59:17 +00:00
});