@@ -2,7 +2,9 @@ YUI.add('toolbar-base', function(Y) {
22 'use strict' ;
33
44 var Lang = Y . Lang ,
5- YArray = Y . Array ;
5+ YArray = Y . Array ,
6+
7+ EMPTY_LINE_REGEX = / \r ? \n / ;
68
79 function ToolbarBase ( ) { }
810
@@ -66,6 +68,8 @@ YUI.add('toolbar-base', function(Y) {
6668 boundingBoxNode ,
6769 height ,
6870 transition ,
71+ x ,
72+ width ,
6973 y ;
7074
7175 transition = this . get ( 'transition' ) ;
@@ -76,18 +80,23 @@ YUI.add('toolbar-base', function(Y) {
7680 boundingBoxNode = boundingBox . getDOMNode ( ) ;
7781
7882 height = boundingBoxNode . offsetHeight ;
83+ width = boundingBoxNode . offsetWidth ;
7984
8085 // Change the original points where the Toolbar should be positioned.
8186 // The X will be the same, but we will extract or add the height of the
8287 // Toolbar to the Y point.
88+ if ( direction === CKEDITOR . SELECTION_TOP_TO_BOTTOM || direction === CKEDITOR . SELECTION_BOTTOM_TO_TOP ) {
8389
84- if ( direction === CKEDITOR . SELECTION_TOP_TO_BOTTOM ) {
85- y = xy [ 1 ] - height ;
86- } else {
87- y = xy [ 1 ] + height ;
90+ x = xy [ 0 ] ;
91+ y = ( direction === CKEDITOR . SELECTION_TOP_TO_BOTTOM ) ? ( xy [ 1 ] - height ) : ( xy [ 1 ] + height ) ;
92+
93+ } else if ( direction === CKEDITOR . SELECTION_LEFT_TO_RIGHT || direction === CKEDITOR . SELECTION_RIGHT_TO_LEFT ) {
94+
95+ x = ( direction === CKEDITOR . SELECTION_LEFT_TO_RIGHT ) ? ( xy [ 0 ] - width ) : ( xy [ 0 ] + width ) ;
96+ y = xy [ 1 ] ;
8897 }
8998
90- this . set ( 'xy' , [ xy [ 0 ] , y ] ) ;
99+ this . set ( 'xy' , [ x , y ] ) ;
91100
92101 transition . left = xy [ 0 ] + 'px' ;
93102 transition . top = xy [ 1 ] + 'px' ;
@@ -142,6 +151,21 @@ YUI.add('toolbar-base', function(Y) {
142151 return 'Button' + buttonName . substring ( 0 , 1 ) . toUpperCase ( ) + buttonName . substring ( 1 ) ;
143152 } ,
144153
154+ /**
155+ * Detects if the current line is empty
156+ *
157+ * @method _isCurrentLineEmpty
158+ * @protected
159+ * @return {Boolean } True if the current line is empty.
160+ */
161+ _isCurrentLineEmpty : function ( ) {
162+ var currentLine ;
163+
164+ currentLine = this . get ( 'editor' ) . getSelection ( ) . getRanges ( ) [ 0 ] . getCommonAncestor ( ) ;
165+
166+ return EMPTY_LINE_REGEX . test ( currentLine . getText ( ) ) ;
167+ } ,
168+
145169 /**
146170 * Moves the Toolbar to a point in page coordinates. If transition was specified via the
147171 * {{#crossLink "ToolbarBase/transition:attribute"}}{{/crossLink}}, the movement will be
0 commit comments