2005-09-30 02:25:07 +00:00
// Make our right side panel and insert appropriatly
function SuperClean ( editor , args )
{
this . editor = editor ;
var superclean = this ;
editor . _superclean _on = false ;
2005-12-07 03:37:36 +00:00
editor . config . registerButton ( 'superclean' , this . _lc ( "Clean up HTML" ) , editor . imgURL ( 'ed_superclean.gif' , 'SuperClean' ) , true , function ( e , objname , obj ) { superclean . _superClean ( null , obj ) ; } ) ;
2005-09-30 02:25:07 +00:00
// See if we can find 'killword' and replace it with superclean
editor . config . addToolbarElement ( "superclean" , "killword" , 0 ) ;
}
SuperClean . _pluginInfo =
{
name : "SuperClean" ,
version : "1.0" ,
2005-12-07 03:37:36 +00:00
developer : "James Sleeman, Niko Sams" ,
2005-09-30 02:25:07 +00:00
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/"
} ;
SuperClean . prototype . _lc = function ( string ) {
return HTMLArea . _lc ( string , 'SuperClean' ) ;
2005-12-07 03:37:36 +00:00
} ;
2005-09-30 02:25:07 +00:00
/ * * s u p e r C l e a n c o m b i n e s H T M L T i d y , W o r d C l e a n i n g a n d f o n t s t r i p p i n g i n t o a s i n g l e f u n c t i o n
* it works a bit differently in how it asks for parameters * /
SuperClean . prototype . _superClean = function ( opts , obj )
{
var superclean = this ;
// Do the clean if we got options
var doOK = function ( )
{
var opts = superclean . _dialog . hide ( ) ;
var editor = superclean . editor ;
if ( opts . word _clean ) editor . _wordClean ( ) ;
var D = editor . getInnerHTML ( ) ;
2005-12-07 03:37:36 +00:00
for ( var filter in editor . config . SuperClean . filters )
2005-09-30 02:25:07 +00:00
{
2005-12-07 03:37:36 +00:00
if ( filter == 'tidy' || filter == 'word_clean' ) continue ;
if ( opts [ filter ] )
{
D = SuperClean . filterFunctions [ filter ] ( D ) ;
}
2005-09-30 02:25:07 +00:00
}
D = D . replace ( /(style|class)="\s*"/gi , '' ) ;
D = D . replace ( /<(font|span)\s*>/gi , '' ) ;
2005-12-07 03:37:36 +00:00
2005-09-30 02:25:07 +00:00
editor . setHTML ( D ) ;
2005-12-07 03:37:36 +00:00
if ( opts . tidy )
2005-09-30 02:25:07 +00:00
{
2005-12-07 03:37:36 +00:00
HTMLArea . _postback ( editor . config . SuperClean . tidy _handler , { 'content' : editor . getInnerHTML ( ) } ,
2005-09-30 02:25:07 +00:00
function ( javascriptResponse ) { eval ( javascriptResponse ) } ) ;
}
return true ;
}
2005-12-07 03:37:36 +00:00
if ( this . editor . config . SuperClean . show _dialog )
{
var inputs = { } ;
this . _dialog . show ( inputs , doOK ) ;
}
else
{
var editor = this . editor ;
var html = editor . getInnerHTML ( ) ;
for ( var filter in editor . config . SuperClean . filters )
{
if ( filter == 'tidy' ) continue ; //call tidy last
html = SuperClean . filterFunctions [ filter ] ( html , editor ) ;
}
html = html . replace ( /(style|class)="\s*"/gi , '' ) ;
html = html . replace ( /<(font|span)\s*>/gi , '' ) ;
editor . setHTML ( html ) ;
if ( editor . config . SuperClean . filters . tidy )
{
SuperClean . filterFunctions . tidy ( html , editor ) ;
}
}
} ;
HTMLArea . Config . prototype . SuperClean =
{
// set to the URL of a handler for html tidy, this handler
// (see tidy.php for an example) must that a single post variable
// "content" which contains the HTML to tidy, and return javascript like
// editor.setHTML('<strong>Tidied Html</strong>')
// it's called through XMLHTTPRequest
'tidy_handler' : _editor _url + 'plugins/SuperClean/tidy.php' ,
//avaliable filters (these are built-in filters)
'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' )
//additional custom filters (defined in plugins/SuperClean/filters/word.js)
//'paragraph': 'remove paragraphs'},
//'word': 'exteded Word-Filter' },
} ,
//if false all filters are applied, if true a dialog asks what filters should be used
'show_dialog' : true
} ;
SuperClean . filterFunctions = { } ;
SuperClean . filterFunctions . remove _colors = function ( D )
{
D = D . replace ( /color="?[^" >]*"?/gi , '' ) ;
// { (stops jedit's fold breaking)
D = D . replace ( /([^-])color:[^;}"']+;?/gi , '$1' ) ;
return ( D ) ;
} ;
SuperClean . filterFunctions . remove _sizes = function ( D )
{
D = D . replace ( /size="?[^" >]*"?/gi , '' ) ;
// { (stops jedit's fold breaking)
D = D . replace ( /font-size:[^;}"']+;?/gi , '' ) ;
return ( D ) ;
} ;
SuperClean . filterFunctions . remove _faces = function ( D )
{
D = D . replace ( /face="?[^" >]*"?/gi , '' ) ;
// { (stops jedit's fold breaking)
D = D . replace ( /font-family:[^;}"']+;?/gi , '' ) ;
return ( D ) ;
} ;
SuperClean . filterFunctions . remove _lang = function ( D )
{
D = D . replace ( /lang="?[^" >]*"?/gi , '' ) ;
return ( D ) ;
} ;
SuperClean . filterFunctions . word _clean = function ( html , editor )
{
editor . setHTML ( html ) ;
editor . _wordClean ( ) ;
return editor . getInnerHTML ( ) ;
} ;
SuperClean . filterFunctions . tidy = function ( html , editor )
{
HTMLArea . _postback ( editor . config . SuperClean . tidy _handler , { 'content' : html } ,
function ( javascriptResponse ) { eval ( javascriptResponse ) } ) ;
} ;
2005-09-30 02:25:07 +00:00
SuperClean . prototype . onGenerate = function ( )
{
2005-12-07 03:37:36 +00:00
if ( this . editor . config . SuperClean . show _dialog && ! this . _dialog )
{
this . _dialog = new SuperClean . Dialog ( this ) ;
}
if ( this . editor . config . tidy _handler )
{
//for backwards compatibility
this . editor . config . SuperClean . tidy _handler = this . editor . config . tidy _handler ;
this . editor . config . tidy _handler = null ;
}
if ( ! this . editor . config . SuperClean . tidy _handler && this . editor . config . filters . tidy ) {
//unset tidy-filter if no tidy_handler
this . editor . config . filters . tidy = null ;
}
var sc = this ;
//load the filter-functions
for ( var filter in this . editor . config . SuperClean . filters )
{
if ( ! SuperClean . filterFunctions [ filter ] )
{
HTMLArea . _getback ( _editor _url + 'plugins/SuperClean/filters/' + filter + '.js' ,
function ( func ) {
eval ( 'SuperClean.filterFunctions.' + filter + '=' + func + ';' ) ;
sc . onGenerate ( ) ;
} ) ;
return ;
}
}
} ;
2005-09-30 02:25:07 +00:00
// Inline Dialog for SuperClean
SuperClean . Dialog = function ( SuperClean )
{
var lDialog = this ;
this . Dialog _nxtid = 0 ;
this . SuperClean = SuperClean ;
this . id = { } ; // This will be filled below with a replace, nifty
this . ready = false ;
this . files = false ;
this . html = false ;
this . dialog = false ;
// load the dTree script
this . _prepareDialog ( ) ;
2005-12-07 03:37:36 +00:00
} ;
2005-09-30 02:25:07 +00:00
SuperClean . Dialog . prototype . _prepareDialog = function ( )
{
var lDialog = this ;
var SuperClean = this . SuperClean ;
if ( this . html == false )
{
HTMLArea . _getback ( _editor _url + 'plugins/SuperClean/dialog.html' , function ( txt ) { lDialog . html = txt ; lDialog . _prepareDialog ( ) ; } ) ;
return ;
}
2005-12-07 03:37:36 +00:00
var htmlFilters = "" ;
for ( var filter in this . SuperClean . editor . config . SuperClean . filters )
{
htmlFilters += " <div>\n" ;
htmlFilters += " <input type=\"checkbox\" name=\"[" + filter + "]\" id=\"[" + filter + "]\" checked />\n" ;
htmlFilters += " <label for=\"[" + filter + "]\">" + this . SuperClean . editor . config . SuperClean . filters [ filter ] + "</label>\n" ;
htmlFilters += " </div>\n" ;
}
this . html = this . html . replace ( '<!--filters-->' , htmlFilters ) ;
2005-09-30 02:25:07 +00:00
var html = this . html ;
// Now we have everything we need, so we can build the dialog.
var dialog = this . dialog = new HTMLArea . Dialog ( SuperClean . editor , this . html , 'SuperClean' ) ;
this . ready = true ;
2005-12-07 03:37:36 +00:00
} ;
2005-09-30 02:25:07 +00:00
SuperClean . Dialog . prototype . _lc = SuperClean . prototype . _lc ;
SuperClean . Dialog . prototype . show = function ( inputs , ok , cancel )
{
if ( ! this . ready )
{
var lDialog = this ;
window . setTimeout ( function ( ) { lDialog . show ( inputs , ok , cancel ) ; } , 100 ) ;
return ;
}
// Connect the OK and Cancel buttons
var dialog = this . dialog ;
var lDialog = this ;
if ( ok )
{
this . dialog . getElementById ( 'ok' ) . onclick = ok ;
}
else
{
this . dialog . getElementById ( 'ok' ) . onclick = function ( ) { lDialog . hide ( ) ; } ;
}
if ( cancel )
{
this . dialog . getElementById ( 'cancel' ) . onclick = cancel ;
}
else
{
this . dialog . getElementById ( 'cancel' ) . onclick = function ( ) { lDialog . hide ( ) } ;
}
// Show the dialog
this . SuperClean . editor . disableToolbar ( [ 'fullscreen' , 'SuperClean' ] ) ;
this . dialog . show ( inputs ) ;
// Init the sizes
this . dialog . onresize ( ) ;
2005-12-07 03:37:36 +00:00
} ;
2005-09-30 02:25:07 +00:00
SuperClean . Dialog . prototype . hide = function ( )
{
this . SuperClean . editor . enableToolbar ( ) ;
return this . dialog . hide ( ) ;
2005-12-07 03:37:36 +00:00
} ;