Stackedit/js/extensions/buttonPublish.js

76 lines
2.0 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/buttonPublish.html",
2013-06-22 23:48:57 +00:00
], function($, _, Extension, buttonPublishHTML) {
2013-05-29 19:55:23 +00:00
2013-06-22 23:48:57 +00:00
var buttonPublish = new Extension("buttonPublish", 'Button "Publish"');
2013-08-04 17:42:22 +00:00
// buttonPublish.settingsBlock = '<p>Adds a "Publish document" button in the
// navigation bar.</p>';
2013-05-29 19:55:23 +00:00
var button = undefined;
var currentFileDesc = undefined;
var publishRunning = false;
var hasPublications = false;
var isOffline = false;
// Enable/disable the button
function updateButtonState() {
if(button === undefined) {
return;
}
if(publishRunning === true || hasPublications === false || isOffline === true) {
button.addClass("disabled");
}
else {
button.removeClass("disabled");
}
}
;
var publisher = undefined;
buttonPublish.onPublisherCreated = function(publisherParameter) {
publisher = publisherParameter;
};
buttonPublish.onCreateButton = function() {
2013-06-10 21:22:32 +00:00
button = $(buttonPublishHTML).click(function() {
2013-05-29 19:55:23 +00:00
if(!$(this).hasClass("disabled")) {
publisher.publish();
}
});
2013-07-30 08:46:36 +00:00
return button[0];
2013-05-29 19:55:23 +00:00
};
buttonPublish.onPublishRunning = function(isRunning) {
publishRunning = isRunning;
updateButtonState();
};
buttonPublish.onOfflineChanged = function(isOfflineParameter) {
isOffline = isOfflineParameter;
updateButtonState();
};
// Check that current file has publications
var checkPublication = function() {
if(_.size(currentFileDesc.publishLocations) === 0) {
hasPublications = false;
}
else {
hasPublications = true;
}
updateButtonState();
};
buttonPublish.onFileSelected = function(fileDesc) {
currentFileDesc = fileDesc;
checkPublication();
};
buttonPublish.onPublishRemoved = checkPublication;
buttonPublish.onNewPublishSuccess = checkPublication;
return buttonPublish;
2013-05-27 19:45:33 +00:00
});