/****** * * EditArea * Developped by Christophe Dolivet * Released under LGPL license * ******/ function EditArea(){ this.error= false; // to know if load is interrrupt this.inlinePopup= new Array({popup_id: "area_search_replace", icon_id: "search"}, {popup_id: "edit_area_help", icon_id: "help"}); this.plugins= new Object(); this.line_number=0; this.nav=parent.editAreaLoader.nav; // navigator identification this.last_selection=new Object(); this.last_text_to_highlight=""; this.last_hightlighted_text= ""; this.textareaFocused= false; this.previous= new Array(); this.next= new Array(); this.last_undo=""; //this.loaded= false; this.assocBracket=new Object(); this.revertAssocBracket= new Object(); // bracket selection init this.assocBracket["("]=")"; this.assocBracket["{"]="}"; this.assocBracket["["]="]"; for(var index in this.assocBracket){ this.revertAssocBracket[this.assocBracket[index]]=index; } /*this.textarea=""; this.state="declare"; this.code = new Array(); // store highlight syntax for languagues*/ // font datas this.lineHeight= 16; /*this.default_font_family= "monospace"; this.default_font_size= 10;*/ this.tab_nb_char= 8; //nb of white spaces corresponding to a tabulation if(this.nav['isOpera']) this.tab_nb_char= 6; this.is_tabbing= false; this.fullscreen= {'isFull': false}; this.isResizing=false; // resize var // init with settings and ID this.id= area_id; this.settings= editAreas[this.id]["settings"]; if((""+this.settings['replace_tab_by_spaces']).match(/^[0-9]+$/)) { this.tab_nb_char= this.settings['replace_tab_by_spaces']; this.tabulation=""; for(var i=0; imax_top) popup.style.top= max_top+"px"; if(popup.offsetLeft>max_left) popup.style.left= max_left+"px"; } } }; EditArea.prototype.init= function(){ this.textarea= document.getElementById("textarea"); this.container= document.getElementById("container"); this.result= document.getElementById("result"); this.content_highlight= document.getElementById("content_highlight"); this.selection_field= document.getElementById("selection_field"); // add plugins buttons in the toolbar spans= parent.getChildren(document.getElementById("toolbar_1"), "span", "", "", "all", -1); for(var i=0; i= this.line_number) { var div_line_number=""; for(i=this.line_number+1; i"; this.line_number++; } var span= document.createElement("span"); if(this.nav['isIE']) span.unselectable=true; span.innerHTML=div_line_number; document.getElementById("line_number").appendChild(span); } //alert(area_height); if(this.textarea.previous_scrollWidth!=area_width) { // need width resizing if(this.nav['isOpera']){ /*if(this.textarea.style.width.replace("px","")-0+50 < area_width) area_width+=50;*/ }else{ if(this.textarea.style.width && (this.textarea.style.width.replace("px","") < area_width)){ area_width+=50; } } //window.status= "width: "+this.textarea.offsetWidth+" scroll-width: "+this.textarea.scrollWidth+" area_width: "+area_width+" container: "+this.container.offsetWidth+" result: "+this.result.offsetWidth; if(this.nav['isGecko'] || this.nav['isOpera']) this.container.style.width= (area_width+45)+"px"; else this.container.style.width= area_width+"px"; this.textarea.style.width= area_width+"px"; this.content_highlight.style.width= area_width+"px"; this.textarea.previous_scrollWidth=area_width; resized=true; } if(this.textarea.previous_scrollHeight!=area_height) { // need height resizing /*container_height=area_height; if(document.getElementById("container").style.height.replace("px", "")<=area_height) container_height+=100;*/ this.container.style.height= (area_height+2)+"px"; this.textarea.style.height= area_height+"px"; this.content_highlight.style.height= area_height+"px"; this.textarea.previous_scrollHeight=area_height; //alert(area_height); resized=true; } this.textarea.scrollTop="0px"; this.textarea.scrollLeft="0px"; if(resized==true){ this.scroll_to_view(); } } setTimeout("editArea.manage_size();", 100); }; EditArea.prototype.add_event = function(obj, name, handler) { if (this.nav['isIE']) { obj.attachEvent("on" + name, handler); } else{ obj.addEventListener(name, handler, false); } }; EditArea.prototype.execCommand= function(cmd, param){ for(var i in this.plugins){ if(typeof(this.plugins[i].execCommand)=="function"){ if(!this.plugins[i].execCommand(cmd, param)) return; } } switch(cmd){ case "save": if(this.settings["save_callback"].length>0) eval("parent."+this.settings["save_callback"]+"('"+ this.id +"', editArea.textarea.value);"); break; case "load": if(this.settings["load_callback"].length>0) eval("parent."+this.settings["load_callback"]+"('"+ this.id +"');"); break; case "onchange": if(this.settings["change_callback"].length>0) eval("parent."+this.settings["change_callback"]+"('"+ this.id +"');"); break; case "EA_load": if(this.settings["EA_load_callback"].length>0) eval("parent."+this.settings["EA_load_callback"]+"('"+ this.id +"');"); break; case "EA_unload": if(this.settings["EA_unload_callback"].length>0) eval("parent."+this.settings["EA_unload_callback"]+"('"+ this.id +"');"); break; case "toggle_on": if(this.settings["EA_toggle_on_callback"].length>0) eval("parent."+this.settings["EA_toggle_on_callback"]+"('"+ this.id +"');"); break; case "toggle_off": if(this.settings["EA_toggle_off_callback"].length>0) eval("parent."+this.settings["EA_toggle_off_callback"]+"('"+ this.id +"');"); break; case "re_sync": if(!this.do_highlight) break; default: //alert(cmd+"\n"+params); if(typeof(eval("editArea."+cmd))=="function") try{eval("editArea."+ cmd +"(param);");}catch(e){}; } }; EditArea.prototype.get_translation= function(word, mode){ if(mode=="template") return parent.editAreaLoader.translate(word, this.settings["language"], mode); else return parent.editAreaLoader.get_word_translation(word, this.settings["language"]); }; EditArea.prototype.add_plugin= function(plug_name, plug_obj){ for(var i=0; i"); } }; EditArea.prototype.load_script= function(url){ try{ script = document.createElement("script"); script.type = "text/javascript"; script.src = url; head = document.getElementsByTagName("head"); head[0].appendChild(script); }catch(e){ document.write("