Changeset 151 for trunk/plugins/SuperClean
- Timestamp:
- 05/11/05 08:21:14 (15 years ago)
- Location:
- trunk/plugins/SuperClean
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/plugins/SuperClean/super-clean.js
r135 r151 3 3 { 4 4 this.editor = editor; 5 var superclean = this; 5 6 editor._superclean_on = false; 6 editor.config.registerButton('superclean', this._lc("Clean Up HTML"), editor.imgURL('ed_superclean.gif', 'SuperClean'), true, function(e, objname, obj) { e._superClean(null, obj); });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); }); 7 8 8 9 // See if we can find 'killword' and replace it with superclean … … 29 30 * it works a bit differently in how it asks for parameters */ 30 31 31 HTMLArea.prototype._superClean = function(opts, obj)32 SuperClean.prototype._superClean = function(opts, obj) 32 33 { 33 var editor= this;34 var superclean = this; 34 35 35 36 // Do the clean if we got options 36 if(opts)37 var doOK = function() 37 38 { 38 if(opts.word_clean) this._wordClean(); 39 var D = this.getInnerHTML(); 39 debugger; 40 var opts = superclean._dialog.hide(); 41 var editor = superclean.editor; 42 43 if(opts.word_clean) editor._wordClean(); 44 var D = editor.getInnerHTML(); 40 45 if(opts.faces) 41 46 { … … 61 66 D = D.replace(/(style|class)="\s*"/gi, ''); 62 67 D = D.replace(/<(font|span)\s*>/gi, ''); 63 this.setHTML(D);68 editor.setHTML(D); 64 69 65 if( this.config.tidy_handler && opts.tidy)70 if(editor.config.tidy_handler && opts.tidy) 66 71 { 67 HTMLArea._postback( this.config.tidy_handler, {'content' : this.getInnerHTML()},72 HTMLArea._postback(editor.config.tidy_handler, {'content' : editor.getInnerHTML()}, 68 73 function(javascriptResponse) { eval(javascriptResponse) }); 69 74 } 70 75 return true; 71 76 } 72 73 // If already cleaning, then cancel it 74 if(editor._superclean_on) 75 { 76 editor._superclean_on.click(); 77 return true; 78 } 79 80 // Otherwise ask for options 81 var frm = document.createElement('div'); 82 frm.style.backgroundColor='window'; 83 frm.style.width = this._iframe.style.width; 84 frm.style.height = this._iframe.style.height; 85 86 var win = document.createElement('div'); 87 win.style.padding = '5px'; 88 frm.appendChild(win); 89 90 win.appendChild(document.createTextNode(HTMLArea._lc("Please select from the following cleaning options...", "SuperClean"))); 91 92 if(this.config.tidy_handler) 93 { 94 var div = document.createElement('div'); 95 var lab = document.createElement('label'); 96 var cb = document.createElement('input'); 97 cb.setAttribute('type', 'checkbox'); 98 cb.setAttribute('name', 'tidy'); 99 lab.appendChild(cb); 100 lab.appendChild(document.createTextNode(HTMLArea._lc("General tidy up and correction of some problems.", "SuperClean"))); 101 div.appendChild(lab); 102 win.appendChild(div); 103 } 104 105 var div = document.createElement('div'); 106 var lab = document.createElement('label'); 107 var cb = document.createElement('input'); 108 cb.setAttribute('type', 'checkbox'); 109 cb.setAttribute('name', 'word_clean'); 110 lab.appendChild(cb); 111 lab.appendChild(document.createTextNode(HTMLArea._lc("Clean bad HTML from Microsoft Word", "SuperClean"))); 112 div.appendChild(lab); 113 win.appendChild(div); 114 115 var div = document.createElement('div'); 116 var lab = document.createElement('label'); 117 var cb = document.createElement('input'); 118 cb.setAttribute('type', 'checkbox'); 119 cb.setAttribute('name', 'faces'); 120 lab.appendChild(cb); 121 lab.appendChild(document.createTextNode(HTMLArea._lc('Remove custom typefaces (font "styles").', "SuperClean"))); 122 div.appendChild(lab); 123 win.appendChild(div); 124 125 var div = document.createElement('div'); 126 var lab = document.createElement('label'); 127 var cb = document.createElement('input'); 128 cb.setAttribute('type', 'checkbox'); 129 cb.setAttribute('name', 'sizes'); 130 lab.appendChild(cb); 131 lab.appendChild(document.createTextNode(HTMLArea._lc('Remove custom font sizes.', "SuperClean"))); 132 div.appendChild(lab); 133 win.appendChild(div); 134 135 var div = document.createElement('div'); 136 var lab = document.createElement('label'); 137 var cb = document.createElement('input'); 138 cb.setAttribute('type', 'checkbox'); 139 cb.setAttribute('name', 'colors'); 140 lab.appendChild(cb); 141 lab.appendChild(document.createTextNode(HTMLArea._lc('Remove custom text colors.', "SuperClean"))); 142 div.appendChild(lab); 143 win.appendChild(div); 144 145 var div = document.createElement('div'); 146 div.style.textAlign = 'center'; 147 var but = document.createElement('input'); 148 but.setAttribute('type', 'button'); 149 but.setAttribute('value', HTMLArea._lc('Go', "SuperClean")); 150 151 152 // We want it in text mode when we do the clean. 153 var modeWhenDone = this._editMode; 154 if(this._editMode != 'textmode') 155 { 156 this.setMode('textmode'); 157 } 158 159 // But we don't want to see the textarea 160 this._textArea.style.display = 'none'; 161 162 but.onclick = function() 163 { 164 f = frm; 165 var elms = f.getElementsByTagName('input'); 166 cfg = { }; 167 for(var i = 0; i < elms.length; i++) 168 { 169 if(elms[i].getAttribute('type') == 'checkbox') 170 { 171 cfg[elms[i].getAttribute('name')] = elms[i].checked; 172 } 173 } 174 175 editor._superClean(cfg, obj); 176 editor._textArea.style.display = ''; 177 if(editor._editMode != modeWhenDone) 178 { 179 editor.setMode(modeWhenDone); 180 editor.updateToolbar(); 181 } 182 editor._superclean_on = false; 183 frm.parentNode.removeChild(frm); 184 } 185 div.appendChild(but); 186 187 var but = document.createElement('input'); 188 but.setAttribute('type', 'button'); 189 but.setAttribute('value', HTMLArea._lc('Cancel', "SuperClean")); 190 but.onclick = function() 191 { 192 editor._textArea.style.display = ''; 193 if(editor._editMode != modeWhenDone) 194 { 195 editor.setMode(modeWhenDone); 196 editor.updateToolbar(); 197 } 198 editor._superclean_on = false; 199 frm.parentNode.removeChild(frm); 200 201 } 202 div.appendChild(but); 203 win.appendChild(div); 204 editor._superclean_on = but; 205 206 this._textArea.parentNode.insertBefore( frm, this._textArea ); 77 var inputs = {}; 78 this._dialog.show(inputs, doOK); 207 79 } 208 80 … … 217 89 218 90 91 SuperClean.prototype.onGenerate = function() 92 { 93 this._dialog = new SuperClean.Dialog(this); 94 } 95 // Inline Dialog for SuperClean 219 96 97 98 SuperClean.Dialog = function (SuperClean) 99 { 100 var lDialog = this; 101 this.Dialog_nxtid = 0; 102 this.SuperClean = SuperClean; 103 this.id = { }; // This will be filled below with a replace, nifty 104 105 this.ready = false; 106 this.files = false; 107 this.html = false; 108 this.dialog = false; 109 110 // load the dTree script 111 this._prepareDialog(); 112 113 } 114 115 SuperClean.Dialog.prototype._prepareDialog = function() 116 { 117 var lDialog = this; 118 var SuperClean = this.SuperClean; 119 120 if(this.html == false) 121 { 122 HTMLArea._getback(_editor_url + 'plugins/SuperClean/dialog.html', function(txt) { lDialog.html = txt; lDialog._prepareDialog(); }); 123 return; 124 } 125 var html = this.html; 126 127 // Now we have everything we need, so we can build the dialog. 128 var dialog = this.dialog = new HTMLArea.Dialog(SuperClean.editor, this.html, 'SuperClean'); 129 130 this.ready = true; 131 } 132 133 SuperClean.Dialog.prototype._lc = SuperClean.prototype._lc; 134 135 SuperClean.Dialog.prototype.show = function(inputs, ok, cancel) 136 { 137 if(!this.ready) 138 { 139 var lDialog = this; 140 window.setTimeout(function() {lDialog.show(inputs,ok,cancel);},100); 141 return; 142 } 143 144 if(!this.SuperClean.editor.config.tidy_handler) { 145 this.dialog.getElementById('divTidy').style.display = 'none'; 146 } 147 148 // Connect the OK and Cancel buttons 149 var dialog = this.dialog; 150 var lDialog = this; 151 if(ok) 152 { 153 this.dialog.getElementById('ok').onclick = ok; 154 } 155 else 156 { 157 this.dialog.getElementById('ok').onclick = function() {lDialog.hide();}; 158 } 159 160 if(cancel) 161 { 162 this.dialog.getElementById('cancel').onclick = cancel; 163 } 164 else 165 { 166 this.dialog.getElementById('cancel').onclick = function() { lDialog.hide()}; 167 } 168 169 // Show the dialog 170 this.SuperClean.editor.disableToolbar(['fullscreen','SuperClean']); 171 172 this.dialog.show(inputs); 173 174 // Init the sizes 175 this.dialog.onresize(); 176 } 177 178 SuperClean.Dialog.prototype.hide = function() 179 { 180 this.SuperClean.editor.enableToolbar(); 181 return this.dialog.hide(); 182 }
Note: See TracChangeset
for help on using the changeset viewer.