1 EditArea.prototype.show_search = function(){
\r
2 if(_$("area_search_replace").style.visibility=="visible"){
\r
3 this.hidden_search();
\r
5 this.open_inline_popup("area_search_replace");
\r
6 var text= this.area_get_selection();
\r
7 var search= text.split("\n")[0];
\r
8 _$("area_search").value= search;
\r
9 _$("area_search").focus();
\r
13 EditArea.prototype.hidden_search= function(){
\r
14 /*_$("area_search_replace").style.visibility="hidden";
\r
15 this.textarea.focus();
\r
16 var icon= _$("search");
\r
17 setAttribute(icon, "class", getAttribute(icon, "class").replace(/ selected/g, "") );*/
\r
18 this.close_inline_popup("area_search_replace");
\r
21 EditArea.prototype.area_search= function(mode){
\r
25 _$("area_search_msg").innerHTML="";
\r
26 var search=_$("area_search").value;
\r
28 this.textarea.focus();
\r
29 this.textarea.textareaFocused=true;
\r
31 var infos= this.get_selection_infos();
\r
32 var start= infos["selectionStart"];
\r
35 var length=search.length;
\r
37 if(_$("area_search_replace").style.visibility!="visible"){
\r
41 if(search.length==0){
\r
42 _$("area_search_msg").innerHTML=this.get_translation("search_field_empty");
\r
45 // advance to the next occurence if no text selected
\r
46 if(mode!="replace" ){
\r
47 if(_$("area_search_reg_exp").checked)
\r
50 start+= search.length;
\r
54 if(_$("area_search_reg_exp").checked){
\r
57 if(!_$("area_search_match_case").checked)
\r
59 var reg= new RegExp(search, opt);
\r
60 pos= infos["full_text"].substr(start).search(reg);
\r
61 pos_begin= infos["full_text"].search(reg);
\r
64 length=infos["full_text"].substr(start).match(reg)[0].length;
\r
65 }else if(pos_begin!=-1){
\r
66 length=infos["full_text"].match(reg)[0].length;
\r
69 if(_$("area_search_match_case").checked){
\r
70 pos= infos["full_text"].indexOf(search, start);
\r
71 pos_begin= infos["full_text"].indexOf(search);
\r
73 pos= infos["full_text"].toLowerCase().indexOf(search.toLowerCase(), start);
\r
74 pos_begin= infos["full_text"].toLowerCase().indexOf(search.toLowerCase());
\r
79 if(pos==-1 && pos_begin==-1){
\r
80 _$("area_search_msg").innerHTML="<strong>"+search+"</strong> "+this.get_translation("not_found");
\r
82 }else if(pos==-1 && pos_begin != -1){
\r
84 _$("area_search_msg").innerHTML=this.get_translation("restart_search_at_begin");
\r
88 //_$("area_search_msg").innerHTML+="<strong>"+search+"</strong> found at "+begin+" strat at "+start+" pos "+pos+" curs"+ infos["indexOfCursor"]+".";
\r
89 if(mode=="replace" && pos==infos["indexOfCursor"]){
\r
90 var replace= _$("area_replace").value;
\r
92 if(_$("area_search_reg_exp").checked){
\r
94 if(!_$("area_search_match_case").checked)
\r
96 var reg= new RegExp(search, opt);
\r
97 new_text= infos["full_text"].substr(0, begin) + infos["full_text"].substr(start).replace(reg, replace);
\r
99 new_text= infos["full_text"].substr(0, begin) + replace + infos["full_text"].substr(begin + length);
\r
101 this.textarea.value=new_text;
\r
102 this.area_select(begin, length);
\r
103 this.area_search();
\r
105 this.area_select(begin, length);
\r
111 EditArea.prototype.area_replace= function(){
\r
112 this.area_search("replace");
\r
115 EditArea.prototype.area_replace_all= function(){
\r
116 /* this.area_select(0, 0);
\r
117 _$("area_search_msg").innerHTML="";
\r
118 while(_$("area_search_msg").innerHTML==""){
\r
119 this.area_replace();
\r
122 var base_text= this.textarea.value;
\r
123 var search= _$("area_search").value;
\r
124 var replace= _$("area_replace").value;
\r
125 if(search.length==0){
\r
126 _$("area_search_msg").innerHTML=this.get_translation("search_field_empty");
\r
132 if(_$("area_search_reg_exp").checked){
\r
135 if(!_$("area_search_match_case").checked)
\r
137 var reg= new RegExp(search, opt);
\r
138 nb_change= infos["full_text"].match(reg).length;
\r
139 new_text= infos["full_text"].replace(reg, replace);
\r
143 if(_$("area_search_match_case").checked){
\r
144 var tmp_tab=base_text.split(search);
\r
145 nb_change= tmp_tab.length -1 ;
\r
146 new_text= tmp_tab.join(replace);
\r
148 // case insensitive
\r
149 var lower_value=base_text.toLowerCase();
\r
150 var lower_search=search.toLowerCase();
\r
153 var pos= lower_value.indexOf(lower_search);
\r
156 new_text+= this.textarea.value.substring(start , pos)+replace;
\r
157 start=pos+ search.length;
\r
158 pos= lower_value.indexOf(lower_search, pos+1);
\r
160 new_text+= this.textarea.value.substring(start);
\r
163 if(new_text==base_text){
\r
164 _$("area_search_msg").innerHTML="<strong>"+search+"</strong> "+this.get_translation("not_found");
\r
166 this.textarea.value= new_text;
\r
167 _$("area_search_msg").innerHTML="<strong>"+nb_change+"</strong> "+this.get_translation("occurrence_replaced");
\r
168 // firefox and opera doesn't manage with the focus if it's done directly
\r
169 //editArea.textarea.focus();editArea.textarea.textareaFocused=true;
\r
170 setTimeout("editArea.textarea.focus();editArea.textarea.textareaFocused=true;", 100);
\r