event refactor, landing on HEAD!
[freeside.git] / httemplate / elements / fckeditor / editor / dialog / fck_replace.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">\r
2 <!--\r
3  * FCKeditor - The text editor for Internet - http://www.fckeditor.net\r
4  * Copyright (C) 2003-2007 Frederico Caldeira Knabben\r
5  *\r
6  * == BEGIN LICENSE ==\r
7  *\r
8  * Licensed under the terms of any of the following licenses at your\r
9  * choice:\r
10  *\r
11  *  - GNU General Public License Version 2 or later (the "GPL")\r
12  *    http://www.gnu.org/licenses/gpl.html\r
13  *\r
14  *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")\r
15  *    http://www.gnu.org/licenses/lgpl.html\r
16  *\r
17  *  - Mozilla Public License Version 1.1 or later (the "MPL")\r
18  *    http://www.mozilla.org/MPL/MPL-1.1.html\r
19  *\r
20  * == END LICENSE ==\r
21  *\r
22  * "Replace" dialog box window.\r
23 -->\r
24 <html xmlns="http://www.w3.org/1999/xhtml">\r
25 <head>\r
26         <title></title>\r
27         <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\r
28         <meta content="noindex, nofollow" name="robots" />\r
29         <script type="text/javascript">\r
30 \r
31 var oEditor = window.parent.InnerDialogLoaded() ;\r
32 \r
33 function OnLoad()\r
34 {\r
35         // First of all, translate the dialog box texts\r
36         oEditor.FCKLanguageManager.TranslatePage( document ) ;\r
37 \r
38         window.parent.SetAutoSize( true ) ;\r
39 \r
40         oEditor.FCKUndo.SaveUndoStep() ;\r
41 }\r
42 \r
43 function btnStat(frm)\r
44 {\r
45         document.getElementById('btnReplace').disabled =\r
46                 document.getElementById('btnReplaceAll').disabled =\r
47                         ( document.getElementById('txtFind').value.length == 0 ) ;\r
48 }\r
49 \r
50 function ReplaceTextNodes( parentNode, regex, replaceValue, replaceAll, hasFound )\r
51 {\r
52         for ( var i = 0 ; i < parentNode.childNodes.length ; i++ )\r
53         {\r
54                 var oNode = parentNode.childNodes[i] ;\r
55                 if ( oNode.nodeType == 3 )\r
56                 {\r
57                         var sReplaced = oNode.nodeValue.replace( regex, replaceValue ) ;\r
58                         if ( oNode.nodeValue != sReplaced )\r
59                         {\r
60                                 oNode.nodeValue = sReplaced ;\r
61                                 if ( ! replaceAll )\r
62                                         return true ;\r
63                                 hasFound = true ;\r
64                         }\r
65                 }\r
66 \r
67                 hasFound = ReplaceTextNodes( oNode, regex, replaceValue, replaceAll, hasFound ) ;\r
68                 if ( ! replaceAll && hasFound )\r
69                         return true ;\r
70         }\r
71 \r
72         return hasFound ;\r
73 }\r
74 \r
75 function GetRegexExpr()\r
76 {\r
77         var sExpr = EscapeRegexString( document.getElementById('txtFind').value ) ;\r
78 \r
79         if ( document.getElementById('chkWord').checked )\r
80                 sExpr = '\\b' + sExpr + '\\b' ;\r
81 \r
82         return sExpr ;\r
83 }\r
84 \r
85 function GetCase()\r
86 {\r
87         return ( document.getElementById('chkCase').checked ? '' : 'i' ) ;\r
88 }\r
89 \r
90 function GetReplacement()\r
91 {\r
92         return document.getElementById('txtReplace').value.replace( /\$/g, '$$$$' ) ;\r
93 }\r
94 \r
95 function EscapeRegexString( str )\r
96 {\r
97         return str.replace( /[\\\^\$\*\+\?\{\}\.\(\)\!\|\[\]\-]/g, '\\$&' ) ;\r
98 }\r
99 \r
100 function Replace()\r
101 {\r
102         var oRegex = new RegExp( GetRegexExpr(), GetCase() ) ;\r
103         if ( !ReplaceTextNodes( oEditor.FCK.EditorDocument.body, oRegex, GetReplacement(), false, false ) )\r
104                 alert( oEditor.FCKLang.DlgFindNotFoundMsg ) ;\r
105 }\r
106 \r
107 function ReplaceAll()\r
108 {\r
109         var oRegex = new RegExp( GetRegexExpr(), GetCase() + 'g' ) ;\r
110         if ( !ReplaceTextNodes( oEditor.FCK.EditorDocument.body, oRegex, GetReplacement(), true, false ) )\r
111                 alert( oEditor.FCKLang.DlgFindNotFoundMsg ) ;\r
112         window.parent.Cancel() ;\r
113 }\r
114         </script>\r
115 </head>\r
116 <body onload="OnLoad()" style="overflow: hidden">\r
117         <table cellspacing="3" cellpadding="2" width="100%" border="0">\r
118                 <tr>\r
119                         <td nowrap="nowrap">\r
120                                 <label for="txtFind" fcklang="DlgReplaceFindLbl">\r
121                                         Find what:</label>\r
122                         </td>\r
123                         <td width="100%">\r
124                                 <input id="txtFind" onkeyup="btnStat(this.form)" style="width: 100%" tabindex="1"\r
125                                         type="text" />\r
126                         </td>\r
127                         <td>\r
128                                 <input id="btnReplace" style="width: 100%" disabled="disabled" onclick="Replace();"\r
129                                         type="button" value="Replace" fcklang="DlgReplaceReplaceBtn" />\r
130                         </td>\r
131                 </tr>\r
132                 <tr>\r
133                         <td valign="top" nowrap="nowrap">\r
134                                 <label for="txtReplace" fcklang="DlgReplaceReplaceLbl">\r
135                                         Replace with:</label>\r
136                         </td>\r
137                         <td valign="top">\r
138                                 <input id="txtReplace" style="width: 100%" tabindex="2" type="text" />\r
139                         </td>\r
140                         <td>\r
141                                 <input id="btnReplaceAll" disabled="disabled" onclick="ReplaceAll()" type="button"\r
142                                         value="Replace All" fcklang="DlgReplaceReplAllBtn" />\r
143                         </td>\r
144                 </tr>\r
145                 <tr>\r
146                         <td valign="bottom" colspan="3">\r
147                                 &nbsp;<input id="chkCase" tabindex="3" type="checkbox" /><label for="chkCase" fcklang="DlgReplaceCaseChk">Match\r
148                                         case</label>\r
149                                 <br />\r
150                                 &nbsp;<input id="chkWord" tabindex="4" type="checkbox" /><label for="chkWord" fcklang="DlgReplaceWordChk">Match\r
151                                         whole word</label>\r
152                         </td>\r
153                 </tr>\r
154         </table>\r
155 </body>\r
156 </html>\r