mirror of
https://github.com/fastmail/Squire.git
synced 2025-01-03 05:00:13 -05:00
Make TreeWalker filter argument optional
This commit is contained in:
parent
e3e7c17315
commit
2d5114c669
5 changed files with 24 additions and 26 deletions
|
@ -84,10 +84,14 @@ var typeToBitArray = {
|
|||
11: 1024
|
||||
};
|
||||
|
||||
var always = function () {
|
||||
return true;
|
||||
};
|
||||
|
||||
function TreeWalker ( root, nodeType, filter ) {
|
||||
this.root = this.currentNode = root;
|
||||
this.nodeType = nodeType;
|
||||
this.filter = filter;
|
||||
this.filter = filter || always;
|
||||
}
|
||||
|
||||
TreeWalker.prototype.nextNode = function () {
|
||||
|
@ -1955,9 +1959,7 @@ var allowedBlock = /^(?:A(?:DDRESS|RTICLE|SIDE|UDIO)|BLOCKQUOTE|CAPTION|D(?:[DLT
|
|||
|
||||
var blacklist = /^(?:HEAD|META|STYLE)/;
|
||||
|
||||
var walker = new TreeWalker( null, SHOW_TEXT|SHOW_ELEMENT, function () {
|
||||
return true;
|
||||
});
|
||||
var walker = new TreeWalker( null, SHOW_TEXT|SHOW_ELEMENT );
|
||||
|
||||
/*
|
||||
Two purposes:
|
||||
|
@ -3040,10 +3042,8 @@ proto.getPath = function () {
|
|||
// the bottom of the tree so the block can be selected. Define that node as the
|
||||
// keepNode.
|
||||
var removeZWS = function ( root, keepNode ) {
|
||||
var walker = new TreeWalker( root, SHOW_TEXT, function () {
|
||||
return true;
|
||||
}, false ),
|
||||
parent, node, index;
|
||||
var walker = new TreeWalker( root, SHOW_TEXT );
|
||||
var parent, node, index;
|
||||
while ( node = walker.nextNode() ) {
|
||||
while ( ( index = node.data.indexOf( ZWS ) ) > -1 &&
|
||||
( !keepNode || node.parentNode !== keepNode ) ) {
|
||||
|
@ -3399,7 +3399,7 @@ proto.hasFormat = function ( tag, attributes, range ) {
|
|||
// the selection and make sure all of them have the format we want.
|
||||
walker = new TreeWalker( common, SHOW_TEXT, function ( node ) {
|
||||
return isNodeContainedInRange( range, node, true );
|
||||
}, false );
|
||||
});
|
||||
|
||||
var seenNode = false;
|
||||
while ( node = walker.nextNode() ) {
|
||||
|
@ -3503,8 +3503,7 @@ proto._addFormat = function ( tag, attributes, range ) {
|
|||
node.nodeName === 'BR' ||
|
||||
node.nodeName === 'IMG'
|
||||
) && isNodeContainedInRange( range, node, true );
|
||||
},
|
||||
false
|
||||
}
|
||||
);
|
||||
|
||||
// Start at the beginning node of the range and iterate through
|
||||
|
@ -4262,7 +4261,7 @@ var addLinks = function ( frag, root, self ) {
|
|||
walker = new TreeWalker( frag, SHOW_TEXT,
|
||||
function ( node ) {
|
||||
return !getNearest( node, root, 'A' );
|
||||
}, false ),
|
||||
}),
|
||||
defaultAttributes = self._config.tagAttributes.a,
|
||||
node, data, parent, match, index, endIndex, child;
|
||||
while ( node = walker.nextNode() ) {
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -183,9 +183,7 @@ var allowedBlock = /^(?:A(?:DDRESS|RTICLE|SIDE|UDIO)|BLOCKQUOTE|CAPTION|D(?:[DLT
|
|||
|
||||
var blacklist = /^(?:HEAD|META|STYLE)/;
|
||||
|
||||
var walker = new TreeWalker( null, SHOW_TEXT|SHOW_ELEMENT, function () {
|
||||
return true;
|
||||
});
|
||||
var walker = new TreeWalker( null, SHOW_TEXT|SHOW_ELEMENT );
|
||||
|
||||
/*
|
||||
Two purposes:
|
||||
|
|
|
@ -574,10 +574,8 @@ proto.getPath = function () {
|
|||
// the bottom of the tree so the block can be selected. Define that node as the
|
||||
// keepNode.
|
||||
var removeZWS = function ( root, keepNode ) {
|
||||
var walker = new TreeWalker( root, SHOW_TEXT, function () {
|
||||
return true;
|
||||
}, false ),
|
||||
parent, node, index;
|
||||
var walker = new TreeWalker( root, SHOW_TEXT );
|
||||
var parent, node, index;
|
||||
while ( node = walker.nextNode() ) {
|
||||
while ( ( index = node.data.indexOf( ZWS ) ) > -1 &&
|
||||
( !keepNode || node.parentNode !== keepNode ) ) {
|
||||
|
@ -933,7 +931,7 @@ proto.hasFormat = function ( tag, attributes, range ) {
|
|||
// the selection and make sure all of them have the format we want.
|
||||
walker = new TreeWalker( common, SHOW_TEXT, function ( node ) {
|
||||
return isNodeContainedInRange( range, node, true );
|
||||
}, false );
|
||||
});
|
||||
|
||||
var seenNode = false;
|
||||
while ( node = walker.nextNode() ) {
|
||||
|
@ -1037,8 +1035,7 @@ proto._addFormat = function ( tag, attributes, range ) {
|
|||
node.nodeName === 'BR' ||
|
||||
node.nodeName === 'IMG'
|
||||
) && isNodeContainedInRange( range, node, true );
|
||||
},
|
||||
false
|
||||
}
|
||||
);
|
||||
|
||||
// Start at the beginning node of the range and iterate through
|
||||
|
@ -1796,7 +1793,7 @@ var addLinks = function ( frag, root, self ) {
|
|||
walker = new TreeWalker( frag, SHOW_TEXT,
|
||||
function ( node ) {
|
||||
return !getNearest( node, root, 'A' );
|
||||
}, false ),
|
||||
}),
|
||||
defaultAttributes = self._config.tagAttributes.a,
|
||||
node, data, parent, match, index, endIndex, child;
|
||||
while ( node = walker.nextNode() ) {
|
||||
|
|
|
@ -26,10 +26,14 @@ var typeToBitArray = {
|
|||
11: 1024
|
||||
};
|
||||
|
||||
var always = function () {
|
||||
return true;
|
||||
};
|
||||
|
||||
function TreeWalker ( root, nodeType, filter ) {
|
||||
this.root = this.currentNode = root;
|
||||
this.nodeType = nodeType;
|
||||
this.filter = filter;
|
||||
this.filter = filter || always;
|
||||
}
|
||||
|
||||
TreeWalker.prototype.nextNode = function () {
|
||||
|
|
Loading…
Reference in a new issue