Skip to content

Commit fa1d945

Browse files
committed
Allows to pass buttons as objects in toolbar configuration
Fixes #31
1 parent 919eaef commit fa1d945

File tree

5 files changed

+47
-15
lines changed

5 files changed

+47
-15
lines changed

src/ui/yui/src/plugins/loader.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,25 @@
9797
}
9898
},
9999

100+
/**
101+
* Resolves the name of a button module passed through configuration.
102+
*
103+
* @method _getButtonName
104+
* @protected
105+
* @param {String|Object} button A string representing the button or an object
106+
* with a name attribute.
107+
* @return {String} The name of the button.
108+
*/
109+
_getButtonName: function(button) {
110+
var buttonName = button;
111+
112+
if (typeof button !== 'string') {
113+
buttonName = button.name;
114+
}
115+
116+
return buttonName
117+
},
118+
100119
/**
101120
* Retrieves a list of modules for all registered buttons and toolbars in the current
102121
* editor configuration.
@@ -133,11 +152,11 @@
133152

134153
if (CKEDITOR.tools.isArray(toolbarsConfig[i])) {
135154
for (j = toolbarsConfig[i].length - 1; j >= 0; j--) { // put button modules
136-
modules.push('button-' + toolbarsConfig[i][j]);
155+
modules.push('button-' + this._getButtonName(toolbarsConfig[i][j]));
137156
}
138157
} else if (toolbarsConfig[i]) {
139158
for (j = toolbarsConfig[i].buttons.length - 1; j >= 0; j--) { // put button modules
140-
modules.push('button-' + toolbarsConfig[i].buttons[j]);
159+
modules.push('button-' + this._getButtonName(toolbarsConfig[i].buttons[j]));
141160
}
142161
}
143162
}

src/ui/yui/src/toolbars/toolbar-add.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,12 @@ YUI.add('toolbar-add', function(Y) {
304304
* or:
305305
* <pre><code>
306306
* buttons: [
307-
* 'image': {
308-
* zIndex: 1024,
309-
* property2: 1024
307+
* {
308+
* name: 'image',
309+
* cfg: {
310+
* zIndex: 1024,
311+
* property2: 1024
312+
* }
310313
* }
311314
* ]
312315
* </pre></code>

src/ui/yui/src/toolbars/toolbar-base.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,17 @@ YUI.add('toolbar-base', function(Y) {
3030
YArray.each(
3131
instance.get('buttons'),
3232
function(item) {
33-
var instanceName;
33+
var buttonName,
34+
cfg,
35+
instanceName;
3436

35-
instanceName = instance._getButtonInstanceName(item);
37+
buttonName = Lang.isObject(item) ? item.name : item;
3638

37-
item = Lang.isObject(item) ? item : null;
39+
instanceName = instance._getButtonInstanceName(buttonName);
3840

39-
instance.plug(Y[instanceName], item);
41+
cfg = Lang.isObject(item) ? item.cfg : null;
42+
43+
instance.plug(Y[instanceName], cfg);
4044

4145
// Each button will fire actionPerformed when user interacts with it. Here we will
4246
// re-fire this event to the other buttons so they will be able to update their UI too.

src/ui/yui/src/toolbars/toolbar-image.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,12 @@ YUI.add('toolbar-image', function(Y) {
148148
* or:
149149
* <pre><code>
150150
* buttons: [
151-
* 'left': {
152-
* zIndex: 1024,
153-
* property2: 1024
151+
* {
152+
* name: 'left',
153+
* cfg: {
154+
* zIndex: 1024,
155+
* property2: 1024
156+
* }
154157
* }
155158
* ]
156159
* </pre></code>

src/ui/yui/src/toolbars/toolbar-styles.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,12 @@ YUI.add('toolbar-styles', function(Y) {
119119
* or:
120120
* <pre><code>
121121
* buttons: [
122-
* 'strong': {
123-
* zIndex: 1024,
124-
* property2: 1024
122+
* {
123+
* name: 'strong',
124+
* cfg: {
125+
* zIndex: 1024,
126+
* property2: 1024
127+
* }
125128
* }
126129
* ]
127130
* </pre></code>

0 commit comments

Comments
 (0)