2013-05-27 19:45:33 +00:00
|
|
|
define([
|
|
|
|
"jquery",
|
|
|
|
"underscore"
|
|
|
|
], function($, _) {
|
2013-05-26 22:59:17 +00:00
|
|
|
|
|
|
|
var documentTitle = {
|
|
|
|
extensionId: "documentTitle",
|
|
|
|
extensionName: "Document title",
|
2013-05-27 19:45:33 +00:00
|
|
|
settingsBloc: '<p>Responsible for showing the document title in the navigation bar.</p>'
|
2013-05-26 22:59:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
var layout = undefined;
|
|
|
|
documentTitle.onLayoutCreated = function(layoutParameter) {
|
|
|
|
layout = layoutParameter;
|
|
|
|
};
|
|
|
|
|
|
|
|
var fileDesc = undefined;
|
|
|
|
var updateTitle = function(fileDescParameter) {
|
2013-05-27 19:45:33 +00:00
|
|
|
if(fileDescParameter !== fileDesc) {
|
2013-05-26 22:59:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
function composeTitle(fileDesc) {
|
|
|
|
var result = [];
|
|
|
|
var syncAttributesList = _.values(fileDesc.syncLocations);
|
|
|
|
var publishAttributesList = _.values(fileDesc.publishLocations);
|
|
|
|
var attributesList = syncAttributesList.concat(publishAttributesList);
|
|
|
|
_.chain(attributesList).sortBy(function(attributes) {
|
2013-05-27 19:45:33 +00:00
|
|
|
return attributes.provider.providerId;
|
2013-05-26 22:59:17 +00:00
|
|
|
}).each(function(attributes) {
|
2013-05-27 19:45:33 +00:00
|
|
|
result.push('<i class="icon-' + attributes.provider.providerId + '"></i>');
|
2013-05-26 22:59:17 +00:00
|
|
|
});
|
|
|
|
result.push(" ");
|
|
|
|
result.push(fileDesc.title);
|
|
|
|
return result.join("");
|
|
|
|
}
|
|
|
|
|
|
|
|
var title = fileDesc.title;
|
|
|
|
document.title = "StackEdit - " + title;
|
|
|
|
$("#file-title").html(composeTitle(fileDesc));
|
|
|
|
$(".file-title").text(title);
|
|
|
|
$("#file-title-input").val(title);
|
|
|
|
|
|
|
|
if(layout !== undefined) {
|
|
|
|
// Use defer to make sure UI has been updated
|
|
|
|
_.defer(layout.resizeAll);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
documentTitle.onFileSelected = function(fileDescParameter) {
|
|
|
|
fileDesc = fileDescParameter;
|
|
|
|
updateTitle(fileDescParameter);
|
|
|
|
};
|
|
|
|
|
|
|
|
documentTitle.onTitleChanged = updateTitle;
|
|
|
|
documentTitle.onSyncExportSuccess = updateTitle;
|
|
|
|
documentTitle.onSyncRemoved = updateTitle;
|
|
|
|
documentTitle.onNewPublishSuccess = updateTitle;
|
|
|
|
documentTitle.onPublishRemoved = updateTitle;
|
|
|
|
|
|
|
|
return documentTitle;
|
|
|
|
|
|
|
|
});
|