From ce824d6299889ed0f1f0179a264f0c3c06153d9d Mon Sep 17 00:00:00 2001 From: Trevor Parscal Date: Fri, 9 Mar 2012 22:45:22 +0000 Subject: [PATCH] Cleanup --- modules/ve/ce/ve.ce.js | 50 +++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/modules/ve/ce/ve.ce.js b/modules/ve/ce/ve.ce.js index b64e772dd7..d48a3a424c 100644 --- a/modules/ve/ce/ve.ce.js +++ b/modules/ve/ce/ve.ce.js @@ -4,29 +4,35 @@ * All classes and functions will be attached to this object to keep the global namespace clean. */ ve.ce = { - -}; + /** + * Gets the plain text of a DOM element. + * + * @static + * @method + * @param {HTMLElement} elem DOM element to get the plan text contents of + * @returns {String} Plain text contents of DOM element + */ + 'getDOMText': function( elem ) { + var nodeType = elem.nodeType, + ret = ''; -ve.ce.getDOMText = function( elem ) { - 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) { - ret += ve.ce.getDOMText( elem ); + 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) { + ret += ve.ce.getDOMText( elem ); + } } + } else if ( nodeType === 3 || nodeType === 4 ) { + return elem.nodeValue; } - } else if ( nodeType === 3 || nodeType === 4 ) { - return elem.nodeValue; - } - return ret; -}; \ No newline at end of file + return ret; + } +};