/EQT_V1/EQTWebApp/fckeditor/editor/_source/classes/fckhtmliterator.js

http://sgsoft-las.googlecode.com/ · JavaScript · 142 lines · 84 code · 6 blank · 52 comment · 10 complexity · 970289717b0f0696c6c00e49745b27d3 MD5 · raw file

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