Esanders has uploaded a new change for review.
https://gerrit.wikimedia.org/r/119744
Change subject: Use registry for tool group types
......................................................................
Use registry for tool group types
Per the comment, so they can be overridden.
Change-Id: I10e5d256ccf9db33be428bcd47db160ecf3a9632
---
M src/Toolbar.js
M src/toolgroups/BarToolGroup.js
M src/toolgroups/ListToolGroup.js
M src/toolgroups/MenuToolGroup.js
4 files changed, 27 insertions(+), 10 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/oojs/ui refs/changes/44/119744/1
diff --git a/src/Toolbar.js b/src/Toolbar.js
index 2088184..1d14057 100644
--- a/src/Toolbar.js
+++ b/src/Toolbar.js
@@ -8,11 +8,12 @@
*
* @constructor
* @param {OO.ui.ToolFactory} toolFactory Factory for creating tools
+ * @param {OO.Factory} toolGroupFactory Factory for creating tool groups
* @param {Object} [config] Configuration options
* @cfg {boolean} [actions] Add an actions section opposite to the tools
* @cfg {boolean} [shadow] Add a shadow below the toolbar
*/
-OO.ui.Toolbar = function OoUiToolbar( toolFactory, config ) {
+OO.ui.Toolbar = function OoUiToolbar( toolFactory, toolGroupFactory, config ) {
// Configuration initialization
config = config || {};
@@ -25,6 +26,7 @@
// Properties
this.toolFactory = toolFactory;
+ this.toolGroupFactory = toolGroupFactory;
this.groups = [];
this.tools = {};
this.$bar = this.$( '<div>' );
@@ -48,6 +50,11 @@
this.$bar.append( '<div class="oo-ui-toolbar-shadow"></div>' );
}
this.$element.addClass( 'oo-ui-toolbar' ).append( this.$bar );
+
+ // Register default toolgroups
+ this.toolGroupFactory.register( OO.ui.BarToolGroup );
+ this.toolGroupFactory.register( OO.ui.ListToolGroup );
+ this.toolGroupFactory.register( OO.ui.MenuToolGroup );
};
/* Inheritance */
@@ -66,6 +73,15 @@
*/
OO.ui.Toolbar.prototype.getToolFactory = function () {
return this.toolFactory;
+};
+
+/**
+ * Get the tool group factory.
+ *
+ * @return {OO.Factory} Tool group factory
+ */
+OO.ui.Toolbar.prototype.getToolGroupFactory = function () {
+ return this.toolGroupFactory;
};
/**
@@ -107,13 +123,7 @@
OO.ui.Toolbar.prototype.setup = function ( groups ) {
var i, len, type, group,
items = [],
- // TODO: Use a registry instead
- defaultType = 'bar',
- constructors = {
- 'bar': OO.ui.BarToolGroup,
- 'list': OO.ui.ListToolGroup,
- 'menu': OO.ui.MenuToolGroup
- };
+ defaultType = 'bar';
// Cleanup previous groups
this.reset();
@@ -130,9 +140,10 @@
group.label = 'ooui-toolbar-more';
}
}
- type = constructors[group.type] ? group.type : defaultType;
+ // Check type has been registered
+ type = this.getToolGroupFactory().lookup( group.type ) ?
group.type : defaultType;
items.push(
- new constructors[type]( this, $.extend( { '$': this.$
}, group ) )
+ this.getToolGroupFactory().create( type, this,
$.extend( { '$': this.$ }, group ) )
);
}
this.addItems( items );
diff --git a/src/toolgroups/BarToolGroup.js b/src/toolgroups/BarToolGroup.js
index cd50c62..961c5f0 100644
--- a/src/toolgroups/BarToolGroup.js
+++ b/src/toolgroups/BarToolGroup.js
@@ -26,3 +26,5 @@
OO.ui.BarToolGroup.static.titleTooltips = true;
OO.ui.BarToolGroup.static.accelTooltips = true;
+
+OO.ui.BarToolGroup.static.name = 'bar';
diff --git a/src/toolgroups/ListToolGroup.js b/src/toolgroups/ListToolGroup.js
index b3c79d6..5e29c91 100644
--- a/src/toolgroups/ListToolGroup.js
+++ b/src/toolgroups/ListToolGroup.js
@@ -24,3 +24,5 @@
/* Static Properties */
OO.ui.ListToolGroup.static.accelTooltips = true;
+
+OO.ui.ListToolGroup.static.name = 'list';
diff --git a/src/toolgroups/MenuToolGroup.js b/src/toolgroups/MenuToolGroup.js
index 6dc106e..dc63fac 100644
--- a/src/toolgroups/MenuToolGroup.js
+++ b/src/toolgroups/MenuToolGroup.js
@@ -31,6 +31,8 @@
OO.ui.MenuToolGroup.static.accelTooltips = true;
+OO.ui.MenuToolGroup.static.name = 'menu';
+
/* Methods */
/**
--
To view, visit https://gerrit.wikimedia.org/r/119744
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I10e5d256ccf9db33be428bcd47db160ecf3a9632
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