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
|
|
|
|
|
2013-11-07 23:10:38 +00:00
|
|
|
|
var layout;
|
2013-05-29 19:55:23 +00:00
|
|
|
|
documentTitle.onLayoutCreated = function(layoutParameter) {
|
|
|
|
|
layout = layoutParameter;
|
|
|
|
|
};
|
|
|
|
|
|
2013-11-07 23:10:38 +00:00
|
|
|
|
var fileDesc;
|
|
|
|
|
var $fileTitleNavbar;
|
2013-12-16 00:31:40 +00:00
|
|
|
|
var updateTitle = _.debounce(function(fileDescParameter) {
|
2013-05-29 19:55:23 +00:00
|
|
|
|
if(fileDescParameter !== fileDesc) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var title = fileDesc.title;
|
2014-01-13 01:39:28 +00:00
|
|
|
|
document.title = "StackEdit – " + title;
|
2013-09-26 23:27:38 +00:00
|
|
|
|
$fileTitleNavbar.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
|
|
|
|
|
2013-12-16 00:31:40 +00:00
|
|
|
|
layout && layout.resizeAll();
|
|
|
|
|
}, 50);
|
2013-05-29 19:55:23 +00:00
|
|
|
|
|
|
|
|
|
documentTitle.onFileSelected = function(fileDescParameter) {
|
|
|
|
|
fileDesc = fileDescParameter;
|
|
|
|
|
updateTitle(fileDescParameter);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
documentTitle.onTitleChanged = updateTitle;
|
|
|
|
|
documentTitle.onSyncExportSuccess = updateTitle;
|
|
|
|
|
documentTitle.onSyncRemoved = updateTitle;
|
|
|
|
|
documentTitle.onNewPublishSuccess = updateTitle;
|
|
|
|
|
documentTitle.onPublishRemoved = updateTitle;
|
2013-12-16 00:31:40 +00:00
|
|
|
|
documentTitle.onReady = updateTitle;
|
2013-09-26 23:27:38 +00:00
|
|
|
|
|
|
|
|
|
documentTitle.onReady = function() {
|
|
|
|
|
$fileTitleNavbar = $(".file-title-navbar");
|
|
|
|
|
// Add a scrolling effect on hover
|
|
|
|
|
$fileTitleNavbar.hover(function() {
|
|
|
|
|
var scrollLeft = $fileTitleNavbar[0].scrollWidth - $fileTitleNavbar.outerWidth();
|
|
|
|
|
$fileTitleNavbar.stop(true, true).animate({
|
|
|
|
|
scrollLeft: scrollLeft
|
|
|
|
|
}, scrollLeft * 15, 'linear');
|
|
|
|
|
}, function() {
|
|
|
|
|
$fileTitleNavbar.stop(true, true).scrollLeft(0);
|
|
|
|
|
}).click(function() {
|
|
|
|
|
$fileTitleNavbar.stop(true, true).scrollLeft(0);
|
|
|
|
|
});
|
|
|
|
|
};
|
2013-05-29 19:55:23 +00:00
|
|
|
|
|
|
|
|
|
return documentTitle;
|
|
|
|
|
|
2013-05-26 22:59:17 +00:00
|
|
|
|
});
|