Remember last editor chosen. Props mdawaffe. fixes #3978

git-svn-id: http://svn.automattic.com/wordpress/trunk@6567 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-01-06 19:01:32 +00:00
parent 92a7e547c5
commit 0a5781da6e
8 changed files with 57 additions and 19 deletions

View File

@ -50,7 +50,7 @@ if (empty($post->post_status)) $post->post_status = 'draft';
?>
<input type="hidden" name="user_ID" value="<?php echo (int) $user_ID ?>" />
<input type="hidden" id="user-id" name="user_ID" value="<?php echo (int) $user_ID ?>" />
<input type="hidden" id="hiddenaction" name="action" value="<?php echo $form_action ?>" />
<input type="hidden" id="originalaction" name="originalaction" value="<?php echo $form_action ?>" />
<input type="hidden" name="post_author" value="<?php echo attribute_escape( $post->post_author ); ?>" />

View File

@ -6,7 +6,7 @@
<?php if (isset($mode) && 'bookmarklet' == $mode) : ?>
<input type="hidden" name="mode" value="bookmarklet" />
<?php endif; ?>
<input type="hidden" name="user_ID" value="<?php echo (int) $user_ID ?>" />
<input type="hidden" id="user-id" name="user_ID" value="<?php echo (int) $user_ID ?>" />
<input type="hidden" name="action" value='post' />
<script type="text/javascript">

View File

@ -33,7 +33,7 @@ if (isset($mode) && 'bookmarklet' == $mode) {
echo '<input type="hidden" name="mode" value="bookmarklet" />';
}
?>
<input type="hidden" name="user_ID" value="<?php echo $user_ID ?>" />
<input type="hidden" id="user-id" name="user_ID" value="<?php echo $user_ID ?>" />
<input type="hidden" id="hiddenaction" name="action" value='<?php echo $form_action ?>' />
<input type="hidden" id="originalaction" name="originalaction" value="<?php echo $form_action ?>" />
<?php echo $form_extra ?>

View File

@ -402,10 +402,6 @@ input.delete:hover {
padding-right: 6px;
}
#postdivrich #quicktags {
display: none;
}
#quicktags #ed_toolbar {
padding: 0 2px;
}

View File

