MCE fix-em-ups from skeltoac. fixes #1962

git-svn-id: http://svn.automattic.com/wordpress/trunk@3283 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2005-12-09 19:24:14 +00:00
parent 25887cc8bc
commit 06c51d01c2
9 changed files with 178 additions and 58 deletions

View File

@ -1077,13 +1077,39 @@ function save_mod_rewrite_rules() {
function the_quicktags() {
// Browser detection sucks, but until Safari supports the JS needed for this to work people just assume it's a bug in WP
if (!strstr($_SERVER['HTTP_USER_AGENT'], 'Safari'))
: echo '
echo '
<div id="quicktags">
<script src="../wp-includes/js/quicktags.js" type="text/javascript"></script>
<script type="text/javascript">edToolbar();</script>
';
echo '</div>';
endif;
<script type="text/javascript">if ( typeof tinyMCE == "undefined" || tinyMCE.configs.length < 1 ) edToolbar();</script>
</div>
';
else echo '
<script type="text/javascript">
function edInsertContent(myField, myValue) {
//IE support
if (document.selection) {
myField.focus();
sel = document.selection.createRange();
sel.text = myValue;
myField.focus();
}
//MOZILLA/NETSCAPE support
else if (myField.selectionStart || myField.selectionStart == "0") {
var startPos = myField.selectionStart;
var endPos = myField.selectionEnd;
myField.value = myField.value.substring(0, startPos)
+ myValue
+ myField.value.substring(endPos, myField.value.length);
myField.focus();
myField.selectionStart = startPos + myValue.length;
myField.selectionEnd = startPos + myValue.length;
} else {
myField.value += myValue;
myField.focus();
}
}
</script>
';
}
function validate_current_theme() {
@ -1801,4 +1827,14 @@ function wp_import_handle_upload() {
return array('file' => $file, 'id' => $id);
}
function user_can_richedit() {
if ( 'true' != get_user_option('rich_editing') )
return false;
if ( preg_match('!opera[ /][2-8]|konqueror|safari!i', $_SERVER['HTTP_USER_AGENT']) )
return false;
return true; // Best guess
}
?>

View File

@ -79,11 +79,13 @@ addLoadEvent(blurry);
<script type="text/javascript" src="../wp-includes/js/tw-sack.js"></script>
<script type="text/javascript" src="list-manipulation.js"></script>
<?php if ( isset( $editing ) ) : ?>
<?php if ( $editing && 'true' == get_user_option('rich_editing') ) :
<?php if ( $editing && user_can_richedit() ) :
$mce_plugins = apply_filters('mce_plugins', array('wordpress', 'autosave', 'wphelp'));
$mce_plugins = implode($mce_plugins, ',');
$mce_buttons = apply_filters('mce_buttons', array('bold', 'italic', 'strikethrough', 'separator', 'bullist', 'numlist', 'outdent', 'indent', 'separator', 'justifyleft', 'justifycenter', 'justifyright' ,'separator', 'link', 'unlink', 'image', 'emotions', 'wordpress', 'separator', 'undo', 'redo', 'code', 'wphelp'));
$mce_buttons = implode($mce_buttons, ',');
$mce_buttons_2 = apply_filters('mce_buttons_2', array());
$mce_buttons_2 = implode($mce_buttons_2, ',');
?>
<script language="javascript" type="text/javascript" src="../wp-includes/js/tinymce/tiny_mce_gzip.php?index=0&theme=advanced&plugins=<?php echo $mce_plugins; ?>"></script>
<script type="text/javascript">
@ -93,7 +95,7 @@ tinyMCE.init({
width : "100%",
theme : "advanced",
theme_advanced_buttons1 : "<?php echo $mce_buttons; ?>",
theme_advanced_buttons2 : "",
theme_advanced_buttons2 : "<?php echo $mce_buttons_2; ?>",
theme_advanced_buttons3 : "",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
@ -110,7 +112,9 @@ tinyMCE.init({
convert_newlines_to_brs : false,
remove_linebreaks : true,
save_callback : "wp_save_callback",
valid_elements : "-a[id|href|title|rel],-strong/b,-em/i,-strike,-del,-u,p[class|align|dir],-ol,-ul,-li,br,img[class|src|alt|title|width|height|align],-sub,-sup,-blockquote[dir],-table[border=0|cellspacing|cellpadding|width|height|class|align|dir],thead[class|rowspan|width|height|align|valign|dir],tr[class|rowspan|width|height|align|valign|dir],th[dir|class|colspan|rowspan|width|height|align|valign|scope],td[dir|class|colspan|rowspan|width|height|align|valign],-div[dir|class|align],-span[class|align],-pre[class],-code[class],-address,-h1[class|align|dir],-h2[class|align|dir],-h3[class|align|dir],-h4[class|align|dir],-h5[class|align|dir],-h6[class|align|dir],hr",
<?php if (current_user_can('unfiltered_html') == false) : ?>
valid_elements : "-a[id|href|title|rel],-strong/b,-em/i,-strike,-del,-u,p[class|align|dir],-ol,-ul,-li,br,img[class|src|alt|title|width|height|align],-sub,-sup,-blockquote[dir],-table[border=0|cellspacing|cellpadding|width|height|class|align|dir],thead[class|rowspan|width|height|align|valign|dir],tr[class|rowspan|width|height|align|valign|dir],th[dir|class|colspan|rowspan|width|height|align|valign|scope],td[dir|class|colspan|rowspan|width|height|align|valign],-div[dir|class|align],-span[class|align],-pre[class],-code[class],-address,-h1[class|align|dir],-h2[class|align|dir],-h3[class|align|dir],-h4[class|align|dir],-h5[class|align|dir],-h6[class|align|dir],hr",
<?php endif; ?>
plugins : "<?php echo $mce_plugins; ?>"
<?php do_action('mce_options'); ?>
});
@ -151,6 +155,7 @@ var ajaxCat = new sack();
var newcat;
function newCatAddIn() {
if ( !document.getElementById('jaxcat') ) return false;
var ajaxcat = document.createElement('p');
ajaxcat.id = 'ajaxcat';

View File

@ -7,8 +7,6 @@ $messages[3] = __('Custom field deleted.');
<div id="message" class="updated fade"><p><?php echo $messages[$_GET['message']]; ?></p></div>
<?php endif; ?>
<?php $richedit = ( 'true' != get_user_option('rich_editing') ) ? false : true; ?>
<form name="post" action="post.php" method="post" id="post">
<?php if ( (isset($mode) && 'bookmarklet' == $mode) ||
isset($_GET['popupurl']) ): ?>
@ -139,7 +137,7 @@ endforeach;
<div><input type="text" name="post_title" size="30" tabindex="1" value="<?php echo $post->post_title; ?>" id="title" /></div>
</fieldset>
<fieldset id="<?php echo $richedit ? 'postdivrich' : 'postdiv'; ?>">
<fieldset id="<?php echo user_can_richedit() ? 'postdivrich' : 'postdiv'; ?>">
<legend><?php _e('Post') ?></legend>
<?php
@ -148,20 +146,15 @@ endforeach;
$rows = 12;
}
?>
<?php if ( !$richedit ) the_quicktags(); ?>
<?php the_quicktags(); ?>
<div><textarea <?php if ( $richedit ) echo 'title="true"'; ?> rows="<?php echo $rows; ?>" cols="40" name="content" tabindex="2" id="content"><?php echo $richedit ? wp_richedit_pre($post->post_content) : $post->post_content; ?></textarea></div>
<div><textarea title="true" rows="<?php echo $rows; ?>" cols="40" name="content" tabindex="2" id="content"><?php echo user_can_richedit() ? wp_richedit_pre($post->post_content) : $post->post_content; ?></textarea></div>
</fieldset>
<?php if ( !$richedit ) : ?>
<script type="text/javascript">
<!--
edCanvas = document.getElementById('content');
//-->
</script>
<?php else : ?>
<script type="text/javascript">
<!--
<?php if ( user_can_richedit() ) : ?>
// This code is meant to allow tabbing from Title to Post (TinyMCE).
if ( tinyMCE.isMSIE )
document.getElementById('title').onkeydown = function (e)
@ -193,10 +186,9 @@ else
return false;
}
}
<?php endif; ?>
//-->
</script>
<?php endif; ?>
<?php echo $form_pingback ?>
<?php echo $form_prevstatus ?>

View File

@ -4,7 +4,6 @@ $toprow_title = sprintf(__('Editing Comment # %s'), $comment->comment_ID);
$form_action = 'editedcomment';
$form_extra = "' />\n<input type='hidden' name='comment_ID' value='" . $comment->comment_ID . "' />\n<input type='hidden' name='comment_post_ID' value='".$comment->comment_post_ID;
?>
<?php $richedit = ( 'true' != get_user_option('rich_editing') ) ? false : true; ?>
<form name="post" action="post.php" method="post" id="post">
<div class="wrap">
@ -32,13 +31,13 @@ addLoadEvent(focusit);
<fieldset id="uridiv">
<legend><?php _e('URI:') ?></legend>
<div>
<input type="text" name="newcomment_author_url" size="35" value="<?php echo $comment->comment_author_url ?>" tabindex="3" id="URL" />
<input type="text" id="newcomment_author_url" name="newcomment_author_url" size="35" value="<?php echo $comment->comment_author_url ?>" tabindex="3" id="URL" />
</div>
</fieldset>
<fieldset style="clear: both;">
<legend><?php _e('Comment') ?></legend>
<?php if ( !$richedit ) the_quicktags(); ?>
<?php the_quicktags(); ?>
<?php
$rows = get_settings('default_post_edit_rows');
@ -46,16 +45,47 @@ addLoadEvent(focusit);
$rows = 10;
}
?>
<div><textarea <?php if ( $richedit ) echo 'title="true"'; ?> rows="<?php echo $rows; ?>" cols="40" name="content" tabindex="4" id="content" style="width: 99%"><?php echo $richedit ? wp_richedit_pre($comment->comment_content) : $comment->comment_content; ?></textarea></div>
<div><textarea title="true" rows="<?php echo $rows; ?>" cols="40" name="content" tabindex="4" id="content" style="width: 99%"><?php echo user_can_richedit() ? wp_richedit_pre($comment->comment_content) : $comment->comment_content; ?></textarea></div>
</fieldset>
<?php if ( !$richedit ) : ?>
<script type="text/javascript">
<!--
edCanvas = document.getElementById('content');
<?php if ( user_can_richedit() ) : ?>
// This code is meant to allow tabbing from Author URL to Post (TinyMCE).
if ( tinyMCE.isMSIE )
document.getElementById('newcomment_author_url').onkeydown = function (e)
{
e = e ? e : window.event;
if (e.keyCode == 9 && !e.shiftKey && !e.controlKey && !e.altKey) {
var i = tinyMCE.selectedInstance;
if(typeof i == 'undefined')
return true;
tinyMCE.execCommand("mceStartTyping");
this.blur();
i.contentWindow.focus();
e.returnValue = false;
return false;
}
}
else
document.getElementById('newcomment_author_url').onkeypress = function (e)
{
e = e ? e : window.event;
if (e.keyCode == 9 && !e.shiftKey && !e.controlKey && !e.altKey) {
var i = tinyMCE.selectedInstance;
if(typeof i == 'undefined')
return true;
tinyMCE.execCommand("mceStartTyping");
this.blur();
i.contentWindow.focus();
e.returnValue = false;
return false;
}
}
<?php endif; ?>
//-->
</script>
<?php endif; ?>
<p class="submit"><input type="submit" name="editcomment" id="editcomment" value="<?php echo $submitbutton_text ?>" style="font-weight: bold;" tabindex="6" />
<input name="referredby" type="hidden" id="referredby" value="<?php echo $_SERVER['HTTP_REFERER']; ?>" />

View File

@ -20,8 +20,6 @@ $sendto = wp_specialchars( $sendto );
?>
<?php $richedit = ( 'true' != get_user_option('rich_editing') ) ? false : true; ?>
<form name="post" action="post.php" method="post" id="post">
<?php
@ -119,7 +117,7 @@ endforeach;
</fieldset>
<fieldset id="<?php echo ( $richedit) ? 'postdivrich' : 'postdiv'; ?>">
<fieldset id="<?php echo user_can_richedit() ? 'postdivrich' : 'postdiv'; ?>">
<legend><?php _e('Page Content') ?></legend>
<?php
$rows = get_settings('default_post_edit_rows');
@ -127,18 +125,49 @@ endforeach;
$rows = 10;
}
?>
<?php if (! $richedit ) the_quicktags(); ?>
<?php the_quicktags(); ?>
<div><textarea title="true" rows="<?php echo $rows; ?>" cols="40" name="content" tabindex="4" id="content"><?php echo $richedit ? wp_richedit_pre($post->post_content) : $post->post_content; ?></textarea></div>
<div><textarea title="true" rows="<?php echo $rows; ?>" cols="40" name="content" tabindex="4" id="content"><?php echo user_can_richedit() ? wp_richedit_pre($post->post_content) : $post->post_content; ?></textarea></div>
</fieldset>
<?php if ( !$richedit ) : ?>
<script type="text/javascript">
<!--
edCanvas = document.getElementById('content');
<?php if ( user_can_richedit() ) : ?>
// This code is meant to allow tabbing from Title to Post (TinyMCE).
if ( tinyMCE.isMSIE )
document.getElementById('title').onkeydown = function (e)
{
e = e ? e : window.event;
if (e.keyCode == 9 && !e.shiftKey && !e.controlKey && !e.altKey) {
var i = tinyMCE.selectedInstance;
if(typeof i == 'undefined')
return true;
tinyMCE.execCommand("mceStartTyping");
this.blur();
i.contentWindow.focus();
e.returnValue = false;
return false;
}
}
else
document.getElementById('title').onkeypress = function (e)
{
e = e ? e : window.event;
if (e.keyCode == 9 && !e.shiftKey && !e.controlKey && !e.altKey) {
var i = tinyMCE.selectedInstance;
if(typeof i == 'undefined')
return true;
tinyMCE.execCommand("mceStartTyping");
this.blur();
i.contentWindow.focus();
e.returnValue = false;
return false;
}
}
<?php endif; ?>
//-->
</script>
<?php endif; ?>
<p class="submit">
<?php if ( $post_ID ) : ?>

