includes/clientside/tinymce/plugins/safari/editor_plugin_src.js
changeset 543 dffcbfbc4e59
parent 476 f26a69c40431
child 778 57ce13805b6f
--- a/includes/clientside/tinymce/plugins/safari/editor_plugin_src.js	Mon May 05 20:06:37 2008 -0400
+++ b/includes/clientside/tinymce/plugins/safari/editor_plugin_src.js	Mon May 05 20:08:44 2008 -0400
@@ -25,15 +25,36 @@
 				ed.execCommand("mceInsertContent", false, '<a href="' + dom.encode(v) + '">' + ed.selection.getContent() + '</a>');
 			});*/
 
+			ed.onPaste.add(function(ed, e) {
+				function removeStyles(e) {
+					e = e.target;
+
+					if (e.nodeType == 1) {
+						e.style.cssText = '';
+
+						each(ed.dom.select('*', e), function(e) {
+							e.style.cssText = '';
+						});
+					}
+				};
+
+				Event.add(ed.getDoc(), 'DOMNodeInserted', removeStyles);
+
+				window.setTimeout(function() {
+					Event.remove(ed.getDoc(), 'DOMNodeInserted', removeStyles);
+				}, 0);
+			});
+
 			ed.onKeyUp.add(function(ed, e) {
-				var h;
+				var h, b;
 
 				// If backspace or delete key
 				if (e.keyCode == 46 || e.keyCode == 8) {
-					h = ed.getBody().innerHTML;
+					b = ed.getBody();
+					h = b.innerHTML;
 
 					// If there is no text content or images or hr elements then remove everything
-					if (!/<(img|hr)/.test(h) && tinymce.trim(h.replace(/<[^>]+>/g, '')).length == 0)
+					if (b.childNodes.length == 1 && !/<(img|hr)/.test(h) && tinymce.trim(h.replace(/<[^>]+>/g, '')).length == 0)
 						ed.setContent('', {format : 'raw'});
 				}
 			});
@@ -107,7 +128,7 @@
 					t.selElm = null;
 			});
 
-			ed.onBeforeExecCommand.add(function(ed, c, b) {
+/*			ed.onBeforeExecCommand.add(function(ed, c, b) {
 				var r = t.bookmarkRng;
 
 				// Restore selection
@@ -116,12 +137,12 @@
 					t.bookmarkRng = null;
 					//console.debug('restore', r.startContainer, r.startOffset, r.endContainer, r.endOffset);
 				}
-			});
+			});*/
 
 			ed.onInit.add(function() {
 				t._fixWebKitSpans();
 
-				ed.windowManager.onOpen.add(function() {
+/*				ed.windowManager.onOpen.add(function() {
 					var r = ed.selection.getRng();
 
 					// Store selection if valid
@@ -133,7 +154,7 @@
 
 				ed.windowManager.onClose.add(function() {
 					t.bookmarkRng = null;
-				});
+				});*/
 
 				if (isOldWebKit)
 					t._patchSafari2x(ed);
@@ -247,6 +268,18 @@
 			});
 		},
 
+		getInfo : function() {
+			return {
+				longname : 'Safari compatibility',
+				author : 'Moxiecode Systems AB',
+				authorurl : 'http://tinymce.moxiecode.com',
+				infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/safari',
+				version : tinymce.majorVersion + "." + tinymce.minorVersion
+			};
+		},
+
+		// Internal methods
+
 		_fixWebKitSpans : function() {
 			var t = this, ed = t.editor;