Stackedit/js/extensions/buttonShare.js

47 lines
1.5 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",
2013-06-22 23:48:57 +00:00
"classes/Extension",
2013-06-10 21:22:32 +00:00
"text!html/buttonShare.html",
"text!html/buttonShareLocation.html",
2013-06-22 23:48:57 +00:00
], function($, _, Extension, buttonShareHTML, buttonShareLocationHTML) {
2013-05-29 19:55:23 +00:00
2013-06-22 23:48:57 +00:00
var buttonShare = new Extension("buttonShare", 'Button "Share"', true);
buttonShare.settingsBlock = '<p>Adds a "Share document" button in the navigation bar.</p>';
2013-05-29 19:55:23 +00:00
buttonShare.onCreateButton = function() {
2013-07-30 08:46:36 +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;
}
2013-08-05 01:31:14 +00:00
var linkList = $(".link-container .link-list").empty();
$(".link-container .no-link").show();
2013-05-29 19:55:23 +00:00
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
}));
linkList.append(lineElement);
2013-08-05 01:31:14 +00:00
$(".link-container .no-link").hide();
2013-05-29 19:55:23 +00:00
}
});
};
buttonShare.onFileSelected = function(fileDescParameter) {
fileDesc = fileDescParameter;
refreshDocumentSharing(fileDescParameter);
};
buttonShare.onNewPublishSuccess = refreshDocumentSharing;
buttonShare.onPublishRemoved = refreshDocumentSharing;
return buttonShare;
2013-05-26 22:59:17 +00:00
});