[ Index ]

PHP Cross Reference of Mambo 4.6.5

[ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/mambots/editors/mostlyce/jscripts/tiny_mce/plugins/visualchars/ -> editor_plugin_src.js (source)

   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  
   8  (function() {
   9      tinymce.create('tinymce.plugins.VisualChars', {
  10          init : function(ed, url) {
  11              var t = this;
  12  
  13              t.editor = ed;
  14  
  15              // Register commands

  16              ed.addCommand('mceVisualChars', t._toggleVisualChars, t);
  17  
  18              // Register buttons

  19              ed.addButton('visualchars', {title : 'visualchars.desc', cmd : 'mceVisualChars'});
  20  
  21              ed.onBeforeGetContent.add(function(ed, o) {
  22                  if (t.state) {
  23                      t.state = true;
  24                      t._toggleVisualChars();
  25                  }
  26              });
  27          },
  28  
  29          getInfo : function() {
  30              return {
  31                  longname : 'Visual characters',
  32                  author : 'Moxiecode Systems AB',
  33                  authorurl : 'http://tinymce.moxiecode.com',
  34                  infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/visualchars',
  35                  version : tinymce.majorVersion + "." + tinymce.minorVersion
  36              };
  37          },
  38  
  39          // Private methods

  40  
  41          _toggleVisualChars : function() {
  42              var t = this, ed = t.editor, nl, i, h, d = ed.getDoc(), b = ed.getBody(), nv, s = ed.selection, bo;
  43  
  44              t.state = !t.state;
  45              ed.controlManager.setActive('visualchars', t.state);
  46  
  47              if (t.state) {
  48                  nl = [];
  49                  tinymce.walk(b, function(n) {
  50                      if (n.nodeType == 3 && n.nodeValue && n.nodeValue.indexOf('\u00a0') != -1)
  51                          nl.push(n);
  52                  }, 'childNodes');
  53  
  54                  for (i=0; i<nl.length; i++) {
  55                      nv = nl[i].nodeValue;
  56                      nv = nv.replace(/(\u00a0+)/g, '<span class="mceItemHidden mceVisualNbsp">$1</span>');
  57                      nv = nv.replace(/\u00a0/g, '\u00b7');
  58                      ed.dom.setOuterHTML(nl[i], nv, d);
  59                  }
  60              } else {
  61                  nl = tinymce.grep(ed.dom.select('span', b), function(n) {
  62                      return ed.dom.hasClass(n, 'mceVisualNbsp');
  63                  });
  64  
  65                  for (i=0; i<nl.length; i++)
  66                      ed.dom.setOuterHTML(nl[i], nl[i].innerHTML.replace(/(&middot;|\u00b7)/g, '&nbsp;'), d);
  67              }
  68          }
  69      });
  70  
  71      // Register plugin

  72      tinymce.PluginManager.add('visualchars', tinymce.plugins.VisualChars);
  73  })();