Esanders has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/300049

Change subject: Give tool's a short title property and use them in MenuGroups
......................................................................

Give tool's a short title property and use them in MenuGroups

Bug: T92315
Change-Id: Id14f5367cd0a05921ce5e1af48bca2a027c973a9
---
M demos/pages/toolbars.js
M src/Tool.js
M src/toolgroups/MenuToolGroup.js
3 files changed, 47 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/oojs/ui refs/changes/49/300049/1

diff --git a/demos/pages/toolbars.js b/demos/pages/toolbars.js
index 580b46a..f5e0cf1 100644
--- a/demos/pages/toolbars.js
+++ b/demos/pages/toolbars.js
@@ -25,7 +25,7 @@
                toolbars[ i ].getToolAccelerator = getToolAccelerator;
        }
 
-       function createTool( toolbar, group, name, icon, title, init, onSelect, 
displayBothIconAndLabel ) {
+       function createTool( toolbar, group, name, icon, title, shortTitle, 
init, onSelect, displayBothIconAndLabel ) {
                var Tool = function () {
                        Tool.parent.apply( this, arguments );
                        this.toggled = false;
@@ -51,6 +51,7 @@
                Tool.static.group = group;
                Tool.static.icon = icon;
                Tool.static.title = title;
+               Tool.static.shortTitle = shortTitle;
                Tool.static.displayBothIconAndLabel = !!displayBothIconAndLabel;
                return Tool;
        }
@@ -238,8 +239,8 @@
 
        toolGroups = {
                barTools: [
-                       [ 'barTool', 'image', 'Basic tool in bar' ],
-                       [ 'disabledBarTool', 'image', 'Basic tool in bar 
disabled', setDisabled ]
+                       [ 'barTool', 'image', 'Basic tool in bar', '' ],
+                       [ 'disabledBarTool', 'image', 'Basic tool in bar 
disabled', '', setDisabled ]
                ],
 
                disabledBarTools: [
@@ -249,7 +250,7 @@
                listTools: [
                        [ 'listTool', 'image', 'First basic tool in list' ],
                        [ 'listTool1', 'image', 'Basic tool in list' ],
-                       [ 'listTool3', 'image', 'Basic disabled tool in list', 
setDisabled ],
+                       [ 'listTool3', 'image', 'Basic disabled tool in list', 
'', setDisabled ],
                        [ 'listTool6', 'image', 'A final tool' ]
                ],
 
@@ -268,13 +269,13 @@
                ],
 
                autoDisableListTools: [
-                       [ 'autoDisableListTool', 'image', 'Click to disable 
this tool', null, setDisabled ]
+                       [ 'autoDisableListTool', 'image', 'Click to disable 
this tool', '', null, setDisabled ]
                ],
 
                menuTools: [
-                       [ 'menuTool', 'image', 'Basic tool' ],
-                       [ 'iconlessMenuTool', null, 'Tool without an icon' ],
-                       [ 'disabledMenuTool', 'image', 'Basic tool disabled', 
setDisabled ]
+                       [ 'menuTool', 'image', 'Basic tool', 'Basic' ],
+                       [ 'iconlessMenuTool', null, 'Tool without an icon', 'No 
icon' ],
+                       [ 'disabledMenuTool', 'image', 'Basic tool disabled', 
'Basic disabled', setDisabled ]
                ],
 
                disabledMenuTools: [
@@ -296,11 +297,11 @@
                ],
 
                cite: [
-                       [ 'citeTool', 'citeArticle', 'Cite', null, null, true ]
+                       [ 'citeTool', 'citeArticle', 'Cite', '', null, null, 
true ]
                ],
 
                citeDisabled: [
-                       [ 'citeToolDisabled', 'citeArticle', 'Cite', 
setDisabled, null, true ]
+                       [ 'citeToolDisabled', 'citeArticle', 'Cite', '', 
setDisabled, null, true ]
                ]
        };
 
diff --git a/src/Tool.js b/src/Tool.js
index 6caeed3..3f44a0c 100644
--- a/src/Tool.js
+++ b/src/Tool.js
@@ -90,6 +90,7 @@
                .toggleClass( 'oo-ui-tool-with-label', 
this.constructor.static.displayBothIconAndLabel )
                .append( this.$link );
        this.setTitle( config.title || this.constructor.static.title );
+       this.setShortTitle( config.shortTitle || 
this.constructor.static.shortTitle );
 };
 
 /* Setup */
@@ -142,6 +143,18 @@
  * @property {string|Function}
  */
 OO.ui.Tool.static.title = '';
+
+/**
+ * Tool short title text or a function that returns shortTitle text. The value 
of the static property is overridden if the #shortTitle config option is used.
+ *
+ * If the value is empty, the title will be used.
+ *
+ * @abstract
+ * @static
+ * @inheritable
+ * @property {string|Function|null}
+ */
+OO.ui.Tool.static.shortTitle = '';
 
 /**
  * Display both icon and label when the tool is used in a {@link 
OO.ui.BarToolGroup bar} toolgroup.
@@ -274,6 +287,28 @@
 };
 
 /**
+ * Set the tool #shortTitle.
+ *
+ * @param {string|Function} shortTitle Short title text or a function that 
returns text
+ * @chainable
+ */
+OO.ui.Tool.prototype.setShortTitle = function ( shortTitle ) {
+       this.shortTitle = OO.ui.resolveMsg( shortTitle );
+       this.updateTitle();
+       return this;
+};
+
+
+/**
+ * Get the tool #shortTitle, a shorter version of the tool's title.
+ *
+ * @return {string} Short title text
+ */
+OO.ui.Tool.prototype.getShortTitle = function () {
+       return this.shortTitle || this.title;
+};
+
+/**
  * Get the tool's symbolic name.
  *
  * @return {string} Symbolic name of tool
diff --git a/src/toolgroups/MenuToolGroup.js b/src/toolgroups/MenuToolGroup.js
index f19bc7d..9016946 100644
--- a/src/toolgroups/MenuToolGroup.js
+++ b/src/toolgroups/MenuToolGroup.js
@@ -146,7 +146,7 @@
 
        for ( name in this.tools ) {
                if ( this.tools[ name ].isActive() ) {
-                       labelTexts.push( this.tools[ name ].getTitle() );
+                       labelTexts.push( this.tools[ name ].getShortTitle() );
                }
        }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/300049
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id14f5367cd0a05921ce5e1af48bca2a027c973a9
Gerrit-PatchSet: 1
Gerrit-Project: oojs/ui
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to