Skip to content

Commit 4c8db76

Browse files
committed
Make ToolbarAdd showAtPoint API consistent
Fixes #32
1 parent fa1d945 commit 4c8db76

File tree

2 files changed

+50
-57
lines changed

2 files changed

+50
-57
lines changed

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

Lines changed: 49 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -70,24 +70,39 @@ YUI.add('toolbar-add', function(Y) {
7070
* Calculates and sets the position of the toolbar.
7171
*
7272
* @method showAtPoint
73-
* @param {Object} triggerPosition Position (x,y) for the trigger.
74-
* @param {Object} toolbarPosition Position (x,y) for the toolbar.
73+
* @param {Number} left The left offset in page coordinates where Toolbar should be shown.
74+
* @param {Number} top The top offset in page coordinates where Toolbar should be shown.
75+
* @param {Number} direction The direction of the selection. May be one of the following:
76+
* CKEDITOR.SELECTION_BOTTOM_TO_TOP or CKEDITOR.SELECTION_TOP_TO_BOTTOM
7577
*/
76-
showAtPoint: function(triggerPosition, toolbarPosition) {
77-
var triggerButtonContainer,
78-
triggerGutter;
78+
showAtPoint: function(left, top, direction) {
79+
var boundingBox,
80+
visible,
81+
xy;
7982

80-
if (!this._trigger.get('visible')) {
81-
this._trigger.show();
83+
boundingBox = this.get('boundingBox');
84+
85+
if (this.get('editor').isSelectionEmpty()) {
86+
direction = CKEDITOR.SELECTION_BOTTOM_TO_TOP;
8287
}
8388

84-
triggerButtonContainer = this._triggerButtonContainer.getDOMNode();
89+
if (direction === CKEDITOR.SELECTION_TOP_TO_BOTTOM) {
90+
boundingBox.replaceClass('alloy-editor-arrow-box-bottom', 'alloy-editor-arrow-box-top');
91+
} else {
92+
boundingBox.replaceClass('alloy-editor-arrow-box-top', 'alloy-editor-arrow-box-bottom');
93+
}
8594

86-
triggerGutter = this.get('triggerGutter');
95+
visible = this.get('visible');
8796

88-
this._trigger.set('xy', this.getConstrainedXY([triggerPosition.x - triggerButtonContainer.offsetWidth - triggerGutter.left, triggerPosition.y - triggerGutter.top - triggerButtonContainer.offsetHeight / 2]));
97+
if (!visible) {
98+
this.show();
99+
}
100+
101+
xy = this._getToolbarXYPoint(left, top, direction);
89102

90-
this._toolbarPosition = toolbarPosition;
103+
this._moveToPoint(this.getConstrainedXY(xy), direction, {
104+
visible: visible
105+
});
91106
},
92107

93108
/**
@@ -136,17 +151,12 @@ YUI.add('toolbar-add', function(Y) {
136151
if (selectionData.region) {
137152
startRect = selectionData.region.startRect || selectionData.region;
138153

139-
triggerPosition = {
140-
x: this._editorNode.getX(),
141-
y: selectionData.region.top + startRect.height / 2
142-
};
143-
144-
toolbarPosition = this._calculatePosition(selectionData, {
154+
this._toolbarPosition = this._calculatePosition(selectionData, {
145155
x: nativeEvent.pageX,
146156
y: nativeEvent.pageY
147157
});
148158

149-
this.showAtPoint(triggerPosition, toolbarPosition);
159+
this._showTriggerAtPoint(this._editorNode.getX(), selectionData.region.top + startRect.height / 2);
150160
}
151161
},
152162

@@ -225,59 +235,42 @@ YUI.add('toolbar-add', function(Y) {
225235
},
226236

227237
/**
228-
* Calculates and sets the position of the toolbar. Internally, uses a toolbarPosition
229-
* object stored from the previous editorInteraction event.
238+
* Shows the toolbar and hides the toolbar trigger on the margin.
230239
*
231-
* @method _showToolbar
240+
* @method _showToolbarAddContent
232241
* @protected
233242
*/
234-
_showToolbar: function() {
235-
var boundingBox,
236-
toolbarPosition,
237-
visible,
238-
xy;
239-
240-
boundingBox = this.get('boundingBox');
241-
242-
toolbarPosition = this._toolbarPosition;
243-
244-
if (this.get('editor').isSelectionEmpty()) {
245-
toolbarPosition.direction = CKEDITOR.SELECTION_BOTTOM_TO_TOP;
246-
}
247-
248-
if (toolbarPosition.direction === CKEDITOR.SELECTION_TOP_TO_BOTTOM) {
249-
boundingBox.replaceClass('alloy-editor-arrow-box-bottom', 'alloy-editor-arrow-box-top');
250-
} else {
251-
boundingBox.replaceClass('alloy-editor-arrow-box-top', 'alloy-editor-arrow-box-bottom');
252-
}
253-
254-
visible = this.get('visible');
243+
_showToolbarAddContent: function() {
244+
this._hideEditorToolbars();
255245

256-
if (!visible) {
257-
this.show();
258-
}
246+
this.showAtPoint(this._toolbarPosition.x, this._toolbarPosition.y, this._toolbarPosition.direction);
259247

260-
xy = this._getToolbarXYPoint(toolbarPosition.x, toolbarPosition.y, toolbarPosition.direction);
248+
this._trigger.hide();
261249

262-
this._moveToPoint(this.getConstrainedXY(xy), toolbarPosition.direction, {
263-
visible: visible
264-
});
250+
this._editorNode.focus();
265251
},
266252

267253
/**
268-
* Shows the toolbar and hides the toolbar trigger on the margin.
254+
* Calculates and sets the position of the add toolbar trigger.
269255
*
270-
* @method _showToolbarAddContent
256+
* @method _showTriggerAtPoint
271257
* @protected
258+
* @param {Number} left The left offset in page coordinates where Trigger should be shown.
259+
* @param {Number} top The top offset in page coordinates where Trigger should be shown.
272260
*/
273-
_showToolbarAddContent: function() {
274-
this._hideEditorToolbars();
261+
_showTriggerAtPoint: function(left, top) {
262+
var triggerButtonContainer,
263+
triggerGutter;
275264

276-
this._showToolbar();
265+
if (!this._trigger.get('visible')) {
266+
this._trigger.show();
267+
}
277268

278-
this._trigger.hide();
269+
triggerButtonContainer = this._triggerButtonContainer.getDOMNode();
279270

280-
this._editorNode.focus();
271+
triggerGutter = this.get('triggerGutter');
272+
273+
this._trigger.set('xy', this.getConstrainedXY([left - triggerButtonContainer.offsetWidth - triggerGutter.left, top - triggerGutter.top - triggerButtonContainer.offsetHeight / 2]));
281274
},
282275

283276
BOUNDING_TEMPLATE: '<div class="alloy-editor-toolbar alloy-editor-toolbar-add alloy-editor-arrow-box"></div>',

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ YUI.add('toolbar-styles', function(Y) {
3535
*
3636
* @method showAtPoint
3737
* @param {Number} left The left offset in page coordinates where Toolbar should be shown.
38-
* @param {Number} right The right offset in page coordinates where Toolbar should be shown.
38+
* @param {Number} top The right offset in page coordinates where Toolbar should be shown.
3939
* @param {Number} direction The direction of the selection. May be one of the following:
4040
* CKEDITOR.SELECTION_BOTTOM_TO_TOP or CKEDITOR.SELECTION_TOP_TO_BOTTOM
4141
*/

0 commit comments

Comments
 (0)