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