comparison default/node_modules/shoestring/src/dom/text.js @ 0:1d038bc9b3d2 default tip

Up:default
author Liny <dev@neowd.com>
date Sat, 31 May 2025 09:21:51 +0800
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:1d038bc9b3d2
1 //>>excludeStart("exclude", pragmas.exclude);
2 define([ "shoestring" ], function(){
3 //>>excludeEnd("exclude");
4
5 var getText = function( elem ){
6 var node,
7 ret = "",
8 i = 0,
9 nodeType = elem.nodeType;
10
11 if ( !nodeType ) {
12 // If no nodeType, this is expected to be an array
13 while ( (node = elem[i++]) ) {
14 // Do not traverse comment nodes
15 ret += getText( node );
16 }
17 } else if ( nodeType === 1 || nodeType === 9 || nodeType === 11 ) {
18 // Use textContent for elements
19 // innerText usage removed for consistency of new lines (jQuery #11153)
20 if ( typeof elem.textContent === "string" ) {
21 return elem.textContent;
22 } else {
23 // Traverse its children
24 for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) {
25 ret += getText( elem );
26 }
27 }
28 } else if ( nodeType === 3 || nodeType === 4 ) {
29 return elem.nodeValue;
30 }
31 // Do not include comment or processing instruction nodes
32
33 return ret;
34 };
35
36 /**
37 * Recursively retrieve the text content of the each element in the current set.
38 *
39 * @return shoestring
40 * @this shoestring
41 */
42 shoestring.fn.text = function() {
43 //>>includeStart("development", pragmas.development);
44 if( arguments.length > 0 ){
45 shoestring.error( 'text-setter' );
46 }
47 //>>includeEnd("development");
48
49 return getText( this );
50 };
51
52 //>>excludeStart("exclude", pragmas.exclude);
53 });
54 //>>excludeEnd("exclude");