mirror of
https://github.com/fastmail/Squire.git
synced 2025-01-03 05:00:13 -05:00
Add setTextDirection method.
Allows setting RTL or LTR text direction on a block level basis.
This commit is contained in:
parent
630a7c4e4f
commit
b87a9c26fe
3 changed files with 47 additions and 6 deletions
12
Readme.md
12
Readme.md
|
@ -302,6 +302,18 @@ Sets the text alignment in all blocks at least partially contained by the select
|
||||||
|
|
||||||
Returns self.
|
Returns self.
|
||||||
|
|
||||||
|
### setTextDirection ###
|
||||||
|
|
||||||
|
Sets the text direction in all blocks at least partially contained by the selection.
|
||||||
|
|
||||||
|
#### Parameters ####
|
||||||
|
|
||||||
|
* **direction**: The text direction. Can be 'ltr' or 'rtl'.
|
||||||
|
|
||||||
|
#### Returns ####
|
||||||
|
|
||||||
|
Returns self.
|
||||||
|
|
||||||
### forEachBlock ###
|
### forEachBlock ###
|
||||||
|
|
||||||
Executes a function on each block in the current selection, or until the function returns a truthy value.
|
Executes a function on each block in the current selection, or until the function returns a truthy value.
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -833,7 +833,10 @@
|
||||||
tag = node.nodeName;
|
tag = node.nodeName;
|
||||||
if ( node.isBlock() ) {
|
if ( node.isBlock() ) {
|
||||||
if ( tag !== 'LI' ) {
|
if ( tag !== 'LI' ) {
|
||||||
replacement = createElement( 'LI', [
|
replacement = createElement( 'LI', {
|
||||||
|
'class': node.dir === 'rtl' ? 'dir-rtl' : '',
|
||||||
|
dir: node.dir
|
||||||
|
}, [
|
||||||
node.empty()
|
node.empty()
|
||||||
]);
|
]);
|
||||||
if ( node.parentNode.nodeName === type ) {
|
if ( node.parentNode.nodeName === type ) {
|
||||||
|
@ -889,7 +892,10 @@
|
||||||
while ( l-- ) {
|
while ( l-- ) {
|
||||||
child = children[l];
|
child = children[l];
|
||||||
if ( child.nodeName === 'LI' ) {
|
if ( child.nodeName === 'LI' ) {
|
||||||
frag.replaceChild( createElement( 'DIV', [
|
frag.replaceChild( createElement( 'DIV', {
|
||||||
|
'class': child.dir === 'rtl' ? 'dir-rtl' : '',
|
||||||
|
dir: child.dir
|
||||||
|
}, [
|
||||||
child.empty()
|
child.empty()
|
||||||
]), child );
|
]), child );
|
||||||
}
|
}
|
||||||
|
@ -921,6 +927,8 @@
|
||||||
// Make sure the new node is the correct type.
|
// Make sure the new node is the correct type.
|
||||||
if ( nodeAfterSplit.nodeName !== splitTag ) {
|
if ( nodeAfterSplit.nodeName !== splitTag ) {
|
||||||
block = createElement( splitTag );
|
block = createElement( splitTag );
|
||||||
|
block.className = nodeAfterSplit.dir === 'rtl' ? 'dir-rtl' : '';
|
||||||
|
block.dir = nodeAfterSplit.dir;
|
||||||
block.replaces( nodeAfterSplit )
|
block.replaces( nodeAfterSplit )
|
||||||
.appendChild( nodeAfterSplit.empty() );
|
.appendChild( nodeAfterSplit.empty() );
|
||||||
nodeAfterSplit = block;
|
nodeAfterSplit = block;
|
||||||
|
@ -1833,10 +1841,31 @@
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
setTextAlignment: function ( dir ) {
|
setTextAlignment: function ( alignment ) {
|
||||||
forEachBlock( function ( block ) {
|
forEachBlock( function ( block ) {
|
||||||
block.className = 'align-' + dir;
|
block.className = ( block.className
|
||||||
block.style.textAlign = dir;
|
.split( /\s+/ )
|
||||||
|
.filter( function ( klass ) {
|
||||||
|
return !( /align/.test( klass ) );
|
||||||
|
})
|
||||||
|
.join( ' ' ) +
|
||||||
|
' align-' + alignment ).trim();
|
||||||
|
block.style.textAlign = alignment;
|
||||||
|
}, true );
|
||||||
|
focus();
|
||||||
|
return this;
|
||||||
|
},
|
||||||
|
|
||||||
|
setTextDirection: function ( direction ) {
|
||||||
|
forEachBlock( function ( block ) {
|
||||||
|
block.className = ( block.className
|
||||||
|
.split( /\s+/ )
|
||||||
|
.filter( function ( klass ) {
|
||||||
|
return !( /dir/.test( klass ) );
|
||||||
|
})
|
||||||
|
.join( ' ' ) +
|
||||||
|
' dir-' + direction ).trim();
|
||||||
|
block.dir = direction;
|
||||||
}, true );
|
}, true );
|
||||||
focus();
|
focus();
|
||||||
return this;
|
return this;
|
||||||
|
|
Loading…
Reference in a new issue