| 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 | } |
| 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 | |
| | 94 | HTMLArea.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 | |
| | 117 | SuperClean.filterFunctions = { }; |
| | 118 | SuperClean.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 | }; |
| | 125 | SuperClean.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 | }; |
| | 132 | SuperClean.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 | }; |
| | 139 | SuperClean.filterFunctions.word_clean = function(html, editor) |
| | 140 | { |
| | 141 | editor.setHTML(html); |
| | 142 | editor._wordClean(); |
| | 143 | return editor.getInnerHTML(); |
| | 144 | }; |
| | 145 | SuperClean.filterFunctions.tidy = function(html, editor) |
| | 146 | { |
| | 147 | HTMLArea._postback(editor.config.SuperClean.tidy_handler, {'content' : html}, |
| | 148 | function(javascriptResponse) { eval(javascriptResponse) }); |
| | 149 | }; |
| | 150 | |
| 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 | } |