Skip to content

Commit

Permalink
Merge branch 't/10986' into major
Browse files Browse the repository at this point in the history
  • Loading branch information
Reinmar committed Jan 9, 2015
2 parents e4ad441 + 426bad9 commit daf04e4
Show file tree
Hide file tree
Showing 11 changed files with 413 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -5,6 +5,7 @@ CKEditor 4 Changelog

New Features:

* [#10986](http://dev.ckeditor.com/ticket/10986): Added support for changing dialog's input and textarea text directions by using *Shift+Alt+Home/End* keystrokes. The direction is stored in the value of the input by prepending [`\u202A`](http://unicode.org/cldr/utility/character.jsp?a=202A) or [`\u202B`](http://unicode.org/cldr/utility/character.jsp?a=202B) marker to it. Read more in the [documentation](http://docs.ckeditor.com/#!/api/CKEDITOR.dialog.definition.textInput-property-bidi) Thanks to [edithkk](https://github.com/edithkk)!
* [#10931](http://dev.ckeditor.com/ticket/10931): Introduce ability to insert widgets into another widget's nested editables. Note that unless nested editable's [allowed content](http://docs.ckeditor.com/#!/api/CKEDITOR.plugins.widget.nestedEditable.definition-property-allowedContent) is defined precisely since CKEditor 4.5 some widget buttons may become enabled.
* [#11437](http://dev.ckeditor.com/ticket/11437): Drag and Drop support.
* [#11460](http://dev.ckeditor.com/ticket/11460): Custom handling for dropped content in the editor.
Expand Down
25 changes: 25 additions & 0 deletions plugins/dialog/dialogDefinition.js
Expand Up @@ -948,6 +948,11 @@
* @property {Function} validate
*/

/**
* @property bidi
* @inheritdoc CKEDITOR.dialog.definition.textarea#bidi
*/

// ----- textarea -------------------------------------------------------------

/**
Expand Down Expand Up @@ -1005,3 +1010,23 @@
*
* @property {String} default
*/

/**
* Whether the text direction in this input should be toggable using the following keystrokes:
*
* * *Shift+Alt+End* - switch to Right-To-Left,
* * *Shift+Alt+Home* - switch to Left-To-Right.
*
* By default the input will be loaded without any direction set, what means that
* the direction will be inherited from the editor's text direction.
*
* If the direction was choosen a marker will be prepended to every non-empty value of this input:
*
* * [`\u202A`](http://unicode.org/cldr/utility/character.jsp?a=202A) - for Right-To-Left,
* * [`\u202B`](http://unicode.org/cldr/utility/character.jsp?a=202B) - for Left-To-Right.
*
* This marker allows restoring the same direction upon next dialog openining.
*
* @since 4.5.0
* @property {Boolean} bidi
*/
88 changes: 87 additions & 1 deletion plugins/dialogui/plugin.js
Expand Up @@ -93,6 +93,19 @@ CKEDITOR.plugins.add( 'dialogui', {
delete def[ i ];
}
return def;
},
// @context {CKEDITOR.dialog.uiElement} UI element (textarea or textInput)
// @param {CKEDITOR.dom.event} evt
toggleBidiKeyUpHandler = function( evt ) {
var keystroke = evt.data.getKeystroke();

// ALT + SHIFT + Home for LTR direction.
if ( keystroke == CKEDITOR.SHIFT + CKEDITOR.ALT + 36 )
this.setDirectionMarker( 'ltr' );

// ALT + SHIFT + End for RTL direction.
else if ( keystroke == CKEDITOR.SHIFT + CKEDITOR.ALT + 35 )
this.setDirectionMarker( 'rtl' );
};

CKEDITOR.tools.extend( CKEDITOR.ui.dialog, {
Expand Down Expand Up @@ -235,6 +248,9 @@ CKEDITOR.plugins.add( 'dialogui', {
}, 0 );
keyPressedOnMe = false;
}

if ( me.bidi )
toggleBidiKeyUpHandler.call( me, evt );
}, null, null, 1000 );
} );

Expand Down Expand Up @@ -302,6 +318,12 @@ CKEDITOR.plugins.add( 'dialogui', {
if ( elementDefinition.dir )
attributes.dir = elementDefinition.dir;

if ( me.bidi ) {
dialog.on( 'load', function() {
me.getInputElement().on( 'keyup', toggleBidiKeyUpHandler );
}, me );
}

var innerHTML = function() {
attributes[ 'aria-labelledby' ] = this._.labelId;
this._.required && ( attributes[ 'aria-required' ] = this._.required );
Expand Down Expand Up @@ -1011,10 +1033,74 @@ CKEDITOR.plugins.add( 'dialogui', {
* @returns {CKEDITOR.ui.dialog.textInput} The current UI element.
*/
setValue: function( value ) {
!value && ( value = '' );
if ( this.bidi ) {
var marker = value && value.charAt( 0 ),
dir = ( marker == '\u202A' ? 'ltr' : marker == '\u202B' ? 'rtl' : null );

if ( dir ) {
value = value.slice( 1 );
}

// Set the marker or reset it (if dir==null).
this.setDirectionMarker( dir );
}

if ( !value ) {
value = '';
}

return CKEDITOR.ui.dialog.uiElement.prototype.setValue.apply( this, arguments );
},

/**
* Gets the value of this text input object.
*
* @returns {String} The value.
*/
getValue: function() {
var value = CKEDITOR.ui.dialog.uiElement.prototype.getValue.call( this );

if ( this.bidi && value ) {
var dir = this.getDirectionMarker();
if ( dir ) {
value = ( dir == 'ltr' ? '\u202A' : '\u202B' ) + value;
}
}

return value;
},

/**
* Sets the direction marker and `dir` attribute of the input element.
*
* @since 4.5.0
* @param {String} dir The direction. Pass `null` to reset.
*/
setDirectionMarker: function( dir ) {
var inputElement = this.getInputElement();

if ( dir ) {
inputElement.setAttributes( {
dir: dir,
'data-cke-dir-marker': dir
} );
// Don't remove the dir attribute if this field hasn't got the marker,
// because the dir attribute could be set independently.
} else if ( this.getDirectionMarker() ) {
inputElement.removeAttributes( [ 'dir', 'data-cke-dir-marker' ] );
}
},

/**
* Gets the value of direction marker.
*
* @since 4.5.0
* @returns {String} `'ltr'`, `'rtl'` or `null` if marker is not set.
*/
getDirectionMarker: function() {
return this.getInputElement().data( 'cke-dir-marker' );
},

keyboardFocusable: true
}, commonPrototype, true );

Expand Down
1 change: 1 addition & 0 deletions plugins/forms/dialogs/button.js
Expand Up @@ -59,6 +59,7 @@ CKEDITOR.dialog.add( 'button', function( editor ) {
{
id: 'name',
type: 'text',
bidi: true,
label: editor.lang.common.name,
'default': '',
setup: function( element ) {
Expand Down
1 change: 1 addition & 0 deletions plugins/forms/dialogs/form.js
Expand Up @@ -61,6 +61,7 @@ CKEDITOR.dialog.add( 'form', function( editor ) {
title: editor.lang.forms.form.title,
elements: [ {
id: 'txtName',
bidi: true,
type: 'text',
label: editor.lang.common.name,
'default': '',
Expand Down
1 change: 1 addition & 0 deletions plugins/table/dialogs/table.js
Expand Up @@ -513,6 +513,7 @@
{
type: 'text',
id: 'txtSummary',
bidi: true,
requiredContent: 'table[summary]',
label: editor.lang.table.summary,
setup: function( selectedTable ) {
Expand Down

0 comments on commit daf04e4

Please sign in to comment.