From 28781ebb081ab8d99b30a33f5cd911b3b050bcc9 Mon Sep 17 00:00:00 2001
From: donncha (\\s| )* [\\s]*', 'mgi'), '');
- content = content.replace(new RegExp('[\\s]* ', 'mgi'), '');
+ content = content.replace(new RegExp('\\s*
)*)*', 'g'), '<$1>');
-
+
// Pretty it up for the source editor.
var blocklist = 'blockquote|ul|ol|li|table|thead|tr|th|td|div|h\\d|pre|p';
content = content.replace(new RegExp('\\s*('+blocklist+')>\\s*', 'mg'), '$1>\n');
- content = content.replace(new RegExp('\\s*<(('+blocklist+')[^>]*)>\\s*', 'mg'), '\n<$1>');
+ content = content.replace(new RegExp('\\s*<(('+blocklist+')[^>]*)>', 'mg'), '\n<$1>');
content = content.replace(new RegExp('<((li|/?tr|/?thead|/?tfoot)( [^>]*)?)>', 'g'), '\t<$1>');
content = content.replace(new RegExp('<((td|th)( [^>]*)?)>', 'g'), '\t\t<$1>');
content = content.replace(new RegExp('\\s*
\\s*', 'mg'), '
\n');
@@ -294,9 +294,9 @@ var TinyMCE_wordpressPlugin = {
// content = content.replace(new RegExp('&', 'g'), '&');
// Get it ready for wpautop.
- content = content.replace(new RegExp('[\\s]*
\\s*', 'gi'), '\n');
// Fix some block element newline issues
@@ -309,8 +309,7 @@ var TinyMCE_wordpressPlugin = {
content = content.replace(new RegExp('
]+>.*
)', 'mg'), '\n$1'); - // Trim any whitespace - content = content.replace(new RegExp('^\\s*', ''), ''); + // Trim trailing whitespace content = content.replace(new RegExp('\\s*$', ''), ''); // Hope. @@ -468,3 +467,126 @@ tinyMCE.wpTriggerSave = function () { inst.wpTriggerSave(false, false); } } + +function switchEditors(id) { + var inst = tinyMCE.getInstanceById(id); + var qt = document.getElementById('quicktags'); + var H = document.getElementById('edButtonHTML'); + var P = document.getElementById('edButtonPreview'); + var ta = document.getElementById(id); + var pdr = ta.parentNode; + + if ( inst ) { + edToggle(H, P); + + if ( tinyMCE.isMSIE && !tinyMCE.isOpera ) { + // IE rejects the later overflow assignment so we skip this step. + // Alternate code might be nice. Until then, IE reflows. + } else { + // Lock the fieldset's height to prevent reflow/flicker + pdr.style.height = pdr.clientHeight + 'px'; + pdr.style.overflow = 'hidden'; + } + + // Save the coords of the bottom right corner of the rich editor + var table = document.getElementById(inst.editorId + '_parent').getElementsByTagName('table')[0]; + var y1 = table.offsetTop + table.offsetHeight; + + if ( TinyMCE_AdvancedTheme._getCookie("TinyMCE_" + inst.editorId + "_height") == null ) { + var expires = new Date(); + expires.setTime(expires.getTime() + 3600000 * 24 * 30); + var offset = tinyMCE.isMSIE ? 1 : 2; + TinyMCE_AdvancedTheme._setCookie("TinyMCE_" + inst.editorId + "_height", "" + (table.offsetHeight - offset), expires); + } + + // Unload the rich editor + inst.triggerSave(false, false); + htm = inst.formElement.value; + tinyMCE.removeMCEControl(id); + document.getElementById(id).value = htm; + --tinyMCE.idCounter; + + // Reveal Quicktags and textarea + qt.style.display = 'block'; + ta.style.display = 'inline'; + + // Set the textarea height to match the rich editor + y2 = ta.offsetTop + ta.offsetHeight; + ta.style.height = (ta.clientHeight + y1 - y2) + 'px'; + + // Tweak the widths + ta.parentNode.style.paddingRight = '2px'; + + if ( tinyMCE.isMSIE && !tinyMCE.isOpera ) { + } else { + // Unlock the fieldset's height + pdr.style.height = 'auto'; + pdr.style.overflow = 'display'; + } + } else { + edToggle(P, H); + edCloseAllTags(); // :-( + + if ( tinyMCE.isMSIE && !tinyMCE.isOpera ) { + } else { + // Lock the fieldset's height + pdr.style.height = pdr.clientHeight + 'px'; + pdr.style.overflow = 'hidden'; + } + + // Hide Quicktags and textarea + qt.style.display = 'none'; + ta.style.display = 'none'; + + // Tweak the widths + ta.parentNode.style.paddingRight = '0px'; + + // Load the rich editor with formatted html + if ( tinyMCE.isMSIE ) { + ta.value = wpautop(ta.value); + tinyMCE.addMCEControl(ta, id); + } else { + htm = wpautop(ta.value); + tinyMCE.addMCEControl(ta, id); + tinyMCE.getInstanceById(id).execCommand('mceSetContent', null, htm); + } + + if ( tinyMCE.isMSIE && !tinyMCE.isOpera ) { + } else { + // Unlock the fieldset's height + pdr.style.height = 'auto'; + pdr.style.overflow = 'display'; + } + } +} + +function edToggle(A, B) { + A.className = 'edButtonFore'; + B.className = 'edButtonBack'; + + B.onclick = A.onclick; + A.onclick = null; +} + +function wpautop(pee) { + pee = pee + "\n\n"; + pee = pee.replace(new RegExp('$1
\n"); + pee = pee.replace(new RegExp('\\s*?
', 'gi'), ''); + pee = pee.replace(new RegExp('\\s*(?(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|hr|pre|select|form|blockquote|address|math|p|h[1-6])[^>]*>)\\s*
', 'gi'), "$1"); + pee = pee.replace(new RegExp("(
]*)>', 'gi'), "'); + pee = pee.replace(new RegExp('', 'gi'), '"); + pee = pee.replace(new RegExp('
\\s*(?(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|hr|pre|select|form|blockquote|address|math|p|h[1-6])[^>]*>)', 'gi'), "$1"); + pee = pee.replace(new RegExp('(?(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|address|math|p|h[1-6])[^>]*>)\\s*
', 'gi'), "$1"); + pee = pee.replace(new RegExp('\\s*\\n', 'gi'), "