2012-02-06 23:50:56 +00:00
|
|
|
/**
|
|
|
|
* VisualEditor ContentEditable namespace.
|
|
|
|
*
|
|
|
|
* All classes and functions will be attached to this object to keep the global namespace clean.
|
|
|
|
*/
|
2012-03-06 22:39:43 +00:00
|
|
|
ve.ce = {
|
2012-02-06 23:50:56 +00:00
|
|
|
|
|
|
|
};
|
2012-02-10 22:19:12 +00:00
|
|
|
|
2012-03-06 22:39:43 +00:00
|
|
|
ve.ce.getDOMText = function( elem ) {
|
2012-02-10 22:19:12 +00:00
|
|
|
var nodeType = elem.nodeType,
|
|
|
|
ret = '';
|
|
|
|
|
|
|
|
if ( nodeType === 1 || nodeType === 9 ) {
|
|
|
|
// Use textContent || innerText for elements
|
|
|
|
if ( typeof elem.textContent === 'string' ) {
|
|
|
|
return elem.textContent;
|
|
|
|
} else if ( typeof elem.innerText === 'string' ) {
|
|
|
|
// Replace IE's carriage returns
|
|
|
|
return elem.innerText.replace( /\r\n/g, '' );
|
|
|
|
} else {
|
|
|
|
// Traverse it's children
|
|
|
|
for ( elem = elem.firstChild; elem; elem = elem.nextSibling) {
|
2012-03-06 22:39:43 +00:00
|
|
|
ret += ve.ce.getDOMText( elem );
|
2012-02-10 22:19:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if ( nodeType === 3 || nodeType === 4 ) {
|
|
|
|
return elem.nodeValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
};
|