Avatar billede nythjem Nybegynder
22. september 2004 - 16:48 Der er 8 kommentarer og
1 løsning

Find 1 fejl..

Hej Alle!

Jeg har en fin editor, hvori jeg har en knap, der cleaner nogle bestemte sætninger.

Men jeg får fejl, når jeg trykker på den.. Nogle der kan finde fejlen?

Fejlen er, der opstod en ukendt kørselsfejl.

---O---

// cleancode
  else if (cmdID == 'cleancode') { 
  var oTags = editdoc.all.tags("SPAN");     
  if (oTags != null) {         
  for (var i = oTags.length - 1; i >= 0; i--) {             
  oTags[i].outerHTML = oTags[i].innerHTML;         
  }     
}       

oTags = editdoc.all.tags("FONT");     
if (oTags != null) {     
for (var i = oTags.length - 1; i >= 0; i--) {     
oTags[i].outerHTML = oTags[i].innerHTML;     
}     
}

  oTags = editdoc.all.tags("P");     
  if (oTags != null) {         
  for (var i = oTags.length - 1; i >= 0; i--) {             
  cleanEmptyTag(oTags[i]);         
  }     

  oTags = editdoc.all.tags("H1");     
  if (oTags != null) {         
  for (var i = oTags.length - 1; i >= 0; i--) {             
  cleanEmptyTag(oTags[i]);        


  oTags = editdoc.all.tags("H2");     
  if (oTags != null) {         
  for (var i = oTags.length - 1; i >= 0; i--) {             
  cleanEmptyTag(oTags[i]);        

}
  oTags = editdoc.all.tags("H3");     
  if (oTags != null) {         
  for (var i = oTags.length - 1; i >= 0; i--) {             
  cleanEmptyTag(oTags[i]);        

}
  oTags = editdoc.all.tags("H4");     
  if (oTags != null) {         
  for (var i = oTags.length - 1; i >= 0; i--) {             
  cleanEmptyTag(oTags[i]);        

}   
  oTags = editdoc.all.tags("OL");     
  if (oTags != null) {         
  for (var i = oTags.length - 1; i >= 0; i--) {             
  cleanEmptyTag(oTags[i]);        

}       
  oTags = editdoc.all.tags("UL");     
  if (oTags != null) {         
  for (var i = oTags.length - 1; i >= 0; i--) {             
  cleanEmptyTag(oTags[i]);          }     

}
Avatar billede roenving Novice
22. september 2004 - 16:53 #1
Du må da have noget foran, for du kan da ikke starte med en else ?-)

-- og hvis ikke du har en if tidligere kan netop det at starte med en else godt være fejlen !-)
Avatar billede nythjem Nybegynder
22. september 2004 - 17:03 #2
Hej Jes!

Jep, det er en del af filen, så her får du den lige.. :)

Har dog lige fundet ud af, at der også er en cleaner i bunden af denne side..

// write out styles for UI buttons
document.write('<style type="text/css">\n');
document.write('.btn    { width: 25px; height: 24px; border: 1px solid buttonface; margin: 0; padding: 0 }\n');
document.write('.btnOver { width: 25px; height: 24px; border: 1px outset; }\n');
document.write('.btnDown { width: 25px; height: 24px; border: 1px inset; background-color: buttonface; }\n');
document.write('.btnNA  { width: 25px; height: 24px; border: 1px solid buttonface; filter: alpha(opacity=25); }\n');
document.write('.cMenu    { background-color: buttonface; color: buttonface; cursor: Default; font-family: MS Sans Serif; font-size: 8pt; padding: 2 12 2 16; }');
document.write('.cMenuOver { background-color: buttonface; color: buttonface; cursor: Default; font-family: MS Sans Serif; font-size: 8pt; padding: 2 12 2 16; }');
document.write('.cMenuDivOuter { background-color: buttonface; height: 9 }');
document.write('.cMenuDivInner { margin: 0 4 0 4; border-width: 1; border-style: solid; border-color: buttonface; }');
document.write('</style>\n');


/* ---------------------------------------------------------------------- *\
  Function    : editor_defaultConfig
  Description : default configuration settings for wysiwyg editor
\* ---------------------------------------------------------------------- */
function editor_defaultConfig(objname) {

this.version = "2.03.1"

this.width =  "auto";
this.height = "auto";
this.bodyStyle = 'background-color: #FFFFFF; font-family: "Verdana"; font-size: x-small;';
this.imgURL = _editor_url + 'images/';
this.debug  = 0;

this.replaceNextlines = 0; // replace nextlines from spaces (on output)
this.plaintextInput = 0;  // replace nextlines with breaks (on input)

this.toolbar = [
        ['fontname','fontsize','copy','paste','separator','undo','redo','separator','bold','italic','underline','separator','cleancode','separator','strikethrough','subscript','superscript'],
    ['justifyleft','justifycenter','justifyright','separator','OrderedList','UnOrderedList','Outdent','Indent','separator','forecolor','backcolor','separator','HorizontalRule','specchar','Insertlink','InsertImage','InsertTable','showborder','separator','htmlmode','separator','template','popupeditor'],
    ];


this.fontnames = {
    "Arial":          "arial, helvetica, sans-serif",
    //"Aharoni":          "Aharoni",
    "Courier New":    "courier new, courier, mono",
    "Georgia":        "Georgia, Times New Roman, Times, Serif",
    "Tahoma":          "Tahoma, Arial, Helvetica, sans-serif",
    "Times New Roman": "times new roman, times, serif",
    "Verdana":        "Verdana, Arial, Helvetica, sans-serif",
    //"David":          "David",
    "Impact":          "impact",
    "WingDings":      "WingDings"};

this.fontsizes = {
    "1 (8 pt)":  "1",
    "2 (10 pt)": "2",
    "3 (12 pt)": "3",
    "4 (14 pt)": "4",
    "5 (18 pt)": "5",
    "6 (24 pt)": "6",
    "7 (36 pt)": "7"
  };

//this.stylesheet = "http://www.webstationone.com/wsone.css"; // full URL to stylesheet


this.btnList = {
//buttonName:        commandID,              title,                              onclick,                  image,           
//Række 1

//Persistent Buttons
"htmlmode":              ['HtmlMode',            'Se html kode',                  'editor_setmode(\''+objname+'\')', 'ed_html.gif'],
"popupeditor":           ['popupeditor',          'Forstør editor',                    'editor_action(this.id)',  'fullscreen_maximize.gif'],
"about":              ['about',                'Ikon forklaring',                      'editor_about(\''+objname+'\')',  'ed_about.gif'],
"help":                  ['showhelp',            'Hjælp',                      'editor_action(this.id)',  'ed_help.gif'],
"refresh":            ['Refresh',              'Opdater',                                'editor_action(this.id)',  'ed_refresh.gif'],
"selectall":           ['selectall',            'Vælg alle',                         'editor_action(this.id)',  'ed_selectall.gif'],
"cut":                ['Cut',                  'Klip',                            'editor_action(this.id)',  'ed_cut.gif'],
"copy":              ['Copy',                'Kopier',                              'editor_action(this.id)',  'ed_copy.gif'],
"paste":              ['Paste',                'Indsæt',                              'editor_action(this.id)',  'ed_paste.gif'],
"delete":              ['delete',              'Slet valg',                  'editor_action(this.id)',  'ed_delete.gif'],
"remove":            ['RemoveFormat',        'Fjern format i det valgte tekst',         'editor_action(this.id)',  'ed_remove.gif'],
"undo":              ['Undo',                'Tilbage',                  'editor_action(this.id)',  'ed_undo.gif'],
"redo":              ['Redo',                'Frem',                              'editor_action(this.id)',  'ed_redo.gif'],
"find":                ['Find',                'Find',                              'editor_action(this.id)',  'ed_find.gif'],
"template":              ['Template',            'Vælg en opsætnings skabelon',                'editor_action(this.id)',  'ed_template.gif'],
"bold":              ['Bold',                'Fed skrift',                              'editor_action(this.id)',  'ed_format_bold.gif'],
"italic":            ['Italic',              'Kursiv skrift',                            'editor_action(this.id)',  'ed_format_italic.gif'],
"underline":          ['Underline',            'Understreget skrift',                          'editor_action(this.id)',  'ed_format_underline.gif'],
"strikethrough":      ['StrikeThrough',        'Gennemstregning',                    'editor_action(this.id)',  'ed_format_strike.gif'],
"subscript":          ['SubScript',            'Sænket skrift',                          'editor_action(this.id)',  'ed_format_sub.gif'],
"superscript":        ['SuperScript',          'Hævet skrift',                        'editor_action(this.id)',  'ed_format_sup.gif'],
"justifyleft":        ['JustifyLeft',          'Venstre justering',                      'editor_action(this.id)',  'ed_align_left.gif'],
"justifycenter":      ['JustifyCenter',        'Centreret justering',                    'editor_action(this.id)',  'ed_align_center.gif'],
"justifyright":      ['JustifyRight',        'Højre justering',                      'editor_action(this.id)',  'ed_align_right.gif'],
"justifyfull":        ['JustifyFull',           'Fuld justering',                     'editor_action(this.id)',  'ed_align_justify.gif'],
"justifynone":        ['JustifyNone',           'Fjern Justering',                 'editor_action(this.id)',  'ed_align_none.gif'],

"orderedlist":        ['InsertOrderedList',    'Tal opstilling',                      'editor_action(this.id)',  'ed_list_num.gif'],
"unorderedlist":      ['InsertUnorderedList',  'Punkt opstilling',                      'editor_action(this.id)',  'ed_list_bullet.gif'],
"outdent":            ['Outdent',              'Formindsk indrykning',                    'editor_action(this.id)',  'ed_indent_less.gif'],
"indent":            ['Indent',              'Forøg indrykning',                    'editor_action(this.id)',  'ed_indent_more.gif'],
"forecolor":          ['ForeColor',            'Skrifttype farve',                        'editor_action(this.id)',  'ed_color_fg.gif'],
"backcolor":          ['BackColor',            'Baggrunds farve',                  'editor_action(this.id)',  'ed_color_bg.gif'],

"cleancode":          ['cleancode',            'Fjern Word indhold" ',              'editor_action(this.id)',  'ed_word.gif'],
"upload":          ['upload',          'Upload Fil',                    'editor_action(this.id)',  'ed_upload.gif'],

"paragraph":            ['InsertParagraph',      'Linieskift',                      'editor_action(this.id)',  'ed_paragraph.gif'],
"marquee":            ['marquee',              'Marquee',                            'editor_action(this.id)',  'ed_marquee.gif'],
"horizontalrule":    ['InsertHorizontalRule', 'Indsæt streg',                      'editor_action(this.id)',  'ed_hr.gif'],
"specchar":          ['SpecChar',            'Indsæt special tegn',             'editor_action(this.id)',  'ed_spec_char.gif'],

"insertlink":        ['insertlink',          'Indsæt link',                        'editor_action(this.id)',  'ed_link.gif'],
"unlink":              ['unlink',              'Fjern link',                        'editor_action(this.id)',  'ed_unlink.gif'],
"anchor":              ['anchor',              'Forfatter',                            'editor_action(this.id)',  'ed_anchor.gif'],
"insertimage":        ['InsertImage',          'Indsæt billede',                      'editor_action(this.id)',  'ed_image.gif'],
//  "createlink":    ['createlink',          'Link i billede',                'editor_action(this.id)',  'ed_linkimage.gif'],
"inserttable":        ['InsertTable',          'Indsæt tabel',                      'editor_action(this.id)',  'insert_table.gif'],
"tableproperties":    ['TableProperties',      'Tabel egenskaber',                  'editor_action(this.id)',  'ed_tableprop.gif'],
"showborder":          ['ShowBorder',          'Vis 0 kanter',                    'editor_action(this.id)',  'ed_show_border.gif'],
"rowproperties":      ['RowProperties',        'Række egenskaber',                    'editor_action(this.id)',  'ed_rowprop.gif'],
"insertrowbefore":    ['InsertRowBefore',      'Indsætte række før',                 'editor_action(this.id)',  'ed_insabove.gif'],
"insertrowafter":    ['InsertRowAfter',      'Indsætte række efter',                  'editor_action(this.id)',  'ed_insunder.gif'],
"deleterow":          ['DeleteRow',            'Slet række',                        'editor_action(this.id)',  'ed_delrow.gif'],
"splitrow":          ['SplitRow',            'Split række',                        'editor_action(this.id)',  'ed_splitrow.gif'],
"mergerows":          ['MergeRows',            'Sammensmelt række',                        'editor_action(this.id)',  'ed_mergerows.gif'],
"insertcolumnbefore": ['InsertColumnBefore',  'Indsæt kolonne før',              'editor_action(this.id)',  'ed_insleft.gif'],
"insertcolumnafter":  ['InsertColumnAfter',    'Indsæt kolonne efter',                'editor_action(this.id)',  'ed_insright.gif'],
"deletecolumn":      ['DeleteColumn',        'Slet kolonne',                  'editor_action(this.id)',  'ed_delcol.gif'], 
"cellproperties":    ['CellProperties',      'Celle egenskaber',                  'editor_action(this.id)',  'ed_cellprop.gif'],
"insertcellbefore":  ['InsertCellBefore',    'Indsæt celle før',                'editor_action(this.id)',  'ed_inscellft.gif'],
"insertcellafter":    ['InsertCellAfter',      'Indsæt celle efter',                 'editor_action(this.id)',  'ed_inscelrgt.gif'],
"deletecell":        ['DeleteCell',          'Slet celle',                      'editor_action(this.id)',  'ed_delcel.gif'],
"splitcell":          ['SplitCell',            'Split celle',                        'editor_action(this.id)',  'ed_splitcel.gif'],
"mergecells":        ['MergeCells',          'Sammensmelt celle',                      'editor_action(this.id)',  'ed_mergecels.gif'],
//Forms   
"inputform"      :  ['InputForm',            'Form',                              'editor_action(this.id)',  'ed_form.gif'],
"inputformelement":  ['InputFormElement',    'Form elementer',                        'editor_action(this.id)',  'ed_form_element.gif'],
"smiley":            ['smiley',              'Indsæt smiley',                  'editor_action(this.id)',  'ed_smiley.gif'],
"changecase":        ['changecase',          'Change Upper/Lower',                  'editor_action(this.id)',  'ed_changecase.gif']
// end: custom buttons

    };

// insert by lvn : check editor changes
this.checkChanges = 0;
}
/* ---------------------------------------------------------------------- *\
  Function    : editor_generate
  Description : replace textarea with wysiwyg editor
  Usage      : editor_generate("textarea_id",[height],[width]);
  Arguments  : objname - ID of textarea to replace
                w      - width of wysiwyg editor
                h      - height of wysiwyg editor
\* ---------------------------------------------------------------------- */
        function editor_generate(objname,userConfig) {
// Default Settings
          var config = new editor_defaultConfig(objname);
          if (userConfig) {
          for (var thisName in userConfig) {
          if (userConfig[thisName]) { config[thisName] = userConfig[thisName]; }
        }
          }
  document.all[objname].config = config; // store config settings

  // set size to specified size or size of original object
  var obj    = document.all[objname];
  if (!config.width || config.width == "auto") {
    if      (obj.style.width) { config.width = obj.style.width; }      // use css style
    else if (obj.cols)        { config.width = (obj.cols * 8) + 22; }  // col width + toolbar
    else                      { config.width = '100%'; }              // default
  }
  if (!config.height || config.height == "auto") {
    if      (obj.style.height) { config.height = obj.style.height; }  // use css style
    else if (obj.rows)        { config.height = obj.rows * 17 }      // row height
    else                      { config.height = '200'; }              // default
  }

  var tblOpen  = '<table border=0 cellspacing=0 cellpadding=0 style="float: left;"  unselectable="on"><tr><td style="border: none; padding: 1 0 0 0; font-family: MS Shell Dlg;"><nobr>';
  var tblClose = '</nobr></td></tr></table>\n';

  // build button toolbar

  var toolbar = '';
  var btnGroup, btnItem, aboutEditor;
  for (var btnGroup in config.toolbar) {

    // linebreak
    if (config.toolbar[btnGroup].length == 1 &&
        config.toolbar[btnGroup][0].toLowerCase() == "linebreak") {
      toolbar += '<br clear="all">';
      continue;
    }

    toolbar += tblOpen;
    for (var btnItem in config.toolbar[btnGroup]) {
      var btnName = config.toolbar[btnGroup][btnItem].toLowerCase();

// inserted by lvn
      // formatblock
      if (btnName == "formatblock") {
        toolbar += '  Format <select id="_' +objname+ '_FormatBlock" onchange="editor_action(this.id)" unselectable="on" style="margin: 1 2 0 2; font-size: 12px;">';
        for (var i in config.formatblocks) {
          var fbObj = config.formatblocks;
          var fbvalue = "";
          var fbname  = "";
          for (var j in fbObj.formatblocklangs) {
              var fblangObj = fbObj.formatblocklangs[j];
              if (fblangObj.lang == config.systemLang[0]) {fbvalue = fblangObj.name;}
              if (fblangObj.lang == config.browserLang[0]) {fbname = fblangObj.name;}
          }
                      toolbar += '<option value="' +fbvalue+ '">' + fbname + '</option>';
        }
        toolbar += '</select>';
        continue;
      }
// end insert by lvn
      // fontname
      if (btnName == "fontname") {
        toolbar += '<select id="_' +objname+ '_FontName" onchange="editor_action(this.id)" unselectable="on" style="margin: 1 2 0 0; font-size: 10px;">';
        for (var fontname in config.fontnames) {
          toolbar += '<option value="' +config.fontnames[fontname]+ '">' +fontname+ '</option>'
        }
        toolbar += '</select>';
        continue;
      }

      // fontsize
      if (btnName == "fontsize") {
        toolbar += '<select id="_' +objname+ '_FontSize" onchange="editor_action(this.id)" unselectable="on" style="margin: 1 2 0 0; font-size: 10px;    scrollbar-face-color : Fuchsia;">';
        for (var fontsize in config.fontsizes) {
          toolbar += '<option value="' +config.fontsizes[fontsize]+ '">' +fontsize+ '</option>'
        }
        toolbar += '</select>\n';
        continue;
      }

      // font style
      if (btnName == "fontstyle") {
        toolbar += '  Font Style <select id="_' +objname+ '_FontStyle" onchange="editor_action(this.id)" unselectable="on" style="margin: 1 2 0 0; font-size: 12px;">';
        + '<option value="">Font Style</option>';
        for (var i in config.fontstyles) {
          var fontstyle = config.fontstyles[i];
          toolbar += '<option value="' +fontstyle.className+ '">' +fontstyle.name+ '</option>'
        }
        toolbar += '</select>';
        continue;
      }
      // separator
      if (btnName == "separator") {
        toolbar += '<span style="border: 1px inset; width: 1px; font-size: 16px; height: 16px; margin: 0 3 0 3"></span>';
        continue;
      }

      // buttons
      var btnObj = config.btnList[btnName];
      if (btnName == 'linebreak') { alert("htmlArea error: 'linebreak' must be in a subgroup by itself, not with other buttons.\n\nhtmlArea wysiwyg editor not created."); return; }
      if (!btnObj) { alert("htmlArea error: button '" +btnName+ "' not found in button list when creating the wysiwyg editor for '"+objname+"'.\nPlease make sure you entered the button name correctly.\n\nhtmlArea wysiwyg editor not created."); return; }
      var btnCmdID  = btnObj[0];
      var btnTitle  = btnObj[1];
      var btnOnClick = btnObj[2];
      var btnImage  = btnObj[3];
      toolbar += '<button title="' +btnTitle+ '" id="_' +objname+ '_' +btnCmdID+ '" class="btn" onClick="' +btnOnClick+ '" onmouseover="if(this.className==\'btn\'){this.className=\'btnOver\'}" onmouseout="if(this.className==\'btnOver\'){this.className=\'btn\'}" unselectable="on"><img src="' +config.imgURL + btnImage+ '" border=0 unselectable="on"></button>';


    } // end of button sub-group
    toolbar += tblClose;
  } // end of entire button set

  // build editor

  var editor = '<span id="_editor_toolbar"><table border=1 cellspacing=0 cellpadding=0 bgcolor="buttonface" style="padding: 1 0 0 2" width=' + config.width + ' unselectable="on"><tr><td>\n'
  + toolbar
  + '</td></tr></table>\n'
  + '</td></tr></table></span>\n'
  + '<textarea ID="_' +objname + '_editor" style="width:' +config.width+ '; height:' +config.height+ '; margin-top: -1px; margin-bottom: -1px;" wrap=soft></textarea>';

  // add context menu
  editor += '<div id="_' +objname + '_cMenu" style="position: absolute; visibility: hidden;"></textarea>';

  //  hide original textarea and insert htmlarea after it
  if (!config.debug) { document.all[objname].style.display = "none"; }

  if (config.plaintextInput) {    // replace nextlines with breaks
    var contents = document.all[objname].value;
    contents = contents.replace(/\r\n/g, '<br>');
    contents = contents.replace(/\n/g, '<br>');
    contents = contents.replace(/\r/g, '<br>');
    document.all[objname].value = contents;
  }

  // insert wysiwyg
  document.all[objname].insertAdjacentHTML('afterEnd', editor)

  // convert htmlarea from textarea to wysiwyg editor
  editor_setmode(objname, 'init');

  // call filterOutput when user submits form
  for (var idx=0; idx < document.forms.length; idx++) {
    var r = document.forms[idx].attachEvent('onsubmit', function() { editor_filterOutput(objname); });
    if (!r) { alert("Error attaching event to form!"); }
  }
return true;
}
/* ---------------------------------------------------------------------- *\
  Function    : editor_action
  Description : perform an editor command on selected editor content
  Usage      :
  Arguments  : button_id - button id string with editor and action name
\* ---------------------------------------------------------------------- */

function editor_action(button_id) {
  // split up button name into "editorID" and "cmdID"
  var BtnParts = Array();
  BtnParts = button_id.split("_");
  var objname    = button_id.replace(/^_(.*)_[^_]*$/, '$1');
  var cmdID      = BtnParts[ BtnParts.length-1 ];
  var button_obj = document.all[button_id];
  var editor_obj = document.all["_" +objname + "_editor"];
  var config    = document.all[objname].config;

  // help popup
  if (cmdID == 'showhelp') {
    window.open(_editor_url + "popups/editor_help.html", 'EditorHelp',
    'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes');
    return;
  }

  // popup editor
  if (cmdID == 'popupeditor') {
    window.open(_editor_url + "popups/fullscreen.html?"+objname,
                'FullScreen',
                'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=640,height=480');
    return;
  }

// inserted by lvn
  // show 0 borders
  if (cmdID == 'ShowBorder'){
    var btnObj = document.all["_" +objname+ "_ShowBorder"];
    if (config.showborders){ // toggle is on : put borders off
        nullBorders(editor_obj.contentWindow.document,'hide');
        btnObj.className = 'btn';
        config.showborders = false;
    } else {
        nullBorders(editor_obj.contentWindow.document,'show');
        btnObj.className = 'btnDown';
        config.showborders = true;
    }
    return;
  }
// inserted by lvn (find function)
// Find
// Changed by Eivind Savio to also work in HTML-mode
// If you don't wan't the Find-function to work in HTML-mode, see http://www.interactivetools.com/forum/forum.cgi?post=12934
  if (cmdID == 'Find') {
    setGlobalVar ("_editor_field",objname);
    var findRange = editor_obj.document.body.createTextRange();
    showModelessDialog(_editor_url + "popups/find.html",window, "resizable: no; help: no; status: no; scroll: no; ");
    return;
  }
// end insert by lvn 



// check editor mode (don't perform actions in textedit mode)
  if (editor_obj.tagName.toLowerCase() == 'textarea') { return; }

  var editdoc = editor_obj.contentWindow.document;
 
  // new
  //if (cmdID == 'New'){document.location.reload()
  //document.location = "test.html"
   
  //}


  editor_focus(editor_obj);
// get index and value for pulldowns
  var idx = button_obj.selectedIndex;
  var val = (idx != null) ? button_obj[ idx ].value : null;

  if (0) {}  // use else if for easy cutting and pasting

// CUSTOM BUTTONS START HERE
else if (cmdID == 'smiley') {
    var myTitle = "Insert Smileys";
    var myText = window.showModalDialog(_editor_url + "/demo/wysiwygdemo/smiley_select.asp",
                                myTitle, "resizable: no; help: no; status: no; scroll: no; ");
    if (myText) { editor_insertHTML(objname, myText); }
  }
  // Custom1
  //else if (cmdID == 'custom1') {
    //alert("Hello, I am custom button 1!");
  //}

// cleancode
  else if (cmdID == 'cleancode') { 
  var oTags = editdoc.all.tags("SPAN");     
  if (oTags != null) {         
  for (var i = oTags.length - 1; i >= 0; i--) {             
  oTags[i].outerHTML = oTags[i].innerHTML;         
  }     
}       

oTags = editdoc.all.tags("FONT");     
if (oTags != null) {     
for (var i = oTags.length - 1; i >= 0; i--) {     
oTags[i].outerHTML = oTags[i].innerHTML;     
}     
}

  oTags = editdoc.all.tags("P");     
  if (oTags != null) {         
  for (var i = oTags.length - 1; i >= 0; i--) {             
  cleanEmptyTag(oTags[i]);         
  }     

  oTags = editdoc.all.tags("H1");     
  if (oTags != null) {         
  for (var i = oTags.length - 1; i >= 0; i--) {             
  cleanEmptyTag(oTags[i]);        


  oTags = editdoc.all.tags("H2");     
  if (oTags != null) {         
  for (var i = oTags.length - 1; i >= 0; i--) {             
  cleanEmptyTag(oTags[i]);        

}
  oTags = editdoc.all.tags("H3");     
  if (oTags != null) {         
  for (var i = oTags.length - 1; i >= 0; i--) {             
  cleanEmptyTag(oTags[i]);        

}
  oTags = editdoc.all.tags("H4");     
  if (oTags != null) {         
  for (var i = oTags.length - 1; i >= 0; i--) {             
  cleanEmptyTag(oTags[i]);        

}   
  oTags = editdoc.all.tags("OL");     
  if (oTags != null) {         
  for (var i = oTags.length - 1; i >= 0; i--) {             
  cleanEmptyTag(oTags[i]);        

}       
  oTags = editdoc.all.tags("UL");     
  if (oTags != null) {         
  for (var i = oTags.length - 1; i >= 0; i--) {             
  cleanEmptyTag(oTags[i]);          }     

}

  // Custom3
  //else if (cmdID == 'custom3') {  // insert some text
//  editor_insertHTML(objname, "It's easy to add buttons that insert text!");
// }

  //
  // END OF CUSTOM BUTTONS
  //

// inserted by lvn : table operations
  else if ( cmdID == 'TableProperties' ||
      cmdID == 'RowProperties' ||
      cmdID == 'InsertRowBefore' ||
      cmdID == 'InsertRowAfter' ||
      cmdID == 'DeleteRow' ||
      cmdID == 'InsertColumnBefore' ||
      cmdID == 'InsertColumnAfter' ||
      cmdID == 'DeleteColumn' ||
      cmdID == 'CellProperties' ||
      cmdID == 'InsertCellBefore' ||
      cmdID == 'InsertCellAfter' ||
      cmdID == 'SplitCell' ||
      cmdID == 'MergeRows' ||
      cmdID == 'SplitRow' ||
      cmdID == 'MergeCells' ||
      cmdID == 'DeleteCell' ) {
    // table operations
    var table_src_element = editdoc.selection.createRange().parentElement();
    while (table_src_element != null && table_src_element.tagName != 'TD' && table_src_element.tagName != 'TH'){
        table_src_element = table_src_element.parentElement;
    }
    if (table_src_element == null) {
        alert('Table operations not allowed here');
    } else {
        tables_action(button_id,table_src_element);
    }
  }
// end insert by lvn

  // FontName
  else if (cmdID == 'FontName' && val) {
    editdoc.execCommand(cmdID,0,val);
  }


 
 
// inserted by lvn
  // Formatblock
  else if (cmdID == 'FormatBlock' && val) {
    editdoc.execCommand(cmdID,0,val);
  }

  // special characters
  else if (cmdID == 'SpecChar') {
    var newchar = showModalDialog(_editor_url + "popups/insert_char.html", '', "dialogWidth:425px; dialogHeight: 390px; resizable: no; help: no; status: no; scroll: no;");
    if (newchar == '') {
      return;
    } else {
      editor_insertHTML(objname,newchar);
    }
  }
 

// end insert by lvn
  // FontSize
  else if (cmdID == 'FontSize' && val) {
    editdoc.execCommand(cmdID,0,val);
  }

  // FontStyle (change CSS className)
  else if (cmdID == 'FontStyle' && val) {
    editdoc.execCommand('RemoveFormat');
    editdoc.execCommand('FontName',0,'636c6173734e616d6520706c616365686f6c646572');
    var fontArray = editdoc.all.tags("FONT");
    for (i=0; i<fontArray.length; i++) {
      if (fontArray[i].face == '636c6173734e616d6520706c616365686f6c646572') {
        fontArray[i].face = "";
        fontArray[i].className = val;
        fontArray[i].outerHTML = fontArray[i].outerHTML.replace(/face=['"]+/, "");
        }
    }
    button_obj.selectedIndex =0;
  }

  // fgColor and bgColor
  else if (cmdID == 'ForeColor' || cmdID == 'BackColor') {
    var oldcolor = _dec_to_rgb(editdoc.queryCommandValue(cmdID));
    var newcolor = showModalDialog(_editor_url + "popups/select_color.html", oldcolor, "resizable: no; help: no; status: no; scroll: no;");
    if (newcolor != null) { editdoc.execCommand(cmdID, false, "#"+newcolor); }
  }
 
  // execute command for buttons - if we didn't catch the cmdID by here we'll assume it's a
  // commandID and pass it to execCommand().  See http://msdn.microsoft.com/workshop/author/dhtml/reference/commandids.asp
  else {
    // subscript & superscript, disable one before enabling the other
    if (cmdID.toLowerCase() == 'subscript' && editdoc.queryCommandState('superscript')) { editdoc.execCommand('superscript'); }
    if (cmdID.toLowerCase() == 'superscript' && editdoc.queryCommandState('subscript')) { editdoc.execCommand('subscript'); }
   

// insert link (modified)   
    if (cmdID.toLowerCase() == 'insertlink') {
        var theRange = editdoc.selection.createRange();
       
        var highlightedText = "";
    var linkText = '';
       
        var href_attribute = '';
        var tar_attribute = '';
       
        var elmSelectedImage;
        var htmlSelectionControl = "Control";
        if (editdoc.selection.type == htmlSelectionControl) {
            // actully we have an image.
            elmSelectedImage = theRange.item(0);
            highlightedText = elmSelectedImage.outerHTML;
           
            //convert the ControlRange to a TextRange
            theRange = editdoc.body.createTextRange();
        theRange.moveToElementText(elmSelectedImage);
            theRange.select();
           
            fullElement = theRange.htmlText;
        } else {
            if (theRange.text != '') {
                highlightedText = theRange.htmlText;
            }
            fullElement = theRange.parentElement().outerHTML;
    }
   
    //in case we happen to select the link itself!
    if (highlightedText.search(/^\<[A|a]/) != -1) {
        fullElement = highlightedText;
    }
   
    //extrect attributes from HTML
    if (fullElement.search(/^\<[A|a]/) != -1) {

        fullElement = fullElement.replace(/\"/g, "");
        fullElement = fullElement.replace(/\'/g, "");

        // here, we have an <a> tag. Now let's extract...
        // 1. the href attribute
        var href_value = fullElement.split(/href=/);
        href_value2 = href_value[1].split(/\s|>/);
        href_attribute = href_value2[0];

        // 2. the target attribute
        if (fullElement.search(/target=/) != -1) {
            var tar = fullElement.split(/target=/);
            tar2 = tar[1].split(/\s|>/);
            tar_attribute = tar2[0];
        }

        // 3. the link text (more robust as includes all html code aswell)
        pos1 = fullElement.indexOf(">");
        pos2 = fullElement.lastIndexOf("<");
        linkText = fullElement.substring(pos1+1,pos2);
    }
       
        var myValues = new Object();
        myValues.highlightedText = highlightedText;
        myValues.tar_attribute = tar_attribute;
        myValues.href_attribute = href_attribute;
        myValues.linkText = linkText;
   
        var myText = showModalDialog(_editor_url + "popups/insert_file.html", myValues, "status=no; scroll=no");
   
        if (linkText != '') {
            if (myText) {
                theRange.parentElement().outerHTML = '';
                editor_insertHTML(objname, unescape( myText) );
            }
        } else {
            if (myText) {
                //if (editdoc.selection.type == htmlSelectionControl) {
                //    theRange.execCommand('Delete');
                //}
                editor_insertHTML(objname, unescape(myText) ); // this function ALWAYS puts in an absolute link
            }
        }
   
    }
       
    // insert image
    else if (cmdID.toLowerCase() == 'insertimage'){
      showModalDialog(_editor_url + "popups/uploading.asp", editdoc, "resizable: no; help: no; status: no; scroll: no; ");
    }
   
    //upload file
    else if (cmdID.toLowerCase() == 'upload'){
      showModalDialog(_editor_url + "popups/upload.asp", editdoc, "resizable: no; help: no; status: no; scroll: no; ");
    }
// insert form
  else if (cmdID.toLowerCase() == 'inputform') {
    var myText = showModalDialog(_editor_url + "popups/mpc.html","","resizable: no; help: no; status: no; scroll: no; ");
    if (myText) {
        editor_insertHTML(objname, unescape( myText) );
    }
  }

// insert formelement
  else if (cmdID.toLowerCase() == 'inputformelement') {
        if (editdoc.selection.createRange().text != "") {
            var highlightedText = editdoc.selection.createRange().text;
        } else {
            var highlightedText = "";
        }
        var myText = showModalDialog(_editor_url + "popups/insert_formelement.html",
                                    highlightedText,
                                    "resizable: no; help: no; status: no; scroll: no; ");
        if (myText) {
            editor_insertHTML(objname, unescape( myText) );
        }
  }
    // insert table
    else if (cmdID.toLowerCase() == 'inserttable'){
      setGlobalVar('_editor_field',objname);
      showModalDialog(_editor_url + "popups/insert_table.html?"+objname,
                                window,
                                "resizable: yes; help: no; status: no; scroll: no; ");
      // inserted by lvn
      if (config.showborders) { nullBorders(editdoc,'show')};
      // end insert by lvn
    }

// insert line
  else if (cmdID == 'line') {  // insert horizontal rule
    setGlobalVar('_editor_field',objname);
    var myText = showModalDialog(_editor_url + "popups/insert_line.html",
                                window,
                                "resizable: yes; help: no; status: no; scroll: no; ");
    if (myText) { editor_insertHTML(objname, unescape( myText) ); }
  }
 
// Change Case
    else if (cmdID == 'changecase') {
    if (editdoc.selection.createRange().htmlText != "") {
    var highlightedText = editdoc.selection.createRange().htmlText;
    editdoc.execCommand('copy');
    editdoc.execCommand('FormatBlock','','Normal')
    editdoc.execCommand('RemoveFormat');
    editdoc.execCommand('unlink');
    var myText = showModalDialog(_editor_url + "popups/changecase.html",
        highlightedText, "resizable: yes; help: no; status: no; scroll: no; ");
        if (myText) { editor_insertHTML(objname, unescape( myText) );}
        else {editdoc.execCommand('paste');}
        window.clipboardData.clearData();
        }
    else {alert('\nYou need to select some text first.');}

 
// insert marquee
  else if (cmdID == 'marquee') {  // insert some text from a popup window
  var myTitle = "";
    var myText = showModalDialog(_editor_url + "popups/insert_marquee.html",
                                myTitle,      // str or obj specified here can be read from dialog as "window.dialogArguments"
                                "resizable: yes; help: no; status: no; scroll: no; ");
    if (myText) { editor_insertHTML(objname, unescape( myText) ); }
  }
   
// Insert anchor
  else if (cmdID == 'anchor') {  // insert some text from a popup window
  var myTitle = "";
    var myText = showModalDialog(_editor_url + "popups/insert_anchor.html",
                                myTitle,      // str or obj specified here can be read from dialog as "window.dialogArguments"
                                "resizable: yes; help: no; status: no; scroll: no; ");
    if (myText) { editor_insertHTML(objname, unescape( myText) ); }
  }
// Insert Template       
    else if (cmdID.toLowerCase() == 'template') {
        window.clipboardData.clearData();
        editdoc.execCommand('SelectAll');
        editdoc.execCommand('cut');
        var myTitle = "";
        var myText = showModalDialog(_editor_url + "popups/insert_template.asp",myTitle,"resizable: yes; help: no; status: no; scroll: yes; ");
        if (myText) { editor_insertHTML(objname, unescape( myText) );
        nullBorders(editor_obj.contentWindow.document,'show');
        config.showborders = true;
        }
        else editdoc.execCommand('paste');
        }

    // all other commands microsoft Command Identifiers
    else { editdoc.execCommand(cmdID); }
  }

  editor_event(objname);
// inserted by lvn
  editor_obj.focus();
// end insert by lvn    
}
// inserted by lvn : table operations
/* ---------------------------------------------------------------------- *\
  Function    : tables_action
  Description : perform an action on selected table
  Usage      :
  Arguments  : table_action - objectname + action to execute
                td - startpoint cell
\* ---------------------------------------------------------------------- */

function tables_action(table_action,td) {

  // operations only valid on table cells
  if (td.tagName == 'TD' || td.tagName == 'TH' ) {
    var TableParts = table_action.split("_");
    var objname    = table_action.replace(/^_(.*)_[^_]*$/, '$1');
    var cmdID      = TableParts[ TableParts.length-1 ];
    var editor_obj = document.all["_" +objname + "_editor"];
    var config    = document.all[objname].config;
    var tr,td,tbody,table,newtr;
    // get the table object model
    tr = td.parentNode;
    while(tr != null && tr.tagName != 'TR'){tr = tr.parentNode;}
    if (tr != null) {
        var tbody = tr.parentNode;
        while(tbody != null && tbody.tagName != 'TBODY' && tbody.tagName != 'THEAD' && tbody.tagName != 'TFOOT'){tbody = tbody.parentNode;}
        if (tbody != null) {
          table = tbody.parentNode;
          while(table!= null && table.tagName != 'TABLE'){table = table.parentNode;}
        }
    }
    // only execute commands if table object model is complete
    if (table != null) {
        // local functions to insert rowdetails and columns
        function insertRowDetails(tr,newtr) {
          //for (var i=0;i < tr.childNodes.length;i++) {
          for (var i=0;i < tr.cells.length;i++) {
              newtr.insertCell(-1);
          }
        }
        function insertColumn(tbody,where) {
          //for (var i=0;i < tbody.childNodes.length;i++) {
          for (var i=0;i < tbody.rows.length;i++) {
              //tr = tbody.childNodes(i);
              tr = tbody.rows(i);
              //if (where > tr.childNodes.length){
              if (where > tr.cells.length){
                tr.insertCell();
              } else {
                tr.insertCell(where);
              }
          }
        }
        function deleteColumn(tbody,where) {
          //for (var i=0;i <  tbody.childNodes.length;i++) {
          for (var i=0;i <  tbody.rows.length;i++) {
            //var tr = tbody.childNodes(i);
            var tr = tbody.rows(i);
            //if (tr.childNodes.length - 1 < where){
            if (tr.cells.length - 1 < where){
                //tr.deleteCell(tr.childNodes.length - 1);
                tr.deleteCell(tr.cells.length - 1);
            } else {
                tr.deleteCell(where);
            }
            //tr = tbody.childNodes(i);
            tr = tbody.rows(i);
            //if (tr.childNodes.length == 0){
            if (tr.cells.length == 0){
                tbody.deleteRow(i);
            }
          } 
        }
        function splitCell(tbody,currTr,currTd){
          if (currTd.colSpan > 1) {
              // rowspan > 1 just insert cell and decrease colspan
              currTd.colSpan = currTd.colSpan - 1;
              currTr.insertCell(currTd.cellIndex + 1);
          } else {
              // rowspan = 1 increase colspan for all other rows and insert cell in current row
              for (var i=0;i <  tbody.rows.length;i++) {
                var tr = tbody.rows(i);
                var td = tr.cells(currTd.cellIndex);
                if (i == currTr.rowIndex) {
                    tr.insertCell(currTd.cellIndex + 1);
                } else {
                    td.colSpan = td.colSpan + 1;
                }
              }
          }
        }
        // commented out!
        /* function mergeCells(tbody,currTr,currTd){
          // check if leftmost of cells to merge
          var left = false;
          for (var i=0;i <  tbody.rows.length;i++) {
              var tr = tbody.rows(i);
              var allTd = tr.cells;
              if (currTd.cellIndex + 2 > allTd.length) {
                left = false;
                break;
              } else {
                var td = tr.cells(currTd.cellIndex);             
                if (i != currTr.rowIndex) {
                    if (td.colSpan > 1) {
                      left = true;
                    } else {
                      left = false;
                      break;
                    }
                }
              }
          }
          if (left){
              for (var i=0;i < tbody.rows.length;i++){
                var tr = tbody.rows(i);
                var td = tr.cells(currTd.cellIndex);
                if (currTd.cellIndex + 2 > tr.length) {
                    alert("You can't merge cells here.");
                    return;
                } else {
                    var mergeCell = tr.cells(currTd.cellIndex + 1);
                    if (i == currTr.rowIndex) {
                      // merge the contents of the current cell with the one on the right
                      currTd.innerHTML = currTd.innerHTML + mergeCell.innerHTML;
                      currTr.deleteCell(currTd.cellIndex + 1);
                    } else {
                      // decrease colspan for non current rows
                      td.colSpan = td.colSpan - 1;
                    }
                }
              }
          } else {
              alert('Select the leftmost cell of the split to merge.');
          }
        } */
        function mergeCells(tbody,currTr,currTd){
        //first check if there are cells to the right
          if (currTd.cellIndex < currTr.cells.length-1) {
              //get current colspan and cell to be merged's colspan
              //add the two together to get the new one,
              //move the conetent and delete the right one
              var currColSpan = currTd.colSpan ;
              var mergeCellColSpan = currTr.cells(currTd.cellIndex+1).colSpan;
              var mergeCell = currTr.cells(currTd.cellIndex+1);
              currTd.innerHTML = currTd.innerHTML + mergeCell.innerHTML;
              currTr.deleteCell(currTd.cellIndex + 1);
              currTd.colSpan = currColSpan+mergeCellColSpan ;
          } else {
              alert('Select the leftmost cell of the split to merge.');
          }
        }
        function splitRow(tbody,currTr,currTd){
          // check rowspan on other cells
          if (currTd.rowSpan > 1){
            currTd.rowSpan = currTd.rowSpan - 1;
            var tr = tbody.rows(currTr.rowIndex + 1);
            var where = 0;
            for (var i=0;i <  currTr.cells.length;i++) {
                if (i < currTd.cellIndex){
                  if (currTr.cells(i).rowSpan < 2){where++;}
                }
            } 
            tr.insertCell(where);
          } else {
              for (var i=0;i <  currTr.cells.length;i++) {
                var td = currTr.cells(i);
                if (i == currTd.cellIndex) {
                    tr = tbody.insertRow(currTr.rowIndex + 1);
                    tr.insertCell(0);
                } else {
                    td.rowSpan = td.rowSpan + 1;
                }
              }
          }
        }
        function mergeRows(tbody,currTr,currTd){
          // check if topmost of cells to merge
          var top = false;
          if (currTd.rowSpan < 2){
              for (var i=0;i <  currTr.cells.length;i++) {
                if (i !== currTd.cellIndex) {
                    if (currTr.cells(i).rowSpan > 1){
                      top = true;
                      break;
                    }
                }
              }
          }
          if (top){
              return;
          } else {
              alert('Select the topmost row of the split to merge.');
          }
        }
        // execute the operation depending on the given command
        switch(cmdID) {
          case 'CreateCaption'      : table.createCaption();break;
          case 'DeleteCaption'      : table.deleteCaption();break;
          case 'CreateTHead'        : table.createTHead();break;
          case 'DeleteTHead'        : table.deleteTHead();break;
          case 'CreateTFoot'        : table.createTFoot();break;
          case 'DeleteTFoot'        : table.deleteTFoot();break;
          case 'InsertRowTop'      : newtr = tbody.insertRow(0);insertRowDetails(tr,newtr);break;
          case 'InsertRowBottom'    : newtr = tbody.insertRow(-1);insertRowDetails(tr,newtr);break;
          case 'InsertRowBefore'    : newtr = tbody.insertRow(tr.rowIndex);insertRowDetails(tr,newtr);break;
          case 'InsertRowAfter'    : newtr = tbody.insertRow(tr.rowIndex+1);insertRowDetails(tr,newtr);break;
          case 'InsertRowStart'    : newtr = tbody.insertRow(0);insertRowDetails(tr,newtr);break;
          case 'DeleteRow'          : tbody.deleteRow(tr.rowIndex);break;
          case 'InsertColumnLeft'  : insertColumn(tbody,0);break;
          case 'InsertColumnRight'  : insertColumn(tbody,-1);break;
          case 'InsertColumnBefore' : insertColumn(tbody,td.cellIndex);break;
          case 'InsertColumnAfter'  : insertColumn(tbody,td.cellIndex+1);break;
          case 'DeleteColumn'      : deleteColumn(tbody,td.cellIndex);break;
          case 'InsertCellLeft'    : tr.insertCell(0);break;
          case 'InsertCellRight'    : tr.insertCell(-1);break;
          case 'InsertCellBefore'  : tr.insertCell(td.cellIndex);break;
          case 'InsertCellAfter'    : tr.insertCell(td.cellIndex+1);break;
          case 'InsertCellStart'    : tr.insertCell(0);break;
          case 'DeleteCell'        : tr.deleteCell(td.cellIndex);break;
          case 'SplitCell'          : splitCell(tbody,tr,td);break;
          case 'MergeCells'        : mergeCells(tbody,tr,td);break;
          case 'SplitRow'          : splitRow(tbody,tr,td);break;
          case 'MergeRows'          : mergeRows(tbody,tr,td);break;
// inserted by lvn : property pallettes
          case 'TableProperties'    : nullBorders(editor_obj.contentWindow.document,'hide');
                                      setGlobalVar('_editor_field',objname);
                                      setGlobalVar('_editor_table',table);
                                      showModalDialog(_editor_url + "popups/tableprop.html?"+objname,
                                                      window,
                                                      "resizable: yes; help: no; status: no; scroll: no; ");
                                      td.focus();
                                      break;
          case 'RowProperties'      : setGlobalVar('_editor_field',objname);
                                      setGlobalVar('_editor_row',tr);
                                      showModalDialog(_editor_url + "popups/rowprop.html?"+objname,
                                                      window,
                                                      "resizable: yes; help: no; status: no; scroll: no; ");
                                      td.focus();
                                      break;
          case 'CellProperties'    : setGlobalVar('_editor_field',objname);
                                      setGlobalVar('_editor_cell',td);
                                      showModalDialog(_editor_url + "popups/cellprop.html?"+objname,
                                                      window,
                                                      "resizable: yes; help: no; status: no; scroll: no; ");
                                      td.focus();
                                      break;
// end insert lvn property pallettes
          default                  : break;
        }
        // if 0 table borders and the switch to show them is on: show them
        if (config.showborders){ // toggle is on : show null borders
          nullBorders(editor_obj.contentWindow.document,'show');
        }
    }
  }
  return;
}
// end insert by lvn

/* ---------------------------------------------------------------------- *\
  Function    : editor_event
  Description : called everytime an editor event occurs
  Usage      : editor_event(objname, runDelay, eventName)
  Arguments  : objname - ID of textarea to replace
                runDelay: -1 = run now, no matter what
                          0  = run now, if allowed
                        1000 = run in 1 sec, if allowed at that point
\* ---------------------------------------------------------------------- */

function editor_event(objname,runDelay) {
  var config = document.all[objname].config;
  var editor_obj  = document.all["_" +objname+  "_editor"];      // html editor object
  if (runDelay == null) { runDelay = 0; }
  var editdoc;
  var editEvent = editor_obj.contentWindow ? editor_obj.contentWindow.event : event;

  // catch keypress events
    if (editEvent && editEvent.keyCode) {
      var ord      = editEvent.keyCode;    // ascii order of key pressed
      var ctrlKey  = editEvent.ctrlKey;
      var altKey    = editEvent.altKey;
      var shiftKey  = editEvent.shiftKey;

      if (ord == 16) { return; }  // ignore shift key by itself
      if (ord == 17) { return; }  // ignore ctrl key by itself
      if (ord == 18) { return; }  // ignore alt key by itself


      // cancel ENTER key and insert <BR> instead
//      if (ord == 13 && editEvent.type == 'keypress') {
//        editEvent.returnValue = false;
//        editor_insertHTML(objname, "<br>");
//        return;
//      }

      if (ctrlKey && (ord == 122 || ord == 90)) {    // catch ctrl-z (UNDO)
//      TODO: Add our own undo/redo functionality
//        editEvent.cancelBubble = true;
        return;
      }
      if ((ctrlKey && (ord == 121 || ord == 89)) ||
          ctrlKey && shiftKey && (ord == 122 || ord == 90)) {    // catch ctrl-y, ctrl-shift-z (REDO)
//      TODO: Add our own undo/redo functionality
        return;
      }
    }

  // setup timer for delayed updates (some events take time to complete)
  if (runDelay > 0) { return setTimeout(function(){ editor_event(objname); }, runDelay); }

  // don't execute more than 3 times a second (eg: too soon after last execution)
  if (this.tooSoon == 1 && runDelay >= 0) { this.queue = 1; return; } // queue all but urgent events
  this.tooSoon = 1;
  setTimeout(function(){
    this.tooSoon = 0;
    if (this.queue) { editor_event(objname,-1); };
    this.queue = 0;
    }, 333);  // 1/3 second


//  editor_updateOutput(objname);
  editor_updateToolbar(objname);

}

/* ---------------------------------------------------------------------- *\
  Function    : editor_updateToolbar
  Description : update toolbar state
  Usage      :
  Arguments  : objname - ID of textarea to replace
                action  - enable, disable, or update (default action)
\* ---------------------------------------------------------------------- */

function editor_updateToolbar(objname,action) {
  var config = document.all[objname].config;
  var editor_obj  = document.all["_" +objname+  "_editor"];

  // disable or enable toolbar

  if (action == "enable" || action == "disable") {
//    var tbItems = new Array('FontName','FontSize','FontStyle');                          // add pulldowns
// updated by lvn
    var tbItems = new Array('FontName','FontSize','FontStyle','FormatBlock');                          // add pulldowns
// end update by lvn
// inserted by lvn (find function)
    if (action == "disable") {
      setGlobalVar("_editor_field","_editor_disabled");  // set _editor_disabled to close the open modeless dialogs
    } else {
      setGlobalVar("_editor_field",objname);
    }
// end update by lvn

  for (var btnName in config.btnList) { tbItems.push(config.btnList[btnName][0]); } // add buttons

    for (var idxN in tbItems) {
      var cmdID = tbItems[idxN].toLowerCase();
      var tbObj = document.all["_" +objname+ "_" +tbItems[idxN]];
      if (cmdID == "htmlmode" ||  cmdID == "showhelp" || cmdID == "about" || cmdID == "popupeditor" || cmdID == "find") { continue; } // don't change these buttons
      if (tbObj == null) { continue; }
      var isBtn = (tbObj.tagName.toLowerCase() == "button") ? true : false;

      if (action == "enable")  { tbObj.disabled = false; if (isBtn) { tbObj.className = 'btn' }}
      if (action == "disable") { tbObj.disabled = true;  if (isBtn) { tbObj.className = 'btnNA' }}
    }
    return;
  }

  // update toolbar state

  if (editor_obj.tagName.toLowerCase() == 'textarea') { return; }  // don't update state in textedit mode
  var editdoc = editor_obj.contentWindow.document;

  // Set FontName pulldown
  var fontname_obj = document.all["_" +objname+ "_FontName"];
  if (fontname_obj) {
    var fontname = editdoc.queryCommandValue('FontName');
    if (fontname == null) { fontname_obj.value = null; }
    else {
      var found = 0;
      for (i=0; i<fontname_obj.length; i++) {
        if (fontname.toLowerCase() == fontname_obj[i].text.toLowerCase()) {
          fontname_obj.selectedIndex = i;
          found = 1;
        }
      }
      if (found != 1) { fontname_obj.value = null; }    // for fonts not in list
    }
  }
// inserted by lvn
  // inserted by lvn
  // Set Formatblock pulldown
  var formatblock_obj = document.all["_" +objname+ "_FormatBlock"];
  if (formatblock_obj) {
    var formatblock = editdoc.queryCommandValue('FormatBlock');
    if (formatblock == null) { formatblock_obj.value = null; }
    else {
   
      var found = 0;
      for (i=0; i<formatblock_obj.length; i++) {
        if (formatblock == formatblock_obj[i].value) {
          formatblock_obj.selectedIndex = i;
          found = 1;
        }
      }
      if (found != 1) { formatblock_obj.value = null; }    // for formatblocks not in list
    }
  }
// end insert by lvn

  // Set FontSize pulldown
  var fontsize_obj = document.all["_" +objname+ "_FontSize"];
  if (fontsize_obj) {
    var fontsize = editdoc.queryCommandValue('FontSize');
    if (fontsize == null) { fontsize_obj.value = null; }
    else {
      var found = 0;
      for (i=0; i<fontsize_obj.length; i++) {
        if (fontsize == fontsize_obj[i].value) { fontsize_obj.selectedIndex = i; found=1; }
      }
      if (found != 1) { fontsize_obj.value = null; }    // for sizes not in list
    }
  }

  // Set FontStyle pulldown
  var classname_obj = document.all["_" +objname+ "_FontStyle"];
  if (classname_obj) {
    var curRange = editdoc.selection.createRange();

    // check element and element parents for class names
    var pElement;
    if (curRange.length) { pElement = curRange[0]; }              // control tange
    else                { pElement = curRange.parentElement(); } // text range
    while (pElement && !pElement.className) { pElement = pElement.parentElement; }  // keep going up

    var thisClass = pElement ? pElement.className.toLowerCase() : "";
    if (!thisClass && classname_obj.value) { classname_obj.value = null; }
    else {
      var found = 0;
      for (i=0; i<classname_obj.length; i++) {
        if (thisClass == classname_obj[i].value.toLowerCase()) {
          classname_obj.selectedIndex = i;
          found=1;
        }
      }
      if (found != 1) { classname_obj.value = null; }    // for classes not in list
    }
  }

  // update button states
  var IDList = Array('Bold','Italic','Underline','StrikeThrough','SubScript','SuperScript','JustifyLeft','JustifyCenter','JustifyRight','justifyfull','justifynone','InsertOrderedList','InsertUnorderedList','BlockDirLTR','BlockDirRTL');
  for (i=0; i<IDList.length; i++) {
    var btnObj = document.all["_" +objname+ "_" +IDList[i]];
    if (btnObj == null) { continue; }
    var cmdActive = editdoc.queryCommandState( IDList[i] );

    if (!cmdActive)  {                                  // option is OK
      if (btnObj.className != 'btn') { btnObj.className = 'btn'; }
      if (btnObj.disabled  != false) { btnObj.disabled = false; }
    } else if (cmdActive)  {                            // option already applied or mixed content
      if (btnObj.className != 'btnDown') { btnObj.className = 'btnDown'; }
      if (btnObj.disabled  != false)  { btnObj.disabled = false; }
    }
  }
// inserted by lvn: table operations
// disable table handling buttons when not in a table cell
  var table_src_element = null;
  // only works on non-control ranges
  if (editdoc.selection.type != 'Control'){
    table_src_element = editdoc.selection.createRange().parentElement();
    while (table_src_element != null && table_src_element.tagName != 'TD' && table_src_element.tagName != 'TH'){
        table_src_element = table_src_element.parentElement;
    }
  }
  // check if buttons are set in the config
  var IDList = Array('TableProperties','RowProperties','InsertRowBefore','InsertRowAfter','DeleteRow','InsertColumnBefore','InsertColumnAfter','DeleteColumn','CellProperties','InsertCellBefore','InsertCellAfter','DeleteCell','SplitCell','MergeCells','SplitRow','MergeRows');
  for (var i=0; i<IDList.length; i++) {
    var found = false;
    for (var j=0;j<config.toolbar.length;j++){
      if(config.toolbar[j]) {
          for (var k=0;k<config.toolbar[j].length;k++){
            if ( IDList[i] ==  config.toolbar[j][k]){found = true;}
          }
      }
    }
    // if in cell enable buttons, else disable them
    if (found) {
      var btnObj = document.all["_" +objname+ "_" +IDList[i]];
      if (table_src_element == null) {
          btnObj.disabled = true;
          btnObj.className = 'btnNA';
      } else {
          btnObj.disabled = false;
          btnObj.className = 'btn';
      }
    }
  }
// end insert by lvn

}

/* ---------------------------------------------------------------------- *\
  Function    : editor_updateOutput
  Description : update hidden output field with data from wysiwg
\* ---------------------------------------------------------------------- */

function editor_updateOutput(objname) {
  var config    = document.all[objname].config;
  var editor_obj  = document.all["_" +objname+  "_editor"];      // html editor object
  var editEvent = editor_obj.contentWindow ? editor_obj.contentWindow.event : event;
  var isTextarea = (editor_obj.tagName.toLowerCase() == 'textarea');
  var editdoc = isTextarea ? null : editor_obj.contentWindow.document;

  // get contents of edit field
  var contents;
  if (isTextarea) { contents = editor_obj.value; }
  else            { contents = editdoc.body.innerHTML; }

  // check if contents has changed since the last time we ran this routine
  if (config.lastUpdateOutput && config.lastUpdateOutput == contents) { return; }
  else { config.lastUpdateOutput = contents; }

  // update hidden output field
  document.all[objname].value = contents;

}

/* ---------------------------------------------------------------------- *\
  Function    : editor_filterOutput
  Description :
\* ---------------------------------------------------------------------- */

function editor_filterOutput(objname) {
  editor_updateOutput(objname);
  var contents = document.all[objname].value;
  var config  = document.all[objname].config;

  // ignore blank contents
  if (contents.toLowerCase() == '<p>&nbsp;</p>') { contents = ""; }
 
  // filter tag - this code is run for each HTML tag matched
  var filterTag = function(tagBody,tagName,tagAttr) {
    tagName = tagName.toLowerCase();
    var closingTag = (tagBody.match(/^<\//)) ? true : false;

    // fix placeholder URLS - remove absolute paths that IE adds
    if (tagName == 'img') { tagBody = tagBody.replace(/(src\s*=\s*.)[^*]*(\*\*\*)/, "$1$2"); }
    if (tagName == 'a')  { tagBody = tagBody.replace(/(href\s*=\s*.)[^*]*(\*\*\*)/, "$1$2"); }

    // add additional tag filtering here

    // convert to vbCode
//    if      (tagName == 'b' || tagName == 'strong') {
//      if (closingTag) { tagBody = "[/b]"; } else { tagBody = "[b]"; }
//    }
//    else if (tagName == 'i' || tagName == 'em') {
//      if (closingTag) { tagBody = "
"; } else { tagBody = "[i]"; }
//    }
//    else if (tagName == 'u') {
//      if (closingTag) { tagBody = "[/u]"; } else { tagBody = "[u]"; }
//    }
//    else {
//      tagBody = ""; // disallow all other tags!
//    }

    return tagBody;
  };

  // match tags and call filterTag
  RegExp.lastIndex = 0;
    var matchTag = /<\/?(\w+)((?:[^'">]*|'[^']*'|"[^"]*")*)>/g;  // this will match tags, but still doesn't handle container tags (textarea, comments, etc)

  contents = contents.replace(matchTag, filterTag);

  // remove nextlines from output (if requested)
  if (config.replaceNextlines) {
    contents = contents.replace(/\r\n/g, ' ');
    contents = contents.replace(/\n/g, ' ');
    contents = contents.replace(/\r/g, ' ');
  }

  // update output with filtered content
  document.all[objname].value = contents;

}

// inserted by lvn
/* ---------------------------------------------------------------------- *\
  Function    : nullBorders
  Description : show 'dotted' borders for tables with border=0
  Usage      : nullBorders(doc,status);
  Arguments  : doc - document object in wich the borders must be shown
                status - show or hide
\* ---------------------------------------------------------------------- */

function nullBorders(doc,status) {
  // show table borders
  var edit_Tables = doc.body.getElementsByTagName("TABLE");
  for (i=0; i < edit_Tables.length; i++) {
      if (edit_Tables[i].border == '' || edit_Tables[i].border == '0' ) {
        if (status == 'show' ) {
            edit_Tables[i].style.border = "1px dotted #C0C0C0";
        } else {
            edit_Tables[i].removeAttribute("style");
        }
      }
      edit_Rows = edit_Tables[i].rows;
      for (j=0; j < edit_Rows.length; j++) {
      edit_Cells = edit_Rows[j].cells;
          for (k=0; k < edit_Cells.length; k++) {
            if (edit_Tables[i].border == '' || edit_Tables[i].border == '0' ) {
                if (!edit_Cells[k].border || edit_Cells[k].border == '' || edit_Cells[k].border == '0' ) {
                  if (status == 'show' ) {
                  edit_Cells[k].style.border = "1px dotted #C0C0C0";
                  } else {
                      edit_Cells[k].removeAttribute("style");
                  }
                }
            } else {
                if ( edit_Cells[k].border == '0' ) {
                  if (status == 'show' ) {
                      edit_Cells[k].style.border = "1px dotted #C0C0C0";
                  } else {
                      edit_Cells[k].removeAttribute("style");
                  }
                }
            }
          }
      }
  }
}

// end insert by lvn

/* ---------------------------------------------------------------------- *\
  Function    : editor_setmode
  Description : change mode between WYSIWYG and HTML editor
  Usage      : editor_setmode(objname, mode);
  Arguments  : objname - button id string with editor and action name
                mode      - init, textedit, or wysiwyg
\* ---------------------------------------------------------------------- */

function editor_setmode(objname, mode) {
  var config    = document.all[objname].config;
  var editor_obj = document.all["_" +objname + "_editor"];

  // wait until document is fully loaded
  if (document.readyState != 'complete') {
    setTimeout(function() { editor_setmode(objname,mode) }, 25);
    return;
  }

  // define different editors
  var TextEdit  = '<textarea ID="_' +objname + '_editor" style="width:' +editor_obj.style.width+ '; height:' +editor_obj.style.height+ '; margin-top: -1px; margin-bottom: -1px;"></textarea>';
  var RichEdit  = '<iframe ID="_' +objname+ '_editor"    style="width:' +editor_obj.style.width+ '; height:' +editor_obj.style.height+ ';"></iframe>';

// src="' +_editor_url+ 'popups/blank.html"

  //
  // Switch to TEXTEDIT mode
  //

  if (mode == "textedit" || editor_obj.tagName.toLowerCase() == 'iframe') {
    config.mode = "textedit";
    var editdoc = editor_obj.contentWindow.document;
    // inserted by lvn
    // show table borders
    nullBorders(editdoc,'hide');
    // end insert by lvn
    var contents = editdoc.body.createTextRange().htmlText;
    editor_obj.outerHTML = TextEdit;
    editor_obj = document.all["_" +objname + "_editor"];
    editor_obj.value = contents;
    editor_event(objname);
    // inserted by lvn
    if (config.showborders) {
      editor_updateToolbar(objname, "disable");
      config.showborders =  true;
    } else {
    // end insert by lvn
    editor_updateToolbar(objname, "disable");  // disable toolbar items
    // insert by lvn
    }
    // end insert by lvn
     
// set event handlers
    editor_obj.onkeydown  = function() { editor_event(objname); }
    editor_obj.onkeypress  = function() { editor_event(objname); }
    editor_obj.onkeyup    = function() { editor_event(objname); }
    editor_obj.onmouseup  = function() { editor_event(objname); }
    editor_obj.ondrop      = function() { editor_event(objname, 100); }    // these events fire before they occur
    editor_obj.oncut      = function() { editor_event(objname, 100); }
    editor_obj.onpaste    = function() { editor_event(objname, 100); }
    editor_obj.onblur      = function() { editor_event(objname, -1); }

    editor_updateOutput(objname);
    editor_focus(editor_obj);
  }

  //
  // Switch to WYSIWYG mode
  //

  else {
    config.mode = "wysiwyg";
    var contents = editor_obj.value;
    if (mode == 'init') { contents = document.all[objname].value; } // on init use original textarea content

    // create editor
    editor_obj.outerHTML = RichEdit;
    editor_obj = document.all["_" +objname + "_editor"];

    // get iframe document object

    // create editor contents (and default styles for editor)
    var html = "";
    html += '<html><head>\n';
    if (config.stylesheet) {
      html += '<link href="' +config.stylesheet+ '" rel="stylesheet" type="text/css">\n';
    }
    html += '<style>\n';
    html += 'body {' +config.bodyStyle+ '} \n';
    html += '.borders {' +config.bordersStyle+ '} \n';
    for (var i in config.fontstyles) {
      var fontstyle = config.fontstyles[i];
      if (fontstyle.classStyle) {
        html += '.' +fontstyle.className+ ' {' +fontstyle.classStyle+ '}\n';
      }
    }
    html += '</style>\n'
      + '</head>\n'
      + '<body contenteditable="true" topmargin=1 leftmargi
Avatar billede nythjem Nybegynder
22. september 2004 - 17:17 #3
Ej, Jes, jeg kan se, at den kun har fået halvdelen med, og det er sgu næsten synd for dig, at skulle side og læse hele den lange fil igennem..

Jeg kigger lige et andet sted, i orden ik? :)
Avatar billede roenving Novice
22. september 2004 - 17:21 #4
Sæ'fø'li'

Men specielt mangler jeg: cleanEmptyTag-funktionen !-)
Avatar billede nythjem Nybegynder
22. september 2004 - 17:40 #5
Ok, jeg har lige lagt den ud, den er jo lidt for stor til, at kunne blive medtaget her..

Den ligger her.. http://www.afront.dk/a.js

Men tak Jes..
Avatar billede roenving Novice
22. september 2004 - 17:58 #6
Såvidt jeg umiddelbart kan se, er der ikke nogen voldsomme fejl, så du må igang med den langsomme debugging:

Indsæt først alerts i grundfunktionen og find på den måde ud af, hvornår fejlen kommer, og så skal du måske ind i cleanEmptyTag-funktionen bagefter ...
Avatar billede nythjem Nybegynder
23. september 2004 - 09:59 #7
Ok Jes, tak skal du have, så går jeg i gang med den herlige debugging :)

Du må gerne lægge et svar, nu du har kigget den laaange fil igennem :)
Avatar billede roenving Novice
23. september 2004 - 12:44 #8
Jeg må jo så indrømme, at jeg var klart doven, så det blev Ctrl+B, cleanEmptyTag, og så Enter, Enter, Enter, Enter, Enter, Enter, Enter, Enter, Enter til jeg nåede den funktion ...

-- men hvorfor er der bare ikke antydning af fornuftige indrykninger, men til gengæld en masse tomme mellemrum i slutningen af linjerne ?-)

-- klart pladsspild, et umiddelbart slag på tasken er, at filen er mindst 20% større end nødvendigt pga. de mellemrum ...

-- og du vender tilbage, hvis dine undersøgelser giver et underligt resultat '-)
Avatar billede nythjem Nybegynder
23. september 2004 - 17:25 #9
Det gør jeg helt sikkert ;)

Og jeg må da indrømme, at java script i den dur slet ikke kan udarbejdes af mig, så jeg har kun det, der er lavet at gå efter.. Men jeg vil lige kigge på det dertilknyttede forum for at finde ud af, om nogle har fået samme fejl. :)
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Vi tilbyder markedets bedste kurser inden for webudvikling

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester