Changeset 1011 for branches/new-dialogs-merge/plugins
- Timestamp:
- 06/07/08 09:08:53 (4 years ago)
- Location:
- branches/new-dialogs-merge/plugins
- Files:
-
- 3 modified
- 2 copied
-
Linker/linker.js (modified) (1 diff)
-
Linker/pluginMethods.js (copied) (copied from branches/new-dialogs-merge/plugins/Linker/linker.js) (5 diffs)
-
PasteText/paste-text.js (modified) (3 diffs)
-
SuperClean/pluginMethods.js (copied) (copied from branches/new-dialogs-merge/plugins/SuperClean/super-clean.js) (13 diffs)
-
SuperClean/super-clean.js (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/new-dialogs-merge/plugins/Linker/linker.js
r1007 r1011 51 51 }; 52 52 53 Linker.prototype._createLink = function(a)54 {55 if(!a && this.editor.selectionEmpty(this.editor.getSelection()))56 {57 alert(this._lc("You must select some text before making a new link."));58 return false;59 }60 61 var inputs =62 {63 type: 'url',64 href: 'http://www.example.com/',65 target: '',66 p_width: '',67 p_height: '',68 p_options: ['menubar=no','toolbar=yes','location=no','status=no','scrollbars=yes','resizeable=yes'],69 to: 'alice@example.com',70 subject: '',71 body: '',72 anchor: ''73 };74 75 if(a && a.tagName.toLowerCase() == 'a')76 {77 var href =this.editor.fixRelativeLinks(a.getAttribute('href'));78 var m = href.match(/^mailto:(.*@[^?&]*)(\?(.*))?$/);79 var anchor = href.match(/^#(.*)$/);80 81 if(m)82 {83 // Mailto84 inputs.type = 'mailto';85 inputs.to = m[1];86 if(m[3])87 {88 var args = m[3].split('&');89 for(var x = 0; x<args.length; x++)90 {91 var j = args[x].match(/(subject|body)=(.*)/);92 if(j)93 {94 inputs[j[1]] = decodeURIComponent(j[2]);95 }96 }97 }98 }99 else if (anchor)100 {101 //Anchor-Link102 inputs.type = 'anchor';103 inputs.anchor = anchor[1];104 105 }106 else107 {108 109 110 if(a.getAttribute('onclick'))111 {112 var m = a.getAttribute('onclick').match(/window\.open\(\s*this\.href\s*,\s*'([a-z0-9_]*)'\s*,\s*'([a-z0-9_=,]*)'\s*\)/i);113 114 // Popup Window115 inputs.href = href ? href : '';116 inputs.target = 'popup';117 inputs.p_name = m[1];118 inputs.p_options = [ ];119 120 121 var args = m[2].split(',');122 for(var x = 0; x < args.length; x++)123 {124 var i = args[x].match(/(width|height)=([0-9]+)/);125 if(i)126 {127 inputs['p_' + i[1]] = parseInt(i[2]);128 }129 else130 {131 inputs.p_options.push(args[x]);132 }133 }134 }135 else136 {137 // Normal138 inputs.href = href;139 inputs.target = a.target;140 }141 }142 }143 144 var linker = this;145 146 // If we are not editing a link, then we need to insert links now using execCommand147 // because for some reason IE is losing the selection between now and when doOK is148 // complete. I guess because we are defocusing the iframe when we click stuff in the149 // linker dialog.150 151 this.a = a; // Why doesn't a get into the closure below, but if I set it as a property then it's fine?152 153 var doOK = function()154 {155 //if(linker.a) alert(linker.a.tagName);156 var a = linker.a;157 158 var values = linker._dialog.hide();159 var atr =160 {161 href: '',162 target:'',163 title:'',164 onclick:''165 };166 167 if(values.type == 'url')168 {169 if(values.href)170 {171 atr.href = values.href;172 atr.target = values.target;173 if(values.target == 'popup')174 {175 176 if(values.p_width)177 {178 values.p_options.push('width=' + values.p_width);179 }180 if(values.p_height)181 {182 values.p_options.push('height=' + values.p_height);183 }184 atr.onclick = 'if(window.parent && window.parent.Xinha){return false}window.open(this.href, \'' + (values.p_name.replace(/[^a-z0-9_]/i, '_')) + '\', \'' + values.p_options.join(',') + '\');return false;';185 }186 }187 }188 else if(values.type == 'anchor')189 {190 if(values.anchor)191 {192 atr.href = values.anchor.value;193 }194 }195 else196 {197 if(values.to)198 {199 atr.href = 'mailto:' + values.to;200 if(values.subject) atr.href += '?subject=' + encodeURIComponent(values.subject);201 if(values.body) atr.href += (values.subject ? '&' : '?') + 'body=' + encodeURIComponent(values.body);202 }203 }204 205 if(a && a.tagName.toLowerCase() == 'a')206 {207 if(!atr.href)208 {209 if(confirm(linker._dialog._lc('Are you sure you wish to remove this link?')))210 {211 var p = a.parentNode;212 while(a.hasChildNodes())213 {214 p.insertBefore(a.removeChild(a.childNodes[0]), a);215 }216 p.removeChild(a);217 linker.editor.updateToolbar();218 return;219 }220 }221 else222 {223 // Update the link224 for(var i in atr)225 {226 a.setAttribute(i, atr[i]);227 }228 229 // If we change a mailto link in IE for some hitherto unknown230 // reason it sets the innerHTML of the link to be the231 // href of the link. Stupid IE.232 if(Xinha.is_ie)233 {234 if(/mailto:([^?<>]*)(\?[^<]*)?$/i.test(a.innerHTML))235 {236 a.innerHTML = RegExp.$1;237 }238 }239 }240 }241 else242 {243 if(!atr.href) return true;244 245 // Insert a link, we let the browser do this, we figure it knows best246 var tmp = Xinha.uniq('http://www.example.com/Link');247 linker.editor._doc.execCommand('createlink', false, tmp);248 249 // Fix them up250 var anchors = linker.editor._doc.getElementsByTagName('a');251 for(var i = 0; i < anchors.length; i++)252 {253 var anchor = anchors[i];254 if(anchor.href == tmp)255 {256 // Found one.257 if (!a) a = anchor;258 for(var j in atr)259 {260 anchor.setAttribute(j, atr[j]);261 }262 }263 }264 }265 linker.editor.selectNodeContents(a);266 linker.editor.updateToolbar();267 };268 269 this._dialog.show(inputs, doOK);270 271 };272 273 Linker.prototype._getSelectedAnchor = function()274 {275 var sel = this.editor.getSelection();276 var rng = this.editor.createRange(sel);277 var a = this.editor.activeElement(sel);278 if(a != null && a.tagName.toLowerCase() == 'a')279 {280 return a;281 }282 else283 {284 a = this.editor._getFirstAncestor(sel, 'a');285 if(a != null)286 {287 return a;288 }289 }290 return null;291 };292 53 293 54 Linker.prototype.onGenerateOnce = function() 294 55 { 295 this._dialog = new Linker.Dialog(this); 56 Linker.loadAssets(); 57 this.loadFiles(); 296 58 }; 297 // Inline Dialog for Linker 59 60 Linker.prototype.onUpdateToolbar = function() 61 { 62 if (typeof dTree == 'undefined' || !Linker.methodsReady || !Linker.html || !this.files) 63 { 64 this.editor._toolbarObjects.createlink.state("enabled", false); 65 } 66 else this.onUpdateToolbar = null; 67 }; 298 68 299 69 Linker.Dialog_dTrees = [ ]; 300 70 71 Linker.loadAssets = function() 72 { 73 var self = Linker; 74 if (self.loading) return; 75 self.loading = true; 76 Xinha._getback(Xinha.getPluginDir("Linker") + '/pluginMethods.js', function(getback) { eval(getback); self.methodsReady = true; }); 77 Xinha._loadback( Xinha.getPluginDir("Linker") + '/dTree/dtree.js', function() {Linker.dTreeReady = true; } ); 78 Xinha._getback( Xinha.getPluginDir("Linker") + '/dialog.html', function(getback) { self.html = getback; } ); 79 } 301 80 302 Linker. Dialog = function (linker)81 Linker.prototype.loadFiles = function() 303 82 { 304 var lDialog = this; 305 this.Dialog_nxtid = 0; 306 this.linker = linker; 307 this.id = { }; // This will be filled below with a replace, nifty 308 309 this.ready = false; 310 this.files = false; 311 this.html = false; 312 this.dialog = false; 313 314 // load the dTree script 315 this._prepareDialog(); 316 317 }; 318 319 Linker.Dialog.prototype._prepareDialog = function() 320 { 321 var lDialog = this; 322 var linker = this.linker; 323 324 // We load some stuff up int he background, recalling this function 325 // when they have loaded. This is to keep the editor responsive while 326 // we prepare the dialog. 327 if(typeof dTree == 'undefined') 328 { 329 this.linker.editor.setLoadingMessage('Loading Tree script'); 330 Xinha._loadback(Xinha.getPluginDir("Linker") + '/dTree/dtree.js', 331 function() {lDialog._prepareDialog(); } 332 ); 333 return; 334 } 335 336 if(this.files === false) 337 { 83 var linker = this; 338 84 if(linker.lConfig.backend) 339 85 { 340 86 //get files from backend 341 this.linker.editor.setLoadingMessage('Loading files from backend');342 87 Xinha._postback(linker.lConfig.backend, 343 88 linker.lConfig.backend_data, 344 89 function(txt) { 345 90 try { 346 l Dialog.files = eval(txt);91 linker.files = eval(txt); 347 92 } catch(Error) { 348 l Dialog.files = [ {url:'',title:Error.toString()} ];93 linker.files = [ {url:'',title:Error.toString()} ]; 349 94 } 350 lDialog._prepareDialog();});95 }); 351 96 } 352 97 else if(linker.lConfig.files != null) 353 98 { 354 99 //get files from plugin-config 355 lDialog.files = linker.lConfig.files; 356 lDialog._prepareDialog(); 100 linker.files = linker.lConfig.files; 357 101 } 358 return; 359 } 360 var files = this.files; 361 362 if(this.html == false) 363 { 364 Xinha._getback(Xinha.getPluginDir("Linker") + '/dialog.html', function(txt) { lDialog.html = txt; lDialog._prepareDialog(); }); 365 return; 366 } 367 var html = this.html; 368 369 // Now we have everything we need, so we can build the dialog. 370 var dialog = this.dialog = new Xinha.Dialog(linker.editor, this.html, 'Linker',{width:600,height:400}); 371 var dTreeName = Xinha.uniq('dTree_'); 372 373 this.dTree = new dTree(dTreeName, Xinha.getPluginDir("Linker") + '/dTree/'); 374 eval(dTreeName + ' = this.dTree'); 375 376 this.dTree.add(this.Dialog_nxtid++, -1, linker.lConfig.treeCaption , null, linker.lConfig.treeCaption); 377 this.makeNodes(files, 0); 378 379 // Put it in 380 var ddTree = this.dialog.getElementById('dTree'); 381 //ddTree.innerHTML = this.dTree.toString(); 382 ddTree.innerHTML = ''; 383 // ddTree.style.position = 'absolute'; 384 // ddTree.style.left = 1 + 'px'; 385 // ddTree.style.top = 0 + 'px'; 386 ddTree.style.overflow = 'auto'; 387 ddTree.style.height = '300px'; 388 if ( Xinha.is_ie ) 389 { 390 ddTree.style.styleFloat = "left"; 391 } 392 else 393 { 394 ddTree.style.cssFloat = "left"; 395 } 396 ddTree.style.backgroundColor = 'white'; 397 this.ddTree = ddTree; 398 399 this.dTree._linker_premade = this.dTree.toString(); 400 401 var options = this.dialog.getElementById('options'); 402 //options.style.position = 'absolute'; 403 //options.style.top = 0 + 'px'; 404 //options.style.right = 0 + 'px'; 405 options.style.width = 320 + 'px'; 406 options.style.overflow = 'auto'; 407 408 // Hookup the resizer 409 this.dialog.rootElem.style.paddingBottom ="0"; 410 this.dialog.onresize = function() 411 { 412 var h = parseInt(dialog.height) - dialog.getElementById('h1').offsetHeight; 413 var w = parseInt(dialog.width) - 330 ; 414 415 // An error is thrown with IE when trying to set a negative width or a negative height 416 // But perhaps a width / height of 0 is not the minimum required we need to set 417 if (w<0) w = 0; 418 if (h<0) h = 0; 419 //options.style.height = 420 lDialog.ddTree.style.height = h + 'px'; 421 lDialog.ddTree.style.width = w + 'px'; 422 } 423 this.ready = true; 424 ddTree = null; 425 Xinha.freeLater(lDialog, 'ddTree'); 426 options = null; 427 }; 428 429 Linker.Dialog.prototype.makeNodes = function(files, parent) 430 { 431 for(var i = 0; i < files.length; i++) 432 { 433 if(typeof files[i] == 'string') 434 { 435 this.dTree.add(Linker.nxtid++, parent, 436 files[i].replace(/^.*\//, ''), 437 'javascript:document.getElementsByName(\'' + this.dialog.id.href + '\')[0].value=decodeURIComponent(\'' + encodeURIComponent(files[i]) + '\');document.getElementsByName(\'' + this.dialog.id.type + '\')[0].click();document.getElementsByName(\'' + this.dialog.id.href + '\')[0].focus();void(0);', 438 files[i]); 439 } 440 else if(typeof files[i]=="object" && files[i] && typeof files[i].length==="number") // there seems to be a strange bug in IE that requires this complicated check, see #1197 441 { 442 var id = this.Dialog_nxtid++; 443 this.dTree.add(id, parent, files[i][0].replace(/^.*\//, ''), null, files[i][0]); 444 this.makeNodes(files[i][1], id); 445 } 446 else if(typeof files[i] == 'object') 447 { 448 if(files[i].children) { 449 var id = this.Dialog_nxtid++; 450 } else { 451 var id = Linker.nxtid++; 452 } 453 454 if(files[i].title) var title = files[i].title; 455 else if(files[i].url) var title = files[i].url.replace(/^.*\//, ''); 456 else var title = "no title defined"; 457 if(files[i].url) var link = 'javascript:document.getElementsByName(\'' + this.dialog.id.href + '\')[0].value=decodeURIComponent(\'' + encodeURIComponent(files[i].url) + '\');document.getElementsByName(\'' + this.dialog.id.type + '\')[0].click();document.getElementsByName(\'' + this.dialog.id.href + '\')[0].focus();void(0);'; 458 else var link = ''; 459 460 this.dTree.add(id, parent, title, link, title); 461 if(files[i].children) { 462 this.makeNodes(files[i].children, id); 463 } 464 } 465 } 466 }; 467 468 Linker.Dialog.prototype._lc = Linker.prototype._lc; 469 470 Linker.Dialog.prototype.show = function(inputs, ok, cancel) 471 { 472 if(!this.ready) 473 { 474 var lDialog = this; 475 window.setTimeout(function() {lDialog.show(inputs,ok,cancel);},100); 476 return; 477 } 478 479 if(this.ddTree.innerHTML == '') 480 { 481 this.ddTree.innerHTML = this.dTree._linker_premade; 482 } 483 484 if(inputs.type=='url') 485 { 486 this.dialog.getElementById('urltable').style.display = ''; 487 this.dialog.getElementById('mailtable').style.display = 'none'; 488 this.dialog.getElementById('anchortable').style.display = 'none'; 489 } 490 else if(inputs.type=='anchor') 491 { 492 this.dialog.getElementById('urltable').style.display = 'none'; 493 this.dialog.getElementById('mailtable').style.display = 'none'; 494 this.dialog.getElementById('anchortable').style.display = ''; 495 } 496 else 497 { 498 this.dialog.getElementById('urltable').style.display = 'none'; 499 this.dialog.getElementById('mailtable').style.display = ''; 500 this.dialog.getElementById('anchortable').style.display = 'none'; 501 } 502 503 if(inputs.target=='popup') 504 { 505 this.dialog.getElementById('popuptable').style.display = ''; 506 } 507 else 508 { 509 this.dialog.getElementById('popuptable').style.display = 'none'; 510 } 511 512 var anchor = this.dialog.getElementById('anchor'); 513 for(var i=anchor.length;i>=0;i--) { 514 anchor[i] = null; 515 } 516 517 var html = this.linker.editor.getHTML(); 518 var anchors = new Array(); 519 520 var m = html.match(/<a[^>]+name="([^"]+)"/gi); 521 if(m) 522 { 523 for(i=0;i<m.length;i++) 524 { 525 var n = m[i].match(/name="([^"]+)"/i); 526 if(!anchors.contains(n[1])) anchors.push(n[1]); 527 } 528 } 529 m = html.match(/id="([^"]+)"/gi); 530 if(m) 531 { 532 for(i=0;i<m.length;i++) 533 { 534 n = m[i].match(/id="([^"]+)"/i); 535 if(!anchors.contains(n[1])) anchors.push(n[1]); 536 } 537 } 538 539 for(i=0;i<anchors.length;i++) 540 { 541 var opt = new Option(anchors[i],'#'+anchors[i],false,(inputs.anchor == anchors[i])); 542 anchor[anchor.length] = opt; 543 } 544 545 //if no anchors found completely hide Anchor-Link 546 if(anchor.length==0) { 547 this.dialog.getElementById('anchorfieldset').style.display = "none"; 548 } 549 550 // if we're not editing an existing link, hide the remove link button 551 if (inputs.href == 'http://www.example.com/' && inputs.to == 'alice@example.com') { 552 this.dialog.getElementById('clear').style.display = "none"; 553 } 554 else { 555 this.dialog.getElementById('clear').style.display = ""; 556 } 557 // Connect the OK and Cancel buttons 558 var dialog = this.dialog; 559 var lDialog = this; 560 if(ok) 561 { 562 this.dialog.getElementById('ok').onclick = ok; 563 } 564 else 565 { 566 this.dialog.getElementById('ok').onclick = function() {lDialog.hide();}; 567 } 568 569 if(cancel) 570 { 571 this.dialog.getElementById('cancel').onclick = cancel; 572 } 573 else 574 { 575 this.dialog.getElementById('cancel').onclick = function() { lDialog.hide()}; 576 } 577 578 // Show the dialog 579 this.linker.editor.disableToolbar(['fullscreen','linker']); 580 581 this.dialog.show(inputs); 582 583 // Init the sizes 584 this.dialog.onresize(); 585 }; 586 587 Linker.Dialog.prototype.hide = function() 588 { 589 this.linker.editor.enableToolbar(); 590 return this.dialog.hide(); 591 }; 102 } -
branches/new-dialogs-merge/plugins/Linker/pluginMethods.js
r1007 r1011 1 /** htmlArea - James' Fork - Linker Plugin **/2 Linker._pluginInfo =3 {4 name : "Linker",5 version : "1.0",6 developer: "James Sleeman",7 developer_url: "http://www.gogo.co.nz/",8 c_owner : "Gogo Internet Services",9 license : "htmlArea",10 sponsor : "Gogo Internet Services",11 sponsor_url : "http://www.gogo.co.nz/"12 };13 14 Xinha.loadStyle('dTree/dtree.css', 'Linker');15 16 Xinha.Config.prototype.Linker =17 {18 'treeCaption' : document.location.host,19 'backend' : Xinha.getPluginDir("Linker") + '/scan.php',20 'backend_data' : null,21 'files' : null22 };23 24 25 function Linker(editor, args)26 {27 this.editor = editor;28 this.lConfig = editor.config.Linker;29 30 var linker = this;31 if(editor.config.btnList.createlink)32 {33 editor.config.btnList.createlink[3]34 = function(e, objname, obj) { linker._createLink(linker._getSelectedAnchor()); };35 }36 else37 {38 editor.config.registerButton(39 'createlink', 'Insert/Modify Hyperlink', [_editor_url + "images/ed_buttons_main.gif",6,1], false,40 function(e, objname, obj) { linker._createLink(linker._getSelectedAnchor()); }41 );42 }43 44 // See if we can find 'createlink'45 editor.config.addToolbarElement("createlink", "createlink", 0);46 }47 48 Linker.prototype._lc = function(string)49 {50 return Xinha._lc(string, 'Linker');51 };52 53 1 Linker.prototype._createLink = function(a) 54 2 { 3 if (!this._dialog) 4 { 5 this._dialog = new Linker.Dialog(this); 6 } 7 55 8 if(!a && this.editor.selectionEmpty(this.editor.getSelection())) 56 9 { … … 106 59 else 107 60 { 108 109 110 61 if(a.getAttribute('onclick')) 111 62 { … … 291 242 }; 292 243 293 Linker.prototype.onGenerateOnce = function()294 {295 this._dialog = new Linker.Dialog(this);296 };297 // Inline Dialog for Linker298 299 244 Linker.Dialog_dTrees = [ ]; 300 301 245 302 246 Linker.Dialog = function (linker) … … 308 252 309 253 this.ready = false; 310 this.files = false; 311 this.html = false; 254 312 255 this.dialog = false; 313 256 … … 322 265 var linker = this.linker; 323 266 324 // We load some stuff up int he background, recalling this function 325 // when they have loaded. This is to keep the editor responsive while 326 // we prepare the dialog. 327 if(typeof dTree == 'undefined') 328 { 329 this.linker.editor.setLoadingMessage('Loading Tree script'); 330 Xinha._loadback(Xinha.getPluginDir("Linker") + '/dTree/dtree.js', 331 function() {lDialog._prepareDialog(); } 332 ); 333 return; 334 } 335 336 if(this.files === false) 337 { 338 if(linker.lConfig.backend) 339 { 340 //get files from backend 341 this.linker.editor.setLoadingMessage('Loading files from backend'); 342 Xinha._postback(linker.lConfig.backend, 343 linker.lConfig.backend_data, 344 function(txt) { 345 try { 346 lDialog.files = eval(txt); 347 } catch(Error) { 348 lDialog.files = [ {url:'',title:Error.toString()} ]; 349 } 350 lDialog._prepareDialog(); }); 351 } 352 else if(linker.lConfig.files != null) 353 { 354 //get files from plugin-config 355 lDialog.files = linker.lConfig.files; 356 lDialog._prepareDialog(); 357 } 358 return; 359 } 360 var files = this.files; 361 362 if(this.html == false) 363 { 364 Xinha._getback(Xinha.getPluginDir("Linker") + '/dialog.html', function(txt) { lDialog.html = txt; lDialog._prepareDialog(); }); 365 return; 366 } 367 var html = this.html; 267 var files = this.linker.files; 268 269 var html = Linker.html; 368 270 369 271 // Now we have everything we need, so we can build the dialog. 370 var dialog = this.dialog = new Xinha.Dialog(linker.editor, this.html, 'Linker',{width:600,height:400});272 var dialog = this.dialog = new Xinha.Dialog(linker.editor, Linker.html, 'Linker',{width:600,height:400}); 371 273 var dTreeName = Xinha.uniq('dTree_'); 372 274 -
branches/new-dialogs-merge/plugins/PasteText/paste-text.js
r1008 r1011 43 43 PasteText.prototype.onGenerateOnce = function() 44 44 { 45 this._prepareDialog(); 45 var self = PasteText; 46 if (self.loading) return; 47 self.loading = true; 48 Xinha._getback(Xinha.getPluginDir("PasteText") + '/popups/paste_text.html', function(getback) { self.html = getback;}); 46 49 }; 47 50 … … 51 54 var editor = this.editor; 52 55 53 if(!this.html) // retrieve the raw dialog contents 54 { 55 Xinha._getback(Xinha.getPluginDir("PasteText") + '/popups/paste_text.html', function(getback) { self.html = getback; self._prepareDialog(); }); 56 return; 57 } 56 var self = this; 58 57 59 // Now we have everything we need, so we can build the dialog.60 this.dialog = new Xinha.Dialog(editor, this.html, 'PasteText',{width:350})58 /// Now we have everything we need, so we can build the dialog. 59 this.dialog = new Xinha.Dialog(editor, PasteText.html, 'PasteText',{width:350}) 61 60 62 61 // Connect the OK and Cancel buttons … … 88 87 89 88 } 90 this.ready = true;91 89 }; 92 90 93 91 PasteText.prototype.show = function() 94 92 { 95 if(!this.ready) // if the user is too fast clicking the, we have to make them wait 96 { 97 var self = this; 98 window.setTimeout(function() {self.show();},100); 99 return; 100 } 93 if (!this.dialog) this._prepareDialog(); 94 101 95 // here we can pass values to the dialog 102 96 // each property pair consists of the "name" of the input we want to populate, and the value to be set -
branches/new-dialogs-merge/plugins/SuperClean/pluginMethods.js
r1008 r1011 1 // Make our right side panel and insert appropriatly2 function 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 superclean10 editor.config.addToolbarElement("superclean", "killword", 0);11 }12 13 SuperClean._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 25 SuperClean.prototype._lc = function(string) {26 return Xinha._lc(string, 'SuperClean');27 };28 29 /** superClean combines HTMLTidy, Word Cleaning and font stripping into a single function30 * it works a bit differently in how it asks for parameters */31 32 1 SuperClean.prototype._superClean = function(opts, obj) 33 2 { 3 if(this.editor.config.SuperClean.show_dialog && !this._dialog) 4 { 5 this._dialog = new SuperClean.Dialog(this); 6 } 34 7 var superclean = this; 35 8 … … 45 18 46 19 if(opts.word_clean) editor._wordClean(); 47 var D = editor.get InnerHTML();20 var D = editor.getEditorContent(); 48 21 49 22 for(var filter in editor.config.SuperClean.filters) … … 59 32 D = D.replace(/<(font|span)\s*>/gi, ''); 60 33 61 editor.set HTML(D);34 editor.setEditorContent(D); 62 35 63 36 if(opts.tidy) … … 69 42 { 70 43 case 'setHTML': 71 editor.set HTML(response.value);44 editor.setEditorContent(response.value); 72 45 superclean._dialog.hide(); 73 46 break; … … 101 74 { 102 75 var editor = this.editor; 103 var html = editor.get InnerHTML();76 var html = editor.getEditorContent(); 104 77 for(var filter in editor.config.SuperClean.filters) 105 78 { … … 111 84 html = html.replace(/<(font|span)\s*>/gi, ''); 112 85 113 editor.set HTML(html);86 editor.setEditorContent(html); 114 87 115 88 if(editor.config.SuperClean.filters.tidy) … … 120 93 }; 121 94 122 Xinha.Config.prototype.SuperClean =123 {124 // set to the URL of a handler for html tidy, this handler125 // (see tidy.php for an example) must that a single post variable126 // "content" which contains the HTML to tidy, and return javascript like127 // editor.setHTML('<strong>Tidied Html</strong>')128 // it's called through XMLHTTPRequest129 'tidy_handler': Xinha.getPluginDir("SuperClean") + '/tidy.php',130 131 //avaliable filters (these are built-in filters)132 // You can either use133 // 'filter_name' : "Label/Description String"134 // or 'filter_name' : {label: "Label", checked: true/false, filterFunction: function(html) { ... return html;} }135 // filterFunction in the second format above is optional.136 137 'filters': { 'tidy': Xinha._lc('General tidy up and correction of some problems.', 'SuperClean'),138 'word_clean': Xinha._lc('Clean bad HTML from Microsoft Word', 'SuperClean'),139 'remove_faces': Xinha._lc('Remove custom typefaces (font "styles").', 'SuperClean'),140 'remove_sizes': Xinha._lc('Remove custom font sizes.', 'SuperClean'),141 'remove_colors': Xinha._lc('Remove custom text colors.', 'SuperClean'),142 'remove_lang': Xinha._lc('Remove lang attributes.', 'SuperClean'),143 'remove_fancy_quotes': {label:Xinha._lc('Replace directional quote marks with non-directional quote marks.', 'SuperClean'), checked:false}144 //additional custom filters (defined in plugins/SuperClean/filters/word.js)145 //'paragraph': 'remove paragraphs'},146 //'word': 'exteded Word-Filter' },147 },148 //if false all filters are applied, if true a dialog asks what filters should be used149 'show_dialog': true150 };151 152 SuperClean.filterFunctions = { };153 95 SuperClean.filterFunctions.remove_colors = function(D) 154 96 { … … 199 141 SuperClean.filterFunctions.tidy = function(html, editor) 200 142 { 201 Xinha._postback(editor.config.SuperClean.tidy_handler, {'content' : html}, 202 function(javascriptResponse) { eval(javascriptResponse) }); 203 }; 204 205 206 207 SuperClean.prototype.onGenerateOnce = function() 208 { 209 if(this.editor.config.SuperClean.show_dialog && !this._dialog) 210 { 211 this._dialog = new SuperClean.Dialog(this); 212 } 213 if(this.editor.config.tidy_handler) 214 { 215 //for backwards compatibility 216 this.editor.config.SuperClean.tidy_handler = this.editor.config.tidy_handler; 217 this.editor.config.tidy_handler = null; 218 } 219 if(!this.editor.config.SuperClean.tidy_handler && this.editor.config.filters.tidy) { 220 //unset tidy-filter if no tidy_handler 221 this.editor.config.filters.tidy = null; 222 } 223 224 this.loadFilters(); 225 }; 226 SuperClean.prototype.loadFilters = function() 227 { 228 var sc = this; 229 //load the filter-functions 230 for(var filter in this.editor.config.SuperClean.filters) 231 { 232 if(!SuperClean.filterFunctions[filter]) 233 { 234 var filtDetail = this.editor.config.SuperClean.filters[filter]; 235 if(typeof filtDetail.filterFunction != 'undefined') 236 { 237 SuperClean.filterFunctions[filter] = filterFunction; 238 } 239 else 240 { 241 Xinha._getback(Xinha.getPluginDir("SuperClean") + '/filters/'+filter+'.js', 242 function(func) { 243 eval('SuperClean.filterFunctions.'+filter+'='+func+';'); 244 sc.loadFilters(); 245 }); 246 } 247 return; 248 } 249 } 250 } 251 // Inline Dialog for SuperClean 143 var callback = function(javascriptResponse) 144 { 145 eval("var response = " + javascriptResponse); 146 switch (response.action) 147 { 148 case 'setHTML': 149 editor.setEditorContent(response.value); 150 break; 151 case 'alert': 152 alert(Xinha._lc(response.value, 'SuperClean')); 153 break; 154 } 155 } 156 Xinha._postback(editor.config.SuperClean.tidy_handler, {'content' : html},callback); 157 }; 252 158 253 159 … … 260 166 261 167 this.ready = false; 262 this.files = false;263 this.html = false;264 168 this.dialog = false; 265 169 … … 274 178 var SuperClean = this.SuperClean; 275 179 276 if(this.html == false) 277 { 278 Xinha._getback( Xinha.getPluginDir("SuperClean") + '/dialog.html', function(txt) { lDialog.html = txt; lDialog._prepareDialog(); }); 279 return; 280 } 180 var html = window.SuperClean.html; 281 181 282 182 var htmlFilters = ""; … … 297 197 htmlFilters += " </div>\n"; 298 198 } 299 this.html = this.html.replace('<!--filters-->', htmlFilters); 300 301 var html = this.html; 199 html = html.replace('<!--filters-->', htmlFilters); 200 302 201 303 202 // Now we have everything we need, so we can build the dialog. 304 var dialog = this.dialog = new Xinha.Dialog(SuperClean.editor, this.html, 'SuperClean',{width:400});203 var dialog = this.dialog = new Xinha.Dialog(SuperClean.editor, html, 'SuperClean',{width:400}); 305 204 306 205 this.ready = true; … … 350 249 SuperClean.Dialog.prototype.hide = function() 351 250 { 251 var ret = this.dialog.hide(); 352 252 this.SuperClean.editor.enableToolbar(); 353 253 this.dialog.getElementById("main").style.display = ""; … … 356 256 this.dialog.getElementById("alert").style.display = "none"; 357 257 this.dialog.getElementById("ok").style.display = ""; 358 return this.dialog.hide();359 }; 258 return ret; 259 }; -
branches/new-dialogs-merge/plugins/SuperClean/super-clean.js
r1008 r1011 1 // Make our right side panel and insert appropriatly 1 /** superClean combines HTMLTidy, Word Cleaning and font stripping into a single function 2 * it works a bit differently in how it asks for parameters */ 3 2 4 function SuperClean(editor, args) 3 5 { … … 25 27 SuperClean.prototype._lc = function(string) { 26 28 return Xinha._lc(string, 'SuperClean'); 27 };28 29 /** superClean combines HTMLTidy, Word Cleaning and font stripping into a single function30 * it works a bit differently in how it asks for parameters */31 32 SuperClean.prototype._superClean = function(opts, obj)33 {34 var superclean = this;35 36 // Do the clean if we got options37 var doOK = function()38 {39 superclean._dialog.dialog.getElementById("main").style.display = "none";40 superclean._dialog.dialog.getElementById("waiting").style.display = "";41 superclean._dialog.dialog.getElementById("buttons").style.display = "none";42 43 var opts = superclean._dialog.dialog.getValues();44 var editor = superclean.editor;45 46 if(opts.word_clean) editor._wordClean();47 var D = editor.getInnerHTML();48 49 for(var filter in editor.config.SuperClean.filters)50 {51 if(filter=='tidy' || filter=='word_clean') continue;52 if(opts[filter])53 {54 D = SuperClean.filterFunctions[filter](D, editor);55 }56 }57 58 D = D.replace(/(style|class)="\s*"/gi, '');59 D = D.replace(/<(font|span)\s*>/gi, '');60 61 editor.setHTML(D);62 63 if(opts.tidy)64 {65 var callback = function(javascriptResponse)66 {67 eval("var response = " + javascriptResponse);68 switch (response.action)69 {70 case 'setHTML':71 editor.setHTML(response.value);72 superclean._dialog.hide();73 break;74 case 'alert':75 superclean._dialog.dialog.getElementById("buttons").style.display = "";76 superclean._dialog.dialog.getElementById("ok").style.display = "none";77 superclean._dialog.dialog.getElementById("waiting").style.display = "none";78 superclean._dialog.dialog.getElementById("alert").style.display = "";79 superclean._dialog.dialog.getElementById("alert").innerHTML = superclean._lc(response.value);80 break;81 default: // make the dialog go away if sth goes wrong, who knows...82 superclean._dialog.hide();83 break;84 }85 }86 Xinha._postback(editor.config.SuperClean.tidy_handler, {'content' : editor.getInnerHTML()},callback);87 }88 else89 {90 superclean._dialog.hide();91 }92 return true;93 }94 95 if(this.editor.config.SuperClean.show_dialog)96 {97 var inputs = {};98 this._dialog.show(inputs, doOK);99 }100 else101 {102 var editor = this.editor;103 var html = editor.getInnerHTML();104 for(var filter in editor.config.SuperClean.filters)105 {106 if(filter=='tidy') continue; //call tidy last107 html = SuperClean.filterFunctions[filter](html, editor);108 }109 110 html = html.replace(/(style|class)="\s*"/gi, '');111 html = html.replace(/<(font|span)\s*>/gi, '');112 113 editor.setHTML(html);114 115 if(editor.config.SuperClean.filters.tidy)116 {117 SuperClean.filterFunctions.tidy(html, editor);118 }119 }120 29 }; 121 30 … … 147 56 }, 148 57 //if false all filters are applied, if true a dialog asks what filters should be used 149 'show_dialog': true58 'show_dialog': false 150 59 }; 151 60 152 61 SuperClean.filterFunctions = { }; 153 SuperClean.filterFunctions.remove_colors = function(D)154 {155 D = D.replace(/color="?[^" >]*"?/gi, '');156 // { (stops jedit's fold breaking)157 D = D.replace(/([^-])color:[^;}"']+;?/gi, '$1');158 return(D);159 };160 SuperClean.filterFunctions.remove_sizes = function(D)161 {162 D = D.replace(/size="?[^" >]*"?/gi, '');163 // { (stops jedit's fold breaking)164 D = D.replace(/font-size:[^;}"']+;?/gi, '');165 return(D);166 };167 SuperClean.filterFunctions.remove_faces = function(D)168 {169 D = D.replace(/face="?[^" >]*"?/gi, '');170 // { (stops jedit's fold breaking)171 D = D.replace(/font-family:[^;}"']+;?/gi, '');172 return(D);173 };174 SuperClean.filterFunctions.remove_lang = function(D)175 {176 D = D.replace(/lang="?[^" >]*"?/gi, '');177 return(D);178 };179 SuperClean.filterFunctions.word_clean = function(html, editor)180 {181 editor.setHTML(html);182 editor._wordClean();183 return editor.getInnerHTML();184 };185 186 SuperClean.filterFunctions.remove_fancy_quotes = function(D)187 {188 D = D.replace(new RegExp(String.fromCharCode(8216),"g"),"'");189 D = D.replace(new RegExp(String.fromCharCode(8217),"g"),"'");190 D = D.replace(new RegExp(String.fromCharCode(8218),"g"),"'");191 D = D.replace(new RegExp(String.fromCharCode(8219),"g"),"'");192 D = D.replace(new RegExp(String.fromCharCode(8220),"g"),"\"");193 D = D.replace(new RegExp(String.fromCharCode(8221),"g"),"\"");194 D = D.replace(new RegExp(String.fromCharCode(8222),"g"),"\"");195 D = D.replace(new RegExp(String.fromCharCode(8223),"g"),"\"");196 return D;197 };198 199 SuperClean.filterFunctions.tidy = function(html, editor)200 {201 Xinha._postback(editor.config.SuperClean.tidy_handler, {'content' : html},202 function(javascriptResponse) { eval(javascriptResponse) });203 };204 205 62 206 63 207 64 SuperClean.prototype.onGenerateOnce = function() 208 65 { 209 if(this.editor.config.SuperClean.show_dialog && !this._dialog) 210 { 211 this._dialog = new SuperClean.Dialog(this); 212 } 66 213 67 if(this.editor.config.tidy_handler) 214 68 { … … 221 75 this.editor.config.filters.tidy = null; 222 76 } 223 77 SuperClean.loadAssets(); 224 78 this.loadFilters(); 225 79 }; 80 81 SuperClean.prototype.onUpdateToolbar = function() 82 { 83 if (!(SuperClean.methodsReady && SuperClean.html)) 84 { 85 this.editor._toolbarObjects.superclean.state("enabled", false); 86 } 87 else this.onUpdateToolbar = null; 88 }; 89 90 SuperClean.loadAssets = function() 91 { 92 var self = SuperClean; 93 if (self.loading) return; 94 self.loading = true; 95 Xinha._getback(Xinha.getPluginDir("SuperClean") + '/pluginMethods.js', function(getback) { eval(getback); self.methodsReady = true; }); 96 Xinha._getback( Xinha.getPluginDir("SuperClean") + '/dialog.html', function(getback) { self.html = getback; } ); 97 }; 98 226 99 SuperClean.prototype.loadFilters = function() 227 100 { … … 230 103 for(var filter in this.editor.config.SuperClean.filters) 231 104 { 105 if (/^(remove_colors|remove_sizes|remove_faces|remove_lang|word_clean|remove_fancy_quotes|tidy)$/.test(filter)) continue; //skip built-in functions 106 232 107 if(!SuperClean.filterFunctions[filter]) 233 108 { … … 248 123 } 249 124 } 250 }251 // Inline Dialog for SuperClean252 253 254 SuperClean.Dialog = function (SuperClean)255 {256 var lDialog = this;257 this.Dialog_nxtid = 0;258 this.SuperClean = SuperClean;259 this.id = { }; // This will be filled below with a replace, nifty260 261 this.ready = false;262 this.files = false;263 this.html = false;264 this.dialog = false;265 266 // load the dTree script267 this._prepareDialog();268 269 125 }; 270 271 SuperClean.Dialog.prototype._prepareDialog = function()272 {273 var lDialog = this;274 var SuperClean = this.SuperClean;275 276 if(this.html == false)277 {278 Xinha._getback( Xinha.getPluginDir("SuperClean") + '/dialog.html', function(txt) { lDialog.html = txt; lDialog._prepareDialog(); });279 return;280 }281 282 var htmlFilters = "";283 for(var filter in this.SuperClean.editor.config.SuperClean.filters)284 {285 htmlFilters += " <div>\n";286 var filtDetail = this.SuperClean.editor.config.SuperClean.filters[filter];287 if(typeof filtDetail.label == 'undefined')288 {289 htmlFilters += " <input type=\"checkbox\" name=\"["+filter+"]\" id=\"["+filter+"]\" checked />\n";290 htmlFilters += " <label for=\"["+filter+"]\">"+this.SuperClean.editor.config.SuperClean.filters[filter]+"</label>\n";291 }292 else293 {294 htmlFilters += " <input type=\"checkbox\" name=\"["+filter+"]\" id=\"["+filter+"]\" " + (filtDetail.checked ? "checked" : "") + " />\n";295 htmlFilters += " <label for=\"["+filter+"]\">"+filtDetail.label+"</label>\n";296 }297 htmlFilters += " </div>\n";298 }299 this.html = this.html.replace('<!--filters-->', htmlFilters);300 301 var html = this.html;302 303 // Now we have everything we need, so we can build the dialog.304 var dialog = this.dialog = new Xinha.Dialog(SuperClean.editor, this.html, 'SuperClean',{width:400});305 306 this.ready = true;307 };308 309 SuperClean.Dialog.prototype._lc = SuperClean.prototype._lc;310 311 SuperClean.Dialog.prototype.show = function(inputs, ok, cancel)312 {313 if(!this.ready)314 {315 var lDialog = this;316 window.setTimeout(function() {lDialog.show(inputs,ok,cancel);},100);317 return;318 }319 320 // Connect the OK and Cancel buttons321 var dialog = this.dialog;322 var lDialog = this;323 if(ok)324 {325 this.dialog.getElementById('ok').onclick = ok;326 }327 else328 {329 this.dialog.getElementById('ok').onclick = function() {lDialog.hide();};330 }331 332 if(cancel)333 {334 this.dialog.getElementById('cancel').onclick = cancel;335 }336 else337 {338 this.dialog.getElementById('cancel').onclick = function() { lDialog.hide()};339 }340 341 // Show the dialog342 this.SuperClean.editor.disableToolbar(['fullscreen','SuperClean']);343 344 this.dialog.show(inputs);345 346 // Init the sizes347 this.dialog.onresize();348 };349 350 SuperClean.Dialog.prototype.hide = function()351 {352 this.SuperClean.editor.enableToolbar();353 this.dialog.getElementById("main").style.display = "";354 this.dialog.getElementById("buttons").style.display = "";355 this.dialog.getElementById("waiting").style.display = "none";356 this.dialog.getElementById("alert").style.display = "none";357 this.dialog.getElementById("ok").style.display = "";358 return this.dialog.hide();359 };
