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