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-2007 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 * This is the sample "Replace" plugin window.
23-->
24<html>
25	<head>
26		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
27		<meta content="noindex, nofollow" name="robots">
28		<script type="text/javascript">
29
30var oEditor = window.parent.InnerDialogLoaded() ;
31
32function OnLoad()
33{
34	// First of all, translate the dialog box texts
35	oEditor.FCKLanguageManager.TranslatePage( document ) ;
36
37	window.parent.SetAutoSize( true ) ;
38}
39
40function btnStat(frm)
41{
42	document.getElementById('btnReplace').disabled =
43		document.getElementById('btnReplaceAll').disabled =
44			( document.getElementById('txtFind').value.length == 0 ) ;
45}
46
47function ReplaceTextNodes( parentNode, regex, replaceValue, replaceAll, hasFound )
48{
49	for ( var i = 0 ; i < parentNode.childNodes.length ; i++ )
50	{
51		var oNode = parentNode.childNodes[i] ;
52		if ( oNode.nodeType == 3 )
53		{
54			var sReplaced = oNode.nodeValue.replace( regex, replaceValue ) ;
55			if ( oNode.nodeValue != sReplaced )
56			{
57				oNode.nodeValue = sReplaced ;
58				if ( ! replaceAll )
59					return true ;
60				hasFound = true ;
61			}
62		}
63
64		hasFound = ReplaceTextNodes( oNode, regex, replaceValue, replaceAll, hasFound ) ;
65		if ( ! replaceAll && hasFound )
66			return true ;
67	}
68
69	return hasFound ;
70}
71
72function GetRegexExpr()
73{
74	if ( document.getElementById('chkWord').checked )
75		var sExpr = '\\b' + document.getElementById('txtFind').value + '\\b' ;
76	else
77		var sExpr = document.getElementById('txtFind').value ;
78
79	return sExpr ;
80}
81
82function GetCase()
83{
84	return ( document.getElementById('chkCase').checked ? '' : 'i' ) ;
85}
86
87function Replace()
88{
89	var oRegex = new RegExp( GetRegexExpr(), GetCase() ) ;
90	ReplaceTextNodes( oEditor.FCK.EditorDocument.body, oRegex, document.getElementById('txtReplace').value, false ) ;
91}
92
93function ReplaceAll()
94{
95	var oRegex = new RegExp( GetRegexExpr(), GetCase() + 'g' ) ;
96	ReplaceTextNodes( oEditor.FCK.EditorDocument.body, oRegex, document.getElementById('txtReplace').value, true ) ;
97	window.parent.Cancel() ;
98}
99		</script>
100	</head>
101	<body onload="OnLoad()" scroll="no" style="OVERFLOW: hidden">
102		<div align="center">
103			This is my Plugin!
104		</div>
105		<table cellSpacing="3" cellPadding="2" width="100%" border="0">
106			<tr>
107				<td noWrap><label for="txtFind" fckLang="DlgMyReplaceFindLbl">Find what:</label>
108				</td>
109				<td width="100%"><input id="txtFind" onkeyup="btnStat(this.form)" style="WIDTH: 100%" tabIndex="1" type="text">
110				</td>
111				<td><input id="btnReplace" style="WIDTH: 100%" disabled onclick="Replace();" type="button"
112						value="Replace" fckLang="DlgMyReplaceReplaceBtn">
113				</td>
114			</tr>
115			<tr>
116				<td vAlign="top" nowrap><label for="txtReplace" fckLang="DlgMyReplaceReplaceLbl">Replace
117						with:</label>
118				</td>
119				<td vAlign="top"><input id="txtReplace" style="WIDTH: 100%" tabIndex="2" type="text">
120				</td>
121				<td><input id="btnReplaceAll" disabled onclick="ReplaceAll()" type="button" value="Replace All"
122						fckLang="DlgMyReplaceReplAllBtn">
123				</td>
124			</tr>
125			<tr>
126				<td vAlign="bottom" colSpan="3">&nbsp;<input id="chkCase" tabIndex="3" type="checkbox"><label for="chkCase" fckLang="DlgMyReplaceCaseChk">Match
127						case</label>
128					<br>
129					&nbsp;<input id="chkWord" tabIndex="4" type="checkbox"><label for="chkWord" fckLang="DlgMyReplaceWordChk">Match
130						whole word</label>
131				</td>
132			</tr>
133		</table>
134	</body>
135</html>
136