0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2024-12-22 15:23:29 -05:00

null arg to setText(Alignment|Direction) should reset value

Resolves #247
This commit is contained in:
Neil Jenkins 2016-12-07 19:22:28 +11:00
parent a899c001eb
commit 65a621abcf
3 changed files with 31 additions and 13 deletions

View file

@ -4353,21 +4353,30 @@ proto.setHighlightColour = function ( colour ) {
proto.setTextAlignment = function ( alignment ) { proto.setTextAlignment = function ( alignment ) {
this.forEachBlock( function ( block ) { this.forEachBlock( function ( block ) {
block.className = ( block.className var className = block.className
.split( /\s+/ ) .split( /\s+/ )
.filter( function ( klass ) { .filter( function ( klass ) {
return !( /align/.test( klass ) ); return !!klass && !/^align/.test( klass );
}) })
.join( ' ' ) + .join( ' ' );
' align-' + alignment ).trim(); if ( alignment ) {
block.className = className + ' align-' + alignment;
block.style.textAlign = alignment; block.style.textAlign = alignment;
} else {
block.className = className;
block.style.textAlign = '';
}
}, true ); }, true );
return this.focus(); return this.focus();
}; };
proto.setTextDirection = function ( direction ) { proto.setTextDirection = function ( direction ) {
this.forEachBlock( function ( block ) { this.forEachBlock( function ( block ) {
if ( direction ) {
block.dir = direction; block.dir = direction;
} else {
block.removeAttribute( 'dir' );
}
}, true ); }, true );
return this.focus(); return this.focus();
}; };

File diff suppressed because one or more lines are too long

View file

@ -1959,21 +1959,30 @@ proto.setHighlightColour = function ( colour ) {
proto.setTextAlignment = function ( alignment ) { proto.setTextAlignment = function ( alignment ) {
this.forEachBlock( function ( block ) { this.forEachBlock( function ( block ) {
block.className = ( block.className var className = block.className
.split( /\s+/ ) .split( /\s+/ )
.filter( function ( klass ) { .filter( function ( klass ) {
return !( /align/.test( klass ) ); return !!klass && !/^align/.test( klass );
}) })
.join( ' ' ) + .join( ' ' );
' align-' + alignment ).trim(); if ( alignment ) {
block.className = className + ' align-' + alignment;
block.style.textAlign = alignment; block.style.textAlign = alignment;
} else {
block.className = className;
block.style.textAlign = '';
}
}, true ); }, true );
return this.focus(); return this.focus();
}; };
proto.setTextDirection = function ( direction ) { proto.setTextDirection = function ( direction ) {
this.forEachBlock( function ( block ) { this.forEachBlock( function ( block ) {
if ( direction ) {
block.dir = direction; block.dir = direction;
} else {
block.removeAttribute( 'dir' );
}
}, true ); }, true );
return this.focus(); return this.focus();
}; };