Stackedit/public/res/extensions/buttonShare.js

52 lines
1.7 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-08-22 00:19:59 +00:00
var buttonShare = new Extension("buttonShare", 'Button "Share"', true, true);
2013-06-22 23:48:57 +00:00
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
};
2013-11-07 23:10:38 +00:00
var fileDesc;
var linkListElt;
var $noLinkElt;
2013-05-29 19:55:23 +00:00
var refreshDocumentSharing = function(fileDescParameter) {
if(fileDescParameter !== undefined && fileDescParameter !== fileDesc) {
return;
}
2013-08-22 00:19:59 +00:00
var linkListHtml = _.reduce(fileDesc.publishLocations, function(result, attributes) {
2013-05-29 19:55:23 +00:00
if(attributes.sharingLink) {
2013-08-22 00:19:59 +00:00
result += _.template(buttonShareLocationHTML, {
2013-05-29 19:55:23 +00:00
link: attributes.sharingLink
2013-08-22 00:19:59 +00:00
});
2013-05-29 19:55:23 +00:00
}
2013-08-22 00:19:59 +00:00
return result;
}, '');
linkListElt.innerHTML = linkListHtml;
$noLinkElt.toggleClass('hide', linkListHtml.length !== 0);
2013-05-29 19:55:23 +00:00
};
buttonShare.onFileSelected = function(fileDescParameter) {
fileDesc = fileDescParameter;
refreshDocumentSharing(fileDescParameter);
};
buttonShare.onNewPublishSuccess = refreshDocumentSharing;
buttonShare.onPublishRemoved = refreshDocumentSharing;
2013-08-22 00:19:59 +00:00
buttonShare.onReady = function() {
var linkContainerElt = document.querySelector('.link-container');
linkListElt = linkContainerElt.querySelector('.link-list');
$noLinkElt = $(linkContainerElt.querySelector('.no-link'));
};
2013-05-29 19:55:23 +00:00
return buttonShare;
2013-05-26 22:59:17 +00:00
});