diff media/js/tiny_mce/plugins/visualchars/editor_plugin_src.js @ 247:6ed2932901fa

Update tinymce to 3.3.9
author Brian Neal <bgneal@gmail.com>
date Sat, 18 Sep 2010 19:54:11 +0000
parents 149c3567fec1
children
line wrap: on
line diff
--- a/media/js/tiny_mce/plugins/visualchars/editor_plugin_src.js	Sat Sep 18 19:39:16 2010 +0000
+++ b/media/js/tiny_mce/plugins/visualchars/editor_plugin_src.js	Sat Sep 18 19:54:11 2010 +0000
@@ -22,9 +22,9 @@
 			ed.addButton('visualchars', {title : 'visualchars.desc', cmd : 'mceVisualChars'});
 
 			ed.onBeforeGetContent.add(function(ed, o) {
-				if (t.state) {
+				if (t.state && o.format != 'raw' && !o.draft) {
 					t.state = true;
-					t._toggleVisualChars();
+					t._toggleVisualChars(false);
 				}
 			});
 		},
@@ -41,12 +41,15 @@
 
 		// Private methods
 
-		_toggleVisualChars : function() {
-			var t = this, ed = t.editor, nl, i, h, d = ed.getDoc(), b = ed.getBody(), nv, s = ed.selection, bo;
+		_toggleVisualChars : function(bookmark) {
+			var t = this, ed = t.editor, nl, i, h, d = ed.getDoc(), b = ed.getBody(), nv, s = ed.selection, bo, div, bm;
 
 			t.state = !t.state;
 			ed.controlManager.setActive('visualchars', t.state);
 
+			if (bookmark)
+				bm = s.getBookmark();
+
 			if (t.state) {
 				nl = [];
 				tinymce.walk(b, function(n) {
@@ -54,20 +57,24 @@
 						nl.push(n);
 				}, 'childNodes');
 
-				for (i=0; i<nl.length; i++) {
+				for (i = 0; i < nl.length; i++) {
 					nv = nl[i].nodeValue;
-					nv = nv.replace(/(\u00a0+)/g, '<span class="mceItemHidden mceVisualNbsp">$1</span>');
-					nv = nv.replace(/\u00a0/g, '\u00b7');
-					ed.dom.setOuterHTML(nl[i], nv, d);
+					nv = nv.replace(/(\u00a0)/g, '<span _mce_bogus="1" class="mceItemHidden mceItemNbsp">$1</span>');
+
+					div = ed.dom.create('div', null, nv);
+					while (node = div.lastChild)
+						ed.dom.insertAfter(node, nl[i]);
+
+					ed.dom.remove(nl[i]);
 				}
 			} else {
-				nl = tinymce.grep(ed.dom.select('span', b), function(n) {
-					return ed.dom.hasClass(n, 'mceVisualNbsp');
-				});
+				nl = ed.dom.select('span.mceItemNbsp', b);
 
-				for (i=0; i<nl.length; i++)
-					ed.dom.setOuterHTML(nl[i], nl[i].innerHTML.replace(/(&middot;|\u00b7)/g, '&nbsp;'), d);
+				for (i = nl.length - 1; i >= 0; i--)
+					ed.dom.remove(nl[i], 1);
 			}
+
+			s.moveToBookmark(bm);
 		}
 	});