home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / groupoffice-com-2.01 / controls / htmlarea / go_htmlarea.js < prev    next >
Text File  |  2004-03-08  |  2KB  |  54 lines

  1. //this file contains additions for HTMLarea required by Group-Office
  2.  
  3. // Returns the next upper parent element (relative to current cursor-position) matching nodeName 
  4. HTMLArea.prototype.getParentElementByName = function(nodeName) 
  5.     var el = null; 
  6.     var ancestors = this.getAllAncestors(); 
  7.     for ( var j = 0; j < ancestors.length; j++) 
  8.     { 
  9.         el =  (ancestors[j] && ancestors[j].nodeName.toLowerCase() == nodeName.toLowerCase()) ? ancestors[j] : null; 
  10.         
  11.         if (el) break; 
  12.     } 
  13.     return el;
  14. }
  15.  
  16. HTMLArea.prototype.removeFormat = function(sel) { 
  17.  
  18.     // make one line 
  19.     sel = sel.replace(/\r\n/g, ''); 
  20.     sel = sel.replace(/\n/g, ''); 
  21.     sel = sel.replace(/\r/g, ''); 
  22.     sel = sel.replace(/\ \;/g,''); 
  23.  
  24.     // keep tags, strip attributes 
  25.     sel = sel.replace(/ class=[^\s|>]*/gi,''); 
  26.     sel = sel.replace(/ style=\"[^>]*\"/gi,''); 
  27.  
  28.     //clean up tags 
  29.     sel = sel.replace(/<b [^>]*>/gi,'<b>'); 
  30.     sel = sel.replace(/<i [^>]*>/gi,'<i>'); 
  31.     sel = sel.replace(/<li [^>]*>/gi,'<li>'); 
  32.     sel = sel.replace(/<ul [^>]*>/gi,'<ul>'); 
  33.  
  34.     // replace outdated tags 
  35.     sel = sel.replace(/<b>/gi,'<strong>'); 
  36.     sel = sel.replace(/<\/b>/gi,'</strong>'); 
  37.     sel = sel.replace(/<i>/gi,'<em>'); 
  38.     sel = sel.replace(/<\/i>/gi,'</em>'); 
  39.  
  40.     // kill unwanted tags 
  41.     sel = sel.replace(/<\?xml:[^>]*>/g, ''); // Word xml 
  42.     sel = sel.replace(/<\/?st1:[^>]*>/g,''); // Word SmartTags 
  43.     sel = sel.replace(/<\/?[a-z]\:[^>]*>/g,''); // All other funny Word non-HTML stuff 
  44.     sel = sel.replace(/<\/?font[^>]*>/gi,''); // Disable if you want to keep font formatting 
  45.     sel = sel.replace(/<\/?span[^>]*>/gi,''); 
  46.     sel = sel.replace(/<\/?div[^>]*>/gi,''); 
  47.  
  48.     //remove empty tags 
  49.     sel = sel.replace(/<strong><\/strong>/gi,''); 
  50.     sel = sel.replace(/<P[^>]*><\/P>/gi,''); 
  51.  
  52.     return sel;