Ignore:
Timestamp:
01/13/07 13:10:07 (13 years ago)
Author:
ray
Message:
  • XinhaCore?.js: changed needless use of eval() at one position see Ticket #905
  • added hotfix for 0.9beta
    • updated XinhaCore?.js
    • included uncompressed super-clean.js
File:
1 edited

Legend:

Unmodified
Added
Removed
  • releases/0.91beta/plugins/SuperClean/super-clean.js

    r652 r654  
    1 function SuperClean(_1,_2){ 
    2 this.editor=_1; 
    3 var _3=this; 
    4 _1._superclean_on=false; 
    5 _1.config.registerButton("superclean",this._lc("Clean up HTML"),_1.imgURL("ed_superclean.gif","SuperClean"),true,function(e,_5,_6){ 
    6 _3._superClean(null,_6); 
    7 }); 
    8 _1.config.addToolbarElement("superclean","killword",0); 
     1// Make our right side panel and insert appropriatly 
     2function SuperClean(editor, args) 
     3{ 
     4  this.editor = editor; 
     5  var superclean = this; 
     6  editor._superclean_on = false; 
     7  editor.config.registerButton('superclean', this._lc("Clean up HTML"), editor.imgURL('ed_superclean.gif', 'SuperClean'), true, function(e, objname, obj) { superclean._superClean(null, obj); }); 
     8 
     9  // See if we can find 'killword' and replace it with superclean 
     10  editor.config.addToolbarElement("superclean", "killword", 0); 
    911} 
    10 SuperClean._pluginInfo={name:"SuperClean",version:"1.0",developer:"James Sleeman, Niko Sams",developer_url:"http://www.gogo.co.nz/",c_owner:"Gogo Internet Services",license:"htmlArea",sponsor:"Gogo Internet Services",sponsor_url:"http://www.gogo.co.nz/"}; 
    11 SuperClean.prototype._lc=function(_7){ 
    12 return HTMLArea._lc(_7,"SuperClean"); 
    13 }; 
    14 SuperClean.prototype._superClean=function(_8,_9){ 
    15 var _a=this; 
    16 var _b=function(){ 
    17 var _c=_a._dialog.hide(); 
    18 var _d=_a.editor; 
    19 if(_c.word_clean){ 
    20 _d._wordClean(); 
    21 } 
    22 var D=_d.getInnerHTML(); 
    23 for(var _f in _d.config.SuperClean.filters){ 
    24 if(_f=="tidy"||_f=="word_clean"){ 
    25 continue; 
    26 } 
    27 if(_c[_f]){ 
    28 D=SuperClean.filterFunctions[_f](D,_d); 
    29 } 
    30 } 
    31 D=D.replace(/(style|class)="\s*"/gi,""); 
    32 D=D.replace(/<(font|span)\s*>/gi,""); 
    33 _d.setHTML(D); 
    34 if(_c.tidy){ 
    35 HTMLArea._postback(_d.config.SuperClean.tidy_handler,{"content":_d.getInnerHTML()},function(_10){ 
    36 eval(_10); 
    37 }); 
    38 } 
    39 return true; 
    40 }; 
    41 if(this.editor.config.SuperClean.show_dialog){ 
    42 var _11={}; 
    43 this._dialog.show(_11,_b); 
    44 }else{ 
    45 var _12=this.editor; 
    46 var _13=_12.getInnerHTML(); 
    47 for(var _14 in _12.config.SuperClean.filters){ 
    48 if(_14=="tidy"){ 
    49 continue; 
    50 } 
    51 _13=SuperClean.filterFunctions[_14](_13,_12); 
    52 } 
    53 _13=_13.replace(/(style|class)="\s*"/gi,""); 
    54 _13=_13.replace(/<(font|span)\s*>/gi,""); 
    55 _12.setHTML(_13); 
    56 if(_12.config.SuperClean.filters.tidy){ 
    57 SuperClean.filterFunctions.tidy(_13,_12); 
    58 } 
    59 } 
    60 }; 
    61 HTMLArea.Config.prototype.SuperClean={"tidy_handler":_editor_url+"plugins/SuperClean/tidy.php","filters":{"tidy":HTMLArea._lc("General tidy up and correction of some problems.","SuperClean"),"word_clean":HTMLArea._lc("Clean bad HTML from Microsoft Word","SuperClean"),"remove_faces":HTMLArea._lc("Remove custom typefaces (font \"styles\").","SuperClean"),"remove_sizes":HTMLArea._lc("Remove custom font sizes.","SuperClean"),"remove_colors":HTMLArea._lc("Remove custom text colors.","SuperClean"),"remove_lang":HTMLArea._lc("Remove lang attributes.","SuperClean"),"remove_fancy_quotes":{label:HTMLArea._lc("Replace directional quote marks with non-directional quote marks.","SuperClean"),checked:false}},"show_dialog":true}; 
    62 SuperClean.filterFunctions={}; 
    63 SuperClean.filterFunctions.remove_colors=function(D){ 
    64 D=D.replace(/color="?[^" >]*"?/gi,""); 
    65 D=D.replace(/([^-])color:[^;}"']+;?/gi,"$1"); 
    66 return (D); 
    67 }; 
    68 SuperClean.filterFunctions.remove_sizes=function(D){ 
    69 D=D.replace(/size="?[^" >]*"?/gi,""); 
    70 D=D.replace(/font-size:[^;}"']+;?/gi,""); 
    71 return (D); 
    72 }; 
    73 SuperClean.filterFunctions.remove_faces=function(D){ 
    74 D=D.replace(/face="?[^" >]*"?/gi,""); 
    75 D=D.replace(/font-family:[^;}"']+;?/gi,""); 
    76 return (D); 
    77 }; 
    78 SuperClean.filterFunctions.remove_lang=function(D){ 
    79 D=D.replace(/lang="?[^" >]*"?/gi,""); 
    80 return (D); 
    81 }; 
    82 SuperClean.filterFunctions.word_clean=function(_19,_1a){ 
    83 _1a.setHTML(_19); 
    84 _1a._wordClean(); 
    85 return _1a.getInnerHTML(); 
    86 }; 
    87 SuperClean.filterFunctions.remove_fancy_quotes=function(D){ 
    88 D=D.replace(new RegExp(String.fromCharCode(8216),"g"),"'"); 
    89 D=D.replace(new RegExp(String.fromCharCode(8217),"g"),"'"); 
    90 D=D.replace(new RegExp(String.fromCharCode(8218),"g"),"'"); 
    91 D=D.replace(new RegExp(String.fromCharCode(8219),"g"),"'"); 
    92 D=D.replace(new RegExp(String.fromCharCode(8220),"g"),"\""); 
    93 D=D.replace(new RegExp(String.fromCharCode(8221),"g"),"\""); 
    94 D=D.replace(new RegExp(String.fromCharCode(8222),"g"),"\""); 
    95 D=D.replace(new RegExp(String.fromCharCode(8223),"g"),"\""); 
    96 return D; 
    97 }; 
    98 SuperClean.filterFunctions.tidy=function(_1c,_1d){ 
    99 HTMLArea._postback(_1d.config.SuperClean.tidy_handler,{"content":_1c},function(_1e){ 
    100 eval(_1e); 
    101 }); 
    102 }; 
    103 SuperClean.prototype.onGenerate=function(){ 
    104 if(this.editor.config.SuperClean.show_dialog&&!this._dialog){ 
    105 this._dialog=new SuperClean.Dialog(this); 
    106 } 
    107 if(this.editor.config.tidy_handler){ 
    108 this.editor.config.SuperClean.tidy_handler=this.editor.config.tidy_handler; 
    109 this.editor.config.tidy_handler=null; 
    110 } 
    111 if(!this.editor.config.SuperClean.tidy_handler&&this.editor.config.filters.tidy){ 
    112 this.editor.config.filters.tidy=null; 
    113 } 
    114 var sc=this; 
    115 for(var _20 in this.editor.config.SuperClean.filters){ 
    116 if(!SuperClean.filterFunctions[_20]){ 
    117 var _21=this.editor.config.SuperClean.filters[_20]; 
    118 if(typeof _21.filterFunction!="undefined"){ 
    119 SuperClean.filterFunctions[_20]=filterFunction; 
    120 }else{ 
    121 HTMLArea._getback(_editor_url+"plugins/SuperClean/filters/"+_20+".js",function(_22){ 
    122 eval("SuperClean.filterFunctions."+_20+"="+_22+";"); 
    123 sc.onGenerate(); 
    124 }); 
    125 } 
    126 return; 
    127 } 
    128 } 
    129 }; 
    130 SuperClean.Dialog=function(_23){ 
    131 var _24=this; 
    132 this.Dialog_nxtid=0; 
    133 this.SuperClean=_23; 
    134 this.id={}; 
    135 this.ready=false; 
    136 this.files=false; 
    137 this.html=false; 
    138 this.dialog=false; 
    139 this._prepareDialog(); 
    140 }; 
    141 SuperClean.Dialog.prototype._prepareDialog=function(){ 
    142 var _25=this; 
    143 var _26=this.SuperClean; 
    144 if(this.html==false){ 
    145 HTMLArea._getback(_editor_url+"plugins/SuperClean/dialog.html",function(txt){ 
    146 _25.html=txt; 
    147 _25._prepareDialog(); 
    148 }); 
    149 return; 
    150 } 
    151 var _28=""; 
    152 for(var _29 in this.SuperClean.editor.config.SuperClean.filters){ 
    153 _28+="    <div>\n"; 
    154 var _2a=this.SuperClean.editor.config.SuperClean.filters[_29]; 
    155 if(typeof _2a.label=="undefined"){ 
    156 _28+="        <input type=\"checkbox\" name=\"["+_29+"]\" id=\"["+_29+"]\" checked />\n"; 
    157 _28+="        <label for=\"["+_29+"]\">"+this.SuperClean.editor.config.SuperClean.filters[_29]+"</label>\n"; 
    158 }else{ 
    159 _28+="        <input type=\"checkbox\" name=\"["+_29+"]\" id=\"["+_29+"]\" "+(_2a.checked?"checked":"")+" />\n"; 
    160 _28+="        <label for=\"["+_29+"]\">"+_2a.label+"</label>\n"; 
    161 } 
    162 _28+="    </div>\n"; 
    163 } 
    164 this.html=this.html.replace("<!--filters-->",_28); 
    165 var _2b=this.html; 
    166 var _2c=this.dialog=new HTMLArea.Dialog(_26.editor,this.html,"SuperClean"); 
    167 this.ready=true; 
    168 }; 
    169 SuperClean.Dialog.prototype._lc=SuperClean.prototype._lc; 
    170 SuperClean.Dialog.prototype.show=function(_2d,ok,_2f){ 
    171 if(!this.ready){ 
    172 var _30=this; 
    173 window.setTimeout(function(){ 
    174 _30.show(_2d,ok,_2f); 
    175 },100); 
    176 return; 
    177 } 
    178 var _31=this.dialog; 
    179 var _30=this; 
    180 if(ok){ 
    181 this.dialog.getElementById("ok").onclick=ok; 
    182 }else{ 
    183 this.dialog.getElementById("ok").onclick=function(){ 
    184 _30.hide(); 
    185 }; 
    186 } 
    187 if(_2f){ 
    188 this.dialog.getElementById("cancel").onclick=_2f; 
    189 }else{ 
    190 this.dialog.getElementById("cancel").onclick=function(){ 
    191 _30.hide(); 
    192 }; 
    193 } 
    194 this.SuperClean.editor.disableToolbar(["fullscreen","SuperClean"]); 
    195 this.dialog.show(_2d); 
    196 this.dialog.onresize(); 
    197 }; 
    198 SuperClean.Dialog.prototype.hide=function(){ 
    199 this.SuperClean.editor.enableToolbar(); 
    200 return this.dialog.hide(); 
    201 }; 
    202  
     12 
     13SuperClean._pluginInfo = 
     14{ 
     15  name     : "SuperClean", 
     16  version  : "1.0", 
     17  developer: "James Sleeman, Niko Sams", 
     18  developer_url: "http://www.gogo.co.nz/", 
     19  c_owner      : "Gogo Internet Services", 
     20  license      : "htmlArea", 
     21  sponsor      : "Gogo Internet Services", 
     22  sponsor_url  : "http://www.gogo.co.nz/" 
     23}; 
     24 
     25SuperClean.prototype._lc = function(string) { 
     26    return HTMLArea._lc(string, 'SuperClean'); 
     27}; 
     28 
     29/** superClean combines HTMLTidy, Word Cleaning and font stripping into a single function 
     30 *  it works a bit differently in how it asks for parameters */ 
     31 
     32SuperClean.prototype._superClean = function(opts, obj) 
     33{ 
     34  var superclean = this; 
     35 
     36  // Do the clean if we got options 
     37  var doOK = function() 
     38  { 
     39    var opts = superclean._dialog.hide(); 
     40    var editor = superclean.editor; 
     41 
     42    if(opts.word_clean) editor._wordClean(); 
     43    var D = editor.getInnerHTML(); 
     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, editor); 
     51      } 
     52    } 
     53 
     54    D = D.replace(/(style|class)="\s*"/gi, ''); 
     55    D = D.replace(/<(font|span)\s*>/gi, ''); 
     56 
     57    editor.setHTML(D); 
     58 
     59    if(opts.tidy) 
     60    { 
     61      HTMLArea._postback(editor.config.SuperClean.tidy_handler, {'content' : editor.getInnerHTML()}, 
     62                         function(javascriptResponse) { eval(javascriptResponse) }); 
     63    } 
     64    return true; 
     65  } 
     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  // You can either use 
     105  //    'filter_name' : "Label/Description String" 
     106  // or 'filter_name' : {label: "Label", checked: true/false, filterFunction: function(html) { ... return html;} } 
     107  // filterFunction in the second format above is optional. 
     108 
     109  'filters': { 'tidy': HTMLArea._lc('General tidy up and correction of some problems.', 'SuperClean'), 
     110               'word_clean': HTMLArea._lc('Clean bad HTML from Microsoft Word', 'SuperClean'), 
     111               'remove_faces': HTMLArea._lc('Remove custom typefaces (font "styles").', 'SuperClean'), 
     112               'remove_sizes': HTMLArea._lc('Remove custom font sizes.', 'SuperClean'), 
     113               'remove_colors': HTMLArea._lc('Remove custom text colors.', 'SuperClean'), 
     114               'remove_lang': HTMLArea._lc('Remove lang attributes.', 'SuperClean'), 
     115               'remove_fancy_quotes': {label:HTMLArea._lc('Replace directional quote marks with non-directional quote marks.', 'SuperClean'), checked:false} 
     116  //additional custom filters (defined in plugins/SuperClean/filters/word.js) 
     117               //'paragraph': 'remove paragraphs'}, 
     118               //'word': 'exteded Word-Filter' }, 
     119              }, 
     120  //if false all filters are applied, if true a dialog asks what filters should be used 
     121  'show_dialog': true 
     122}; 
     123 
     124SuperClean.filterFunctions = { }; 
     125SuperClean.filterFunctions.remove_colors = function(D) 
     126{ 
     127  D = D.replace(/color="?[^" >]*"?/gi, ''); 
     128  // { (stops jedit's fold breaking) 
     129  D = D.replace(/([^-])color:[^;}"']+;?/gi, '$1'); 
     130  return(D); 
     131}; 
     132SuperClean.filterFunctions.remove_sizes = function(D) 
     133{ 
     134  D = D.replace(/size="?[^" >]*"?/gi, ''); 
     135  // { (stops jedit's fold breaking) 
     136  D = D.replace(/font-size:[^;}"']+;?/gi, ''); 
     137  return(D); 
     138}; 
     139SuperClean.filterFunctions.remove_faces = function(D) 
     140{ 
     141  D = D.replace(/face="?[^" >]*"?/gi, ''); 
     142  // { (stops jedit's fold breaking) 
     143  D = D.replace(/font-family:[^;}"']+;?/gi, ''); 
     144  return(D); 
     145}; 
     146SuperClean.filterFunctions.remove_lang = function(D) 
     147{ 
     148  D = D.replace(/lang="?[^" >]*"?/gi, ''); 
     149  return(D); 
     150}; 
     151SuperClean.filterFunctions.word_clean = function(html, editor) 
     152{ 
     153  editor.setHTML(html); 
     154  editor._wordClean(); 
     155  return editor.getInnerHTML(); 
     156}; 
     157 
     158SuperClean.filterFunctions.remove_fancy_quotes = function(D) 
     159{ 
     160  D = D.replace(new RegExp(String.fromCharCode(8216),"g"),"'"); 
     161  D = D.replace(new RegExp(String.fromCharCode(8217),"g"),"'"); 
     162  D = D.replace(new RegExp(String.fromCharCode(8218),"g"),"'"); 
     163  D = D.replace(new RegExp(String.fromCharCode(8219),"g"),"'"); 
     164  D = D.replace(new RegExp(String.fromCharCode(8220),"g"),"\""); 
     165  D = D.replace(new RegExp(String.fromCharCode(8221),"g"),"\""); 
     166  D = D.replace(new RegExp(String.fromCharCode(8222),"g"),"\""); 
     167  D = D.replace(new RegExp(String.fromCharCode(8223),"g"),"\""); 
     168  return D; 
     169}; 
     170 
     171SuperClean.filterFunctions.tidy = function(html, editor) 
     172{ 
     173  HTMLArea._postback(editor.config.SuperClean.tidy_handler, {'content' : html}, 
     174                      function(javascriptResponse) { eval(javascriptResponse) }); 
     175}; 
     176 
     177 
     178 
     179SuperClean.prototype.onGenerate = function() 
     180{ 
     181  if(this.editor.config.SuperClean.show_dialog && !this._dialog) 
     182  { 
     183    this._dialog = new SuperClean.Dialog(this); 
     184  } 
     185  if(this.editor.config.tidy_handler) 
     186  { 
     187    //for backwards compatibility 
     188    this.editor.config.SuperClean.tidy_handler = this.editor.config.tidy_handler; 
     189    this.editor.config.tidy_handler = null; 
     190  } 
     191  if(!this.editor.config.SuperClean.tidy_handler && this.editor.config.filters.tidy) { 
     192    //unset tidy-filter if no tidy_handler 
     193    this.editor.config.filters.tidy = null; 
     194  } 
     195 
     196  var sc = this; 
     197  //load the filter-functions 
     198  for(var filter in this.editor.config.SuperClean.filters) 
     199  { 
     200    if(!SuperClean.filterFunctions[filter]) 
     201    { 
     202      var filtDetail = this.editor.config.SuperClean.filters[filter]; 
     203      if(typeof filtDetail.filterFunction != 'undefined') 
     204      { 
     205        SuperClean.filterFunctions[filter] = filterFunction; 
     206      } 
     207      else 
     208      { 
     209        HTMLArea._getback(_editor_url + 'plugins/SuperClean/filters/'+filter+'.js', 
     210                      function(func) { 
     211                        eval('SuperClean.filterFunctions.'+filter+'='+func+';'); 
     212                        sc.onGenerate(); 
     213                      }); 
     214      } 
     215      return; 
     216    } 
     217  } 
     218}; 
     219// Inline Dialog for SuperClean 
     220 
     221 
     222SuperClean.Dialog = function (SuperClean) 
     223{ 
     224  var  lDialog = this; 
     225  this.Dialog_nxtid = 0; 
     226  this.SuperClean = SuperClean; 
     227  this.id = { }; // This will be filled below with a replace, nifty 
     228 
     229  this.ready = false; 
     230  this.files  = false; 
     231  this.html   = false; 
     232  this.dialog = false; 
     233 
     234  // load the dTree script 
     235  this._prepareDialog(); 
     236 
     237}; 
     238 
     239SuperClean.Dialog.prototype._prepareDialog = function() 
     240{ 
     241  var lDialog = this; 
     242  var SuperClean = this.SuperClean; 
     243 
     244  if(this.html == false) 
     245  { 
     246    HTMLArea._getback(_editor_url + 'plugins/SuperClean/dialog.html', function(txt) { lDialog.html = txt; lDialog._prepareDialog(); }); 
     247    return; 
     248  } 
     249 
     250  var htmlFilters = ""; 
     251  for(var filter in this.SuperClean.editor.config.SuperClean.filters) 
     252  { 
     253    htmlFilters += "    <div>\n"; 
     254    var filtDetail = this.SuperClean.editor.config.SuperClean.filters[filter]; 
     255    if(typeof filtDetail.label == 'undefined') 
     256    { 
     257      htmlFilters += "        <input type=\"checkbox\" name=\"["+filter+"]\" id=\"["+filter+"]\" checked />\n"; 
     258      htmlFilters += "        <label for=\"["+filter+"]\">"+this.SuperClean.editor.config.SuperClean.filters[filter]+"</label>\n"; 
     259    } 
     260    else 
     261    { 
     262      htmlFilters += "        <input type=\"checkbox\" name=\"["+filter+"]\" id=\"["+filter+"]\" " + (filtDetail.checked ? "checked" : "") + " />\n"; 
     263      htmlFilters += "        <label for=\"["+filter+"]\">"+filtDetail.label+"</label>\n"; 
     264    } 
     265    htmlFilters += "    </div>\n"; 
     266  } 
     267  this.html = this.html.replace('<!--filters-->', htmlFilters); 
     268 
     269  var html = this.html; 
     270 
     271  // Now we have everything we need, so we can build the dialog. 
     272  var dialog = this.dialog = new HTMLArea.Dialog(SuperClean.editor, this.html, 'SuperClean'); 
     273 
     274  this.ready = true; 
     275}; 
     276 
     277SuperClean.Dialog.prototype._lc = SuperClean.prototype._lc; 
     278 
     279SuperClean.Dialog.prototype.show = function(inputs, ok, cancel) 
     280{ 
     281  if(!this.ready) 
     282  { 
     283    var lDialog = this; 
     284    window.setTimeout(function() {lDialog.show(inputs,ok,cancel);},100); 
     285    return; 
     286  } 
     287 
     288  // Connect the OK and Cancel buttons 
     289  var dialog = this.dialog; 
     290  var lDialog = this; 
     291  if(ok) 
     292  { 
     293    this.dialog.getElementById('ok').onclick = ok; 
     294  } 
     295  else 
     296  { 
     297    this.dialog.getElementById('ok').onclick = function() {lDialog.hide();}; 
     298  } 
     299 
     300  if(cancel) 
     301  { 
     302    this.dialog.getElementById('cancel').onclick = cancel; 
     303  } 
     304  else 
     305  { 
     306    this.dialog.getElementById('cancel').onclick = function() { lDialog.hide()}; 
     307  } 
     308 
     309  // Show the dialog 
     310  this.SuperClean.editor.disableToolbar(['fullscreen','SuperClean']); 
     311 
     312  this.dialog.show(inputs); 
     313 
     314  // Init the sizes 
     315  this.dialog.onresize(); 
     316}; 
     317 
     318SuperClean.Dialog.prototype.hide = function() 
     319{ 
     320  this.SuperClean.editor.enableToolbar(); 
     321  return this.dialog.hide(); 
     322}; 
Note: See TracChangeset for help on using the changeset viewer.