PageRenderTime 45ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/BlogEngine/BlogEngine.NET/editors/tiny_mce_3_4_3_1/plugins/visualchars/editor_plugin_src.js

#
JavaScript | 83 lines | 53 code | 17 blank | 13 comment | 15 complexity | f285c8f2ffac745325e86687b8cf0fb5 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0, BSD-3-Clause
  1. /**
  2. * editor_plugin_src.js
  3. *
  4. * Copyright 2009, Moxiecode Systems AB
  5. * Released under LGPL License.
  6. *
  7. * License: http://tinymce.moxiecode.com/license
  8. * Contributing: http://tinymce.moxiecode.com/contributing
  9. */
  10. (function() {
  11. tinymce.create('tinymce.plugins.VisualChars', {
  12. init : function(ed, url) {
  13. var t = this;
  14. t.editor = ed;
  15. // Register commands
  16. ed.addCommand('mceVisualChars', t._toggleVisualChars, t);
  17. // Register buttons
  18. ed.addButton('visualchars', {title : 'visualchars.desc', cmd : 'mceVisualChars'});
  19. ed.onBeforeGetContent.add(function(ed, o) {
  20. if (t.state && o.format != 'raw' && !o.draft) {
  21. t.state = true;
  22. t._toggleVisualChars(false);
  23. }
  24. });
  25. },
  26. getInfo : function() {
  27. return {
  28. longname : 'Visual characters',
  29. author : 'Moxiecode Systems AB',
  30. authorurl : 'http://tinymce.moxiecode.com',
  31. infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/visualchars',
  32. version : tinymce.majorVersion + "." + tinymce.minorVersion
  33. };
  34. },
  35. // Private methods
  36. _toggleVisualChars : function(bookmark) {
  37. var t = this, ed = t.editor, nl, i, h, d = ed.getDoc(), b = ed.getBody(), nv, s = ed.selection, bo, div, bm;
  38. t.state = !t.state;
  39. ed.controlManager.setActive('visualchars', t.state);
  40. if (bookmark)
  41. bm = s.getBookmark();
  42. if (t.state) {
  43. nl = [];
  44. tinymce.walk(b, function(n) {
  45. if (n.nodeType == 3 && n.nodeValue && n.nodeValue.indexOf('\u00a0') != -1)
  46. nl.push(n);
  47. }, 'childNodes');
  48. for (i = 0; i < nl.length; i++) {
  49. nv = nl[i].nodeValue;
  50. nv = nv.replace(/(\u00a0)/g, '<span data-mce-bogus="1" class="mceItemHidden mceItemNbsp">$1</span>');
  51. div = ed.dom.create('div', null, nv);
  52. while (node = div.lastChild)
  53. ed.dom.insertAfter(node, nl[i]);
  54. ed.dom.remove(nl[i]);
  55. }
  56. } else {
  57. nl = ed.dom.select('span.mceItemNbsp', b);
  58. for (i = nl.length - 1; i >= 0; i--)
  59. ed.dom.remove(nl[i], 1);
  60. }
  61. s.moveToBookmark(bm);
  62. }
  63. });
  64. // Register plugin
  65. tinymce.PluginManager.add('visualchars', tinymce.plugins.VisualChars);
  66. })();