Index: trunk/extensions/VisualEditor/modules/ve/ce/ve.ce.js |
— | — | @@ -4,29 +4,35 @@ |
5 | 5 | * All classes and functions will be attached to this object to keep the global namespace clean. |
6 | 6 | */ |
7 | 7 | ve.ce = { |
8 | | - |
9 | | -}; |
| 8 | + /** |
| 9 | + * Gets the plain text of a DOM element. |
| 10 | + * |
| 11 | + * @static |
| 12 | + * @method |
| 13 | + * @param {HTMLElement} elem DOM element to get the plan text contents of |
| 14 | + * @returns {String} Plain text contents of DOM element |
| 15 | + */ |
| 16 | + 'getDOMText': function( elem ) { |
| 17 | + var nodeType = elem.nodeType, |
| 18 | + ret = ''; |
10 | 19 | |
11 | | -ve.ce.getDOMText = function( elem ) { |
12 | | - var nodeType = elem.nodeType, |
13 | | - ret = ''; |
14 | | - |
15 | | - if ( nodeType === 1 || nodeType === 9 ) { |
16 | | - // Use textContent || innerText for elements |
17 | | - if ( typeof elem.textContent === 'string' ) { |
18 | | - return elem.textContent; |
19 | | - } else if ( typeof elem.innerText === 'string' ) { |
20 | | - // Replace IE's carriage returns |
21 | | - return elem.innerText.replace( /\r\n/g, '' ); |
22 | | - } else { |
23 | | - // Traverse it's children |
24 | | - for ( elem = elem.firstChild; elem; elem = elem.nextSibling) { |
25 | | - ret += ve.ce.getDOMText( elem ); |
| 20 | + if ( nodeType === 1 || nodeType === 9 ) { |
| 21 | + // Use textContent || innerText for elements |
| 22 | + if ( typeof elem.textContent === 'string' ) { |
| 23 | + return elem.textContent; |
| 24 | + } else if ( typeof elem.innerText === 'string' ) { |
| 25 | + // Replace IE's carriage returns |
| 26 | + return elem.innerText.replace( /\r\n/g, '' ); |
| 27 | + } else { |
| 28 | + // Traverse it's children |
| 29 | + for ( elem = elem.firstChild; elem; elem = elem.nextSibling) { |
| 30 | + ret += ve.ce.getDOMText( elem ); |
| 31 | + } |
26 | 32 | } |
| 33 | + } else if ( nodeType === 3 || nodeType === 4 ) { |
| 34 | + return elem.nodeValue; |
27 | 35 | } |
28 | | - } else if ( nodeType === 3 || nodeType === 4 ) { |
29 | | - return elem.nodeValue; |
| 36 | + |
| 37 | + return ret; |
30 | 38 | } |
31 | | - |
32 | | - return ret; |
33 | | -}; |
\ No newline at end of file |
| 39 | +}; |