searchreplace.html 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2. "http://www.w3.org/TR/html4/loose.dtd">
  3. <html>
  4. <head>
  5. <title></title>
  6. <meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
  7. <style type="text/css">
  8. *{color: #838383}
  9. body {
  10. font-size: 12px;
  11. width:380px;
  12. height: 170px;
  13. overflow: hidden;
  14. margin:0;padding:0;
  15. }
  16. .warp{ padding: 39px 0 0 15px;height:88%;position:relative;}
  17. * +html .warp{height:80%}
  18. .head{position:absolute;height:31px;top:9px;}
  19. .content{height:110px;border: 1px solid #ddd;padding:5px}
  20. .head span{width:62px;height:29px;line-height:29px;background:red;display:block;float: left;text-align: center;margin-right: 1px;cursor: pointer }
  21. .head span.def{background:url("../../themes/default/images/dialog-title-bg.png") repeat-x;border:1px solid #ccc;}
  22. .head span.act{background:#FFF;border:1px solid #ccc;border-bottom: 1px solid #FFF}
  23. .content table{width:100%;}
  24. .content input.int{ width:190px;height:21px;background: #FFF;border:1px solid #d7d7d7;padding: 0; margin: 0;line-height:21px;}
  25. .content input.btn{padding: 0 5px; text-align:center;line-height:24px; text-decoration: none;height:24px;border: 0;margin:0;background:url("../../themes/default/images/dialog-title-bg.png") repeat-x;border:1px solid #ccc; }
  26. </style>
  27. </head>
  28. <body>
  29. <div class="warp">
  30. <div id="head" class="head">
  31. <span name="find" class="act"><var id="lang_tab_search"></var></span> <span name="replace" class="def"><var id="lang_tab_replace"></var></span>
  32. </div>
  33. <div class="content" id="find">
  34. <table>
  35. <tr>
  36. <td width="80"><var id="lang_search1"></var>: </td>
  37. <td><input id="findtxt" type="text" class="int" /></td>
  38. </tr>
  39. <tr>
  40. <td><var id="lang_case_sensitive1"></var></td>
  41. <td>
  42. <input id="matchCase" type="checkbox" />
  43. </td>
  44. </tr>
  45. <tr>
  46. <td colspan="2">
  47. <input id="nextFindBtn" type="button" class="btn" />
  48. <input id="preFindBtn" type="button" class="btn" />
  49. </td>
  50. </tr>
  51. </table>
  52. </div>
  53. <div class="content" id="replace">
  54. <table>
  55. <tr>
  56. <td width="80"><var id="lang_search2"></var>: </td>
  57. <td><input id="findtxt1" type="text" class="int" /></td>
  58. </tr>
  59. <tr>
  60. <td><var id="lang_replace"></var>: </td>
  61. <td><input id="replacetxt" type="text" class="int" /></td>
  62. </tr>
  63. <tr>
  64. <td><var id="lang_case_sensitive2"></var></td>
  65. <td>
  66. <input id="matchCase1" type="checkbox" />
  67. </td>
  68. </tr>
  69. <tr>
  70. <td colspan="2">
  71. <input id="nextReplaceBtn" type="button" class="btn" />
  72. <input id="preReplaceBtn" type="button" class="btn" />
  73. <input id="repalceBtn" type="button" class="btn" />
  74. <input id="repalceAllBtn" type="button" class="btn" />
  75. </td>
  76. </tr>
  77. </table>
  78. </div>
  79. </div>
  80. <script type="text/javascript" src="../internal.js"></script>
  81. <script type="text/javascript">
  82. //清空上次查选的痕迹
  83. editor.firstForSR = 0;
  84. editor.currentRangeForSR = null;
  85. $G("replace").style.display = "none";
  86. //给tab注册切换事件
  87. function toggletab(){
  88. var tabs = document.getElementsByTagName("span");
  89. for(var i=0,j;j=tabs[i];i++){
  90. domUtils.on(j,"click",function(){
  91. var name = this.getAttribute("name");
  92. var spans = document.getElementsByTagName("span");
  93. var len = spans.length;
  94. for(var s=0;s<len;s++){
  95. spans[s].className = 'def';
  96. }
  97. this.className = 'act';
  98. $G("find").style.display = "none";
  99. $G("replace").style.display = "none";
  100. $G(name).style.display = "";
  101. $G('findtxt1').value = $G('findtxt').value;
  102. if(name =="replace"){
  103. $focus($G("findtxt1"));
  104. }else{
  105. $focus($G("findtxt"));
  106. }
  107. });
  108. }
  109. }
  110. //是否区分大小写
  111. function getMatchCase (id){
  112. return $G(id).checked ? true : false;
  113. }
  114. //查找
  115. $G("nextFindBtn").onclick = function(txt,dir,mcase){
  116. var findtxt = $G("findtxt").value,obj;
  117. if(!findtxt){
  118. return false;
  119. }
  120. obj = {
  121. searchStr : findtxt,
  122. dir : 1,
  123. casesensitive : getMatchCase("matchCase")
  124. };
  125. if(!frCommond(obj)){
  126. alert(lang.getEnd);
  127. }
  128. };
  129. $G("nextReplaceBtn").onclick = function(txt,dir,mcase){
  130. var findtxt = $G("findtxt1").value,obj;
  131. if(!findtxt){
  132. return false;
  133. }
  134. obj = {
  135. searchStr : findtxt,
  136. dir : 1,
  137. casesensitive : getMatchCase("matchCase1")
  138. };
  139. frCommond(obj);
  140. }
  141. $G("preFindBtn").onclick = function(txt,dir,mcase){
  142. var findtxt = $G("findtxt").value,obj;
  143. if(!findtxt){
  144. return false;
  145. }
  146. obj = {
  147. searchStr : findtxt,
  148. dir : -1,
  149. casesensitive : getMatchCase("matchCase")
  150. };
  151. if(!frCommond(obj)){
  152. alert(lang.getStart);
  153. }
  154. }
  155. $G("preReplaceBtn").onclick = function(txt,dir,mcase){
  156. var findtxt = $G("findtxt1").value,obj;
  157. if(!findtxt){
  158. return false;
  159. }
  160. obj = {
  161. searchStr : findtxt,
  162. dir : -1,
  163. casesensitive : getMatchCase("matchCase1")
  164. };
  165. frCommond(obj);
  166. }
  167. //替换
  168. $G("repalceBtn").onclick = function(){
  169. var findtxt = $G("findtxt1").value.replace(/^\s|\s$/g,""),obj,
  170. replacetxt = $G("replacetxt").value.replace(/^\s|\s$/g,"");
  171. if(!findtxt){
  172. return false;
  173. }
  174. if(findtxt == replacetxt || (!getMatchCase("matchCase1") && findtxt.toLowerCase() == replacetxt.toLowerCase())){
  175. return false;
  176. }
  177. obj = {
  178. searchStr : findtxt,
  179. dir : 1,
  180. casesensitive : getMatchCase("matchCase1"),
  181. replaceStr : replacetxt
  182. };
  183. frCommond(obj);
  184. }
  185. //全部替换
  186. $G("repalceAllBtn").onclick = function(){
  187. var findtxt = $G("findtxt1").value.replace(/^\s|\s$/g,""),obj,
  188. replacetxt = $G("replacetxt").value.replace(/^\s|\s$/g,"");
  189. if(!findtxt){
  190. return false;
  191. }
  192. if(findtxt == replacetxt || (!getMatchCase("matchCase1") && findtxt.toLowerCase() == replacetxt.toLowerCase())){
  193. return false;
  194. }
  195. obj = {
  196. searchStr : findtxt,
  197. casesensitive : getMatchCase("matchCase1"),
  198. replaceStr : replacetxt,
  199. all : true
  200. };
  201. var num = frCommond(obj);
  202. if(num){
  203. alert(lang.countMsg.replace("{#count}",num));
  204. }
  205. }
  206. //执行
  207. var frCommond = function(obj){
  208. return editor.execCommand("searchreplace",obj);
  209. }
  210. toggletab();
  211. </script>
  212. </body>
  213. </html>