/static/scripts/tiny_mce/plugins/visualchars/editor_plugin_src.js

http://n23.googlecode.com/ · JavaScript · 73 lines · 50 code · 13 blank · 10 comment · 10 complexity · cb35100b75dc297fb4d42fe6abaa10b2 MD5 · raw file

  1. /**
  2. * $Id: editor_plugin_src.js 201 2007-02-12 15:56:56Z spocke $
  3. *
  4. * @author Moxiecode
  5. * @copyright Copyright Š 2004-2008, Moxiecode Systems AB, All rights reserved.
  6. */
  7. (function() {
  8. tinymce.create('tinymce.plugins.VisualChars', {
  9. init : function(ed, url) {
  10. var t = this;
  11. t.editor = ed;
  12. // Register commands
  13. ed.addCommand('mceVisualChars', t._toggleVisualChars, t);
  14. // Register buttons
  15. ed.addButton('visualchars', {title : 'visualchars.desc', cmd : 'mceVisualChars'});
  16. ed.onBeforeGetContent.add(function(ed, o) {
  17. if (t.state) {
  18. t.state = true;
  19. t._toggleVisualChars();
  20. }
  21. });
  22. },
  23. getInfo : function() {
  24. return {
  25. longname : 'Visual characters',
  26. author : 'Moxiecode Systems AB',
  27. authorurl : 'http://tinymce.moxiecode.com',
  28. infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/visualchars',
  29. version : tinymce.majorVersion + "." + tinymce.minorVersion
  30. };
  31. },
  32. // Private methods
  33. _toggleVisualChars : function() {
  34. var t = this, ed = t.editor, nl, i, h, d = ed.getDoc(), b = ed.getBody(), nv, s = ed.selection, bo;
  35. t.state = !t.state;
  36. ed.controlManager.setActive('visualchars', t.state);
  37. if (t.state) {
  38. nl = [];
  39. tinymce.walk(b, function(n) {
  40. if (n.nodeType == 3 && n.nodeValue && n.nodeValue.indexOf('\u00a0') != -1)
  41. nl.push(n);
  42. }, 'childNodes');
  43. for (i=0; i<nl.length; i++) {
  44. nv = nl[i].nodeValue;
  45. nv = nv.replace(/(\u00a0+)/g, '<span class="mceItemHidden mceVisualNbsp">$1</span>');
  46. nv = nv.replace(/\u00a0/g, '\u00b7');
  47. ed.dom.setOuterHTML(nl[i], nv, d);
  48. }
  49. } else {
  50. nl = tinymce.grep(ed.dom.select('span', b), function(n) {
  51. return ed.dom.hasClass(n, 'mceVisualNbsp');
  52. });
  53. for (i=0; i<nl.length; i++)
  54. ed.dom.setOuterHTML(nl[i], nl[i].innerHTML.replace(/(&middot;|\u00b7)/g, '&nbsp;'), d);
  55. }
  56. }
  57. });
  58. // Register plugin
  59. tinymce.PluginManager.add('visualchars', tinymce.plugins.VisualChars);
  60. })();