annotate media/js/tiny_mce/plugins/visualchars/editor_plugin_src.js @ 172:0fa78ef80356

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