You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cryptpad/www/common/sframe-common-title.js

96 lines
3.1 KiB
JavaScript

define(['jquery'], function ($) {
var module = {};
module.create = function (cfg, onLocal, Common, metadataMgr) {
var exp = {};
exp.defaultTitle = Common.getDefaultTitle();
exp.title = document.title; // TOOD slides
cfg = cfg || {};
var getHeadingText = cfg.getHeadingText || function () { return; };
7 years ago
/* var updateLocalTitle = function (newTitle) {
console.error(newTitle);
exp.title = newTitle;
onLocal();
if (typeof cfg.updateLocalTitle === "function") {
cfg.updateLocalTitle(newTitle);
} else {
document.title = newTitle;
}
7 years ago
};*/
var $title;
exp.setToolbar = function (toolbar) {
$title = toolbar && toolbar.title;
};
exp.getTitle = function () { return exp.title; };
var isDefaultTitle = exp.isDefaultTitle = function (){return exp.title === exp.defaultTitle;};
var suggestTitle = exp.suggestTitle = function (fallback) {
if (isDefaultTitle()) {
return getHeadingText() || fallback || "";
} else {
return exp.title || getHeadingText() || exp.defaultTitle;
}
};
7 years ago
/*var renameCb = function (err, newTitle) {
if (err) { return; }
onLocal();
7 years ago
//updateLocalTitle(newTitle);
};*/
// update title: href is optional; if not specified, we use window.location.href
exp.updateTitle = function (newTitle, cb) {
cb = cb || $.noop;
if (newTitle === exp.title) { return; }
// Change the title now, and set it back to the old value if there is an error
var oldTitle = exp.title;
Common.setPadTitleInDrive(newTitle, function (err, data) {
if (err) {
console.log("Couldn't set pad title");
console.error(err);
updateLocalTitle(oldTitle);
return void cb(err);
}
7 years ago
metadataMgr.updateTitle(newTitle);
//onLocal();
cb(null, data);
if (!$title) { return; }
});
};
// TODO not needed?
/*exp.updateDefaultTitle = function (newDefaultTitle) {
exp.defaultTitle = newDefaultTitle;
if (!$title) { return; }
$title.find('input').attr("placeholder", exp.defaultTitle);
};*/
metadataMgr.onChange(function () {
var md = metadataMgr.getMetadata();
7 years ago
$title.find('span.title').text(md.title || md.defaultTitle);
$title.find('input').val(md.title || md.defaultTitle);
//exp.updateTitle(md.title || md.defaultTitle);
});
exp.getTitleConfig = function () {
return {
7 years ago
updateTitle: exp.updateTitle,
suggestName: suggestTitle,
defaultName: exp.defaultTitle
};
};
return exp;
};
return module;
});