29sHyVu1J3iljnGks30yY3 changeset

Changeset326530663566 (b)
ParentNone (a)
ab
0+// jQuery function to find all the text nodes inside an element
0+$.fn.textNodes = function() {
0+  // array we will store all the text nodes in
0+  var ret = [];
0+
0+  // nodes we want to skip
0+  var restricted_nodes = {'SCRIPT':1, 'NOSCRIPT':1, 'STYLE':1};
0+
0+  $.each(this[0].childNodes, function() {
0+      if (this.nodeType == 3 && $.trim(this.nodeValue)) {
0+          ret.push(this);
0+      } else if (!restricted_nodes.hasOwnProperty(this.nodeName)) {
0+          $.each(this.childNodes, arguments.callee);
0+      }
0+  });
0+  return ret;
0+}
0+
0+var textNodes = $('body').textNodes();
0+
0+var text = '';
0+for (var i = 0; i < textNodes.length; ++i) {
0+    text += textNodes[i].nodeValue + ' ';
0+}
0+// text is now a string containing the full text of a webpage with no html
0+
0+
0+// see http://docs.jquery.com/Release:jQuery_1.3.2#:visible.2F:hidden_Overhauled
0+// for details on how jquery handles finding hidden elements
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
--- Revision None
+++ Revision 326530663566
@@ -0,0 +1,29 @@
+// jQuery function to find all the text nodes inside an element
+$.fn.textNodes = function() {
+ // array we will store all the text nodes in
+ var ret = [];
+
+ // nodes we want to skip
+ var restricted_nodes = {'SCRIPT':1, 'NOSCRIPT':1, 'STYLE':1};
+
+ $.each(this[0].childNodes, function() {
+ if (this.nodeType == 3 && $.trim(this.nodeValue)) {
+ ret.push(this);
+ } else if (!restricted_nodes.hasOwnProperty(this.nodeName)) {
+ $.each(this.childNodes, arguments.callee);
+ }
+ });
+ return ret;
+}
+
+var textNodes = $('body').textNodes();
+
+var text = '';
+for (var i = 0; i < textNodes.length; ++i) {
+ text += textNodes[i].nodeValue + ' ';
+}
+// text is now a string containing the full text of a webpage with no html
+
+
+// see http://docs.jquery.com/Release:jQuery_1.3.2#:visible.2F:hidden_Overhauled
+// for details on how jquery handles finding hidden elements