import rt 3.8.7
[freeside.git] / rt / share / html / NoAuth / RichText / FCKeditor / editor / _source / classes / fckhtmliterator.js
1 /*\r
2  * FCKeditor - The text editor for Internet - http://www.fckeditor.net\r
3  * Copyright (C) 2003-2009 Frederico Caldeira Knabben\r
4  *\r
5  * == BEGIN LICENSE ==\r
6  *\r
7  * Licensed under the terms of any of the following licenses at your\r
8  * choice:\r
9  *\r
10  *  - GNU General Public License Version 2 or later (the "GPL")\r
11  *    http://www.gnu.org/licenses/gpl.html\r
12  *\r
13  *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")\r
14  *    http://www.gnu.org/licenses/lgpl.html\r
15  *\r
16  *  - Mozilla Public License Version 1.1 or later (the "MPL")\r
17  *    http://www.mozilla.org/MPL/MPL-1.1.html\r
18  *\r
19  * == END LICENSE ==\r
20  *\r
21  * This class can be used to interate through nodes inside a range.\r
22  *\r
23  * During interation, the provided range can become invalid, due to document\r
24  * mutations, so CreateBookmark() used to restore it after processing, if\r
25  * needed.\r
26  */\r
27 \r
28 var FCKHtmlIterator = function( source )\r
29 {\r
30         this._sourceHtml = source ;\r
31 }\r
32 FCKHtmlIterator.prototype =\r
33 {\r
34         Next : function()\r
35         {\r
36                 var sourceHtml = this._sourceHtml ;\r
37                 if ( sourceHtml == null )\r
38                         return null ;\r
39 \r
40                 var match = FCKRegexLib.HtmlTag.exec( sourceHtml ) ;\r
41                 var isTag = false ;\r
42                 var value = "" ;\r
43                 if ( match )\r
44                 {\r
45                         if ( match.index > 0 )\r
46                         {\r
47                                 value = sourceHtml.substr( 0, match.index ) ;\r
48                                 this._sourceHtml = sourceHtml.substr( match.index ) ;\r
49                         }\r
50                         else\r
51                         {\r
52                                 isTag = true ;\r
53                                 value = match[0] ;\r
54                                 this._sourceHtml = sourceHtml.substr( match[0].length ) ;\r
55                         }\r
56                 }\r
57                 else\r
58                 {\r
59                         value = sourceHtml ;\r
60                         this._sourceHtml = null ;\r
61                 }\r
62                 return { 'isTag' : isTag, 'value' : value } ;\r
63         },\r
64 \r
65         Each : function( func )\r
66         {\r
67                 var chunk ;\r
68                 while ( ( chunk = this.Next() ) )\r
69                         func( chunk.isTag, chunk.value ) ;\r
70         }\r
71 } ;\r
72 /*\r
73  * FCKeditor - The text editor for Internet - http://www.fckeditor.net\r
74  * Copyright (C) 2003-2009 Frederico Caldeira Knabben\r
75  *\r
76  * == BEGIN LICENSE ==\r
77  *\r
78  * Licensed under the terms of any of the following licenses at your\r
79  * choice:\r
80  *\r
81  *  - GNU General Public License Version 2 or later (the "GPL")\r
82  *    http://www.gnu.org/licenses/gpl.html\r
83  *\r
84  *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")\r
85  *    http://www.gnu.org/licenses/lgpl.html\r
86  *\r
87  *  - Mozilla Public License Version 1.1 or later (the "MPL")\r
88  *    http://www.mozilla.org/MPL/MPL-1.1.html\r
89  *\r
90  * == END LICENSE ==\r
91  *\r
92  * This class can be used to interate through nodes inside a range.\r
93  *\r
94  * During interation, the provided range can become invalid, due to document\r
95  * mutations, so CreateBookmark() used to restore it after processing, if\r
96  * needed.\r
97  */\r
98 \r
99 var FCKHtmlIterator = function( source )\r
100 {\r
101         this._sourceHtml = source ;\r
102 }\r
103 FCKHtmlIterator.prototype =\r
104 {\r
105         Next : function()\r
106         {\r
107                 var sourceHtml = this._sourceHtml ;\r
108                 if ( sourceHtml == null )\r
109                         return null ;\r
110 \r
111                 var match = FCKRegexLib.HtmlTag.exec( sourceHtml ) ;\r
112                 var isTag = false ;\r
113                 var value = "" ;\r
114                 if ( match )\r
115                 {\r
116                         if ( match.index > 0 )\r
117                         {\r
118                                 value = sourceHtml.substr( 0, match.index ) ;\r
119                                 this._sourceHtml = sourceHtml.substr( match.index ) ;\r
120                         }\r
121                         else\r
122                         {\r
123                                 isTag = true ;\r
124                                 value = match[0] ;\r
125                                 this._sourceHtml = sourceHtml.substr( match[0].length ) ;\r
126                         }\r
127                 }\r
128                 else\r
129                 {\r
130                         value = sourceHtml ;\r
131                         this._sourceHtml = null ;\r
132                 }\r
133                 return { 'isTag' : isTag, 'value' : value } ;\r
134         },\r
135 \r
136         Each : function( func )\r
137         {\r
138                 var chunk ;\r
139                 while ( ( chunk = this.Next() ) )\r
140                         func( chunk.isTag, chunk.value ) ;\r
141         }\r
142 } ;\r