Stackedit/js/extensions/documentTitle.js

45 lines
1.2 KiB
JavaScript
Raw Normal View History

2013-05-27 19:45:33 +00:00
define([
"jquery",
2013-06-22 23:48:57 +00:00
"underscore",
"classes/Extension",
], function($, _, Extension) {
2013-05-29 19:55:23 +00:00
2013-06-22 23:48:57 +00:00
var documentTitle = new Extension("documentTitle", "Document Title");
2013-05-29 19:55:23 +00:00
var layout = undefined;
documentTitle.onLayoutCreated = function(layoutParameter) {
layout = layoutParameter;
};
var fileDesc = undefined;
var updateTitle = function(fileDescParameter) {
if(fileDescParameter !== fileDesc) {
return;
}
var title = fileDesc.title;
document.title = "StackEdit - " + title;
2013-08-12 00:10:26 +00:00
$(".file-title-navbar").html(fileDesc.composeTitle());
2013-05-29 19:55:23 +00:00
$(".file-title").text(title);
2013-08-06 23:52:58 +00:00
$(".input-file-title").val(title);
2013-05-29 19:55:23 +00:00
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;
2013-05-26 22:59:17 +00:00
});