@ -907,6 +907,15 @@ function user_can_richedit() {
return apply_filters('user_can_richedit', $wp_rich_edit);
}
function wp_default_editor() {
$r = user_can_richedit() ? 'tinymce' : 'html'; // defaults
if ( $user = wp_get_current_user() ) { // look for cookie
if ( isset($_COOKIE['wordpress_editor_' . $user->ID]) && in_array($_COOKIE['wordpress_editor_' . $user->ID], array('tinymce', 'html', 'test') ) )
$r = $_COOKIE['wordpress_editor_' . $user->ID];
}
return apply_filters( 'wp_default_editor', $r ); // filter
}
function the_editor($content, $id = 'content', $prev_id = 'title') {
$rows = get_option('default_post_edit_rows');
if (($rows < 3) || ($rows > 100))
@ -915,7 +924,12 @@ function the_editor($content, $id = 'content', $prev_id = 'title') {
$rows = "rows='$rows'";
if ( user_can_richedit() ) :
add_filter('the_editor_content', 'wp_richedit_pre');
$wp_default_editor = wp_default_editor();
$active = " class='active'";
$inactive = " onclick='switchEditors(\"$id\");'";
if ( 'tinymce' == $wp_default_editor )
add_filter('the_editor_content', 'wp_richedit_pre');
// The following line moves the border so that the active button "attaches" to the toolbar. Only IE needs it.
?>
@ -925,13 +939,15 @@ function the_editor($content, $id = 'content', $prev_id = 'title') {
</style>
<div id='editor-toolbar' style='display:none;'>
<div class='zerosize'><input accesskey='e' type='button' onclick='switchEditors("<?php echo $id; ?>")' /></div>
<a id='edButtonHTML' class='' onclick='switchEditors("<?php echo $id; ?>")'><?php _e('HTML'); ?></a>
<a id='edButtonPreview' class='active'><?php _e('Visual'); ?></a>
<div id="media-buttons">
<?php _e('Add media:'); ?>
<?php do_action( 'media_buttons'); ?>
</div>
<a id='edButtonHTML'<?php echo 'html' == $wp_default_editor ? $active : $inactive; ?>><?php _e('HTML'); ?></a>
<a id='edButtonPreview'<?php echo 'tinymce' == $wp_default_editor ? $active : $inactive; ?>><?php _e('Visual'); ?></a>
<div id="media-buttons">
<?php _e('Add media:'); ?>
<?php do_action( 'media_buttons'); ?>
</div>
</div>
<script type="text/javascript">
// <![CDATA[
if ( typeof tinyMCE != "undefined" && tinyMCE.configs.length > 0 )
@ -939,20 +955,23 @@ function the_editor($content, $id = 'content', $prev_id = 'title') {
// ]]>
</script>
<?php endif; ?>
<?php endif; // user_can_richedit() ?>
<div id="quicktags">
<?php wp_print_scripts( 'quicktags' ); ?>
<script type="text/javascript">edToolbar()</script>
</div>
<?php if ( 'html' != $wp_default_editor ) : ?>
<script type="text/javascript">
// <![CDATA[
if ( typeof tinyMCE != "undefined" && tinyMCE.configs.length > 0 )
document.getElementById("quicktags").style.display="none";
// ]]>
</script>
<?php
<?php endif; // 'html' != $wp_default_editor
$the_editor = apply_filters('the_editor', "<div><textarea class='mceEditor' $rows cols='40' name='$id' tabindex='2' id='$id'>%s</textarea></div>\n");
$the_editor = apply_filters('the_editor', "<div><textarea class='' $rows cols='40' name='$id' tabindex='2' id='$id'>%s</textarea></div>\n");
$the_editor_content = apply_filters('the_editor_content', $content);
printf($the_editor, $the_editor_content);

View File

@ -523,6 +523,7 @@ function switchEditors(id) {
pdr.style.height = 'auto';
pdr.style.overflow = 'display';
}
wpSetDefaultEditor( 'html' );
} else {
edToggle(P, H);
edCloseAllTags(); // :-(
@ -557,6 +558,7 @@ function switchEditors(id) {
pdr.style.height = 'auto';
pdr.style.overflow = 'display';
}
wpSetDefaultEditor( 'tinymce' );
}
}
@ -568,6 +570,19 @@ function edToggle(A, B) {
A.onclick = null;
}
function wpSetDefaultEditor( editor ) {
try {
editor = escape( editor.toString() );
} catch(err) {
editor = 'tinymce';
}
var userID = document.getElementById('user-id');
var date = new Date();
date.setTime(date.getTime()+(10*365*24*60*60*1000));
document.cookie = "wordpress_editor_" + userID.value + "=" + editor + "; expires=" + date.toGMTString();
}
function wpautop(pee) {
pee = pee + "\n\n";
pee = pee.replace(new RegExp('<br />\\s*<br />', 'gi'), "\n\n");

View File

@ -54,9 +54,16 @@
$mce_locale = ( '' == get_locale() ) ? 'en' : strtolower(get_locale());
?>
wpEditorInit = function() {
// Activate tinyMCE if it's the user's default editor
if ( ( 'undefined' == typeof wpTinyMCEConfig ) || 'tinymce' == wpTinyMCEConfig.defaultEditor )
tinyMCE.execCommand("mceAddControl", true, 'content');
};
initArray = {
mode : "specific_textareas",
editor_selector : "mceEditor",
oninit : "wpEditorInit",
width : "100%",
theme : "advanced",
theme_advanced_buttons1 : "<?php echo $mce_buttons; ?>",

View File

@ -31,10 +31,11 @@ class WP_Scripts {
$this->add( 'colorpicker', '/wp-includes/js/colorpicker.js', false, '3517' );
// Modify this version when tinyMCE plugins are changed
$this->add( 'tiny_mce', '/wp-includes/js/tinymce/tiny_mce_gzip.php', false, '20080103' );
$this->add( 'tiny_mce', '/wp-includes/js/tinymce/tiny_mce_gzip.php', false, '20080105' );
$mce_config = apply_filters('tiny_mce_config_url', '/wp-includes/js/tinymce/tiny_mce_config.php');
$this->add( 'wp_tiny_mce', $mce_config, array('tiny_mce'), '20070528' );
$this->add( 'wp_tiny_mce', $mce_config, array('tiny_mce'), '20080105' );
$this->localize( 'wp_tiny_mce', 'wpTinyMCEConfig', array( 'defaultEditor' => wp_default_editor() ) );
$this->add( 'prototype', '/wp-includes/js/prototype.js', false, '1.6');