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

Calling functions from modifyBlocks and forEachBlock with arguments

This commit is contained in:
dryoma 2015-05-13 17:46:38 +08:00
parent bdc8b0c576
commit cd3526e223
3 changed files with 36 additions and 12 deletions

View file

@ -2448,7 +2448,13 @@ var splitBlock = function ( self, block, node, offset ) {
return nodeAfterSplit;
};
proto.forEachBlock = function ( fn, mutates, range ) {
proto.forEachBlock = function ( fn, mutates, args, range ) {
if ( !range && args &&
args.collapse && typeof( args.collapse ) === 'function' ) {
range = args;
args = null;
}
if ( !range && !( range = this.getSelection() ) ) {
return this;
}
@ -2463,7 +2469,7 @@ proto.forEachBlock = function ( fn, mutates, range ) {
end = getEndBlockOfRange( range );
if ( start && end ) {
do {
if ( fn( start ) || start === end ) { break; }
if ( fn( start, args ) || start === end ) { break; }
} while ( start = getNextBlock( start ) );
}
@ -2481,7 +2487,13 @@ proto.forEachBlock = function ( fn, mutates, range ) {
return this;
};
proto.modifyBlocks = function ( modify, range ) {
proto.modifyBlocks = function ( modify, args, range ) {
if ( !range && args &&
args.collapse && typeof( args.collapse ) === 'function' ) {
range = args;
args = null;
}
if ( !range && !( range = this.getSelection() ) ) {
return this;
}
@ -2503,7 +2515,7 @@ proto.modifyBlocks = function ( modify, range ) {
frag = extractContentsOfRange( range, body );
// 4. Modify tree of fragment and reinsert.
insertNodeInRange( range, modify.call( this, frag ) );
insertNodeInRange( range, modify.call( this, frag, args ) );
// 5. Merge containers at edges
if ( range.endOffset < range.endContainer.childNodes.length ) {

File diff suppressed because one or more lines are too long

View file

@ -972,7 +972,13 @@ var splitBlock = function ( self, block, node, offset ) {
return nodeAfterSplit;
};
proto.forEachBlock = function ( fn, mutates, range ) {
proto.forEachBlock = function ( fn, mutates, args, range ) {
if ( !range && args &&
args.collapse && typeof( args.collapse ) === 'function' ) {
range = args;
args = null;
}
if ( !range && !( range = this.getSelection() ) ) {
return this;
}
@ -987,7 +993,7 @@ proto.forEachBlock = function ( fn, mutates, range ) {
end = getEndBlockOfRange( range );
if ( start && end ) {
do {
if ( fn( start ) || start === end ) { break; }
if ( fn( start, args ) || start === end ) { break; }
} while ( start = getNextBlock( start ) );
}
@ -1005,7 +1011,13 @@ proto.forEachBlock = function ( fn, mutates, range ) {
return this;
};
proto.modifyBlocks = function ( modify, range ) {
proto.modifyBlocks = function ( modify, args, range ) {
if ( !range && args &&
args.collapse && typeof( args.collapse ) === 'function' ) {
range = args;
args = null;
}
if ( !range && !( range = this.getSelection() ) ) {
return this;
}
@ -1027,7 +1039,7 @@ proto.modifyBlocks = function ( modify, range ) {
frag = extractContentsOfRange( range, body );
// 4. Modify tree of fragment and reinsert.
insertNodeInRange( range, modify.call( this, frag ) );
insertNodeInRange( range, modify.call( this, frag, args ) );
// 5. Merge containers at edges
if ( range.endOffset < range.endContainer.childNodes.length ) {