]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/debian/missing-sources/framework/Web/Javascripts/source/tinymce-405/classes/dom/TreeWalker.js
baculum: Add missing-sources directory in debian metadata structure
[bacula/bacula] / gui / baculum / debian / missing-sources / framework / Web / Javascripts / source / tinymce-405 / classes / dom / TreeWalker.js
1 /**
2  * TreeWalker.js
3  *
4  * Copyright, Moxiecode Systems AB
5  * Released under LGPL License.
6  *
7  * License: http://www.tinymce.com/license
8  * Contributing: http://www.tinymce.com/contributing
9  */
10
11 /**
12  * TreeWalker class enables you to walk the DOM in a linear manner.
13  *
14  * @class tinymce.dom.TreeWalker
15  */
16 define("tinymce/dom/TreeWalker", [], function() {
17         return function(start_node, root_node) {
18                 var node = start_node;
19
20                 function findSibling(node, start_name, sibling_name, shallow) {
21                         var sibling, parent;
22
23                         if (node) {
24                                 // Walk into nodes if it has a start
25                                 if (!shallow && node[start_name]) {
26                                         return node[start_name];
27                                 }
28
29                                 // Return the sibling if it has one
30                                 if (node != root_node) {
31                                         sibling = node[sibling_name];
32                                         if (sibling) {
33                                                 return sibling;
34                                         }
35
36                                         // Walk up the parents to look for siblings
37                                         for (parent = node.parentNode; parent && parent != root_node; parent = parent.parentNode) {
38                                                 sibling = parent[sibling_name];
39                                                 if (sibling) {
40                                                         return sibling;
41                                                 }
42                                         }
43                                 }
44                         }
45                 }
46
47                 /**
48                  * Returns the current node.
49                  *
50                  * @method current
51                  * @return {Node} Current node where the walker is.
52                  */
53                 this.current = function() {
54                         return node;
55                 };
56
57                 /**
58                  * Walks to the next node in tree.
59                  *
60                  * @method next
61                  * @return {Node} Current node where the walker is after moving to the next node.
62                  */
63                 this.next = function(shallow) {
64                         node = findSibling(node, 'firstChild', 'nextSibling', shallow);
65                         return node;
66                 };
67
68                 /**
69                  * Walks to the previous node in tree.
70                  *
71                  * @method prev
72                  * @return {Node} Current node where the walker is after moving to the previous node.
73                  */
74                 this.prev = function(shallow) {
75                         node = findSibling(node, 'lastChild', 'previousSibling', shallow);
76                         return node;
77                 };
78         };
79 });