View File

@ -150,6 +150,7 @@ if ( $start > 0 ) {
$uwidth_sum = 0;
$html = '';
$popups = '';
$style = '';
$script = '';
if ( count($attachments) > 0 ) {
@ -162,6 +163,7 @@ if ( count($attachments) > 0 ) {
$__using_thumbnail = __('Using Thumbnail');
$__using_original = __('Using Original');
$__no_thumbnail = '<del>'.__('No Thumbnail').'</del>';
$__send_to_editor = __('Send to editor');
$__close = __('Close Options');
$__confirmdelete = __('Delete this file from the server?');
$__nothumb = __('There is no thumbnail associated with this photo.');
@ -190,7 +192,8 @@ var srcb = new Array();
add_post_meta($ID, '_wp_attachment_metadata', $meta);
}
$attachment = array_merge($attachment, $meta);
$delete_cancel = "<a onclick=\"return confirm('$__confirmdelete')\" href=\"".basename(__FILE__)."?action=delete&amp;attachment={$ID}&amp;all=$all&amp;start=$start&amp;post=$post\">$__delete</a>
$send_delete_cancel = "<a onclick=\"sendToEditor({$ID});return false;\" href=\"javascript:void()\">$__send_to_editor</a>
<a onclick=\"return confirm('$__confirmdelete')\" href=\"".basename(__FILE__)."?action=delete&amp;attachment={$ID}&amp;all=$all&amp;start=$start&amp;post=$post\">$__delete</a>
<a onclick=\"popup.style.display='none';return false;\" href=\"javascript:void()\">$__close</a>
";
$uwidth_sum += 128;
@ -219,30 +222,32 @@ imga[{$ID}] = '<img id=\"image{$ID}\" src=\"$src\" alt=\"{$image['post_title']}\
imgb[{$ID}] = '<img id=\"image{$ID}\" src=\"{$image['guid']}\" alt=\"{$image['post_title']}\" $height_width />';
";
$html .= "<div id='target{$ID}' class='attwrap left'>
<div id='popup{$ID}' class='popup'>
<a id=\"I{$ID}\" onclick=\"if($thumb)toggleImage({$ID});else alert('$__nothumb');return false;\" href=\"javascript:void()\">$thumbtext</a>
<a id=\"L{$ID}\" onclick=\"toggleLink({$ID});return false;\" href=\"javascript:void()\">$__not_linked</a>
{$delete_cancel}
</div>
<div id='div{$ID}' class='imagewrap' onclick=\"doPopup({$ID});\">
<img id=\"image{$ID}\" src=\"$src\" alt=\"{$image['post_title']}\" $height_width />
</div>
</div>
";
$popups .= "<div id='popup{$ID}' class='popup'>
<a id=\"I{$ID}\" onclick=\"if($thumb)toggleImage({$ID});else alert('$__nothumb');return false;\" href=\"javascript:void()\">$thumbtext</a>
<a id=\"L{$ID}\" onclick=\"toggleLink({$ID});return false;\" href=\"javascript:void()\">$__not_linked</a>
{$send_delete_cancel}
</div>
";
} else {
$script .= "a{$ID}a = '<a id=\"{$ID}\" rel=\"attachment\" href=\"$href\" onclick=\"doPopup({$ID});return false;\" title=\"{$attachment['post_title']}\">{$attachment['post_title']}</a>';
a{$ID}b = '<a id=\"{$ID}\" href=\"{$attachment['guid']}\" onclick=\"doPopup({$ID});return false;\" title=\"{$attachment['post_title']}\">{$attachment['post_title']}</a>';
$script .= "aa[{$ID}] = '<a id=\"{$ID}\" rel=\"attachment\" href=\"$href\" onclick=\"doPopup({$ID});return false;\" title=\"{$attachment['post_title']}\">{$attachment['post_title']}</a>';
ab[{$ID}] = '<a id=\"{$ID}\" href=\"{$attachment['guid']}\" onclick=\"doPopup({$ID});return false;\" title=\"{$attachment['post_title']}\">{$attachment['post_title']}</a>';
";
$html .= "<div id='target{$ID}' class='attwrap left'>
<div id='popup{$ID}' class='popup'>
<div class='filetype'>File Type: ".str_replace('/',"/\n",$attachment['post_mime_type'])."</div>
<a id=\"L{$ID}\" onclick=\"toggleOtherLink({$ID});return false;\" href=\"javascript:void()\">$__linked_to_file</a>
{$delete_cancel}
</div>
<div id='div{$ID}' class='otherwrap' onmousedown=\"selectLink({$ID})\" onclick=\"doPopup({$ID});return false;\">
<a id=\"{$ID}\" href=\"{$attachment['guid']}\" onmousedown=\"selectLink({$ID});\" onclick=\"return false;\">{$attachment['post_title']}</a>
</div>
</div>
";
$popups .= "<div id='popup{$ID}' class='popup'>
<div class='filetype'>File Type: ".str_replace('/',"/\n",$attachment['post_mime_type'])."</div>
<a id=\"L{$ID}\" onclick=\"toggleOtherLink({$ID});return false;\" href=\"javascript:void()\">$__linked_to_file</a>
{$send_delete_cancel}
</div>
";
}
}
@ -278,13 +283,14 @@ function doPopup(i) {
target = document.getElementById('target'+i);
popup = document.getElementById('popup'+i);
popup.style.left = (target.offsetLeft) + 'px';
popup.style.top = (target.offsetTop) + 'px';
popup.style.display = 'block';
}
function init() {
popup = false;
}
popup = false;
function selectLink(n) {
o=document.getElementById('div'+n);
if ( typeof document.body.createTextRange == 'undefined' || typeof win.tinyMCE == 'undefined' || win.tinyMCE.configs.length < 1 )
return;
r = document.body.createTextRange();
if ( typeof r != 'undefined' ) {
r.moveToElementText(o);
@ -333,6 +339,24 @@ function toggleImage(n) {
oi.innerHTML = usingthumbnail;
}
}
var win = window.opener ? window.opener : window.dialogArguments;
if (!win) win = top;
tinyMCE = win.tinyMCE;
richedit = ( typeof tinyMCE == 'object' && tinyMCE.configs.length > 0 );
function sendToEditor(n) {
o = document.getElementById('div'+n);
h = o.innerHTML.replace(new RegExp('^\\s*(.*?)\\s*$', ''), '$1'); // Trim
h = h.replace(new RegExp(' (class|title|width|height|id|onclick|onmousedown)=([^\'"][^ ]*)( |/|>)', 'g'), ' $1="$2"$3'); // Enclose attribs in quotes
h = h.replace(new RegExp(' on(click|mousedown)="[^"]*"', 'g'), ''); // Drop menu events
h = h.replace(new RegExp('<(/?)A', 'g'), '<$1a'); // Lowercase tagnames
h = h.replace(new RegExp('<IMG', 'g'), '<img'); // Lowercase again
h = h.replace(new RegExp('(<img .+?")>', 'g'), '$1 />'); // XHTML
if ( richedit )
win.tinyMCE.execCommand('mceInsertContent', false, h);
else
win.edInsertContent(win.edCanvas, h);
}
</script>
<style type="text/css">
body {
@ -351,9 +375,10 @@ form {
width: 100%;
}
#images {
position: absolute;
clear: both;
margin: 0px;
padding: 3px 15px;
padding: 15px 15px;
height: 96px;
/* white-space: nowrap;*/
width: <?php echo $images_width; ?>px;
@ -492,7 +517,7 @@ form {
}
</style>
</head>
<body onload="init()">
<body>
<ul id="upload-menu">
<li<?php echo $current_1; ?>><a href="<?php echo basename(__FILE__); ?>?action=upload&amp;post=<?php echo $post; ?>&amp;all=<?php echo $all; ?>"><?php _e('Upload'); ?></a></li>
<?php if ( $attachments = $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE post_parent = '$post'") ) { ?>
@ -521,9 +546,10 @@ form {
</ul>
<?php if ( $action == 'view' ) : ?>
<div id="wrap">
<div class="tip"><?php _e('You can drag and drop these items into your post. Click on one for more options.'); ?></div>
<!--<div class="tip"><?php _e('You can drag and drop these items into your post. Click on one for more options.'); ?></div>-->
<div id="images">
<?php echo $html; ?>
<?php echo $popups; ?>
</div>
</div>
<?php elseif ( $action == 'upload' ) : ?>

View File

@ -1,7 +1,9 @@
* html #poststuff {
height: 100%; /* kill peekaboo bug in IE */
}
body {
border: none;
}
a {
border-bottom: 1px solid #69c;
color: #00019b;

View File

@ -5526,7 +5526,7 @@ TinyMCEControl.prototype.execCommand = function(command, user_interface, value)
case "mceInsertContent":
var insertHTMLFailed = false;
this.getWin().focus();
/* WP
if (tinyMCE.isGecko || tinyMCE.isOpera) {
try {
// Is plain text or HTML
@ -5560,7 +5560,7 @@ TinyMCEControl.prototype.execCommand = function(command, user_interface, value)
return;
}
}
*/
// Ugly hack in Opera due to non working "inserthtml"
if (tinyMCE.isOpera && insertHTMLFailed) {
this.getDoc().execCommand("insertimage", false, tinyMCE.uniqueURL);