Ability to edit the title in the toolbar by clicking it
This commit is contained in:
parent
10bb5e1607
commit
9e92a597b3
@ -302,13 +302,17 @@ define([
|
|||||||
var type = parsed.type;
|
var type = parsed.type;
|
||||||
var untitledIndex = 1;
|
var untitledIndex = 1;
|
||||||
var name = (Messages.type)[type] + ' - ' + new Date().toString().split(' ').slice(0,4).join(' ');
|
var name = (Messages.type)[type] + ' - ' + new Date().toString().split(' ').slice(0,4).join(' ');
|
||||||
|
return name;
|
||||||
|
/*
|
||||||
|
* Pad titles are shared in the document so it does not make sense anymore to avoid duplicates
|
||||||
if (isNameAvailable(name, parsed, recentPads)) { return name; }
|
if (isNameAvailable(name, parsed, recentPads)) { return name; }
|
||||||
while (!isNameAvailable(name + ' - ' + untitledIndex, parsed, recentPads)) { untitledIndex++; }
|
while (!isNameAvailable(name + ' - ' + untitledIndex, parsed, recentPads)) { untitledIndex++; }
|
||||||
return name + ' - ' + untitledIndex;
|
return name + ' - ' + untitledIndex;
|
||||||
|
*/
|
||||||
};
|
};
|
||||||
var isDefaultName = common.isDefaultName = function (parsed, title) {
|
var isDefaultName = common.isDefaultName = function (parsed, title) {
|
||||||
var name = getDefaultName(parsed, []);
|
var name = getDefaultName(parsed, []);
|
||||||
return title.slice(0, name.length) === name;
|
return title === name;
|
||||||
};
|
};
|
||||||
|
|
||||||
var makePad = function (href, title) {
|
var makePad = function (href, title) {
|
||||||
@ -622,6 +626,20 @@ define([
|
|||||||
var renamePad = common.renamePad = function (title, callback) {
|
var renamePad = common.renamePad = function (title, callback) {
|
||||||
if (title === null) { return; }
|
if (title === null) { return; }
|
||||||
|
|
||||||
|
if (title.trim() === "") {
|
||||||
|
var parsed = parsePadUrl(window.location.href);
|
||||||
|
title = getDefaultName(parsed);
|
||||||
|
}
|
||||||
|
|
||||||
|
common.setPadTitle(title, function (err, data) {
|
||||||
|
if (err) {
|
||||||
|
console.log("unable to set pad title");
|
||||||
|
console.log(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
callback(null, title);
|
||||||
|
});
|
||||||
|
/* Pad titles are shared in the document. We don't check for duplicates anymore.
|
||||||
common.causesNamingConflict(title, function (err, conflicts) {
|
common.causesNamingConflict(title, function (err, conflicts) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log("Unable to determine if name caused a conflict");
|
console.log("Unable to determine if name caused a conflict");
|
||||||
@ -644,6 +662,7 @@ define([
|
|||||||
callback(null, title);
|
callback(null, title);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
};
|
};
|
||||||
var createButton = common.createButton = function (type, rightside, data, callback) {
|
var createButton = common.createButton = function (type, rightside, data, callback) {
|
||||||
var button;
|
var button;
|
||||||
|
|||||||
@ -303,29 +303,40 @@ define([
|
|||||||
$(lagElement).append(lagLight);
|
$(lagElement).append(lagLight);
|
||||||
};
|
};
|
||||||
|
|
||||||
var createTitle = function ($container, readOnly, cb) {
|
var createTitle = function ($container, readOnly, config, Cryptpad) {
|
||||||
|
var callback = config.onRename;
|
||||||
|
var placeholder = config.defaultName;
|
||||||
|
|
||||||
var $titleContainer = $('<span>', {
|
var $titleContainer = $('<span>', {
|
||||||
id: 'toolbarTitle',
|
id: 'toolbarTitle',
|
||||||
'class': TITLE_CLS
|
'class': TITLE_CLS
|
||||||
}).appendTo($container);
|
}).appendTo($container);
|
||||||
var $text = $('<span>').appendTo($titleContainer);
|
var $text = $('<span>').appendTo($titleContainer);
|
||||||
if (readOnly === 1) { return; }
|
if (readOnly === 1 || typeof(Cryptpad) === "unedfined") { return; }
|
||||||
var $input = $('<input>', {
|
var $input = $('<input>', {
|
||||||
type: 'text'
|
type: 'text',
|
||||||
|
placeholder: placeholder
|
||||||
}).appendTo($titleContainer).hide();
|
}).appendTo($titleContainer).hide();
|
||||||
|
$input.on('mousedown', function (e) {
|
||||||
|
if (!$input.is(":focus")) {
|
||||||
|
$input.focus();
|
||||||
|
}
|
||||||
|
e.stopPropagation();
|
||||||
|
return true;
|
||||||
|
});
|
||||||
$input.on('keyup', function (e) {
|
$input.on('keyup', function (e) {
|
||||||
if (e.which === 13) {
|
if (e.which === 13) {
|
||||||
Cryptpad.renamePad(title, function (err, newtitle) {
|
var name = $input.val().trim();
|
||||||
|
Cryptpad.renamePad($input.val(), function (err, newtitle) {
|
||||||
if (err) { return; }
|
if (err) { return; }
|
||||||
$text.text(newtitle);
|
$text.text(newtitle);
|
||||||
cb(null, newtitle);
|
callback(null, newtitle);
|
||||||
$input.hide();
|
$input.hide();
|
||||||
$text.show();
|
$text.show();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$text.on('click', function () {
|
$text.on('click', function () {
|
||||||
console.log('click');
|
|
||||||
$text.hide();
|
$text.hide();
|
||||||
$input.val($text.text());
|
$input.val($text.text());
|
||||||
$input.show();
|
$input.show();
|
||||||
@ -335,12 +346,13 @@ define([
|
|||||||
|
|
||||||
var create = Bar.create = function ($container, myUserName, realtime, getLag, userList, config) {
|
var create = Bar.create = function ($container, myUserName, realtime, getLag, userList, config) {
|
||||||
var readOnly = (typeof config.readOnly !== "undefined") ? (config.readOnly ? 1 : 0) : -1;
|
var readOnly = (typeof config.readOnly !== "undefined") ? (config.readOnly ? 1 : 0) : -1;
|
||||||
|
var Cryptpad = config.common;
|
||||||
|
|
||||||
var toolbar = createRealtimeToolbar($container);
|
var toolbar = createRealtimeToolbar($container);
|
||||||
var userListElement = createUserList(toolbar.find('.' + LEFTSIDE_CLS), readOnly);
|
var userListElement = createUserList(toolbar.find('.' + LEFTSIDE_CLS), readOnly);
|
||||||
var spinner = createSpinner(toolbar.find('.' + RIGHTSIDE_CLS));
|
var spinner = createSpinner(toolbar.find('.' + RIGHTSIDE_CLS));
|
||||||
var lagElement = createLagElement(toolbar.find('.' + RIGHTSIDE_CLS));
|
var lagElement = createLagElement(toolbar.find('.' + RIGHTSIDE_CLS));
|
||||||
var $titleElement = createTitle(toolbar.find('.' + TOP_CLS), readOnly, config.onRename);
|
var $titleElement = createTitle(toolbar.find('.' + TOP_CLS), readOnly, config.title, Cryptpad);
|
||||||
var userData = config.userData;
|
var userData = config.userData;
|
||||||
// readOnly = 1 (readOnly enabled), 0 (disabled), -1 (old pad without readOnly mode)
|
// readOnly = 1 (readOnly enabled), 0 (disabled), -1 (old pad without readOnly mode)
|
||||||
var saveElement;
|
var saveElement;
|
||||||
|
|||||||
@ -86,6 +86,8 @@ define([
|
|||||||
|
|
||||||
editor.on('instanceReady', function (Ckeditor) {
|
editor.on('instanceReady', function (Ckeditor) {
|
||||||
var $bar = $('#pad-iframe')[0].contentWindow.$('#cke_1_toolbox');
|
var $bar = $('#pad-iframe')[0].contentWindow.$('#cke_1_toolbox');
|
||||||
|
var parsedHash = Cryptpad.parsePadUrl(window.location.href);
|
||||||
|
var defaultName = Cryptpad.getDefaultName(parsedHash);
|
||||||
|
|
||||||
if (readOnly) {
|
if (readOnly) {
|
||||||
$('#pad-iframe')[0].contentWindow.$('#cke_1_toolbox > .cke_toolbar').hide();
|
$('#pad-iframe')[0].contentWindow.$('#cke_1_toolbox > .cke_toolbar').hide();
|
||||||
@ -318,13 +320,10 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
var suggestName = function () {
|
var suggestName = function () {
|
||||||
var parsed = Cryptpad.parsePadUrl(window.location.href);
|
if (Cryptpad.isDefaultName(parsedHash, document.title)) {
|
||||||
var name = Cryptpad.getDefaultName(parsed, []);
|
return getHeadingText() || defaultName;
|
||||||
|
|
||||||
if (Cryptpad.isDefaultName(parsed, document.title)) {
|
|
||||||
return getHeadingText() || document.title;
|
|
||||||
} else {
|
} else {
|
||||||
return document.title || getHeadingText() || name;
|
return document.title || getHeadingText() || defaultName;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -350,6 +349,8 @@ define([
|
|||||||
};
|
};
|
||||||
if (!isDefaultTitle()) {
|
if (!isDefaultTitle()) {
|
||||||
hjson[3].metadata.title = document.title;
|
hjson[3].metadata.title = document.title;
|
||||||
|
} else {
|
||||||
|
hjson[3].metadata.title = "";
|
||||||
}
|
}
|
||||||
return stringify(hjson);
|
return stringify(hjson);
|
||||||
};
|
};
|
||||||
@ -396,14 +397,16 @@ define([
|
|||||||
// Change the title now, and set it back to the old value if there is an error
|
// Change the title now, and set it back to the old value if there is an error
|
||||||
var oldTitle = document.title;
|
var oldTitle = document.title;
|
||||||
document.title = newTitle;
|
document.title = newTitle;
|
||||||
Cryptpad.setPadTitle(newTitle, function (err, data) {
|
Cryptpad.renamePad(newTitle, function (err, data) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log("Couldn't set pad title");
|
console.log("Couldn't set pad title");
|
||||||
console.error(err);
|
console.error(err);
|
||||||
document.title = oldTitle;
|
document.title = oldTitle;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$bar.find('.' + Toolbar.constants.title).find('span').text(newTitle);
|
document.title = data;
|
||||||
|
$bar.find('.' + Toolbar.constants.title).find('span').text(data);
|
||||||
|
$bar.find('.' + Toolbar.constants.title).find('input').val(data);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -417,7 +420,7 @@ define([
|
|||||||
// Update the local user data
|
// Update the local user data
|
||||||
addToUserList(userData);
|
addToUserList(userData);
|
||||||
}
|
}
|
||||||
if (peerMetadata.metadata.title) {
|
if (typeof peerMetadata.metadata.title !== "undefined") {
|
||||||
updateTitle(peerMetadata.metadata.title);
|
updateTitle(peerMetadata.metadata.title);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -526,7 +529,11 @@ define([
|
|||||||
userData: userList,
|
userData: userList,
|
||||||
readOnly: readOnly,
|
readOnly: readOnly,
|
||||||
ifrw: ifrw,
|
ifrw: ifrw,
|
||||||
onRename: renameCb
|
title: {
|
||||||
|
onRename: renameCb,
|
||||||
|
defaultName: defaultName
|
||||||
|
},
|
||||||
|
common: Cryptpad
|
||||||
};
|
};
|
||||||
if (readOnly) {delete config.changeNameID; }
|
if (readOnly) {delete config.changeNameID; }
|
||||||
toolbar = info.realtime.toolbar = Toolbar.create($bar, info.myID, info.realtime, info.getLag, info.userList, config);
|
toolbar = info.realtime.toolbar = Toolbar.create($bar, info.myID, info.realtime, info.getLag, info.userList, config);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user