From b87612d937355725bd4177e9d0fa3e3f55d8d471 Mon Sep 17 00:00:00 2001 From: Inductiveload Date: Mon, 4 Oct 2021 14:49:36 +0100 Subject: [PATCH] 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 --- modules/jquery.wikiEditor.toolbar.js | 13 ++++++++++--- tests/qunit/ext.wikiEditor.toolbar.test.js | 15 ++++++++++++++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/modules/jquery.wikiEditor.toolbar.js b/modules/jquery.wikiEditor.toolbar.js index 63d110c9..f8547da5 100644 --- a/modules/jquery.wikiEditor.toolbar.js +++ b/modules/jquery.wikiEditor.toolbar.js @@ -581,11 +581,18 @@ } if ( character && 'action' in character && 'label' in character ) { actions[ character.label ] = character.action; - if ( character.titleMsg !== undefined ) { + 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 { diff --git a/tests/qunit/ext.wikiEditor.toolbar.test.js b/tests/qunit/ext.wikiEditor.toolbar.test.js index 934e5597..ecfd864e 100644 --- a/tests/qunit/ext.wikiEditor.toolbar.test.js +++ b/tests/qunit/ext.wikiEditor.toolbar.test.js @@ -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 = {