mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/WikiEditor
synced 2024-11-24 00:06:49 +00:00
Allow a free-text string 'title' field when adding characters
When adding characters to the WikiEditor toolbar, it's possible to set titleMsg, but it's not possible to set a free-form string title. This is rather limiting for personal or site-local scripts which might wish to use a title tooltip but not be able to set a MediaWiki message. This commit adds the ability to pass a 'title' field of a character definition object. If both 'title' and 'titleMsg' are defined, 'titleMsg' is used. Bug: T292434 Change-Id: I00775d5e4690c0fd45c20639a122c39dc756135e
This commit is contained in:
parent
8a57d552bf
commit
b87612d937
|
@ -581,11 +581,18 @@
|
|||
}
|
||||
if ( character && 'action' in character && 'label' in character ) {
|
||||
actions[ character.label ] = character.action;
|
||||
if ( character.titleMsg !== undefined || character.title !== undefined ) {
|
||||
var title;
|
||||
if ( character.titleMsg !== undefined ) {
|
||||
// eslint-disable-next-line mediawiki/msg-doc
|
||||
title = mw.msg( character.titleMsg );
|
||||
} else {
|
||||
title = character.title;
|
||||
}
|
||||
|
||||
return mw.html.element(
|
||||
'span',
|
||||
// eslint-disable-next-line mediawiki/msg-doc
|
||||
{ rel: character.label, title: mw.msg( character.titleMsg ) },
|
||||
{ rel: character.label, title: title },
|
||||
character.label
|
||||
);
|
||||
} else {
|
||||
|
|
|
@ -237,11 +237,24 @@
|
|||
data = {
|
||||
section: 'info',
|
||||
page: 'emoticons',
|
||||
characters: [ ':)', ':))', ':(', '<3', ';)' ]
|
||||
characters: [
|
||||
':)', ':))', ':(', '<3', ';)',
|
||||
{
|
||||
label: ':-s',
|
||||
title: 'unsure-face',
|
||||
action: {
|
||||
type: 'replace',
|
||||
options: {
|
||||
peri: ':-s',
|
||||
selectPeri: false
|
||||
}
|
||||
}
|
||||
} ]
|
||||
};
|
||||
assert.strictEqual( this.$ui.find( '*[rel="info"].section *[rel="emoticons"].page *[rel=":))"]' ).length, 0, 'Before adding characters' );
|
||||
this.$target.wikiEditor( 'addToToolbar', data );
|
||||
assert.strictEqual( this.$ui.find( '*[rel="info"].section *[rel="emoticons"].page *[rel=":))"]' ).length, 1, 'After adding characters' );
|
||||
assert.strictEqual( this.$ui.find( '*[rel="info"].section *[rel="emoticons"].page *[title="unsure-face"]' ).length, 1, 'After adding characters find the set title' );
|
||||
|
||||
// Remove character
|
||||
data = {
|
||||
|
|
Loading…
Reference in a new issue