You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by la...@apache.org on 2013/07/11 13:55:32 UTC
[18/22] refactoring theme-mgt components,
service stub and changing service stub parent name to
stratos-service-stubs-parent
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/f6330834/components/org.apache.stratos.theme.mgt.ui/src/main/resources/web/tenant-theme/js/editarea/edit_area/edit_area_functions.js
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.theme.mgt.ui/src/main/resources/web/tenant-theme/js/editarea/edit_area/edit_area_functions.js b/components/org.apache.stratos.theme.mgt.ui/src/main/resources/web/tenant-theme/js/editarea/edit_area/edit_area_functions.js
new file mode 100644
index 0000000..984d4c6
--- /dev/null
+++ b/components/org.apache.stratos.theme.mgt.ui/src/main/resources/web/tenant-theme/js/editarea/edit_area/edit_area_functions.js
@@ -0,0 +1,1203 @@
+ //replace tabulation by the good number of white spaces
+ EditArea.prototype.replace_tab= function(text){
+ return text.replace(/((\n?)([^\t\n]*)\t)/gi, editArea.smartTab); // slower than simple replace...
+ };
+
+ // call by the replace_tab function
+ EditArea.prototype.smartTab= function(){
+ val=" ";
+ return EditArea.prototype.smartTab.arguments[2] + EditArea.prototype.smartTab.arguments[3] + val.substr(0, editArea.tab_nb_char - (EditArea.prototype.smartTab.arguments[3].length)%editArea.tab_nb_char);
+ };
+
+ EditArea.prototype.show_waiting_screen= function(){
+ width = this.editor_area.offsetWidth;
+ height = this.editor_area.offsetHeight;
+ if( !(this.isIE && this.isIE<6) )
+ {
+ width -= 2;
+ height -= 2;
+ }
+ this.processing_screen.style.display= "block";
+ this.processing_screen.style.width = width+"px";
+ this.processing_screen.style.height = height+"px";
+ this.waiting_screen_displayed = true;
+ };
+
+ EditArea.prototype.hide_waiting_screen= function(){
+ this.processing_screen.style.display="none";
+ this.waiting_screen_displayed= false;
+ };
+
+ EditArea.prototype.add_style= function(styles){
+ if(styles.length>0){
+ newcss = document.createElement("style");
+ newcss.type="text/css";
+ newcss.media="all";
+ if(newcss.styleSheet){ // IE
+ newcss.styleSheet.cssText = styles;
+ } else { // W3C
+ newcss.appendChild(document.createTextNode(styles));
+ }
+ document.getElementsByTagName("head")[0].appendChild(newcss);
+ }
+ };
+
+ EditArea.prototype.set_font= function(family, size){
+ var t=this, a=this.textarea, s=this.settings, elem_font, i, elem;
+ // list all elements concerned by font changes
+ var elems= ["textarea", "content_highlight", "cursor_pos", "end_bracket", "selection_field", "selection_field_text", "line_number"];
+
+ if(family && family!="")
+ s["font_family"]= family;
+ if(size && size>0)
+ s["font_size"] = size;
+ if( t.isOpera && t.isOpera < 9.6 ) // opera<9.6 can't manage non monospace font
+ s['font_family']="monospace";
+
+ // update the select tag
+ if( elem_font = _$("area_font_size") )
+ {
+ for( i = 0; i < elem_font.length; i++ )
+ {
+ if( elem_font.options[i].value && elem_font.options[i].value == s["font_size"] )
+ elem_font.options[i].selected=true;
+ }
+ }
+
+ /*
+ * somethimes firefox has rendering mistake with non-monospace font for text width in textarea vs in div for changing font size (eg: verdana change between 11pt to 12pt)
+ * => looks like a browser internal random bug as text width can change while content_highlight is updated
+ * we'll check if the font-size produce the same text width inside textarea and div and if not, we'll increment the font-size
+ *
+ * This is an ugly fix
+ */
+ if( t.isFirefox )
+ {
+ var nbTry = 3;
+ do {
+ var div1 = document.createElement( 'div' ), text1 = document.createElement( 'textarea' );
+ var styles = {
+ width: '40px',
+ overflow: 'scroll',
+ zIndex: 50,
+ visibility: 'hidden',
+ fontFamily: s["font_family"],
+ fontSize: s["font_size"]+"pt",
+ lineHeight: t.lineHeight+"px",
+ padding: '0',
+ margin: '0',
+ border: 'none',
+ whiteSpace: 'nowrap'
+ };
+ var diff, changed = false;
+ for( i in styles )
+ {
+ div1.style[ i ] = styles[i];
+ text1.style[ i ] = styles[i];
+ }
+ // no wrap for this text
+ text1.wrap = 'off';
+ text1.setAttribute('wrap', 'off');
+ t.container.appendChild( div1 );
+ t.container.appendChild( text1 );
+ // try to make FF to bug
+ div1.innerHTML = text1.value = 'azertyuiopqsdfghjklm';
+ div1.innerHTML = text1.value = text1.value+'wxcvbn^p*รน$!:;,,';
+ diff = text1.scrollWidth - div1.scrollWidth;
+
+ // firefox return here a diff of 1 px between equals scrollWidth (can't explain)
+ if( Math.abs( diff ) >= 2 )
+ {
+ s["font_size"]++;
+ changed = true;
+ }
+ t.container.removeChild( div1 );
+ t.container.removeChild( text1 );
+ nbTry--;
+ }while( changed && nbTry > 0 );
+ }
+
+
+ // calc line height
+ elem = t.test_font_size;
+ elem.style.fontFamily = ""+s["font_family"];
+ elem.style.fontSize = s["font_size"]+"pt";
+ elem.innerHTML = "0";
+ t.lineHeight = elem.offsetHeight;
+
+ // update font for all concerned elements
+ for( i=0; i<elems.length; i++)
+ {
+ elem = _$(elems[i]);
+ elem.style.fontFamily = s["font_family"];
+ elem.style.fontSize = s["font_size"]+"pt";
+ elem.style.lineHeight = t.lineHeight+"px";
+ }
+ // define a css for <pre> tags
+ t.add_style("pre{font-family:"+s["font_family"]+"}");
+
+ // old opera and IE>=8 doesn't update font changes to the textarea
+ if( ( t.isOpera && t.isOpera < 9.6 ) || t.isIE >= 8 )
+ {
+ var parNod = a.parentNode, nxtSib = a.nextSibling, start= a.selectionStart, end= a.selectionEnd;
+ parNod.removeChild(a);
+ parNod.insertBefore(a, nxtSib);
+ t.area_select(start, end-start);
+ }
+
+ // force update of selection field
+ this.focus();
+ this.update_size();
+ this.check_line_selection();
+ };
+
+ EditArea.prototype.change_font_size= function(){
+ var size=_$("area_font_size").value;
+ if(size>0)
+ this.set_font("", size);
+ };
+
+
+ EditArea.prototype.open_inline_popup= function(popup_id){
+ this.close_all_inline_popup();
+ var popup= _$(popup_id);
+ var editor= _$("editor");
+
+ // search matching icon
+ for(var i=0; i<this.inlinePopup.length; i++){
+ if(this.inlinePopup[i]["popup_id"]==popup_id){
+ var icon= _$(this.inlinePopup[i]["icon_id"]);
+ if(icon){
+ this.switchClassSticky(icon, 'editAreaButtonSelected', true);
+ break;
+ }
+ }
+ }
+ // check size
+ popup.style.height="auto";
+ popup.style.overflow= "visible";
+
+ if(document.body.offsetHeight< popup.offsetHeight){
+ popup.style.height= (document.body.offsetHeight-10)+"px";
+ popup.style.overflow= "auto";
+ }
+
+ if(!popup.positionned){
+ var new_left= editor.offsetWidth /2 - popup.offsetWidth /2;
+ var new_top= editor.offsetHeight /2 - popup.offsetHeight /2;
+ //var new_top= area.offsetHeight /2 - popup.offsetHeight /2;
+ //var new_left= area.offsetWidth /2 - popup.offsetWidth /2;
+ //alert("new_top: ("+new_top+") = calculeOffsetTop(area) ("+calculeOffsetTop(area)+") + area.offsetHeight /2("+ area.offsetHeight /2+") - popup.offsetHeight /2("+popup.offsetHeight /2+") - scrollTop: "+document.body.scrollTop);
+ popup.style.left= new_left+"px";
+ popup.style.top= new_top+"px";
+ popup.positionned=true;
+ }
+ popup.style.visibility="visible";
+
+ //popup.style.display="block";
+ };
+
+ EditArea.prototype.close_inline_popup= function(popup_id){
+ var popup= _$(popup_id);
+ // search matching icon
+ for(var i=0; i<this.inlinePopup.length; i++){
+ if(this.inlinePopup[i]["popup_id"]==popup_id){
+ var icon= _$(this.inlinePopup[i]["icon_id"]);
+ if(icon){
+ this.switchClassSticky(icon, 'editAreaButtonNormal', false);
+ break;
+ }
+ }
+ }
+
+ popup.style.visibility="hidden";
+ };
+
+ EditArea.prototype.close_all_inline_popup= function(e){
+ for(var i=0; i<this.inlinePopup.length; i++){
+ this.close_inline_popup(this.inlinePopup[i]["popup_id"]);
+ }
+ this.textarea.focus();
+ };
+
+ EditArea.prototype.show_help= function(){
+
+ this.open_inline_popup("edit_area_help");
+
+ };
+
+ EditArea.prototype.new_document= function(){
+ this.textarea.value="";
+ this.area_select(0,0);
+ };
+
+ EditArea.prototype.get_all_toolbar_height= function(){
+ var area= _$("editor");
+ var results= parent.getChildren(area, "div", "class", "area_toolbar", "all", "0"); // search only direct children
+ //results= results.concat(getChildren(area, "table", "class", "area_toolbar", "all", "0"));
+ var height=0;
+ for(var i=0; i<results.length; i++){
+ height+= results[i].offsetHeight;
+ }
+ //alert("toolbar height: "+height);
+ return height;
+ };
+
+ EditArea.prototype.go_to_line= function(line){
+ if(!line)
+ {
+ var icon= _$("go_to_line");
+ if(icon != null){
+ this.restoreClass(icon);
+ this.switchClassSticky(icon, 'editAreaButtonSelected', true);
+ }
+
+ line= prompt(this.get_translation("go_to_line_prompt"));
+ if(icon != null)
+ this.switchClassSticky(icon, 'editAreaButtonNormal', false);
+ }
+ if(line && line!=null && line.search(/^[0-9]+$/)!=-1){
+ var start=0;
+ var lines= this.textarea.value.split("\n");
+ if(line > lines.length)
+ start= this.textarea.value.length;
+ else{
+ for(var i=0; i<Math.min(line-1, lines.length); i++)
+ start+= lines[i].length + 1;
+ }
+ this.area_select(start, 0);
+ }
+
+
+ };
+
+
+ EditArea.prototype.change_smooth_selection_mode= function(setTo){
+ //alert("setTo: "+setTo);
+ if(this.do_highlight)
+ return;
+
+ if(setTo != null){
+ if(setTo === false)
+ this.smooth_selection=true;
+ else
+ this.smooth_selection=false;
+ }
+ var icon= _$("change_smooth_selection");
+ this.textarea.focus();
+ if(this.smooth_selection===true){
+ //setAttribute(icon, "class", getAttribute(icon, "class").replace(/ selected/g, "") );
+ /*setAttribute(icon, "oldClassName", "editAreaButtonNormal" );
+ setAttribute(icon, "className", "editAreaButtonNormal" );*/
+ //this.restoreClass(icon);
+ //this.restoreAndSwitchClass(icon,'editAreaButtonNormal');
+ this.switchClassSticky(icon, 'editAreaButtonNormal', false);
+
+ this.smooth_selection=false;
+ this.selection_field.style.display= "none";
+ _$("cursor_pos").style.display= "none";
+ _$("end_bracket").style.display= "none";
+ }else{
+ //setAttribute(icon, "class", getAttribute(icon, "class") + " selected");
+ //this.switchClass(icon,'editAreaButtonSelected');
+ this.switchClassSticky(icon, 'editAreaButtonSelected', false);
+ this.smooth_selection=true;
+ this.selection_field.style.display= "block";
+ _$("cursor_pos").style.display= "block";
+ _$("end_bracket").style.display= "block";
+ }
+ };
+
+ // the auto scroll of the textarea has some lacks when it have to show cursor in the visible area when the textarea size change
+ // show specifiy whereas it is the "top" or "bottom" of the selection that is showned
+ EditArea.prototype.scroll_to_view= function(show){
+ var zone, lineElem;
+ if(!this.smooth_selection)
+ return;
+ zone= _$("result");
+
+ // manage height scroll
+ var cursor_pos_top= _$("cursor_pos").cursor_top;
+ if(show=="bottom")
+ {
+ //cursor_pos_top+= (this.last_selection["line_nb"]-1)* this.lineHeight;
+ cursor_pos_top+= this.getLinePosTop( this.last_selection['line_start'] + this.last_selection['line_nb'] - 1 );
+ }
+
+ var max_height_visible= zone.clientHeight + zone.scrollTop;
+ var miss_top = cursor_pos_top + this.lineHeight - max_height_visible;
+ if(miss_top>0){
+ //alert(miss_top);
+ zone.scrollTop= zone.scrollTop + miss_top;
+ }else if( zone.scrollTop > cursor_pos_top){
+ // when erase all the content -> does'nt scroll back to the top
+ //alert("else: "+cursor_pos_top);
+ zone.scrollTop= cursor_pos_top;
+ }
+
+ // manage left scroll
+ //var cursor_pos_left= parseInt(_$("cursor_pos").style.left.replace("px",""));
+ var cursor_pos_left= _$("cursor_pos").cursor_left;
+ var max_width_visible= zone.clientWidth + zone.scrollLeft;
+ var miss_left= cursor_pos_left + 10 - max_width_visible;
+ if(miss_left>0){
+ zone.scrollLeft= zone.scrollLeft + miss_left + 50;
+ }else if( zone.scrollLeft > cursor_pos_left){
+ zone.scrollLeft= cursor_pos_left ;
+ }else if( zone.scrollLeft == 45){
+ // show the line numbers if textarea align to it's left
+ zone.scrollLeft=0;
+ }
+ };
+
+ EditArea.prototype.check_undo= function(only_once){
+ if(!editAreas[this.id])
+ return false;
+ if(this.textareaFocused && editAreas[this.id]["displayed"]==true){
+ var text=this.textarea.value;
+ if(this.previous.length<=1)
+ this.switchClassSticky(_$("undo"), 'editAreaButtonDisabled', true);
+
+ if(!this.previous[this.previous.length-1] || this.previous[this.previous.length-1]["text"] != text){
+ this.previous.push({"text": text, "selStart": this.textarea.selectionStart, "selEnd": this.textarea.selectionEnd});
+ if(this.previous.length > this.settings["max_undo"]+1)
+ this.previous.shift();
+
+ }
+ if(this.previous.length >= 2)
+ this.switchClassSticky(_$("undo"), 'editAreaButtonNormal', false);
+ }
+
+ if(!only_once)
+ setTimeout("editArea.check_undo()", 3000);
+ };
+
+ EditArea.prototype.undo= function(){
+ //alert("undo"+this.previous.length);
+ if(this.previous.length > 0)
+ {
+ this.getIESelection();
+ // var pos_cursor=this.textarea.selectionStart;
+ this.next.push( { "text": this.textarea.value, "selStart": this.textarea.selectionStart, "selEnd": this.textarea.selectionEnd } );
+ var prev= this.previous.pop();
+ if( prev["text"] == this.textarea.value && this.previous.length > 0 )
+ prev =this.previous.pop();
+ this.textarea.value = prev["text"];
+ this.last_undo = prev["text"];
+ this.area_select(prev["selStart"], prev["selEnd"]-prev["selStart"]);
+ this.switchClassSticky(_$("redo"), 'editAreaButtonNormal', false);
+ this.resync_highlight(true);
+ //alert("undo"+this.previous.length);
+ this.check_file_changes();
+ }
+ };
+
+ EditArea.prototype.redo= function(){
+ if(this.next.length > 0)
+ {
+ /*this.getIESelection();*/
+ //var pos_cursor=this.textarea.selectionStart;
+ var next= this.next.pop();
+ this.previous.push(next);
+ this.textarea.value= next["text"];
+ this.last_undo= next["text"];
+ this.area_select(next["selStart"], next["selEnd"]-next["selStart"]);
+ this.switchClassSticky(_$("undo"), 'editAreaButtonNormal', false);
+ this.resync_highlight(true);
+ this.check_file_changes();
+ }
+ if( this.next.length == 0)
+ this.switchClassSticky(_$("redo"), 'editAreaButtonDisabled', true);
+ };
+
+ EditArea.prototype.check_redo= function(){
+ if(editArea.next.length == 0 || editArea.textarea.value!=editArea.last_undo){
+ editArea.next= []; // undo the ability to use "redo" button
+ editArea.switchClassSticky(_$("redo"), 'editAreaButtonDisabled', true);
+ }
+ else
+ {
+ this.switchClassSticky(_$("redo"), 'editAreaButtonNormal', false);
+ }
+ };
+
+
+ // functions that manage icons roll over, disabled, etc...
+ EditArea.prototype.switchClass = function(element, class_name, lock_state) {
+ var lockChanged = false;
+
+ if (typeof(lock_state) != "undefined" && element != null) {
+ element.classLock = lock_state;
+ lockChanged = true;
+ }
+
+ if (element != null && (lockChanged || !element.classLock)) {
+ element.oldClassName = element.className;
+ element.className = class_name;
+ }
+ };
+
+ EditArea.prototype.restoreAndSwitchClass = function(element, class_name) {
+ if (element != null && !element.classLock) {
+ this.restoreClass(element);
+ this.switchClass(element, class_name);
+ }
+ };
+
+ EditArea.prototype.restoreClass = function(element) {
+ if (element != null && element.oldClassName && !element.classLock) {
+ element.className = element.oldClassName;
+ element.oldClassName = null;
+ }
+ };
+
+ EditArea.prototype.setClassLock = function(element, lock_state) {
+ if (element != null)
+ element.classLock = lock_state;
+ };
+
+ EditArea.prototype.switchClassSticky = function(element, class_name, lock_state) {
+ var lockChanged = false;
+ if (typeof(lock_state) != "undefined" && element != null) {
+ element.classLock = lock_state;
+ lockChanged = true;
+ }
+
+ if (element != null && (lockChanged || !element.classLock)) {
+ element.className = class_name;
+ element.oldClassName = class_name;
+ }
+ };
+
+ //make the "page up" and "page down" buttons works correctly
+ EditArea.prototype.scroll_page= function(params){
+ var dir= params["dir"], shift_pressed= params["shift"];
+ var lines= this.textarea.value.split("\n");
+ var new_pos=0, length=0, char_left=0, line_nb=0, curLine=0;
+ var toScrollAmount = _$("result").clientHeight -30;
+ var nbLineToScroll = 0, diff= 0;
+
+ if(dir=="up"){
+ nbLineToScroll = Math.ceil( toScrollAmount / this.lineHeight );
+
+ // fix number of line to scroll
+ for( i = this.last_selection["line_start"]; i - diff > this.last_selection["line_start"] - nbLineToScroll ; i-- )
+ {
+ if( elem = _$('line_'+ i) )
+ {
+ diff += Math.floor( ( elem.offsetHeight - 1 ) / this.lineHeight );
+ }
+ }
+ nbLineToScroll -= diff;
+
+ if(this.last_selection["selec_direction"]=="up"){
+ for(line_nb=0; line_nb< Math.min(this.last_selection["line_start"]-nbLineToScroll, lines.length); line_nb++){
+ new_pos+= lines[line_nb].length + 1;
+ }
+ char_left=Math.min(lines[Math.min(lines.length-1, line_nb)].length, this.last_selection["curr_pos"]-1);
+ if(shift_pressed)
+ length=this.last_selection["selectionEnd"]-new_pos-char_left;
+ this.area_select(new_pos+char_left, length);
+ view="top";
+ }else{
+ view="bottom";
+ for(line_nb=0; line_nb< Math.min(this.last_selection["line_start"]+this.last_selection["line_nb"]-1-nbLineToScroll, lines.length); line_nb++){
+ new_pos+= lines[line_nb].length + 1;
+ }
+ char_left=Math.min(lines[Math.min(lines.length-1, line_nb)].length, this.last_selection["curr_pos"]-1);
+ if(shift_pressed){
+ //length=this.last_selection["selectionEnd"]-new_pos-char_left;
+ start= Math.min(this.last_selection["selectionStart"], new_pos+char_left);
+ length= Math.max(new_pos+char_left, this.last_selection["selectionStart"] )- start ;
+ if(new_pos+char_left < this.last_selection["selectionStart"])
+ view="top";
+ }else
+ start=new_pos+char_left;
+ this.area_select(start, length);
+
+ }
+ }
+ else
+ {
+ var nbLineToScroll= Math.floor( toScrollAmount / this.lineHeight );
+ // fix number of line to scroll
+ for( i = this.last_selection["line_start"]; i + diff < this.last_selection["line_start"] + nbLineToScroll ; i++ )
+ {
+ if( elem = _$('line_'+ i) )
+ {
+ diff += Math.floor( ( elem.offsetHeight - 1 ) / this.lineHeight );
+ }
+ }
+ nbLineToScroll -= diff;
+
+ if(this.last_selection["selec_direction"]=="down"){
+ view="bottom";
+ for(line_nb=0; line_nb< Math.min(this.last_selection["line_start"]+this.last_selection["line_nb"]-2+nbLineToScroll, lines.length); line_nb++){
+ if(line_nb==this.last_selection["line_start"]-1)
+ char_left= this.last_selection["selectionStart"] -new_pos;
+ new_pos+= lines[line_nb].length + 1;
+
+ }
+ if(shift_pressed){
+ length=Math.abs(this.last_selection["selectionStart"]-new_pos);
+ length+=Math.min(lines[Math.min(lines.length-1, line_nb)].length, this.last_selection["curr_pos"]);
+ //length+=Math.min(lines[Math.min(lines.length-1, line_nb)].length, char_left);
+ this.area_select(Math.min(this.last_selection["selectionStart"], new_pos), length);
+ }else{
+ this.area_select(new_pos+char_left, 0);
+ }
+
+ }else{
+ view="top";
+ for(line_nb=0; line_nb< Math.min(this.last_selection["line_start"]+nbLineToScroll-1, lines.length, lines.length); line_nb++){
+ if(line_nb==this.last_selection["line_start"]-1)
+ char_left= this.last_selection["selectionStart"] -new_pos;
+ new_pos+= lines[line_nb].length + 1;
+ }
+ if(shift_pressed){
+ length=Math.abs(this.last_selection["selectionEnd"]-new_pos-char_left);
+ length+=Math.min(lines[Math.min(lines.length-1, line_nb)].length, this.last_selection["curr_pos"])- char_left-1;
+ //length+=Math.min(lines[Math.min(lines.length-1, line_nb)].length, char_left);
+ this.area_select(Math.min(this.last_selection["selectionEnd"], new_pos+char_left), length);
+ if(new_pos+char_left > this.last_selection["selectionEnd"])
+ view="bottom";
+ }else{
+ this.area_select(new_pos+char_left, 0);
+ }
+
+ }
+ }
+ //console.log( new_pos, char_left, length, nbLineToScroll, toScrollAmount, _$("result").clientHeigh );
+ this.check_line_selection();
+ this.scroll_to_view(view);
+ };
+
+ EditArea.prototype.start_resize= function(e){
+ parent.editAreaLoader.resize["id"] = editArea.id;
+ parent.editAreaLoader.resize["start_x"] = (e)? e.pageX : event.x + document.body.scrollLeft;
+ parent.editAreaLoader.resize["start_y"] = (e)? e.pageY : event.y + document.body.scrollTop;
+ if(editArea.isIE)
+ {
+ editArea.textarea.focus();
+ editArea.getIESelection();
+ }
+ parent.editAreaLoader.resize["selectionStart"] = editArea.textarea.selectionStart;
+ parent.editAreaLoader.resize["selectionEnd"] = editArea.textarea.selectionEnd;
+ parent.editAreaLoader.start_resize_area();
+ };
+
+ EditArea.prototype.toggle_full_screen= function(to){
+ var t=this, p=parent, a=t.textarea, html, frame, selStart, selEnd, old, icon;
+ if(typeof(to)=="undefined")
+ to= !t.fullscreen['isFull'];
+ old = t.fullscreen['isFull'];
+ t.fullscreen['isFull']= to;
+ icon = _$("fullscreen");
+ selStart = t.textarea.selectionStart;
+ selEnd = t.textarea.selectionEnd;
+ html = p.document.getElementsByTagName("html")[0];
+ frame = p.document.getElementById("frame_"+t.id);
+
+ if(to && to!=old)
+ { // toogle on fullscreen
+
+ t.fullscreen['old_overflow'] = p.get_css_property(html, "overflow");
+ t.fullscreen['old_height'] = p.get_css_property(html, "height");
+ t.fullscreen['old_width'] = p.get_css_property(html, "width");
+ t.fullscreen['old_scrollTop'] = html.scrollTop;
+ t.fullscreen['old_scrollLeft'] = html.scrollLeft;
+ t.fullscreen['old_zIndex'] = p.get_css_property(frame, "z-index");
+ if(t.isOpera){
+ html.style.height = "100%";
+ html.style.width = "100%";
+ }
+ html.style.overflow = "hidden";
+ html.scrollTop = 0;
+ html.scrollLeft = 0;
+
+ frame.style.position = "absolute";
+ frame.style.width = html.clientWidth+"px";
+ frame.style.height = html.clientHeight+"px";
+ frame.style.display = "block";
+ frame.style.zIndex = "999999";
+ frame.style.top = "0px";
+ frame.style.left = "0px";
+
+ // if the iframe was in a div with position absolute, the top and left are the one of the div,
+ // so I fix it by seeing at witch position the iframe start and correcting it
+ frame.style.top = "-"+p.calculeOffsetTop(frame)+"px";
+ frame.style.left = "-"+p.calculeOffsetLeft(frame)+"px";
+
+ // parent.editAreaLoader.execCommand(t.id, "update_size();");
+ // var body=parent.document.getElementsByTagName("body")[0];
+ // body.appendChild(frame);
+
+ t.switchClassSticky(icon, 'editAreaButtonSelected', false);
+ t.fullscreen['allow_resize']= t.resize_allowed;
+ t.allow_resize(false);
+
+ //t.area_select(selStart, selEnd-selStart);
+
+
+ // opera can't manage to do a direct size update
+ if(t.isFirefox){
+ p.editAreaLoader.execCommand(t.id, "update_size();");
+ t.area_select(selStart, selEnd-selStart);
+ t.scroll_to_view();
+ t.focus();
+ }else{
+ setTimeout("p.editAreaLoader.execCommand('"+ t.id +"', 'update_size();');editArea.focus();", 10);
+ }
+
+
+ }
+ else if(to!=old)
+ { // toogle off fullscreen
+ frame.style.position="static";
+ frame.style.zIndex= t.fullscreen['old_zIndex'];
+
+ if(t.isOpera)
+ {
+ html.style.height = "auto";
+ html.style.width = "auto";
+ html.style.overflow = "auto";
+ }
+ else if(t.isIE && p!=top)
+ { // IE doesn't manage html overflow in frames like in normal page...
+ html.style.overflow = "auto";
+ }
+ else
+ {
+ html.style.overflow = t.fullscreen['old_overflow'];
+ }
+ html.scrollTop = t.fullscreen['old_scrollTop'];
+ html.scrollLeft = t.fullscreen['old_scrollLeft'];
+
+ p.editAreaLoader.hide(t.id);
+ p.editAreaLoader.show(t.id);
+
+ t.switchClassSticky(icon, 'editAreaButtonNormal', false);
+ if(t.fullscreen['allow_resize'])
+ t.allow_resize(t.fullscreen['allow_resize']);
+ if(t.isFirefox){
+ t.area_select(selStart, selEnd-selStart);
+ setTimeout("editArea.scroll_to_view();", 10);
+ }
+
+ //p.editAreaLoader.remove_event(p.window, "resize", editArea.update_size);
+ }
+
+ };
+
+ EditArea.prototype.allow_resize= function(allow){
+ var resize= _$("resize_area");
+ if(allow){
+
+ resize.style.visibility="visible";
+ parent.editAreaLoader.add_event(resize, "mouseup", editArea.start_resize);
+ }else{
+ resize.style.visibility="hidden";
+ parent.editAreaLoader.remove_event(resize, "mouseup", editArea.start_resize);
+ }
+ this.resize_allowed= allow;
+ };
+
+
+ EditArea.prototype.change_syntax= function(new_syntax, is_waiting){
+ // alert("cahnge to "+new_syntax);
+ // the syntax is the same
+ if(new_syntax==this.settings['syntax'])
+ return true;
+
+ // check that the syntax is one allowed
+ var founded= false;
+ for(var i=0; i<this.syntax_list.length; i++)
+ {
+ if(this.syntax_list[i]==new_syntax)
+ founded= true;
+ }
+
+ if(founded==true)
+ {
+ // the reg syntax file is not loaded
+ if(!parent.editAreaLoader.load_syntax[new_syntax])
+ {
+ // load the syntax file and wait for file loading
+ if(!is_waiting)
+ parent.editAreaLoader.load_script(parent.editAreaLoader.baseURL + "reg_syntax/" + new_syntax + ".js");
+ setTimeout("editArea.change_syntax('"+ new_syntax +"', true);", 100);
+ this.show_waiting_screen();
+ }
+ else
+ {
+ if(!this.allready_used_syntax[new_syntax])
+ { // the syntax has still not been used
+ // rebuild syntax definition for new languages
+ parent.editAreaLoader.init_syntax_regexp();
+ // add style to the new list
+ this.add_style(parent.editAreaLoader.syntax[new_syntax]["styles"]);
+ this.allready_used_syntax[new_syntax]=true;
+ }
+ // be sure that the select option is correctly updated
+ var sel= _$("syntax_selection");
+ if(sel && sel.value!=new_syntax)
+ {
+ for(var i=0; i<sel.length; i++){
+ if(sel.options[i].value && sel.options[i].value == new_syntax)
+ sel.options[i].selected=true;
+ }
+ }
+
+ /* if(this.settings['syntax'].length==0)
+ {
+ this.switchClassSticky(_$("highlight"), 'editAreaButtonNormal', false);
+ this.switchClassSticky(_$("reset_highlight"), 'editAreaButtonNormal', false);
+ this.change_highlight(true);
+ }
+ */
+ this.settings['syntax']= new_syntax;
+ this.resync_highlight(true);
+ this.hide_waiting_screen();
+ return true;
+ }
+ }
+ return false;
+ };
+
+
+ // check if the file has changed
+ EditArea.prototype.set_editable= function(is_editable){
+ if(is_editable)
+ {
+ document.body.className= "";
+ this.textarea.readOnly= false;
+ this.is_editable= true;
+ }
+ else
+ {
+ document.body.className= "non_editable";
+ this.textarea.readOnly= true;
+ this.is_editable= false;
+ }
+
+ if(editAreas[this.id]["displayed"]==true)
+ this.update_size();
+ };
+
+ /***** Wrap mode *****/
+
+ // toggling function for set_wrap_mode
+ EditArea.prototype.toggle_word_wrap= function(){
+ this.set_word_wrap( !this.settings['word_wrap'] );
+ };
+
+
+ // open a new tab for the given file
+ EditArea.prototype.set_word_wrap= function(to){
+ var t=this, a= t.textarea;
+
+ if( t.isOpera )
+ {
+ this.settings['word_wrap']= false;
+ t.switchClassSticky( _$("word_wrap"), 'editAreaButtonDisabled', true );
+ return false;
+ }
+
+ if( to )
+ {
+ wrap_mode = 'soft';
+ this.container.className+= ' word_wrap';
+ this.container.style.width="";
+ this.content_highlight.style.width="";
+ a.style.width="100%";
+ if( t.isIE && t.isIE < 7 ) // IE 6 count 50 px too much
+ {
+ a.style.width = ( a.offsetWidth-5 )+"px";
+ }
+
+ t.switchClassSticky( _$("word_wrap"), 'editAreaButtonSelected', false );
+ }
+ else
+ {
+ wrap_mode = 'off';
+ this.container.className = this.container.className.replace(/word_wrap/g, '');
+ t.switchClassSticky( _$("word_wrap"), 'editAreaButtonNormal', true );
+ }
+ this.textarea.previous_scrollWidth = '';
+ this.textarea.previous_scrollHeight = '';
+
+ a.wrap= wrap_mode;
+ a.setAttribute('wrap', wrap_mode);
+ // only IE can change wrap mode on the fly without element reloading
+ if(!this.isIE)
+ {
+ var start=a.selectionStart, end= a.selectionEnd;
+ var parNod = a.parentNode, nxtSib = a.nextSibling;
+ parNod.removeChild(a);
+ parNod.insertBefore(a, nxtSib);
+ this.area_select(start, end-start);
+ }
+ // reset some optimisation
+ this.settings['word_wrap'] = to;
+ this.focus();
+ this.update_size();
+ this.check_line_selection();
+ };
+ /***** tabbed files managing functions *****/
+
+ // open a new tab for the given file
+ EditArea.prototype.open_file= function(settings){
+
+ if(settings['id']!="undefined")
+ {
+ var id= settings['id'];
+ // create a new file object with defautl values
+ var new_file= {};
+ new_file['id'] = id;
+ new_file['title'] = id;
+ new_file['text'] = "";
+ new_file['last_selection'] = "";
+ new_file['last_text_to_highlight'] = "";
+ new_file['last_hightlighted_text'] = "";
+ new_file['previous'] = [];
+ new_file['next'] = [];
+ new_file['last_undo'] = "";
+ new_file['smooth_selection'] = this.settings['smooth_selection'];
+ new_file['do_highlight']= this.settings['start_highlight'];
+ new_file['syntax'] = this.settings['syntax'];
+ new_file['scroll_top'] = 0;
+ new_file['scroll_left'] = 0;
+ new_file['selection_start']= 0;
+ new_file['selection_end']= 0;
+ new_file['edited'] = false;
+ new_file['font_size'] = this.settings["font_size"];
+ new_file['font_family'] = this.settings["font_family"];
+ new_file['word_wrap'] = this.settings["word_wrap"];
+ new_file['toolbar'] = {'links':{}, 'selects': {}};
+ new_file['compare_edited_text']= new_file['text'];
+
+
+ this.files[id]= new_file;
+ this.update_file(id, settings);
+ this.files[id]['compare_edited_text']= this.files[id]['text'];
+
+
+ var html_id= 'tab_file_'+encodeURIComponent(id);
+ this.filesIdAssoc[html_id]= id;
+ this.files[id]['html_id']= html_id;
+
+ if(!_$(this.files[id]['html_id']) && id!="")
+ {
+ // be sure the tab browsing area is displayed
+ this.tab_browsing_area.style.display= "block";
+ var elem= document.createElement('li');
+ elem.id= this.files[id]['html_id'];
+ var close= "<img src=\""+ parent.editAreaLoader.baseURL +"images/close.gif\" title=\""+ this.get_translation('close_tab', 'word') +"\" onclick=\"editArea.execCommand('close_file', editArea.filesIdAssoc['"+ html_id +"']);return false;\" class=\"hidden\" onmouseover=\"this.className=''\" onmouseout=\"this.className='hidden'\" />";
+ elem.innerHTML= "<a onclick=\"javascript:editArea.execCommand('switch_to_file', editArea.filesIdAssoc['"+ html_id +"']);\" selec=\"none\"><b><span><strong class=\"edited\">*</strong>"+ this.files[id]['title'] + close +"</span></b></a>";
+ _$('tab_browsing_list').appendChild(elem);
+ var elem= document.createElement('text');
+ this.update_size();
+ }
+
+ // open file callback (for plugin)
+ if(id!="")
+ this.execCommand('file_open', this.files[id]);
+
+ this.switch_to_file(id, true);
+ return true;
+ }
+ else
+ return false;
+ };
+
+ // close the given file
+ EditArea.prototype.close_file= function(id){
+ if(this.files[id])
+ {
+ this.save_file(id);
+
+ // close file callback
+ if(this.execCommand('file_close', this.files[id])!==false)
+ {
+ // remove the tab in the toolbar
+ var li= _$(this.files[id]['html_id']);
+ li.parentNode.removeChild(li);
+ // select a new file
+ if(id== this.curr_file)
+ {
+ var next_file= "";
+ var is_next= false;
+ for(var i in this.files)
+ {
+ if( is_next )
+ {
+ next_file = i;
+ break;
+ }
+ else if( i == id )
+ is_next = true;
+ else
+ next_file = i;
+ }
+ // display the next file
+ this.switch_to_file(next_file);
+ }
+ // clear datas
+ delete (this.files[id]);
+ this.update_size();
+ }
+ }
+ };
+
+ // backup current file datas
+ EditArea.prototype.save_file= function(id){
+ var t= this, save, a_links, a_selects, save_butt, img, i;
+ if(t.files[id])
+ {
+ var save= t.files[id];
+ save['last_selection'] = t.last_selection;
+ save['last_text_to_highlight'] = t.last_text_to_highlight;
+ save['last_hightlighted_text'] = t.last_hightlighted_text;
+ save['previous'] = t.previous;
+ save['next'] = t.next;
+ save['last_undo'] = t.last_undo;
+ save['smooth_selection'] = t.smooth_selection;
+ save['do_highlight'] = t.do_highlight;
+ save['syntax'] = t.settings['syntax'];
+ save['text'] = t.textarea.value;
+ save['scroll_top'] = t.result.scrollTop;
+ save['scroll_left'] = t.result.scrollLeft;
+ save['selection_start'] = t.last_selection["selectionStart"];
+ save['selection_end'] = t.last_selection["selectionEnd"];
+ save['font_size'] = t.settings["font_size"];
+ save['font_family'] = t.settings["font_family"];
+ save['word_wrap'] = t.settings["word_wrap"];
+ save['toolbar'] = {'links':{}, 'selects': {}};
+
+ // save toolbar buttons state for fileSpecific buttons
+ a_links= _$("toolbar_1").getElementsByTagName("a");
+ for( i=0; i<a_links.length; i++ )
+ {
+ if( a_links[i].getAttribute('fileSpecific') == 'yes' )
+ {
+ save_butt = {};
+ img = a_links[i].getElementsByTagName('img')[0];
+ save_butt['classLock'] = img.classLock;
+ save_butt['className'] = img.className;
+ save_butt['oldClassName'] = img.oldClassName;
+
+ save['toolbar']['links'][a_links[i].id]= save_butt;
+ }
+ }
+
+ // save toolbar select state for fileSpecific buttons
+ a_selects= _$("toolbar_1").getElementsByTagName("select");
+ for( i=0; i<a_selects.length; i++)
+ {
+ if(a_selects[i].getAttribute('fileSpecific')=='yes')
+ {
+ save['toolbar']['selects'][a_selects[i].id]= a_selects[i].value;
+ }
+ }
+
+ t.files[id]= save;
+
+ return save;
+ }
+
+ return false;
+ };
+
+ // update file_datas
+ EditArea.prototype.update_file= function(id, new_values){
+ for(var i in new_values)
+ {
+ this.files[id][i]= new_values[i];
+ }
+ };
+
+ // display file datas
+ EditArea.prototype.display_file= function(id){
+ var t = this, a= t.textarea, new_file, a_lis, a_selects, a_links, a_options, i, j;
+
+ // we're showing the empty file
+ if(id=='')
+ {
+ a.readOnly= true;
+ t.tab_browsing_area.style.display= "none";
+ _$("no_file_selected").style.display= "block";
+ t.result.className= "empty";
+ // clear current datas
+ if(!t.files[''])
+ {
+ t.open_file({id: ''});
+ }
+ }
+ // we try to show a non existent file, so we left
+ else if( typeof( t.files[id] ) == 'undefined' )
+ {
+ return false;
+ }
+ // display a normal file
+ else
+ {
+ t.result.className= "";
+ a.readOnly= !t.is_editable;
+ _$("no_file_selected").style.display= "none";
+ t.tab_browsing_area.style.display= "block";
+ }
+
+ // ensure to have last state for undo/redo actions
+ t.check_redo(true);
+ t.check_undo(true);
+ t.curr_file= id;
+
+ // replace selected tab file
+ a_lis= t.tab_browsing_area.getElementsByTagName('li');
+ for( i=0; i<a_lis.length; i++)
+ {
+ if(a_lis[i].id == t.files[id]['html_id'])
+ a_lis[i].className='selected';
+ else
+ a_lis[i].className='';
+ }
+
+ // replace next files datas
+ new_file= t.files[id];
+
+ // restore text content
+ a.value= new_file['text'];
+
+ // restore font-size
+ t.set_font(new_file['font_family'], new_file['font_size']);
+
+ // restore selection and scroll
+ t.area_select(new_file['last_selection']['selection_start'], new_file['last_selection']['selection_end'] - new_file['last_selection']['selection_start']);
+ t.manage_size(true);
+ t.result.scrollTop= new_file['scroll_top'];
+ t.result.scrollLeft= new_file['scroll_left'];
+
+ // restore undo, redo
+ t.previous= new_file['previous'];
+ t.next= new_file['next'];
+ t.last_undo= new_file['last_undo'];
+ t.check_redo(true);
+ t.check_undo(true);
+
+ // restore highlight
+ t.execCommand("change_highlight", new_file['do_highlight']);
+ t.execCommand("change_syntax", new_file['syntax']);
+
+ // smooth mode
+ t.execCommand("change_smooth_selection_mode", new_file['smooth_selection']);
+
+ // word_wrap
+ t.execCommand("set_word_wrap", new_file['word_wrap']);
+
+ // restore links state in toolbar
+ a_links= new_file['toolbar']['links'];
+ for( i in a_links)
+ {
+ if( img = _$(i).getElementsByTagName('img')[0] )
+ {
+ img.classLock = a_links[i]['classLock'];
+ img.className = a_links[i]['className'];
+ img.oldClassName= a_links[i]['oldClassName'];
+ }
+ }
+
+ // restore select state in toolbar
+ a_selects = new_file['toolbar']['selects'];
+ for( i in a_selects)
+ {
+ a_options = _$(i).options;
+ for( j=0; j<a_options.length; j++)
+ {
+ if( a_options[j].value == a_selects[i] )
+ _$(i).options[j].selected=true;
+ }
+ }
+
+ };
+
+ // change tab for displaying a new one
+ EditArea.prototype.switch_to_file= function(file_to_show, force_refresh){
+ if(file_to_show!=this.curr_file || force_refresh)
+ {
+ this.save_file(this.curr_file);
+ if(this.curr_file!='')
+ this.execCommand('file_switch_off', this.files[this.curr_file]);
+ this.display_file(file_to_show);
+ if(file_to_show!='')
+ this.execCommand('file_switch_on', this.files[file_to_show]);
+ }
+ };
+
+ // get all infos for the given file
+ EditArea.prototype.get_file= function(id){
+ if(id==this.curr_file)
+ this.save_file(id);
+ return this.files[id];
+ };
+
+ // get all available files infos
+ EditArea.prototype.get_all_files= function(){
+ tmp_files= this.files;
+ this.save_file(this.curr_file);
+ if(tmp_files[''])
+ delete(this.files['']);
+ return tmp_files;
+ };
+
+
+ // check if the file has changed
+ EditArea.prototype.check_file_changes= function(){
+
+ var id= this.curr_file;
+ if(this.files[id] && this.files[id]['compare_edited_text']!=undefined)
+ {
+ if(this.files[id]['compare_edited_text'].length==this.textarea.value.length && this.files[id]['compare_edited_text']==this.textarea.value)
+ {
+ if(this.files[id]['edited']!= false)
+ this.set_file_edited_mode(id, false);
+ }
+ else
+ {
+ if(this.files[id]['edited']!= true)
+ this.set_file_edited_mode(id, true);
+ }
+ }
+ };
+
+ // set if the file is edited or not
+ EditArea.prototype.set_file_edited_mode= function(id, to){
+ // change CSS for edited tab
+ if(this.files[id] && _$(this.files[id]['html_id']))
+ {
+ var link= _$(this.files[id]['html_id']).getElementsByTagName('a')[0];
+ if(to==true)
+ {
+ link.className= 'edited';
+ }
+ else
+ {
+ link.className= '';
+ if(id==this.curr_file)
+ text= this.textarea.value;
+ else
+ text= this.files[id]['text'];
+ this.files[id]['compare_edited_text']= text;
+ }
+
+ this.files[id]['edited']= to;
+ }
+ };
+
+ EditArea.prototype.set_show_line_colors = function(new_value){
+ this.show_line_colors = new_value;
+
+ if( new_value )
+ this.selection_field.className += ' show_colors';
+ else
+ this.selection_field.className = this.selection_field.className.replace( / show_colors/g, '' );
+ };
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/f6330834/components/org.apache.stratos.theme.mgt.ui/src/main/resources/web/tenant-theme/js/editarea/edit_area/edit_area_loader.js
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.theme.mgt.ui/src/main/resources/web/tenant-theme/js/editarea/edit_area/edit_area_loader.js b/components/org.apache.stratos.theme.mgt.ui/src/main/resources/web/tenant-theme/js/editarea/edit_area/edit_area_loader.js
new file mode 100644
index 0000000..34a17dd
--- /dev/null
+++ b/components/org.apache.stratos.theme.mgt.ui/src/main/resources/web/tenant-theme/js/editarea/edit_area/edit_area_loader.js
@@ -0,0 +1,1080 @@
+/******
+ *
+ * EditArea
+ * Developped by Christophe Dolivet
+ * Released under LGPL, Apache and BSD licenses (use the one you want)
+ *
+******/
+
+function EditAreaLoader(){
+ var t=this;
+ t.version= "0.8.1.1";
+ date= new Date();
+ t.start_time=date.getTime();
+ t.win= "loading"; // window loading state
+ t.error= false; // to know if load is interrrupt
+ t.baseURL="";
+ //t.suffix="";
+ t.template="";
+ t.lang= {}; // array of loaded speech language
+ t.load_syntax= {}; // array of loaded syntax language for highlight mode
+ t.syntax= {}; // array of initilized syntax language for highlight mode
+ t.loadedFiles= [];
+ t.waiting_loading= {}; // files that must be loaded in order to allow the script to really start
+ // scripts that must be loaded in the iframe
+ t.scripts_to_load= ["elements_functions", "resize_area", "reg_syntax"];
+ t.sub_scripts_to_load= ["edit_area", "manage_area" ,"edit_area_functions", "keyboard", "search_replace", "highlight", "regexp"];
+
+ t.resize= []; // contain resizing datas
+ t.hidden= {}; // store datas of the hidden textareas
+
+ t.default_settings= {
+ //id: "src" // id of the textarea to transform
+ debug: false
+ ,smooth_selection: true
+ ,font_size: "10" // not for IE
+ ,font_family: "monospace" // can be "verdana,monospace". Allow non monospace font but Firefox get smaller tabulation with non monospace fonts. IE doesn't change the tabulation width and Opera doesn't take this option into account...
+ ,start_highlight: false // if start with highlight
+ ,toolbar: "search, go_to_line, fullscreen, |, undo, redo, |, select_font,|, change_smooth_selection, highlight, reset_highlight, word_wrap, |, help"
+ ,begin_toolbar: "" // "new_document, save, load, |"
+ ,end_toolbar: "" // or end_toolbar
+ ,is_multi_files: false // enable the multi file mode (the textarea content is ignored)
+ ,allow_resize: "both" // possible values: "no", "both", "x", "y"
+ ,show_line_colors: false // if the highlight is disabled for the line currently beeing edited (if enabled => heavy CPU use)
+ ,min_width: 400
+ ,min_height: 125
+ ,replace_tab_by_spaces: false
+ ,allow_toggle: true // true or false
+ ,language: "en"
+ ,syntax: ""
+ ,syntax_selection_allow: "basic,brainfuck,c,coldfusion,cpp,css,html,java,js,pas,perl,php,python,ruby,robotstxt,sql,tsql,vb,xml"
+ ,display: "onload" // onload or later
+ ,max_undo: 30
+ ,browsers: "known" // all or known
+ ,plugins: "" // comma separated plugin list
+ ,gecko_spellcheck: false // enable/disable by default the gecko_spellcheck
+ ,fullscreen: false
+ ,is_editable: true
+ ,cursor_position: "begin"
+ ,word_wrap: false // define if the text is wrapped of not in the textarea
+ ,autocompletion: false // NOT IMPLEMENTED
+ ,load_callback: "" // click on load button (function name)
+ ,save_callback: "" // click on save button (function name)
+ ,change_callback: "" // textarea onchange trigger (function name)
+ ,submit_callback: "" // form submited (function name)
+ ,EA_init_callback: "" // EditArea initiliazed (function name)
+ ,EA_delete_callback: "" // EditArea deleted (function name)
+ ,EA_load_callback: "" // EditArea fully loaded and displayed (function name)
+ ,EA_unload_callback: "" // EditArea delete while being displayed (function name)
+ ,EA_toggle_on_callback: "" // EditArea toggled on (function name)
+ ,EA_toggle_off_callback: "" // EditArea toggled off (function name)
+ ,EA_file_switch_on_callback: "" // a new tab is selected (called for the newly selected file)
+ ,EA_file_switch_off_callback: "" // a new tab is selected (called for the previously selected file)
+ ,EA_file_close_callback: "" // close a tab
+ };
+
+ t.advanced_buttons = [
+ // id, button img, command (it will try to find the translation of "id"), is_file_specific
+ ['new_document', 'newdocument.gif', 'new_document', false],
+ ['search', 'search.gif', 'show_search', false],
+ ['go_to_line', 'go_to_line.gif', 'go_to_line', false],
+ ['undo', 'undo.gif', 'undo', true],
+ ['redo', 'redo.gif', 'redo', true],
+ ['change_smooth_selection', 'smooth_selection.gif', 'change_smooth_selection_mode', true],
+ ['reset_highlight', 'reset_highlight.gif', 'resync_highlight', true],
+ ['highlight', 'highlight.gif','change_highlight', true],
+ ['help', 'help.gif', 'show_help', false],
+ ['save', 'save.gif', 'save', false],
+ ['load', 'load.gif', 'load', false],
+ ['fullscreen', 'fullscreen.gif', 'toggle_full_screen', false],
+ ['word_wrap', 'word_wrap.gif', 'toggle_word_wrap', true],
+ ['autocompletion', 'autocompletion.gif', 'toggle_autocompletion', true]
+ ];
+
+ // navigator identification
+ t.set_browser_infos(t);
+
+ if(t.isIE>=6 || t.isGecko || ( t.isWebKit && !t.isSafari<3 ) || t.isOpera>=9 || t.isCamino )
+ t.isValidBrowser=true;
+ else
+ t.isValidBrowser=false;
+
+ t.set_base_url();
+
+ for(var i=0; i<t.scripts_to_load.length; i++){
+ setTimeout("editAreaLoader.load_script('"+t.baseURL + t.scripts_to_load[i]+ ".js');", 1); // let the time to Object editAreaLoader to be created before loading additionnal scripts
+ t.waiting_loading[t.scripts_to_load[i]+ ".js"]= false;
+ }
+ t.add_event(window, "load", EditAreaLoader.prototype.window_loaded);
+};
+
+EditAreaLoader.prototype ={
+ has_error : function(){
+ this.error= true;
+ // set to empty all EditAreaLoader functions
+ for(var i in EditAreaLoader.prototype){
+ EditAreaLoader.prototype[i]=function(){};
+ }
+ },
+
+ // add browser informations to the object passed in parameter
+ set_browser_infos : function(o){
+ ua= navigator.userAgent;
+
+ // general detection
+ o.isWebKit = /WebKit/.test(ua);
+ o.isGecko = !o.isWebKit && /Gecko/.test(ua);
+ o.isMac = /Mac/.test(ua);
+
+ o.isIE = (navigator.appName == "Microsoft Internet Explorer");
+ if(o.isIE){
+ o.isIE = ua.replace(/^.*?MSIE\s+([0-9\.]+).*$/, "$1");
+ if(o.isIE<6)
+ o.has_error();
+ }
+
+ if(o.isOpera = (ua.indexOf('Opera') != -1)){
+ o.isOpera= ua.replace(/^.*?Opera.*?([0-9\.]+).*$/i, "$1");
+ if(o.isOpera<9)
+ o.has_error();
+ o.isIE=false;
+ }
+
+ if(o.isFirefox =(ua.indexOf('Firefox') != -1))
+ o.isFirefox = ua.replace(/^.*?Firefox.*?([0-9\.]+).*$/i, "$1");
+ // Firefox clones
+ if( ua.indexOf('Iceweasel') != -1 )
+ o.isFirefox = ua.replace(/^.*?Iceweasel.*?([0-9\.]+).*$/i, "$1");
+ if( ua.indexOf('GranParadiso') != -1 )
+ o.isFirefox = ua.replace(/^.*?GranParadiso.*?([0-9\.]+).*$/i, "$1");
+ if( ua.indexOf('BonEcho') != -1 )
+ o.isFirefox = ua.replace(/^.*?BonEcho.*?([0-9\.]+).*$/i, "$1");
+ if( ua.indexOf('SeaMonkey') != -1)
+ o.isFirefox = (ua.replace(/^.*?SeaMonkey.*?([0-9\.]+).*$/i, "$1") ) + 1;
+
+ if(o.isCamino =(ua.indexOf('Camino') != -1))
+ o.isCamino = ua.replace(/^.*?Camino.*?([0-9\.]+).*$/i, "$1");
+
+ if(o.isSafari =(ua.indexOf('Safari') != -1))
+ o.isSafari= ua.replace(/^.*?Version\/([0-9]+\.[0-9]+).*$/i, "$1");
+
+ if(o.isChrome =(ua.indexOf('Chrome') != -1)) {
+ o.isChrome = ua.replace(/^.*?Chrome.*?([0-9\.]+).*$/i, "$1");
+ o.isSafari = false;
+ }
+
+ },
+
+ window_loaded : function(){
+ editAreaLoader.win="loaded";
+
+ // add events on forms
+ if (document.forms) {
+ for (var i=0; i<document.forms.length; i++) {
+ var form = document.forms[i];
+ form.edit_area_replaced_submit=null;
+ try {
+
+ form.edit_area_replaced_submit = form.onsubmit;
+ form.onsubmit="";
+ } catch (e) {// Do nothing
+ }
+ editAreaLoader.add_event(form, "submit", EditAreaLoader.prototype.submit);
+ editAreaLoader.add_event(form, "reset", EditAreaLoader.prototype.reset);
+ }
+ }
+ editAreaLoader.add_event(window, "unload", function(){for(var i in editAreas){editAreaLoader.delete_instance(i);}}); // ini callback
+ },
+
+ // init the checkup of the selection of the IE textarea
+ init_ie_textarea : function(id){
+ var a=document.getElementById(id);
+ try{
+ if(a && typeof(a.focused)=="undefined"){
+ a.focus();
+ a.focused=true;
+ a.selectionStart= a.selectionEnd= 0;
+ get_IE_selection(a);
+ editAreaLoader.add_event(a, "focus", IE_textarea_focus);
+ editAreaLoader.add_event(a, "blur", IE_textarea_blur);
+
+ }
+ }catch(ex){}
+ },
+
+ init : function(settings){
+ var t=this,s=settings,i;
+
+ if(!s["id"])
+ t.has_error();
+ if(t.error)
+ return;
+ // if an instance of the editor already exists for this textarea => delete the previous one
+ if(editAreas[s["id"]])
+ t.delete_instance(s["id"]);
+
+ // init settings
+ for(i in t.default_settings){
+ if(typeof(s[i])=="undefined")
+ s[i]=t.default_settings[i];
+ }
+
+ if(s["browsers"]=="known" && t.isValidBrowser==false){
+ return;
+ }
+
+ if(s["begin_toolbar"].length>0)
+ s["toolbar"]= s["begin_toolbar"] +","+ s["toolbar"];
+ if(s["end_toolbar"].length>0)
+ s["toolbar"]= s["toolbar"] +","+ s["end_toolbar"];
+ s["tab_toolbar"]= s["toolbar"].replace(/ /g,"").split(",");
+
+ s["plugins"]= s["plugins"].replace(/ /g,"").split(",");
+ for(i=0; i<s["plugins"].length; i++){
+ if(s["plugins"][i].length==0)
+ s["plugins"].splice(i,1);
+ }
+ // alert(settings["plugins"].length+": "+ settings["plugins"].join(","));
+ t.get_template();
+ t.load_script(t.baseURL + "langs/"+ s["language"] + ".js");
+
+ if(s["syntax"].length>0){
+ s["syntax"]=s["syntax"].toLowerCase();
+ t.load_script(t.baseURL + "reg_syntax/"+ s["syntax"] + ".js");
+ }
+ //alert(this.template);
+
+ editAreas[s["id"]]= {"settings": s};
+ editAreas[s["id"]]["displayed"]=false;
+ editAreas[s["id"]]["hidden"]=false;
+
+ //if(settings["display"]=="onload")
+ t.start(s["id"]);
+ },
+
+ // delete an instance of an EditArea
+ delete_instance : function(id){
+ var d=document,fs=window.frames,span,iframe;
+ editAreaLoader.execCommand(id, "EA_delete");
+ if(fs["frame_"+id] && fs["frame_"+id].editArea)
+ {
+ if(editAreas[id]["displayed"])
+ editAreaLoader.toggle(id, "off");
+ fs["frame_"+id].editArea.execCommand("EA_unload");
+ }
+
+ // remove toggle infos and debug textarea
+ span= d.getElementById("EditAreaArroundInfos_"+id);
+ if(span)
+ span.parentNode.removeChild(span);
+
+ // remove the iframe
+ iframe= d.getElementById("frame_"+id);
+ if(iframe){
+ iframe.parentNode.removeChild(iframe);
+ //delete iframe;
+ try {
+ delete fs["frame_"+id];
+ } catch (e) {// Do nothing
+ }
+ }
+
+ delete editAreas[id];
+ },
+
+
+ start : function(id){
+ var t=this,d=document,f,span,father,next,html='',html_toolbar_content='',template,content,i;
+
+ // check that the window is loaded
+ if(t.win!="loaded"){
+ setTimeout("editAreaLoader.start('"+id+"');", 50);
+ return;
+ }
+
+ // check that all needed scripts are loaded
+ for( i in t.waiting_loading){
+ if(t.waiting_loading[i]!="loaded" && typeof(t.waiting_loading[i])!="function"){
+ setTimeout("editAreaLoader.start('"+id+"');", 50);
+ return;
+ }
+ }
+
+ // wait until language and syntax files are loaded
+ if(!t.lang[editAreas[id]["settings"]["language"]] || (editAreas[id]["settings"]["syntax"].length>0 && !t.load_syntax[editAreas[id]["settings"]["syntax"]]) ){
+ setTimeout("editAreaLoader.start('"+id+"');", 50);
+ return;
+ }
+ // init the regexp for syntax highlight
+ if(editAreas[id]["settings"]["syntax"].length>0)
+ t.init_syntax_regexp();
+
+
+ // display toggle option and debug area
+ if(!d.getElementById("EditAreaArroundInfos_"+id) && (editAreas[id]["settings"]["debug"] || editAreas[id]["settings"]["allow_toggle"]))
+ {
+ span= d.createElement("span");
+ span.id= "EditAreaArroundInfos_"+id;
+ if(editAreas[id]["settings"]["allow_toggle"]){
+ checked=(editAreas[id]["settings"]["display"]=="onload")?"checked='checked'":"";
+ html+="<div id='edit_area_toggle_"+i+"'>";
+ html+="<input id='edit_area_toggle_checkbox_"+ id +"' class='toggle_"+ id +"' type='checkbox' onclick='editAreaLoader.toggle(\""+ id +"\");' accesskey='e' "+checked+" />";
+ html+="<label for='edit_area_toggle_checkbox_"+ id +"'>{$toggle}</label></div>";
+ }
+ if(editAreas[id]["settings"]["debug"])
+ html+="<textarea id='edit_area_debug_"+ id +"' spellcheck='off' style='z-index: 20; width: 100%; height: 120px;overflow: auto; border: solid black 1px;'></textarea><br />";
+ html= t.translate(html, editAreas[id]["settings"]["language"]);
+ span.innerHTML= html;
+ father= d.getElementById(id).parentNode;
+ next= d.getElementById(id).nextSibling;
+ if(next==null)
+ father.appendChild(span);
+ else
+ father.insertBefore(span, next);
+ }
+
+ if(!editAreas[id]["initialized"])
+ {
+ t.execCommand(id, "EA_init"); // ini callback
+ if(editAreas[id]["settings"]["display"]=="later"){
+ editAreas[id]["initialized"]= true;
+ return;
+ }
+ }
+
+ if(t.isIE){ // launch IE selection checkup
+ t.init_ie_textarea(id);
+ }
+
+ // get toolbar content
+ area=editAreas[id];
+
+ for(i=0; i<area["settings"]["tab_toolbar"].length; i++){
+ // alert(this.tab_toolbar[i]+"\n"+ this.get_control_html(this.tab_toolbar[i]));
+ html_toolbar_content+= t.get_control_html(area["settings"]["tab_toolbar"][i], area["settings"]["language"]);
+ }
+ // translate toolbar text here for chrome 2
+ html_toolbar_content = t.translate(html_toolbar_content, area["settings"]["language"], "template");
+
+
+ // create javascript import rules for the iframe if the javascript has not been already loaded by the compressor
+ if(!t.iframe_script){
+ t.iframe_script="";
+ for(i=0; i<t.sub_scripts_to_load.length; i++)
+ t.iframe_script+='<script language="javascript" type="text/javascript" src="'+ t.baseURL + t.sub_scripts_to_load[i] +'.js"></script>';
+ }
+
+ // add plugins scripts if not already loaded by the compressor (but need to load language in all the case)
+ for(i=0; i<area["settings"]["plugins"].length; i++){
+ //if(typeof(area["settings"]["plugins"][i])=="function") continue;
+ if(!t.all_plugins_loaded)
+ t.iframe_script+='<script language="javascript" type="text/javascript" src="'+ t.baseURL + 'plugins/' + area["settings"]["plugins"][i] + '/' + area["settings"]["plugins"][i] +'.js"></script>';
+ t.iframe_script+='<script language="javascript" type="text/javascript" src="'+ t.baseURL + 'plugins/' + area["settings"]["plugins"][i] + '/langs/' + area["settings"]["language"] +'.js"></script>';
+ }
+
+
+ // create css link for the iframe if the whole css text has not been already loaded by the compressor
+ if(!t.iframe_css){
+ t.iframe_css="<link href='"+ t.baseURL +"edit_area.css' rel='stylesheet' type='text/css' />";
+ }
+
+
+ // create template
+ template= t.template.replace(/\[__BASEURL__\]/g, t.baseURL);
+ template= template.replace("[__TOOLBAR__]",html_toolbar_content);
+
+
+ // fill template with good language sentences
+ template= t.translate(template, area["settings"]["language"], "template");
+
+ // add css_code
+ template= template.replace("[__CSSRULES__]", t.iframe_css);
+ // add js_code
+ template= template.replace("[__JSCODE__]", t.iframe_script);
+
+ // add version_code
+ template= template.replace("[__EA_VERSION__]", t.version);
+ //template=template.replace(/\{\$([^\}]+)\}/gm, this.traduc_template);
+
+ //editAreas[area["settings"]["id"]]["template"]= template;
+
+ area.textarea=d.getElementById(area["settings"]["id"]);
+ editAreas[area["settings"]["id"]]["textarea"]=area.textarea;
+
+ // if removing previous instances from DOM before (fix from Marcin)
+ if(typeof(window.frames["frame_"+area["settings"]["id"]])!='undefined')
+ delete window.frames["frame_"+area["settings"]["id"]];
+
+ // insert template in the document after the textarea
+ father= area.textarea.parentNode;
+ /* var container= document.createElement("div");
+ container.id= "EditArea_frame_container_"+area["settings"]["id"];
+ */
+ content= d.createElement("iframe");
+ content.name= "frame_"+area["settings"]["id"];
+ content.id= "frame_"+area["settings"]["id"];
+ content.style.borderWidth= "0px";
+ setAttribute(content, "frameBorder", "0"); // IE
+ content.style.overflow="hidden";
+ content.style.display="none";
+
+
+ next= area.textarea.nextSibling;
+ if(next==null)
+ father.appendChild(content);
+ else
+ father.insertBefore(content, next) ;
+ f=window.frames["frame_"+area["settings"]["id"]];
+ f.document.open();
+ f.editAreas=editAreas;
+ f.area_id= area["settings"]["id"];
+ f.document.area_id= area["settings"]["id"];
+ f.document.write(template);
+ f.document.close();
+
+ // frame.editAreaLoader=this;
+ //editAreas[area["settings"]["id"]]["displayed"]=true;
+
+ },
+
+ toggle : function(id, toggle_to){
+
+ /* if((editAreas[id]["displayed"]==true && toggle_to!="on") || toggle_to=="off"){
+ this.toggle_off(id);
+ }else if((editAreas[id]["displayed"]==false && toggle_to!="off") || toggle_to=="on"){
+ this.toggle_on(id);
+ }*/
+ if(!toggle_to)
+ toggle_to= (editAreas[id]["displayed"]==true)?"off":"on";
+ if(editAreas[id]["displayed"]==true && toggle_to=="off"){
+ this.toggle_off(id);
+ }else if(editAreas[id]["displayed"]==false && toggle_to=="on"){
+ this.toggle_on(id);
+ }
+
+ return false;
+ },
+
+ // static function
+ toggle_off : function(id){
+ var fs=window.frames,f,t,parNod,nxtSib,selStart,selEnd,scrollTop,scrollLeft;
+ if(fs["frame_"+id])
+ {
+ f = fs["frame_"+id];
+ t = editAreas[id]["textarea"];
+ if(f.editArea.fullscreen['isFull'])
+ f.editArea.toggle_full_screen(false);
+ editAreas[id]["displayed"]=false;
+
+ // set wrap to off to keep same display mode (some browser get problem with this, so it need more complex operation
+ t.wrap = "off"; // for IE
+ setAttribute(t, "wrap", "off"); // for Firefox
+ parNod = t.parentNode;
+ nxtSib = t.nextSibling;
+ parNod.removeChild(t);
+ parNod.insertBefore(t, nxtSib);
+
+ // restore values
+ t.value= f.editArea.textarea.value;
+ selStart = f.editArea.last_selection["selectionStart"];
+ selEnd = f.editArea.last_selection["selectionEnd"];
+ scrollTop = f.document.getElementById("result").scrollTop;
+ scrollLeft = f.document.getElementById("result").scrollLeft;
+
+
+ document.getElementById("frame_"+id).style.display='none';
+
+ t.style.display="inline";
+
+ try{ // IE will give an error when trying to focus an invisible or disabled textarea
+ t.focus();
+ } catch(e){};
+ if(this.isIE){
+ t.selectionStart= selStart;
+ t.selectionEnd = selEnd;
+ t.focused = true;
+ set_IE_selection(t);
+ }else{
+ if(this.isOpera && this.isOpera < 9.6 ){ // Opera bug when moving selection start and selection end
+ t.setSelectionRange(0, 0);
+ }
+ try{
+ t.setSelectionRange(selStart, selEnd);
+ } catch(e) {};
+ }
+ t.scrollTop= scrollTop;
+ t.scrollLeft= scrollLeft;
+ f.editArea.execCommand("toggle_off");
+
+ }
+ },
+
+ // static function
+ toggle_on : function(id){
+ var fs=window.frames,f,t,selStart=0,selEnd=0,scrollTop=0,scrollLeft=0,curPos,elem;
+
+ if(fs["frame_"+id])
+ {
+ f = fs["frame_"+id];
+ t = editAreas[id]["textarea"];
+ area= f.editArea;
+ area.textarea.value= t.value;
+
+ // store display values;
+ curPos = editAreas[id]["settings"]["cursor_position"];
+
+ if(t.use_last==true)
+ {
+ selStart = t.last_selectionStart;
+ selEnd = t.last_selectionEnd;
+ scrollTop = t.last_scrollTop;
+ scrollLeft = t.last_scrollLeft;
+ t.use_last=false;
+ }
+ else if( curPos == "auto" )
+ {
+ try{
+ selStart = t.selectionStart;
+ selEnd = t.selectionEnd;
+ scrollTop = t.scrollTop;
+ scrollLeft = t.scrollLeft;
+ //alert(scrollTop);
+ }catch(ex){}
+ }
+
+ // set to good size
+ this.set_editarea_size_from_textarea(id, document.getElementById("frame_"+id));
+ t.style.display="none";
+ document.getElementById("frame_"+id).style.display="inline";
+ area.execCommand("focus"); // without this focus opera doesn't manage well the iframe body height
+
+
+ // restore display values
+ editAreas[id]["displayed"]=true;
+ area.execCommand("update_size");
+
+ f.document.getElementById("result").scrollTop= scrollTop;
+ f.document.getElementById("result").scrollLeft= scrollLeft;
+ area.area_select(selStart, selEnd-selStart);
+ area.execCommand("toggle_on");
+
+
+ }
+ else
+ {
+ /* if(this.isIE)
+ get_IE_selection(document.getElementById(id)); */
+ elem= document.getElementById(id);
+ elem.last_selectionStart= elem.selectionStart;
+ elem.last_selectionEnd= elem.selectionEnd;
+ elem.last_scrollTop= elem.scrollTop;
+ elem.last_scrollLeft= elem.scrollLeft;
+ elem.use_last=true;
+ editAreaLoader.start(id);
+ }
+ },
+
+ set_editarea_size_from_textarea : function(id, frame){
+ var elem,width,height;
+ elem = document.getElementById(id);
+
+ width = Math.max(editAreas[id]["settings"]["min_width"], elem.offsetWidth)+"px";
+ height = Math.max(editAreas[id]["settings"]["min_height"], elem.offsetHeight)+"px";
+ if(elem.style.width.indexOf("%")!=-1)
+ width = elem.style.width;
+ if(elem.style.height.indexOf("%")!=-1)
+ height = elem.style.height;
+ //alert("h: "+height+" w: "+width);
+
+ frame.style.width= width;
+ frame.style.height= height;
+ },
+
+ set_base_url : function(){
+ var t=this,elems,i,docBasePath;
+
+ if( !this.baseURL ){
+ elems = document.getElementsByTagName('script');
+
+ for( i=0; i<elems.length; i++ ){
+ if (elems[i].src && elems[i].src.match(/edit_area_[^\\\/]*$/i) ) {
+ var src = elems[i].src;
+ src = src.substring(0, src.lastIndexOf('/'));
+ this.baseURL = src;
+ this.file_name= elems[i].src.substr(elems[i].src.lastIndexOf("/")+1);
+ break;
+ }
+ }
+ }
+
+ docBasePath = document.location.href;
+ if (docBasePath.indexOf('?') != -1)
+ docBasePath = docBasePath.substring(0, docBasePath.indexOf('?'));
+ docBasePath = docBasePath.substring(0, docBasePath.lastIndexOf('/'));
+
+ // If not HTTP absolute
+ if (t.baseURL.indexOf('://') == -1 && t.baseURL.charAt(0) != '/') {
+ // If site absolute
+ t.baseURL = docBasePath + "/" + t.baseURL;
+ }
+ t.baseURL +="/";
+ },
+
+ get_button_html : function(id, img, exec, isFileSpecific, baseURL) {
+ var cmd,html;
+ if(!baseURL)
+ baseURL= this.baseURL;
+ cmd = 'editArea.execCommand(\'' + exec + '\')';
+ html = '<a id="a_'+ id +'" href="javascript:' + cmd + '" onclick="' + cmd + ';return false;" onmousedown="return false;" target="_self" fileSpecific="'+ (isFileSpecific?'yes':'no') +'">';
+ html += '<img id="' + id + '" src="'+ baseURL +'images/' + img + '" title="{$' + id + '}" width="20" height="20" class="editAreaButtonNormal" onmouseover="editArea.switchClass(this,\'editAreaButtonOver\');" onmouseout="editArea.restoreClass(this);" onmousedown="editArea.restoreAndSwitchClass(this,\'editAreaButtonDown\');" /></a>';
+ return html;
+ },
+
+ get_control_html : function(button_name, lang) {
+ var t=this,i,but,html,si;
+ for (i=0; i<t.advanced_buttons.length; i++)
+ {
+ but = t.advanced_buttons[i];
+ if (but[0] == button_name)
+ {
+ return t.get_button_html(but[0], but[1], but[2], but[3]);
+ }
+ }
+
+ switch (button_name){
+ case "*":
+ case "return":
+ return "<br />";
+ case "|":
+ case "separator":
+ return '<img src="'+ t.baseURL +'images/spacer.gif" width="1" height="15" class="editAreaSeparatorLine">';
+ case "select_font":
+ html= "<select id='area_font_size' onchange='javascript:editArea.execCommand(\"change_font_size\")' fileSpecific='yes'>";
+ html+="<option value='-1'>{$font_size}</option>";
+ si=[8,9,10,11,12,14];
+ for( i=0;i<si.length;i++){
+ html+="<option value='"+si[i]+"'>"+si[i]+" pt</option>";
+ }
+ html+="</select>";
+ return html;
+ case "syntax_selection":
+ html= "<select id='syntax_selection' onchange='javascript:editArea.execCommand(\"change_syntax\", this.value)' fileSpecific='yes'>";
+ html+="<option value='-1'>{$syntax_selection}</option>";
+ html+="</select>";
+ return html;
+ }
+
+ return "<span id='tmp_tool_"+button_name+"'>["+button_name+"]</span>";
+ },
+
+
+ get_template : function(){
+ if(this.template=="")
+ {
+ var xhr_object = null;
+ if(window.XMLHttpRequest) // Firefox
+ xhr_object = new XMLHttpRequest();
+ else if(window.ActiveXObject) // Internet Explorer
+ xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
+ else { // XMLHttpRequest not supported
+ alert("XMLHTTPRequest not supported. EditArea not loaded");
+ return;
+ }
+
+ xhr_object.open("GET", this.baseURL+"template.html", false);
+ xhr_object.send(null);
+ if(xhr_object.readyState == 4)
+ this.template=xhr_object.responseText;
+ else
+ this.has_error();
+ }
+ },
+
+ // translate text
+ translate : function(text, lang, mode){
+ if(mode=="word")
+ text=editAreaLoader.get_word_translation(text, lang);
+ else if(mode="template"){
+ editAreaLoader.current_language= lang;
+ text=text.replace(/\{\$([^\}]+)\}/gm, editAreaLoader.translate_template);
+ }
+ return text;
+ },
+
+ translate_template : function(){
+ return editAreaLoader.get_word_translation(EditAreaLoader.prototype.translate_template.arguments[1], editAreaLoader.current_language);
+ },
+
+ get_word_translation : function(val, lang){
+ var i;
+
+ for( i in editAreaLoader.lang[lang]){
+ if(i == val)
+ return editAreaLoader.lang[lang][i];
+ }
+ return "_"+val;
+ },
+
+ load_script : function(url){
+ var t=this,d=document,script,head;
+
+ if( t.loadedFiles[url] )
+ return;
+ //alert("load: "+url);
+ try{
+ script= d.createElement("script");
+ script.type= "text/javascript";
+ script.src= url;
+ script.charset= "UTF-8";
+ d.getElementsByTagName("head")[0].appendChild(script);
+ }catch(e){
+ d.write('<sc'+'ript language="javascript" type="text/javascript" src="' + url + '" charset="UTF-8"></sc'+'ript>');
+ }
+
+ t.loadedFiles[url] = true;
+ },
+
+ add_event : function(obj, name, handler) {
+ try{
+ if (obj.attachEvent) {
+ obj.attachEvent("on" + name, handler);
+ } else{
+ obj.addEventListener(name, handler, false);
+ }
+ }catch(e){}
+ },
+
+ remove_event : function(obj, name, handler){
+ try{
+ if (obj.detachEvent)
+ obj.detachEvent("on" + name, handler);
+ else
+ obj.removeEventListener(name, handler, false);
+ }catch(e){}
+ },
+
+
+ // reset all the editareas in the form that have been reseted
+ reset : function(e){
+ var formObj,is_child,i,x;
+
+ formObj = editAreaLoader.isIE ? window.event.srcElement : e.target;
+ if(formObj.tagName!='FORM')
+ formObj= formObj.form;
+
+ for( i in editAreas ){
+ is_child= false;
+ for( x=0;x<formObj.elements.length;x++ ) {
+ if(formObj.elements[x].id == i)
+ is_child=true;
+ }
+
+ if(window.frames["frame_"+i] && is_child && editAreas[i]["displayed"]==true){
+
+ var exec= 'window.frames["frame_'+ i +'"].editArea.textarea.value= document.getElementById("'+ i +'").value;';
+ exec+= 'window.frames["frame_'+ i +'"].editArea.execCommand("focus");';
+ exec+= 'window.frames["frame_'+ i +'"].editArea.check_line_selection();';
+ exec+= 'window.frames["frame_'+ i +'"].editArea.execCommand("reset");';
+ window.setTimeout(exec, 10);
+ }
+ }
+ return;
+ },
+
+
+ // prepare all the textarea replaced by an editarea to be submited
+ submit : function(e){
+ var formObj,is_child,fs=window.frames,i,x;
+ formObj = editAreaLoader.isIE ? window.event.srcElement : e.target;
+ if(formObj.tagName!='FORM')
+ formObj= formObj.form;
+
+ for( i in editAreas){
+ is_child= false;
+ for( x=0;x<formObj.elements.length;x++ ) {
+ if(formObj.elements[x].id == i)
+ is_child=true;
+ }
+
+ if(is_child)
+ {
+ if(fs["frame_"+i] && editAreas[i]["displayed"]==true)
+ document.getElementById(i).value= fs["frame_"+ i].editArea.textarea.value;
+ editAreaLoader.execCommand(i,"EA_submit");
+ }
+ }
+ if( typeof(formObj.edit_area_replaced_submit) == "function" ){
+ res= formObj.edit_area_replaced_submit();
+ if(res==false){
+ if(editAreaLoader.isIE)
+ return false;
+ else
+ e.preventDefault();
+ }
+ }
+ return;
+ },
+
+ // allow to get the value of the editarea
+ getValue : function(id){
+ if(window.frames["frame_"+id] && editAreas[id]["displayed"]==true){
+ return window.frames["frame_"+ id].editArea.textarea.value;
+ }else if(elem=document.getElementById(id)){
+ return elem.value;
+ }
+ return false;
+ },
+
+ // allow to set the value of the editarea
+ setValue : function(id, new_val){
+ var fs=window.frames;
+
+ if( ( f=fs["frame_"+id] ) && editAreas[id]["displayed"]==true){
+ f.editArea.textarea.value= new_val;
+ f.editArea.execCommand("focus");
+ f.editArea.check_line_selection(false);
+ f.editArea.execCommand("onchange");
+ }else if(elem=document.getElementById(id)){
+ elem.value= new_val;
+ }
+ },
+
+ // allow to get infos on the selection: array(start, end)
+ getSelectionRange : function(id){
+ var sel,eA,fs=window.frames;
+
+ sel= {"start": 0, "end": 0};
+ if(fs["frame_"+id] && editAreas[id]["displayed"]==true){
+ eA= fs["frame_"+ id].editArea;
+
+ sel["start"] = eA.textarea.selectionStart;
+ sel["end"] = eA.textarea.selectionEnd;
+
+ }else if( elem=document.getElementById(id) ){
+ sel= getSelectionRange(elem);
+ }
+ return sel;
+ },
+
+ // allow to set the selection with the given start and end positions
+ setSelectionRange : function(id, new_start, new_end){
+ var fs=window.frames;
+
+ if(fs["frame_"+id] && editAreas[id]["displayed"]==true){
+ fs["frame_"+ id].editArea.area_select(new_start, new_end-new_start);
+ // make an auto-scroll to the selection
+ if(!this.isIE){
+ fs["frame_"+ id].editArea.check_line_selection(false);
+ fs["frame_"+ id].editArea.scroll_to_view();
+ }
+ }else if(elem=document.getElementById(id)){
+ setSelectionRange(elem, new_start, new_end);
+ }
+ },
+
+ getSelectedText : function(id){
+ var sel= this.getSelectionRange(id);
+
+ return this.getValue(id).substring(sel["start"], sel["end"]);
+ },
+
+ setSelectedText : function(id, new_val){
+ var fs=window.frames,d=document,sel,text,scrollTop,scrollLeft,new_sel_end;
+
+ new_val = new_val.replace(/\r/g, "");
+ sel = this.getSelectionRange(id);
+ text = this.getValue(id);
+ if(fs["frame_"+id] && editAreas[id]["displayed"]==true){
+ scrollTop = fs["frame_"+ id].document.getElementById("result").scrollTop;
+ scrollLeft = fs["frame_"+ id].document.getElementById("result").scrollLeft;
+ }else{
+ scrollTop = d.getElementById(id).scrollTop;
+ scrollLeft = d.getElementById(id).scrollLeft;
+ }
+
+ text = text.substring(0, sel["start"])+ new_val +text.substring(sel["end"]);
+ this.setValue(id, text);
+ new_sel_end = sel["start"]+ new_val.length;
+ this.setSelectionRange(id, sel["start"], new_sel_end);
+
+
+ // fix \r problem for selection length count on IE & Opera
+ if(new_val != this.getSelectedText(id).replace(/\r/g, "")){
+ this.setSelectionRange(id, sel["start"], new_sel_end+ new_val.split("\n").length -1);
+ }
+ // restore scrolling position
+ if(fs["frame_"+id] && editAreas[id]["displayed"]==true){
+ fs["frame_"+ id].document.getElementById("result").scrollTop= scrollTop;
+ fs["frame_"+ id].document.getElementById("result").scrollLeft= scrollLeft;
+ fs["frame_"+ id].editArea.execCommand("onchange");
+ }else{
+ d.getElementById(id).scrollTop= scrollTop;
+ d.getElementById(id).scrollLeft= scrollLeft;
+ }
+ },
+
+ insertTags : function(id, open_tag, close_tag){
+ var old_sel,new_sel;
+
+ old_sel = this.getSelectionRange(id);
+ text = open_tag + this.getSelectedText(id) + close_tag;
+
+ editAreaLoader.setSelectedText(id, text);
+
+ new_sel = this.getSelectionRange(id);
+ if(old_sel["end"] > old_sel["start"]) // if text was selected, cursor at the end
+ this.setSelectionRange(id, new_sel["end"], new_sel["end"]);
+ else // cursor in the middle
+ this.setSelectionRange(id, old_sel["start"]+open_tag.length, old_sel["start"]+open_tag.length);
+ },
+
+ // hide both EditArea and normal textarea
+ hide : function(id){
+ var fs= window.frames,d=document,t=this,scrollTop,scrollLeft,span;
+ if(d.getElementById(id) && !t.hidden[id])
+ {
+ t.hidden[id]= {};
+ t.hidden[id]["selectionRange"]= t.getSelectionRange(id);
+ if(d.getElementById(id).style.display!="none")
+ {
+ t.hidden[id]["scrollTop"]= d.getElementById(id).scrollTop;
+ t.hidden[id]["scrollLeft"]= d.getElementById(id).scrollLeft;
+ }
+
+ if(fs["frame_"+id])
+ {
+ t.hidden[id]["toggle"]= editAreas[id]["displayed"];
+
+ if(fs["frame_"+id] && editAreas[id]["displayed"]==true){
+ scrollTop = fs["frame_"+ id].document.getElementById("result").scrollTop;
+ scrollLeft = fs["frame_"+ id].document.getElementById("result").scrollLeft;
+ }else{
+ scrollTop = d.getElementById(id).scrollTop;
+ scrollLeft = d.getElementById(id).scrollLeft;
+ }
+ t.hidden[id]["scrollTop"]= scrollTop;
+ t.hidden[id]["scrollLeft"]= scrollLeft;
+
+ if(editAreas[id]["displayed"]==true)
+ editAreaLoader.toggle_off(id);
+ }
+
+ // hide toggle button and debug box
+ span= d.getElementById("EditAreaArroundInfos_"+id);
+ if(span){
+ span.style.display='none';
+ }
+
+ // hide textarea
+ d.getElementById(id).style.display= "none";
+ }
+ },
+
+ // restore hidden EditArea and normal textarea
+ show : function(id){
+ var fs= window.frames,d=document,t=this,span;
+ if((elem=d.getElementById(id)) && t.hidden[id])
+ {
+ elem.style.display= "inline";
+ elem.scrollTop= t.hidden[id]["scrollTop"];
+ elem.scrollLeft= t.hidden[id]["scrollLeft"];
+ span= d.getElementById("EditAreaArroundInfos_"+id);
+ if(span){
+ span.style.display='inline';
+ }
+
+ if(fs["frame_"+id])
+ {
+
+ // restore toggle button and debug box
+
+
+ // restore textarea
+ elem.style.display= "inline";
+
+ // restore EditArea
+ if(t.hidden[id]["toggle"]==true)
+ editAreaLoader.toggle_on(id);
+
+ scrollTop = t.hidden[id]["scrollTop"];
+ scrollLeft = t.hidden[id]["scrollLeft"];
+
+ if(fs["frame_"+id] && editAreas[id]["displayed"]==true){
+ fs["frame_"+ id].document.getElementById("result").scrollTop = scrollTop;
+ fs["frame_"+ id].document.getElementById("result").scrollLeft = scrollLeft;
+ }else{
+ elem.scrollTop = scrollTop;
+ elem.scrollLeft = scrollLeft;
+ }
+
+ }
+ // restore selection
+ sel = t.hidden[id]["selectionRange"];
+ t.setSelectionRange(id, sel["start"], sel["end"]);
+ delete t.hidden[id];
+ }
+ },
+
+ // get the current file datas (for multi file editing mode)
+ getCurrentFile : function(id){
+ return this.execCommand(id, 'get_file', this.execCommand(id, 'curr_file'));
+ },
+
+ // get the given file datas (for multi file editing mode)
+ getFile : function(id, file_id){
+ return this.execCommand(id, 'get_file', file_id);
+ },
+
+ // get all the openned files datas (for multi file editing mode)
+ getAllFiles : function(id){
+ return this.execCommand(id, 'get_all_files()');
+ },
+
+ // open a file (for multi file editing mode)
+ openFile : function(id, file_infos){
+ return this.execCommand(id, 'open_file', file_infos);
+ },
+
+ // close the given file (for multi file editing mode)
+ closeFile : function(id, file_id){
+ return this.execCommand(id, 'close_file', file_id);
+ },
+
+ // close the given file (for multi file editing mode)
+ setFileEditedMode : function(id, file_id, to){
+ var reg1,reg2;
+ reg1 = new RegExp('\\\\', 'g');
+ reg2 = new RegExp('"', 'g');
+ return this.execCommand(id, 'set_file_edited_mode("'+ file_id.replace(reg1, '\\\\').replace(reg2, '\\"') +'", '+ to +')');
+ },
+
+
+ // allow to access to editarea functions and datas (for advanced users only)
+ execCommand : function(id, cmd, fct_param){
+ switch(cmd){
+ case "EA_init":
+ if(editAreas[id]['settings']["EA_init_callback"].length>0)
+ eval(editAreas[id]['settings']["EA_init_callback"]+"('"+ id +"');");
+ break;
+ case "EA_delete":
+ if(editAreas[id]['settings']["EA_delete_callback"].length>0)
+ eval(editAreas[id]['settings']["EA_delete_callback"]+"('"+ id +"');");
+ break;
+ case "EA_submit":
+ if(editAreas[id]['settings']["submit_callback"].length>0)
+ eval(editAreas[id]['settings']["submit_callback"]+"('"+ id +"');");
+ break;
+ }
+ if(window.frames["frame_"+id] && window.frames["frame_"+ id].editArea){
+ if(fct_param!=undefined)
+ return eval('window.frames["frame_'+ id +'"].editArea.'+ cmd +'(fct_param);');
+ else
+ return eval('window.frames["frame_'+ id +'"].editArea.'+ cmd +';');
+ }
+ return false;
+ }
+};
+
+ var editAreaLoader= new EditAreaLoader();
+ var editAreas= {};
+