includes/clientside/tinymce/plugins/safari/editor_plugin_src.js
changeset 543 dffcbfbc4e59
parent 476 f26a69c40431
child 778 57ce13805b6f
equal deleted inserted replaced
542:5841df0ab575 543:dffcbfbc4e59
    23 			// Safari will crash if the build in createlink command is used
    23 			// Safari will crash if the build in createlink command is used
    24 /*			ed.addCommand('CreateLink', function(u, v) {
    24 /*			ed.addCommand('CreateLink', function(u, v) {
    25 				ed.execCommand("mceInsertContent", false, '<a href="' + dom.encode(v) + '">' + ed.selection.getContent() + '</a>');
    25 				ed.execCommand("mceInsertContent", false, '<a href="' + dom.encode(v) + '">' + ed.selection.getContent() + '</a>');
    26 			});*/
    26 			});*/
    27 
    27 
       
    28 			ed.onPaste.add(function(ed, e) {
       
    29 				function removeStyles(e) {
       
    30 					e = e.target;
       
    31 
       
    32 					if (e.nodeType == 1) {
       
    33 						e.style.cssText = '';
       
    34 
       
    35 						each(ed.dom.select('*', e), function(e) {
       
    36 							e.style.cssText = '';
       
    37 						});
       
    38 					}
       
    39 				};
       
    40 
       
    41 				Event.add(ed.getDoc(), 'DOMNodeInserted', removeStyles);
       
    42 
       
    43 				window.setTimeout(function() {
       
    44 					Event.remove(ed.getDoc(), 'DOMNodeInserted', removeStyles);
       
    45 				}, 0);
       
    46 			});
       
    47 
    28 			ed.onKeyUp.add(function(ed, e) {
    48 			ed.onKeyUp.add(function(ed, e) {
    29 				var h;
    49 				var h, b;
    30 
    50 
    31 				// If backspace or delete key
    51 				// If backspace or delete key
    32 				if (e.keyCode == 46 || e.keyCode == 8) {
    52 				if (e.keyCode == 46 || e.keyCode == 8) {
    33 					h = ed.getBody().innerHTML;
    53 					b = ed.getBody();
       
    54 					h = b.innerHTML;
    34 
    55 
    35 					// If there is no text content or images or hr elements then remove everything
    56 					// If there is no text content or images or hr elements then remove everything
    36 					if (!/<(img|hr)/.test(h) && tinymce.trim(h.replace(/<[^>]+>/g, '')).length == 0)
    57 					if (b.childNodes.length == 1 && !/<(img|hr)/.test(h) && tinymce.trim(h.replace(/<[^>]+>/g, '')).length == 0)
    37 						ed.setContent('', {format : 'raw'});
    58 						ed.setContent('', {format : 'raw'});
    38 				}
    59 				}
    39 			});
    60 			});
    40 
    61 
    41 			// Workaround for FormatBlock bug, http://bugs.webkit.org/show_bug.cgi?id=16004
    62 			// Workaround for FormatBlock bug, http://bugs.webkit.org/show_bug.cgi?id=16004
   105 					ed.selection.select(e);
   126 					ed.selection.select(e);
   106 				} else
   127 				} else
   107 					t.selElm = null;
   128 					t.selElm = null;
   108 			});
   129 			});
   109 
   130 
   110 			ed.onBeforeExecCommand.add(function(ed, c, b) {
   131 /*			ed.onBeforeExecCommand.add(function(ed, c, b) {
   111 				var r = t.bookmarkRng;
   132 				var r = t.bookmarkRng;
   112 
   133 
   113 				// Restore selection
   134 				// Restore selection
   114 				if (r) {
   135 				if (r) {
   115 					ed.selection.setRng(r);
   136 					ed.selection.setRng(r);
   116 					t.bookmarkRng = null;
   137 					t.bookmarkRng = null;
   117 					//console.debug('restore', r.startContainer, r.startOffset, r.endContainer, r.endOffset);
   138 					//console.debug('restore', r.startContainer, r.startOffset, r.endContainer, r.endOffset);
   118 				}
   139 				}
   119 			});
   140 			});*/
   120 
   141 
   121 			ed.onInit.add(function() {
   142 			ed.onInit.add(function() {
   122 				t._fixWebKitSpans();
   143 				t._fixWebKitSpans();
   123 
   144 
   124 				ed.windowManager.onOpen.add(function() {
   145 /*				ed.windowManager.onOpen.add(function() {
   125 					var r = ed.selection.getRng();
   146 					var r = ed.selection.getRng();
   126 
   147 
   127 					// Store selection if valid
   148 					// Store selection if valid
   128 					if (r.startContainer != ed.getDoc()) {
   149 					if (r.startContainer != ed.getDoc()) {
   129 						t.bookmarkRng = r.cloneRange();
   150 						t.bookmarkRng = r.cloneRange();
   131 					}
   152 					}
   132 				});
   153 				});
   133 
   154 
   134 				ed.windowManager.onClose.add(function() {
   155 				ed.windowManager.onClose.add(function() {
   135 					t.bookmarkRng = null;
   156 					t.bookmarkRng = null;
   136 				});
   157 				});*/
   137 
   158 
   138 				if (isOldWebKit)
   159 				if (isOldWebKit)
   139 					t._patchSafari2x(ed);
   160 					t._patchSafari2x(ed);
   140 			});
   161 			});
   141 
   162 
   245 				// Safari adds id="undefined" to HR elements
   266 				// Safari adds id="undefined" to HR elements
   246 				o.content = o.content.replace(/ id=\"undefined\"/g, '');
   267 				o.content = o.content.replace(/ id=\"undefined\"/g, '');
   247 			});
   268 			});
   248 		},
   269 		},
   249 
   270 
       
   271 		getInfo : function() {
       
   272 			return {
       
   273 				longname : 'Safari compatibility',
       
   274 				author : 'Moxiecode Systems AB',
       
   275 				authorurl : 'http://tinymce.moxiecode.com',
       
   276 				infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/safari',
       
   277 				version : tinymce.majorVersion + "." + tinymce.minorVersion
       
   278 			};
       
   279 		},
       
   280 
       
   281 		// Internal methods
       
   282 
   250 		_fixWebKitSpans : function() {
   283 		_fixWebKitSpans : function() {
   251 			var t = this, ed = t.editor;
   284 			var t = this, ed = t.editor;
   252 
   285 
   253 			if (!isOldWebKit) {
   286 			if (!isOldWebKit) {
   254 				// Use mutator events on new WebKit
   287 				// Use mutator events on new WebKit