Changeset 363


Ignore:
Timestamp:
09/30/05 08:08:53 (14 years ago)
Author:
niko
Message:

#538
improved SuperClean? (more settings, custom filters)

Location:
trunk/plugins/SuperClean
Files:
3 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/plugins/SuperClean/dialog.html

    r361 r363  
    22<div style="margin-left: 10px;"> 
    33    <l10n>Please select from the following cleaning options...</l10n> 
    4     <div id="[divTidy]"> 
    5         <input type="checkbox" name="[tidy]" id="[tidy]" checked /> 
    6         <label for="[tidy]"> 
    7         <l10n>General tidy up and correction of some problems.</l10n></label> 
    8     </div> 
    9     <div> 
    10         <input type="checkbox" name="[word_clean]" id="[word_clean]" checked /> 
    11         <label for="[word_clean]"> 
    12         <l10n>Clean bad HTML from Microsoft Word</l10n></label> 
    13     </div> 
    14     <div> 
    15         <input type="checkbox" name="[faces]" id="[faces]" checked /> 
    16         <label for="[faces]"> 
    17         <l10n>Remove custom typefaces (font "styles").</l10n></label> 
    18     </div> 
    19     <div> 
    20         <input type="checkbox" name="[sizes]" id="[sizes]" checked /> 
    21         <label for="[sizes]"> 
    22         <l10n>Remove custom font sizes.</l10n></label> 
    23     </div> 
    24     <div> 
    25         <input type="checkbox" name="[colors]" id="[colors]" checked /> 
    26         <label for="[colors]"> 
    27         <l10n>Remove custom text colors.</l10n></label> 
    28     </div> 
     4    <!--filters--> 
    295  <div style="margin-top: 10px;"> 
    306    <input type="button" id="[ok]"     value="_(OK)"     /> 
  • trunk/plugins/SuperClean/super-clean.js

    r362 r363  
    1515  name     : "SuperClean", 
    1616  version  : "1.0", 
    17   developer: "James Sleeman", 
     17  developer: "James Sleeman, Niko Sams", 
    1818  developer_url: "http://www.gogo.co.nz/", 
    1919  c_owner      : "Gogo Internet Services", 
     
    4242    if(opts.word_clean) editor._wordClean(); 
    4343    var D = editor.getInnerHTML(); 
    44     if(opts.faces) 
    45     { 
    46       D = D.replace(/face="?[^" >]*"?/gi, ''); 
    47       // { (stops jedit's fold breaking) 
    48       D = D.replace(/font-family:[^;}"']+;?/gi, ''); 
    49     } 
    50  
    51     if(opts.sizes) 
    52     { 
    53       D = D.replace(/size="?[^" >]*"?/gi, ''); 
    54       // { (stops jedit's fold breaking) 
    55       D = D.replace(/font-size:[^;}"']+;?/gi, ''); 
    56     } 
    57  
    58     if(opts.colors) 
    59     { 
    60       D = D.replace(/color="?[^" >]*"?/gi, ''); 
    61       // { (stops jedit's fold breaking) 
    62       D = D.replace(/([^-])color:[^;}"']+;?/gi, '$1'); 
     44 
     45    for(var filter in editor.config.SuperClean.filters) 
     46    { 
     47      if(filter=='tidy' || filter=='word_clean') continue; 
     48      if(opts[filter]) 
     49      { 
     50        D = SuperClean.filterFunctions[filter](D); 
     51      } 
    6352    } 
    6453 
    6554    D = D.replace(/(style|class)="\s*"/gi, ''); 
    6655    D = D.replace(/<(font|span)\s*>/gi, ''); 
     56 
    6757    editor.setHTML(D); 
    6858 
    69     if(editor.config.tidy_handler && opts.tidy) 
    70     { 
    71       HTMLArea._postback(editor.config.tidy_handler, {'content' : editor.getInnerHTML()}, 
     59    if(opts.tidy) 
     60    { 
     61      HTMLArea._postback(editor.config.SuperClean.tidy_handler, {'content' : editor.getInnerHTML()}, 
    7262                         function(javascriptResponse) { eval(javascriptResponse) }); 
    7363    } 
    7464    return true; 
    7565  } 
    76   var inputs = {}; 
    77   this._dialog.show(inputs, doOK); 
    78 } 
    79  
    80 // set to the URL of a handler for html tidy, this handler 
    81 //  (see tidy.php for an example) must that a single post variable 
    82 //  "content" which contains the HTML to tidy, and return javascript like 
    83 //  editor.setHTML('<strong>Tidied Html</strong>') 
    84 // it's called through XMLHTTPRequest 
    85 // 
    86 // set to false if you need to disable this. 
    87 HTMLArea.Config.prototype.tidy_handler = _editor_url + 'plugins/SuperClean/tidy.php'; 
     66 
     67  if(this.editor.config.SuperClean.show_dialog) 
     68  { 
     69    var inputs = {}; 
     70    this._dialog.show(inputs, doOK); 
     71  } 
     72  else 
     73  { 
     74    var editor = this.editor; 
     75    var html = editor.getInnerHTML(); 
     76    for(var filter in editor.config.SuperClean.filters) 
     77    { 
     78      if(filter=='tidy') continue; //call tidy last 
     79      html = SuperClean.filterFunctions[filter](html, editor); 
     80    } 
     81 
     82    html = html.replace(/(style|class)="\s*"/gi, ''); 
     83    html = html.replace(/<(font|span)\s*>/gi, ''); 
     84 
     85    editor.setHTML(html); 
     86 
     87    if(editor.config.SuperClean.filters.tidy) 
     88    { 
     89      SuperClean.filterFunctions.tidy(html, editor); 
     90    } 
     91  } 
     92} 
     93 
     94HTMLArea.Config.prototype.SuperClean = 
     95{ 
     96  // set to the URL of a handler for html tidy, this handler 
     97  //  (see tidy.php for an example) must that a single post variable 
     98  //  "content" which contains the HTML to tidy, and return javascript like 
     99  //  editor.setHTML('<strong>Tidied Html</strong>') 
     100  // it's called through XMLHTTPRequest 
     101  'tidy_handler': _editor_url + 'plugins/SuperClean/tidy.php', 
     102 
     103  //avaliable filters (these are built-in filters) 
     104  'filters': { 'tidy': HTMLArea._lc('General tidy up and correction of some problems.', 'SuperClean'), 
     105               'word_clean': HTMLArea._lc('Clean bad HTML from Microsoft Word', 'SuperClean'), 
     106               'remove_faces': HTMLArea._lc('Remove custom typefaces (font "styles").', 'SuperClean'), 
     107               'remove_sizes': HTMLArea._lc('Remove custom font sizes.', 'SuperClean'), 
     108               'remove_colors': HTMLArea._lc('Remove custom text colors.', 'SuperClean') 
     109  //additional custom filters (defined in plugins/SuperClean/filters/word.js) 
     110               //'paragraph': 'remove paragraphs'}, 
     111               //'word': 'exteded Word-Filter' }, 
     112              }, 
     113  //if false all filters are applied, if true a dialog asks what filters should be used 
     114  'show_dialog': true 
     115} 
     116 
     117SuperClean.filterFunctions = { }; 
     118SuperClean.filterFunctions.remove_colors = function(D) 
     119{ 
     120  D = D.replace(/color="?[^" >]*"?/gi, ''); 
     121  // { (stops jedit's fold breaking) 
     122  D = D.replace(/([^-])color:[^;}"']+;?/gi, '$1'); 
     123  return(D); 
     124}; 
     125SuperClean.filterFunctions.remove_sizes = function(D) 
     126{ 
     127  D = D.replace(/size="?[^" >]*"?/gi, ''); 
     128  // { (stops jedit's fold breaking) 
     129  D = D.replace(/font-size:[^;}"']+;?/gi, ''); 
     130  return(D); 
     131}; 
     132SuperClean.filterFunctions.remove_faces = function(D) 
     133{ 
     134  D = D.replace(/face="?[^" >]*"?/gi, ''); 
     135  // { (stops jedit's fold breaking) 
     136  D = D.replace(/font-family:[^;}"']+;?/gi, ''); 
     137  return(D); 
     138}; 
     139SuperClean.filterFunctions.word_clean = function(html, editor) 
     140{ 
     141  editor.setHTML(html); 
     142  editor._wordClean(); 
     143  return editor.getInnerHTML(); 
     144}; 
     145SuperClean.filterFunctions.tidy = function(html, editor) 
     146{ 
     147  HTMLArea._postback(editor.config.SuperClean.tidy_handler, {'content' : html}, 
     148                      function(javascriptResponse) { eval(javascriptResponse) }); 
     149}; 
     150 
    88151 
    89152 
    90153SuperClean.prototype.onGenerate = function() 
    91154{ 
    92   this._dialog = new SuperClean.Dialog(this); 
     155  if(this.editor.config.SuperClean.show_dialog && !this._dialog) 
     156  { 
     157    this._dialog = new SuperClean.Dialog(this); 
     158  } 
     159  if(this.editor.config.tidy_handler) 
     160  { 
     161    //for backwards compatibility 
     162    this.editor.config.SuperClean.tidy_handler = this.editor.config.tidy_handler; 
     163    this.editor.config.tidy_handler = null; 
     164  } 
     165  if(!this.editor.config.SuperClean.tidy_handler && this.editor.config.filters.tidy) { 
     166    //unset tidy-filter if no tidy_handler 
     167    this.editor.config.filters.tidy = null; 
     168  } 
     169 
     170  var sc = this; 
     171  //load the filter-functions 
     172  for(var filter in this.editor.config.SuperClean.filters) 
     173  { 
     174    if(!SuperClean.filterFunctions[filter]) 
     175    { 
     176      HTMLArea._getback(_editor_url + 'plugins/SuperClean/filters/'+filter+'.js', 
     177                      function(func) { 
     178                        eval('SuperClean.filterFunctions.'+filter+'='+func+';'); 
     179                        sc.onGenerate(); 
     180                      }); 
     181      return; 
     182    } 
     183  } 
    93184} 
    94185// Inline Dialog for SuperClean 
     
    122213    return; 
    123214  } 
     215 
     216  var htmlFilters = ""; 
     217  for(var filter in this.SuperClean.editor.config.SuperClean.filters) 
     218  { 
     219    htmlFilters += "    <div>\n"; 
     220    htmlFilters += "        <input type=\"checkbox\" name=\"["+filter+"]\" id=\"["+filter+"]\" checked />\n"; 
     221    htmlFilters += "        <label for=\"["+filter+"]\">"+this.SuperClean.editor.config.SuperClean.filters[filter]+"</label>\n"; 
     222    htmlFilters += "    </div>\n"; 
     223  } 
     224  this.html = this.html.replace('<!--filters-->', htmlFilters); 
     225 
    124226  var html = this.html; 
    125227 
     
    139241    window.setTimeout(function() {lDialog.show(inputs,ok,cancel);},100); 
    140242    return; 
    141   } 
    142  
    143   if(!this.SuperClean.editor.config.tidy_handler) { 
    144     this.dialog.getElementById('divTidy').style.display = 'none'; 
    145243  } 
    146244 
Note: See TracChangeset for help on using the changeset viewer.