PageRenderTime 63ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/plugins/fckeditor/public/javascripts/fckeditor/editor/dialog/fck_replace.html

https://github.com/donatello83/project_fedena
HTML | 530 lines | 465 code | 43 blank | 22 comment | 0 complexity | 45cc893530dc58b4ac7984af55f7490d MD5 | raw file
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2. <!--
  3. * FCKeditor - The text editor for Internet - http://www.fckeditor.net
  4. * Copyright (C) 2003-2008 Frederico Caldeira Knabben
  5. *
  6. * == BEGIN LICENSE ==
  7. *
  8. * Licensed under the terms of any of the following licenses at your
  9. * choice:
  10. *
  11. * - GNU General Public License Version 2 or later (the "GPL")
  12. * http://www.gnu.org/licenses/gpl.html
  13. *
  14. * - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
  15. * http://www.gnu.org/licenses/lgpl.html
  16. *
  17. * - Mozilla Public License Version 1.1 or later (the "MPL")
  18. * http://www.mozilla.org/MPL/MPL-1.1.html
  19. *
  20. * == END LICENSE ==
  21. *
  22. * "Find" and "Replace" dialog box window.
  23. -->
  24. <html xmlns="http://www.w3.org/1999/xhtml">
  25. <head>
  26. <title></title>
  27. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  28. <meta content="noindex, nofollow" name="robots" />
  29. <script src="common/fck_dialog_common.js" type="text/javascript"></script>
  30. <script type="text/javascript">
  31. var dialog = window.parent ;
  32. var oEditor = dialog.InnerDialogLoaded() ;
  33. var dialogArguments = dialog.Args() ;
  34. var FCKLang = oEditor.FCKLang ;
  35. dialog.AddTab( 'Find', FCKLang.DlgFindTitle ) ;
  36. dialog.AddTab( 'Replace', FCKLang.DlgReplaceTitle ) ;
  37. var idMap = {} ;
  38. function OnDialogTabChange( tabCode )
  39. {
  40. ShowE( 'divFind', ( tabCode == 'Find' ) ) ;
  41. ShowE( 'divReplace', ( tabCode == 'Replace' ) ) ;
  42. idMap['FindText'] = 'txtFind' + tabCode ;
  43. idMap['CheckCase'] = 'chkCase' + tabCode ;
  44. idMap['CheckWord'] = 'chkWord' + tabCode ;
  45. if ( tabCode == 'Replace' )
  46. dialog.SetAutoSize( true ) ;
  47. }
  48. // Place a range at the start of document.
  49. // This will be the starting point of our search.
  50. var GlobalRange = new oEditor.FCKDomRange( oEditor.FCK.EditorWindow ) ;
  51. function ResetGlobalRange()
  52. {
  53. GlobalRange.SetStart( oEditor.FCK.EditorDocument.body, 1 ) ;
  54. GlobalRange.SetEnd( oEditor.FCK.EditorDocument.body, 1 ) ;
  55. GlobalRange.Collapse( true ) ;
  56. }
  57. ResetGlobalRange() ;
  58. var HighlightRange = null ;
  59. function Highlight()
  60. {
  61. if ( HighlightRange )
  62. ClearHighlight() ;
  63. var cloneRange = GlobalRange.Clone() ;
  64. oEditor.FCKStyles.GetStyle( '_FCK_SelectionHighlight' ).ApplyToRange( cloneRange, false, true ) ;
  65. HighlightRange = cloneRange ;
  66. GlobalRange = HighlightRange.Clone() ;
  67. }
  68. function ClearHighlight()
  69. {
  70. if ( HighlightRange )
  71. {
  72. oEditor.FCKStyles.GetStyle( '_FCK_SelectionHighlight' ).RemoveFromRange( HighlightRange, false, true ) ;
  73. HighlightRange = null ;
  74. }
  75. }
  76. function OnLoad()
  77. {
  78. // First of all, translate the dialog box texts.
  79. oEditor.FCKLanguageManager.TranslatePage( document ) ;
  80. // Show the appropriate tab at startup.
  81. if ( dialogArguments.CustomValue == 'Find' )
  82. {
  83. dialog.SetSelectedTab( 'Find' ) ;
  84. dialog.SetAutoSize( true ) ;
  85. }
  86. else
  87. dialog.SetSelectedTab( 'Replace' ) ;
  88. SelectField( 'txtFind' + dialogArguments.CustomValue ) ;
  89. }
  90. function btnStat()
  91. {
  92. GetE('btnReplace').disabled =
  93. GetE('btnReplaceAll').disabled =
  94. GetE('btnFind').disabled =
  95. ( GetE(idMap["FindText"]).value.length == 0 ) ;
  96. }
  97. function btnStatDelayed()
  98. {
  99. setTimeout( btnStat, 1 ) ;
  100. }
  101. function GetSearchString()
  102. {
  103. return GetE(idMap['FindText']).value ;
  104. }
  105. function GetReplaceString()
  106. {
  107. return GetE("txtReplace").value ;
  108. }
  109. function GetCheckCase()
  110. {
  111. return !! ( GetE(idMap['CheckCase']).checked ) ;
  112. }
  113. function GetMatchWord()
  114. {
  115. return !! ( GetE(idMap['CheckWord']).checked ) ;
  116. }
  117. // Get the data pointed to by a bookmark.
  118. function GetData( bookmark )
  119. {
  120. var cursor = oEditor.FCK.EditorDocument.documentElement ;
  121. for ( var i = 0 ; i < bookmark.length ; i++ )
  122. {
  123. var target = bookmark[i] ;
  124. var currentIndex = -1 ;
  125. if ( cursor.nodeType != 3 )
  126. {
  127. for (var j = 0 ; j < cursor.childNodes.length ; j++ )
  128. {
  129. var candidate = cursor.childNodes[j] ;
  130. if ( candidate.nodeType == 3 &&
  131. candidate.previousSibling &&
  132. candidate.previousSibling.nodeType == 3 )
  133. continue ;
  134. currentIndex++ ;
  135. if ( currentIndex == target )
  136. {
  137. cursor = candidate ;
  138. break ;
  139. }
  140. }
  141. if ( currentIndex < target )
  142. return null ;
  143. }
  144. else
  145. {
  146. if ( i != bookmark.length - 1 )
  147. return null ;
  148. while ( target >= cursor.length && cursor.nextSibling && cursor.nextSibling.nodeType == 3 )
  149. {
  150. target -= cursor.length ;
  151. cursor = cursor.nextSibling ;
  152. }
  153. cursor = cursor.nodeValue.charAt( target ) ;
  154. if ( cursor == "" )
  155. cursor = null ;
  156. }
  157. }
  158. return cursor ;
  159. }
  160. // With this function, we can treat the bookmark as an iterator for DFS.
  161. function NextPosition( bookmark )
  162. {
  163. // See if there's anything further down the tree.
  164. var next = bookmark.concat( [0] ) ;
  165. if ( GetData( next ) != null )
  166. return next ;
  167. // Nothing down there? See if there's anything next to me.
  168. var next = bookmark.slice( 0, bookmark.length - 1 ).concat( [ bookmark[ bookmark.length - 1 ] + 1 ] ) ;
  169. if ( GetData( next ) != null )
  170. return next ;
  171. // Nothing even next to me? See if there's anything next to my ancestors.
  172. for ( var i = bookmark.length - 1 ; i > 0 ; i-- )
  173. {
  174. var next = bookmark.slice( 0, i - 1 ).concat( [ bookmark[ i - 1 ] + 1 ] ) ;
  175. if ( GetData( next ) != null )
  176. return next ;
  177. }
  178. // There's absolutely nothing left to walk, return null.
  179. return null ;
  180. }
  181. // Is this character a unicode whitespace?
  182. // Reference: http://unicode.org/Public/UNIDATA/PropList.txt
  183. function CheckIsWhitespace( c )
  184. {
  185. var code = c.charCodeAt( 0 );
  186. if ( code >= 9 && code <= 0xd )
  187. return true;
  188. if ( code >= 0x2000 && code <= 0x200a )
  189. return true;
  190. switch ( code )
  191. {
  192. case 0x20:
  193. case 0x85:
  194. case 0xa0:
  195. case 0x1680:
  196. case 0x180e:
  197. case 0x2028:
  198. case 0x2029:
  199. case 0x202f:
  200. case 0x205f:
  201. case 0x3000:
  202. return true;
  203. default:
  204. return false;
  205. }
  206. }
  207. // Knuth-Morris-Pratt Algorithm for stream input
  208. KMP_NOMATCH = 0 ;
  209. KMP_ADVANCED = 1 ;
  210. KMP_MATCHED = 2 ;
  211. function KmpMatch( pattern, ignoreCase )
  212. {
  213. var overlap = [ -1 ] ;
  214. for ( var i = 0 ; i < pattern.length ; i++ )
  215. {
  216. overlap.push( overlap[i] + 1 ) ;
  217. while ( overlap[ i + 1 ] > 0 && pattern.charAt( i ) != pattern.charAt( overlap[ i + 1 ] - 1 ) )
  218. overlap[ i + 1 ] = overlap[ overlap[ i + 1 ] - 1 ] + 1 ;
  219. }
  220. this._Overlap = overlap ;
  221. this._State = 0 ;
  222. this._IgnoreCase = ( ignoreCase === true ) ;
  223. if ( ignoreCase )
  224. this.Pattern = pattern.toLowerCase();
  225. else
  226. this.Pattern = pattern ;
  227. }
  228. KmpMatch.prototype = {
  229. "FeedCharacter" : function( c )
  230. {
  231. if ( this._IgnoreCase )
  232. c = c.toLowerCase();
  233. while ( true )
  234. {
  235. if ( c == this.Pattern.charAt( this._State ) )
  236. {
  237. this._State++ ;
  238. if ( this._State == this.Pattern.length )
  239. {
  240. // found a match, start over, don't care about partial matches involving the current match
  241. this._State = 0;
  242. return KMP_MATCHED;
  243. }
  244. return KMP_ADVANCED ;
  245. }
  246. else if ( this._State == 0 )
  247. return KMP_NOMATCH;
  248. else
  249. this._State = this._Overlap[ this._State ];
  250. }
  251. return null ;
  252. },
  253. "Reset" : function()
  254. {
  255. this._State = 0 ;
  256. }
  257. };
  258. function _Find()
  259. {
  260. // Start from the end of the current selection.
  261. var matcher = new KmpMatch( GetSearchString(), ! GetCheckCase() ) ;
  262. var cursor = GlobalRange.CreateBookmark2().End ;
  263. var matchState = KMP_NOMATCH ;
  264. var matchBookmark = null ;
  265. var matchBookmarkStart = [] ;
  266. // Match finding.
  267. while ( true )
  268. {
  269. // Perform KMP stream matching.
  270. // - Reset KMP matcher if we encountered a block element.
  271. var data = GetData( cursor ) ;
  272. if ( data )
  273. {
  274. if ( data.tagName )
  275. {
  276. if ( oEditor.FCKListsLib.BlockElements[ data.tagName.toLowerCase() ] )
  277. {
  278. matcher.Reset();
  279. matchBookmarkStart = [] ;
  280. }
  281. }
  282. else if ( data.charAt != undefined )
  283. {
  284. matchState = matcher.FeedCharacter(data) ;
  285. // No possible match of any useful substring in the pattern for the currently scanned character.
  286. // So delete any positional information.
  287. if ( matchState == KMP_NOMATCH )
  288. matchBookmarkStart = [] ;
  289. // We've matched something, but it's not a complete match, so let's just mark down the position for backtracking later.
  290. else if ( matchState == KMP_ADVANCED )
  291. {
  292. matchBookmarkStart.push( cursor.concat( [] ) ) ;
  293. if ( matchBookmarkStart.length > matcher._State )
  294. matchBookmarkStart.shift() ;
  295. }
  296. // Found a complete match! Mark down the ending position as well.
  297. else if ( matchState == KMP_MATCHED )
  298. {
  299. // It is possible to get a KMP_MATCHED without KMP_ADVANCED when the match pattern is only 1 character.
  300. // So need to check and mark down the starting position as well.
  301. if ( matchBookmarkStart.length == 0 )
  302. matchBookmarkStart = [cursor.concat( [] )] ;
  303. matchBookmark = { 'Start' : matchBookmarkStart.shift(), 'End' : cursor.concat( [] ) } ;
  304. matchBookmark.End[ matchBookmark.End.length - 1 ]++;
  305. // Wait, do we have to match a whole word?
  306. // If yes, carry out additional checks on what we've got.
  307. if ( GetMatchWord() )
  308. {
  309. var startOk = false ;
  310. var endOk = false ;
  311. var start = matchBookmark.Start ;
  312. var end = matchBookmark.End ;
  313. if ( start[ start.length - 1 ] == 0 )
  314. startOk = true ;
  315. else
  316. {
  317. var cursorBeforeStart = start.slice( 0, start.length - 1 ) ;
  318. cursorBeforeStart.push( start[ start.length - 1 ] - 1 ) ;
  319. var dataBeforeStart = GetData( cursorBeforeStart ) ;
  320. if ( dataBeforeStart == null || dataBeforeStart.charAt == undefined )
  321. startOk = true ;
  322. else if ( CheckIsWhitespace( dataBeforeStart ) )
  323. startOk = true ;
  324. }
  325. // this is already one character beyond the last char, no need to move
  326. var cursorAfterEnd = end ;
  327. var dataAfterEnd = GetData( cursorAfterEnd );
  328. if ( dataAfterEnd == null || dataAfterEnd.charAt == undefined )
  329. endOk = true ;
  330. else if ( CheckIsWhitespace( dataAfterEnd ) )
  331. endOk = true ;
  332. if ( startOk && endOk )
  333. break ;
  334. else
  335. matcher.Reset() ;
  336. }
  337. else
  338. break ;
  339. }
  340. }
  341. }
  342. // Perform DFS across the document, until we've reached the end.
  343. cursor = NextPosition( cursor ) ;
  344. if ( cursor == null )
  345. break;
  346. }
  347. // If we've found a match, highlight the match.
  348. if ( matchState == KMP_MATCHED )
  349. {
  350. GlobalRange.MoveToBookmark2( matchBookmark ) ;
  351. Highlight() ;
  352. var focus = GlobalRange._Range.endContainer ;
  353. while ( focus && focus.nodeType != 1 )
  354. focus = focus.parentNode ;
  355. if ( focus )
  356. {
  357. if ( oEditor.FCKBrowserInfo.IsSafari )
  358. oEditor.FCKDomTools.ScrollIntoView( focus, false ) ;
  359. else
  360. focus.scrollIntoView( false ) ;
  361. }
  362. return true ;
  363. }
  364. else
  365. {
  366. ResetGlobalRange() ;
  367. return false ;
  368. }
  369. }
  370. function Find()
  371. {
  372. if ( ! _Find() )
  373. {
  374. ClearHighlight() ;
  375. alert( FCKLang.DlgFindNotFoundMsg ) ;
  376. }
  377. }
  378. function Replace()
  379. {
  380. if ( GlobalRange.CheckIsCollapsed() )
  381. {
  382. if (! _Find() )
  383. {
  384. ClearHighlight() ;
  385. alert( FCKLang.DlgFindNotFoundMsg ) ;
  386. }
  387. }
  388. else
  389. {
  390. oEditor.FCKUndo.SaveUndoStep() ;
  391. GlobalRange.DeleteContents() ;
  392. GlobalRange.InsertNode( oEditor.FCK.EditorDocument.createTextNode( GetReplaceString() ) ) ;
  393. GlobalRange.Collapse( false ) ;
  394. }
  395. }
  396. function ReplaceAll()
  397. {
  398. oEditor.FCKUndo.SaveUndoStep() ;
  399. var replaceCount = 0 ;
  400. while ( _Find() )
  401. {
  402. dialog.Selection.EnsureSelection() ;
  403. GlobalRange.DeleteContents() ;
  404. GlobalRange.InsertNode( oEditor.FCK.EditorDocument.createTextNode( GetReplaceString() ) ) ;
  405. GlobalRange.Collapse( false ) ;
  406. replaceCount++ ;
  407. }
  408. if ( replaceCount == 0 )
  409. {
  410. ClearHighlight() ;
  411. alert( FCKLang.DlgFindNotFoundMsg ) ;
  412. }
  413. dialog.Cancel() ;
  414. }
  415. window.onunload = function(){ ClearHighlight() ; }
  416. </script>
  417. </head>
  418. <body onload="OnLoad()" style="overflow: hidden">
  419. <div id="divFind" style="display: none">
  420. <table cellspacing="3" cellpadding="2" width="100%" border="0">
  421. <tr>
  422. <td nowrap="nowrap">
  423. <label for="txtFindFind" fcklang="DlgReplaceFindLbl">
  424. Find what:</label>
  425. </td>
  426. <td width="100%">
  427. <input id="txtFindFind" onkeyup="btnStat()" oninput="btnStat()" onpaste="btnStatDelayed()" style="width: 100%" tabindex="1"
  428. type="text" />
  429. </td>
  430. <td>
  431. <input id="btnFind" style="width: 80px" disabled="disabled" onclick="Find();"
  432. type="button" value="Find" fcklang="DlgFindFindBtn" />
  433. </td>
  434. </tr>
  435. <tr>
  436. <td valign="bottom" colspan="3">
  437. &nbsp;<input id="chkCaseFind" tabindex="3" type="checkbox" /><label for="chkCaseFind" fcklang="DlgReplaceCaseChk">Match
  438. case</label>
  439. <br />
  440. &nbsp;<input id="chkWordFind" tabindex="4" type="checkbox" /><label for="chkWordFind" fcklang="DlgReplaceWordChk">Match
  441. whole word</label>
  442. </td>
  443. </tr>
  444. </table>
  445. </div>
  446. <div id="divReplace" style="display:none">
  447. <table cellspacing="3" cellpadding="2" width="100%" border="0">
  448. <tr>
  449. <td nowrap="nowrap">
  450. <label for="txtFindReplace" fcklang="DlgReplaceFindLbl">
  451. Find what:</label>
  452. </td>
  453. <td width="100%">
  454. <input id="txtFindReplace" onkeyup="btnStat()" oninput="btnStat()" onpaste="btnStatDelayed()" style="width: 100%" tabindex="1"
  455. type="text" />
  456. </td>
  457. <td>
  458. <input id="btnReplace" style="width: 80px" disabled="disabled" onclick="Replace();"
  459. type="button" value="Replace" fcklang="DlgReplaceReplaceBtn" />
  460. </td>
  461. </tr>
  462. <tr>
  463. <td valign="top" nowrap="nowrap">
  464. <label for="txtReplace" fcklang="DlgReplaceReplaceLbl">
  465. Replace with:</label>
  466. </td>
  467. <td valign="top">
  468. <input id="txtReplace" style="width: 100%" tabindex="2" type="text" />
  469. </td>
  470. <td>
  471. <input id="btnReplaceAll" style="width: 80px" disabled="disabled" onclick="ReplaceAll()" type="button"
  472. value="Replace All" fcklang="DlgReplaceReplAllBtn" />
  473. </td>
  474. </tr>
  475. <tr>
  476. <td valign="bottom" colspan="3">
  477. &nbsp;<input id="chkCaseReplace" tabindex="3" type="checkbox" /><label for="chkCaseReplace" fcklang="DlgReplaceCaseChk">Match
  478. case</label>
  479. <br />
  480. &nbsp;<input id="chkWordReplace" tabindex="4" type="checkbox" /><label for="chkWordReplace" fcklang="DlgReplaceWordChk">Match
  481. whole word</label>
  482. </td>
  483. </tr>
  484. </table>
  485. </div>
  486. </body>
  487. </html>