mirror of
https://github.com/fastmail/Squire.git
synced 2025-01-03 05:00:13 -05:00
Remove FILTER_(ACCEPT|SKIP) constants.
Just return a boolean for the TreeWalker filter fn. This diverges from the spec, but since the goal of this implementation is not to fully implement the spec and we're never going to use a native implementation, this doesn't matter and the code is easier to read when the function is just returning a boolean like any normal filter function.
This commit is contained in:
parent
a280cb4946
commit
597024eecb
7 changed files with 24 additions and 52 deletions
|
@ -11,8 +11,6 @@ var ELEMENT_NODE = 1; // Node.ELEMENT_NODE;
|
||||||
var TEXT_NODE = 3; // Node.TEXT_NODE;
|
var TEXT_NODE = 3; // Node.TEXT_NODE;
|
||||||
var SHOW_ELEMENT = 1; // NodeFilter.SHOW_ELEMENT;
|
var SHOW_ELEMENT = 1; // NodeFilter.SHOW_ELEMENT;
|
||||||
var SHOW_TEXT = 4; // NodeFilter.SHOW_TEXT;
|
var SHOW_TEXT = 4; // NodeFilter.SHOW_TEXT;
|
||||||
var FILTER_ACCEPT = 1; // NodeFilter.FILTER_ACCEPT;
|
|
||||||
var FILTER_SKIP = 3; // NodeFilter.FILTER_SKIP;
|
|
||||||
|
|
||||||
var START_TO_START = 0; // Range.START_TO_START
|
var START_TO_START = 0; // Range.START_TO_START
|
||||||
var START_TO_END = 1; // Range.START_TO_END
|
var START_TO_END = 1; // Range.START_TO_END
|
||||||
|
@ -49,7 +47,6 @@ var hasBuggySplit = ( function () {
|
||||||
var notWS = /[^ \t\r\n]/;
|
var notWS = /[^ \t\r\n]/;
|
||||||
|
|
||||||
var indexOf = Array.prototype.indexOf;
|
var indexOf = Array.prototype.indexOf;
|
||||||
/*global FILTER_ACCEPT */
|
|
||||||
/*jshint strict:false */
|
/*jshint strict:false */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -103,7 +100,7 @@ TreeWalker.prototype.nextNode = function () {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if ( ( typeToBitArray[ node.nodeType ] & nodeType ) &&
|
if ( ( typeToBitArray[ node.nodeType ] & nodeType ) &&
|
||||||
filter( node ) === FILTER_ACCEPT ) {
|
filter( node ) ) {
|
||||||
this.currentNode = node;
|
this.currentNode = node;
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
@ -133,7 +130,7 @@ TreeWalker.prototype.previousNode = function () {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if ( ( typeToBitArray[ node.nodeType ] & nodeType ) &&
|
if ( ( typeToBitArray[ node.nodeType ] & nodeType ) &&
|
||||||
filter( node ) === FILTER_ACCEPT ) {
|
filter( node ) ) {
|
||||||
this.currentNode = node;
|
this.currentNode = node;
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
@ -144,8 +141,6 @@ TreeWalker.prototype.previousNode = function () {
|
||||||
ELEMENT_NODE,
|
ELEMENT_NODE,
|
||||||
TEXT_NODE,
|
TEXT_NODE,
|
||||||
SHOW_ELEMENT,
|
SHOW_ELEMENT,
|
||||||
FILTER_ACCEPT,
|
|
||||||
FILTER_SKIP,
|
|
||||||
win,
|
win,
|
||||||
isOpera,
|
isOpera,
|
||||||
useTextFixer,
|
useTextFixer,
|
||||||
|
@ -214,13 +209,10 @@ function isContainer ( node ) {
|
||||||
!isInline( node ) && !isBlock( node );
|
!isInline( node ) && !isBlock( node );
|
||||||
}
|
}
|
||||||
|
|
||||||
function acceptIfBlock ( el ) {
|
|
||||||
return isBlock( el ) ? FILTER_ACCEPT : FILTER_SKIP;
|
|
||||||
}
|
|
||||||
function getBlockWalker ( node ) {
|
function getBlockWalker ( node ) {
|
||||||
var doc = node.ownerDocument,
|
var doc = node.ownerDocument,
|
||||||
walker = new TreeWalker(
|
walker = new TreeWalker(
|
||||||
doc.body, SHOW_ELEMENT, acceptIfBlock, false );
|
doc.body, SHOW_ELEMENT, isBlock, false );
|
||||||
walker.currentNode = node;
|
walker.currentNode = node;
|
||||||
return walker;
|
return walker;
|
||||||
}
|
}
|
||||||
|
@ -610,7 +602,6 @@ function createElement ( doc, tag, props, children ) {
|
||||||
ELEMENT_NODE,
|
ELEMENT_NODE,
|
||||||
TEXT_NODE,
|
TEXT_NODE,
|
||||||
SHOW_TEXT,
|
SHOW_TEXT,
|
||||||
FILTER_ACCEPT,
|
|
||||||
START_TO_START,
|
START_TO_START,
|
||||||
START_TO_END,
|
START_TO_END,
|
||||||
END_TO_END,
|
END_TO_END,
|
||||||
|
@ -668,8 +659,8 @@ var forEachTextNodeInRange = function ( range, fn ) {
|
||||||
endContainer = range.endContainer,
|
endContainer = range.endContainer,
|
||||||
root = range.commonAncestorContainer,
|
root = range.commonAncestorContainer,
|
||||||
walker = new TreeWalker(
|
walker = new TreeWalker(
|
||||||
root, SHOW_TEXT, function ( node ) {
|
root, SHOW_TEXT, function (/* node */) {
|
||||||
return FILTER_ACCEPT;
|
return true;
|
||||||
}, false ),
|
}, false ),
|
||||||
textnode = walker.currentNode = startContainer;
|
textnode = walker.currentNode = startContainer;
|
||||||
|
|
||||||
|
@ -1130,8 +1121,6 @@ var expandRangeToBlockBoundaries = function ( range ) {
|
||||||
TEXT_NODE,
|
TEXT_NODE,
|
||||||
SHOW_ELEMENT,
|
SHOW_ELEMENT,
|
||||||
SHOW_TEXT,
|
SHOW_TEXT,
|
||||||
FILTER_ACCEPT,
|
|
||||||
FILTER_SKIP,
|
|
||||||
win,
|
win,
|
||||||
isIOS,
|
isIOS,
|
||||||
isMac,
|
isMac,
|
||||||
|
@ -1467,7 +1456,7 @@ proto._removeZWS = function () {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var walker = new TreeWalker( this._body, SHOW_TEXT, function () {
|
var walker = new TreeWalker( this._body, SHOW_TEXT, function () {
|
||||||
return FILTER_ACCEPT;
|
return true;
|
||||||
}, false ),
|
}, false ),
|
||||||
node, index;
|
node, index;
|
||||||
while ( node = walker.nextNode() ) {
|
while ( node = walker.nextNode() ) {
|
||||||
|
@ -1724,8 +1713,7 @@ proto.hasFormat = function ( tag, attributes, range ) {
|
||||||
// Otherwise, check each text node at least partially contained within
|
// Otherwise, check each text node at least partially contained within
|
||||||
// the selection and make sure all of them have the format we want.
|
// the selection and make sure all of them have the format we want.
|
||||||
walker = new TreeWalker( root, SHOW_TEXT, function ( node ) {
|
walker = new TreeWalker( root, SHOW_TEXT, function ( node ) {
|
||||||
return isNodeContainedInRange( range, node, true ) ?
|
return isNodeContainedInRange( range, node, true );
|
||||||
FILTER_ACCEPT : FILTER_SKIP;
|
|
||||||
}, false );
|
}, false );
|
||||||
|
|
||||||
var seenNode = false;
|
var seenNode = false;
|
||||||
|
@ -1764,8 +1752,7 @@ proto._addFormat = function ( tag, attributes, range ) {
|
||||||
range.commonAncestorContainer,
|
range.commonAncestorContainer,
|
||||||
SHOW_TEXT,
|
SHOW_TEXT,
|
||||||
function ( node ) {
|
function ( node ) {
|
||||||
return isNodeContainedInRange( range, node, true ) ?
|
return isNodeContainedInRange( range, node, true );
|
||||||
FILTER_ACCEPT : FILTER_SKIP;
|
|
||||||
},
|
},
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
@ -2224,7 +2211,7 @@ var addLinks = function ( frag ) {
|
||||||
var doc = frag.ownerDocument,
|
var doc = frag.ownerDocument,
|
||||||
walker = new TreeWalker( frag, SHOW_TEXT,
|
walker = new TreeWalker( frag, SHOW_TEXT,
|
||||||
function ( node ) {
|
function ( node ) {
|
||||||
return getNearest( node, 'A' ) ? FILTER_SKIP : FILTER_ACCEPT;
|
return !getNearest( node, 'A' );
|
||||||
}, false ),
|
}, false ),
|
||||||
node, data, parent, match, index, endIndex, child;
|
node, data, parent, match, index, endIndex, child;
|
||||||
while ( node = walker.nextNode() ) {
|
while ( node = walker.nextNode() ) {
|
||||||
|
@ -2514,10 +2501,9 @@ var cleanTree = function ( node, allowStyles ) {
|
||||||
};
|
};
|
||||||
|
|
||||||
var notWSTextNode = function ( node ) {
|
var notWSTextNode = function ( node ) {
|
||||||
return ( node.nodeType === ELEMENT_NODE ?
|
return node.nodeType === ELEMENT_NODE ?
|
||||||
node.nodeName === 'BR' :
|
node.nodeName === 'BR' :
|
||||||
notWS.test( node.data ) ) ?
|
notWS.test( node.data );
|
||||||
FILTER_ACCEPT : FILTER_SKIP;
|
|
||||||
};
|
};
|
||||||
var isLineBreak = function ( br ) {
|
var isLineBreak = function ( br ) {
|
||||||
var block = br.parentNode,
|
var block = br.parentNode,
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -6,8 +6,6 @@ var ELEMENT_NODE = 1; // Node.ELEMENT_NODE;
|
||||||
var TEXT_NODE = 3; // Node.TEXT_NODE;
|
var TEXT_NODE = 3; // Node.TEXT_NODE;
|
||||||
var SHOW_ELEMENT = 1; // NodeFilter.SHOW_ELEMENT;
|
var SHOW_ELEMENT = 1; // NodeFilter.SHOW_ELEMENT;
|
||||||
var SHOW_TEXT = 4; // NodeFilter.SHOW_TEXT;
|
var SHOW_TEXT = 4; // NodeFilter.SHOW_TEXT;
|
||||||
var FILTER_ACCEPT = 1; // NodeFilter.FILTER_ACCEPT;
|
|
||||||
var FILTER_SKIP = 3; // NodeFilter.FILTER_SKIP;
|
|
||||||
|
|
||||||
var START_TO_START = 0; // Range.START_TO_START
|
var START_TO_START = 0; // Range.START_TO_START
|
||||||
var START_TO_END = 1; // Range.START_TO_END
|
var START_TO_END = 1; // Range.START_TO_END
|
||||||
|
|
|
@ -4,8 +4,6 @@
|
||||||
TEXT_NODE,
|
TEXT_NODE,
|
||||||
SHOW_ELEMENT,
|
SHOW_ELEMENT,
|
||||||
SHOW_TEXT,
|
SHOW_TEXT,
|
||||||
FILTER_ACCEPT,
|
|
||||||
FILTER_SKIP,
|
|
||||||
win,
|
win,
|
||||||
isIOS,
|
isIOS,
|
||||||
isMac,
|
isMac,
|
||||||
|
@ -341,7 +339,7 @@ proto._removeZWS = function () {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var walker = new TreeWalker( this._body, SHOW_TEXT, function () {
|
var walker = new TreeWalker( this._body, SHOW_TEXT, function () {
|
||||||
return FILTER_ACCEPT;
|
return true;
|
||||||
}, false ),
|
}, false ),
|
||||||
node, index;
|
node, index;
|
||||||
while ( node = walker.nextNode() ) {
|
while ( node = walker.nextNode() ) {
|
||||||
|
@ -598,8 +596,7 @@ proto.hasFormat = function ( tag, attributes, range ) {
|
||||||
// Otherwise, check each text node at least partially contained within
|
// Otherwise, check each text node at least partially contained within
|
||||||
// the selection and make sure all of them have the format we want.
|
// the selection and make sure all of them have the format we want.
|
||||||
walker = new TreeWalker( root, SHOW_TEXT, function ( node ) {
|
walker = new TreeWalker( root, SHOW_TEXT, function ( node ) {
|
||||||
return isNodeContainedInRange( range, node, true ) ?
|
return isNodeContainedInRange( range, node, true );
|
||||||
FILTER_ACCEPT : FILTER_SKIP;
|
|
||||||
}, false );
|
}, false );
|
||||||
|
|
||||||
var seenNode = false;
|
var seenNode = false;
|
||||||
|
@ -638,8 +635,7 @@ proto._addFormat = function ( tag, attributes, range ) {
|
||||||
range.commonAncestorContainer,
|
range.commonAncestorContainer,
|
||||||
SHOW_TEXT,
|
SHOW_TEXT,
|
||||||
function ( node ) {
|
function ( node ) {
|
||||||
return isNodeContainedInRange( range, node, true ) ?
|
return isNodeContainedInRange( range, node, true );
|
||||||
FILTER_ACCEPT : FILTER_SKIP;
|
|
||||||
},
|
},
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
@ -1098,7 +1094,7 @@ var addLinks = function ( frag ) {
|
||||||
var doc = frag.ownerDocument,
|
var doc = frag.ownerDocument,
|
||||||
walker = new TreeWalker( frag, SHOW_TEXT,
|
walker = new TreeWalker( frag, SHOW_TEXT,
|
||||||
function ( node ) {
|
function ( node ) {
|
||||||
return getNearest( node, 'A' ) ? FILTER_SKIP : FILTER_ACCEPT;
|
return !getNearest( node, 'A' );
|
||||||
}, false ),
|
}, false ),
|
||||||
node, data, parent, match, index, endIndex, child;
|
node, data, parent, match, index, endIndex, child;
|
||||||
while ( node = walker.nextNode() ) {
|
while ( node = walker.nextNode() ) {
|
||||||
|
@ -1388,10 +1384,9 @@ var cleanTree = function ( node, allowStyles ) {
|
||||||
};
|
};
|
||||||
|
|
||||||
var notWSTextNode = function ( node ) {
|
var notWSTextNode = function ( node ) {
|
||||||
return ( node.nodeType === ELEMENT_NODE ?
|
return node.nodeType === ELEMENT_NODE ?
|
||||||
node.nodeName === 'BR' :
|
node.nodeName === 'BR' :
|
||||||
notWS.test( node.data ) ) ?
|
notWS.test( node.data );
|
||||||
FILTER_ACCEPT : FILTER_SKIP;
|
|
||||||
};
|
};
|
||||||
var isLineBreak = function ( br ) {
|
var isLineBreak = function ( br ) {
|
||||||
var block = br.parentNode,
|
var block = br.parentNode,
|
||||||
|
|
|
@ -2,8 +2,6 @@
|
||||||
ELEMENT_NODE,
|
ELEMENT_NODE,
|
||||||
TEXT_NODE,
|
TEXT_NODE,
|
||||||
SHOW_ELEMENT,
|
SHOW_ELEMENT,
|
||||||
FILTER_ACCEPT,
|
|
||||||
FILTER_SKIP,
|
|
||||||
win,
|
win,
|
||||||
isOpera,
|
isOpera,
|
||||||
useTextFixer,
|
useTextFixer,
|
||||||
|
@ -72,13 +70,10 @@ function isContainer ( node ) {
|
||||||
!isInline( node ) && !isBlock( node );
|
!isInline( node ) && !isBlock( node );
|
||||||
}
|
}
|
||||||
|
|
||||||
function acceptIfBlock ( el ) {
|
|
||||||
return isBlock( el ) ? FILTER_ACCEPT : FILTER_SKIP;
|
|
||||||
}
|
|
||||||
function getBlockWalker ( node ) {
|
function getBlockWalker ( node ) {
|
||||||
var doc = node.ownerDocument,
|
var doc = node.ownerDocument,
|
||||||
walker = new TreeWalker(
|
walker = new TreeWalker(
|
||||||
doc.body, SHOW_ELEMENT, acceptIfBlock, false );
|
doc.body, SHOW_ELEMENT, isBlock, false );
|
||||||
walker.currentNode = node;
|
walker.currentNode = node;
|
||||||
return walker;
|
return walker;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
ELEMENT_NODE,
|
ELEMENT_NODE,
|
||||||
TEXT_NODE,
|
TEXT_NODE,
|
||||||
SHOW_TEXT,
|
SHOW_TEXT,
|
||||||
FILTER_ACCEPT,
|
|
||||||
START_TO_START,
|
START_TO_START,
|
||||||
START_TO_END,
|
START_TO_END,
|
||||||
END_TO_END,
|
END_TO_END,
|
||||||
|
@ -60,8 +59,8 @@ var forEachTextNodeInRange = function ( range, fn ) {
|
||||||
endContainer = range.endContainer,
|
endContainer = range.endContainer,
|
||||||
root = range.commonAncestorContainer,
|
root = range.commonAncestorContainer,
|
||||||
walker = new TreeWalker(
|
walker = new TreeWalker(
|
||||||
root, SHOW_TEXT, function ( node ) {
|
root, SHOW_TEXT, function (/* node */) {
|
||||||
return FILTER_ACCEPT;
|
return true;
|
||||||
}, false ),
|
}, false ),
|
||||||
textnode = walker.currentNode = startContainer;
|
textnode = walker.currentNode = startContainer;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
/*global FILTER_ACCEPT */
|
|
||||||
/*jshint strict:false */
|
/*jshint strict:false */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -52,7 +51,7 @@ TreeWalker.prototype.nextNode = function () {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if ( ( typeToBitArray[ node.nodeType ] & nodeType ) &&
|
if ( ( typeToBitArray[ node.nodeType ] & nodeType ) &&
|
||||||
filter( node ) === FILTER_ACCEPT ) {
|
filter( node ) ) {
|
||||||
this.currentNode = node;
|
this.currentNode = node;
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
@ -82,7 +81,7 @@ TreeWalker.prototype.previousNode = function () {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if ( ( typeToBitArray[ node.nodeType ] & nodeType ) &&
|
if ( ( typeToBitArray[ node.nodeType ] & nodeType ) &&
|
||||||
filter( node ) === FILTER_ACCEPT ) {
|
filter( node ) ) {
|
||||||
this.currentNode = node;
|
this.currentNode = node;
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue