Fix bugs in getDomText method.

This commit is contained in:
Inez Korczynski 2012-06-13 22:04:52 -07:00
parent f4a4952d18
commit ba680afcc3

View file

@ -32,9 +32,10 @@ ve.ce.whitespacePattern = /[\u0020\u00A0]/g;
* @returns {String} Plain text of DOM element
*/
ve.ce.getDomText = function( element ) {
var func = function( element ) {
var nodeType = element.nodeType,
text = '';
if ( nodeType === 1 || nodeType === 9 ) {
if ( nodeType === 1 || nodeType === 9 || nodeType === 11 ) {
// Use textContent || innerText for elements
if ( typeof element.textContent === 'string' ) {
return element.textContent;
@ -44,15 +45,17 @@ ve.ce.getDomText = function( element ) {
} else {
// Traverse it's children
for ( element = element.firstChild; element; element = element.nextSibling) {
text += ve.ce.getDomText( element );
text += func( element );
}
}
} else if ( nodeType === 3 || nodeType === 4 ) {
return element.nodeValue;
}
return text;
}
// Return the text, replacing spaces and non-breaking spaces with spaces?
// TODO: Why are we replacing spaces (\u0020) with spaces (' ')
return text.replace( ve.ce.whitespacePattern, ' ' );
return func( element ).replace( ve.ce.whitespacePattern, ' ' );
};
/**