TinyMCE config enhancements from azaozz. fixes #5896 #5888

git-svn-id: http://svn.automattic.com/wordpress/trunk@6894 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-02-18 17:11:12 +00:00
parent 8efbdbbec1
commit 6bef16a574
9 changed files with 108 additions and 127 deletions

View File

@ -5,7 +5,8 @@ $parent_file = 'post-new.php';
$editing = true;
wp_enqueue_script('autosave');
wp_enqueue_script('page');
wp_enqueue_script('editor');
if ( user_can_richedit() )
wp_enqueue_script('editor');
wp_enqueue_script('thickbox');
wp_enqueue_script('media-upload');

View File

@ -53,7 +53,8 @@ case 'edit':
}
wp_enqueue_script('page');
wp_enqueue_script('editor');
if ( user_can_richedit() )
wp_enqueue_script('editor');
wp_enqueue_script('thickbox');
wp_enqueue_script('media-upload');

View File

@ -5,7 +5,8 @@ $parent_file = 'post-new.php';
$editing = true;
wp_enqueue_script('autosave');
wp_enqueue_script('post');
wp_enqueue_script('editor');
if ( user_can_richedit() )
wp_enqueue_script('editor');
wp_enqueue_script('thickbox');
wp_enqueue_script('media-upload');

View File

@ -62,7 +62,8 @@ case 'edit':
}
wp_enqueue_script('post');
wp_enqueue_script('editor');
if ( user_can_richedit() )
wp_enqueue_script('editor');
wp_enqueue_script('thickbox');
wp_enqueue_script('media-upload');

View File

@ -260,16 +260,12 @@ input.delete:hover {
color: #fff;
}
#postdivrich #quicktags {
#postdivrich #quicktags, #postdiv #quicktags {
background: #cee1ef;
padding: 0;
border: 0 none;
}
#postdiv #quicktags {
padding-right: 6px;
}
#quicktags #ed_toolbar {
padding: 0 2px;
}

View File

@ -923,67 +923,40 @@ function the_editor($content, $id = 'content', $prev_id = 'title') {
if (($rows < 3) || ($rows > 100))
$rows = 12;
$rows = "rows='$rows'";
if ( user_can_richedit() ) :
$wp_default_editor = wp_default_editor();
$active = " class='active'";
$inactive = " onclick='switchEditors.go(\"$id\");'";
if ( 'tinymce' == $wp_default_editor )
add_filter('the_editor_content', 'wp_richedit_pre');
else if ( 'html' == $wp_default_editor )
add_filter('the_editor_content', 'wp_htmledit_pre');
// The following line moves the border so that the active button "attaches" to the toolbar. Only IE needs it.
?>
<style type="text/css">
#postdivrich table, #postdivrich #quicktags {border-top: none;}
#quicktags {border-bottom: none; padding-bottom: 2px; margin-bottom: -1px;}
</style>
<div id='editor-toolbar' style='display:none;'>
<div class='zerosize'><input accesskey='e' type='button' onclick='switchEditors.go("<?php echo $id; ?>")' /></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>
$rows = "rows='$rows'"; ?>
<div id="editor-toolbar">
<?php if ( user_can_richedit() ) {
$wp_default_editor = wp_default_editor(); ?>
<div class="zerosize"><input accesskey="e" type="button" onclick="switchEditors.go('<?php echo $id; ?>')" /></div>
<?php if ( 'tinymce' == $wp_default_editor ) {
add_filter('the_editor_content', 'wp_richedit_pre'); ?>
<a id="edButtonHTML" onclick="switchEditors.go('<?php echo $id; ?>');"><?php _e('HTML'); ?></a>
<a id="edButtonPreview" class="active"><?php _e('Visual'); ?></a>
<?php } elseif ( 'html' == $wp_default_editor ) {
add_filter('the_editor_content', 'wp_htmledit_pre'); ?>
<a id="edButtonHTML" class="active"><?php _e('HTML'); ?></a>
<a id="edButtonPreview" onclick="switchEditors.go('<?php echo $id; ?>');"><?php _e('Visual'); ?></a>
<?php }
} ?>
<div id="media-buttons">
<?php _e('Add media:'); ?>
<?php do_action( 'media_buttons'); ?>
</div>
</div>
<script type="text/javascript">
// <![CDATA[
if ( typeof tinyMCE != "undefined" )
document.getElementById('editor-toolbar').style.display = 'block';
// ]]>
</script>
<?php else: // Rich editor is disabled in profile but we still need the media buttons ?>
<div id='editor-toolbar' style='display:block;'>
<div id="media-buttons">
<?php _e('Add media:'); ?>
<?php do_action( 'media_buttons'); ?>
</div>
</div>
<?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" )
document.getElementById("quicktags").style.display="none";
// ]]>
</script>
<?php endif; // 'html' != $wp_default_editor
<?php if ( 'html' != $wp_default_editor ) : ?>
<script type="text/javascript">
// <![CDATA[
if ( typeof tinyMCE != "undefined" )
document.getElementById("quicktags").style.display="none";
// ]]>
</script>
<?php endif; // 'html' != $wp_default_editor
$the_editor = apply_filters('the_editor', "<div id='editorcontainer'><textarea class='' $rows cols='40' name='$id' tabindex='2' id='$id'>%s</textarea></div>\n");
$the_editor_content = apply_filters('the_editor_content', $content);
@ -991,13 +964,13 @@ function the_editor($content, $id = 'content', $prev_id = 'title') {
printf($the_editor, $the_editor_content);
?>
<script type="text/javascript">
//<!--
edCanvas = document.getElementById('<?php echo $id; ?>');
<?php if ( $prev_id && user_can_richedit() ) : ?>
// If tinyMCE is defined.
if ( typeof tinyMCE != 'undefined' ) {
// This code is meant to allow tabbing from Title to Post (TinyMCE).
<script type="text/javascript">
// <![CDATA[
edCanvas = document.getElementById('<?php echo $id; ?>');
<?php if ( $prev_id && user_can_richedit() ) : ?>
// If tinyMCE is defined.
if ( typeof tinyMCE != 'undefined' ) {
// This code is meant to allow tabbing from Title to Post (TinyMCE).
document.getElementById('<?php echo $prev_id; ?>').onkeydown = function (e) {
e = e || window.event;
if (e.keyCode == 9 && !e.shiftKey && !e.controlKey && !e.altKey) {
@ -1010,11 +983,11 @@ function the_editor($content, $id = 'content', $prev_id = 'title') {
return true;
}
}
}
<?php endif; ?>
//-->
</script>
<?php
}
<?php endif; ?>
// ]]>
</script>
<?php
}
function get_search_query() {

View File

@ -47,11 +47,11 @@ function putFileContents( $path, $content ) {
$https = ( isset($_SERVER['HTTPS']) && 'on' == $_SERVER['HTTPS'] ) ? true : false;
$baseurl = get_option('siteurl') . '/wp-includes/js/tinymce';
$baseurl = $https ? str_replace('http://', 'https://', $baseurl) : $baseurl;
if ( $https ) str_replace('http://', 'https://', $baseurl);
$mce_css = $baseurl . '/wordpress.css';
$mce_css = apply_filters('mce_css', $mce_css);
$mce_css = $https ? str_replace('http://', 'https://', $mce_css) : $mce_css;
if ( $https ) str_replace('http://', 'https://', $mce_css);
$valid_elements = '*[*]';
$valid_elements = apply_filters('mce_valid_elements', $valid_elements);
@ -72,17 +72,17 @@ $mce_external_plugins = apply_filters('mce_external_plugins', array());
$ext_plugins = "\n";
foreach ( $mce_external_plugins as $name => $url ) {
$plugins[] = '-' . $name;
$url = $https ? str_replace('http://', 'https://', $url) : $url;
if ( $https ) str_replace('http://', 'https://', $url);
$ext_plugins .= 'tinymce.PluginManager.load("' . $name . '", "' . $url . '");' . "\n";
}
$plugins = implode($plugins, ',');
$mce_buttons = apply_filters('mce_buttons', array('bold', 'italic', 'strikethrough', '|', 'bullist', 'numlist', 'outdent', 'indent', '|', 'justifyleft', 'justifycenter', 'justifyright', '|', 'link', 'unlink', 'image', 'wp_more', '|', 'spellchecker', '|', 'wp_help', 'wp_adv' ));
$mce_buttons = apply_filters('mce_buttons', array('bold', 'italic', 'strikethrough', '|', 'bullist', 'numlist', 'outdent', 'indent', '|', 'justifyleft', 'justifycenter', 'justifyright', '|', 'link', 'unlink', 'image', 'wp_more', '|', 'spellchecker', 'fullscreen', 'wp_adv' ));
$mce_buttons = implode($mce_buttons, ',');
$mce_buttons_2 = apply_filters('mce_buttons_2', array('formatselect', 'underline', 'justifyfull', 'forecolor', '|', 'pastetext', 'pasteword', '|', 'removeformat', 'cleanup', '|', 'media', 'charmap', 'blockquote', '|', 'undo', 'redo', 'fullscreen' ));
$mce_buttons_2 = apply_filters('mce_buttons_2', array('formatselect', 'underline', 'justifyfull', 'forecolor', '|', 'pastetext', 'pasteword', '|', 'removeformat', 'cleanup', '|', 'media', 'charmap', 'blockquote', '|', 'undo', 'redo', 'wp_help' ));
$mce_buttons_2 = implode($mce_buttons_2, ',');
$mce_buttons_3 = apply_filters('mce_buttons_3', array());
@ -91,10 +91,6 @@ $mce_buttons_3 = implode($mce_buttons_3, ',');
$mce_buttons_4 = apply_filters('mce_buttons_4', array());
$mce_buttons_4 = implode($mce_buttons_4, ',');
// all these browsers are now 100% supported, no need for this
//$mce_browsers = apply_filters('mce_browsers', array('msie', 'gecko', 'opera', 'safari'));
//$mce_browsers = implode($mce_browsers, ',');
$mce_locale = ( '' == get_locale() ) ? 'en' : strtolower( substr(get_locale(), 0, 2) ); // only ISO 639-1
// TinyMCE init settings
@ -114,13 +110,11 @@ $initArray = array (
'theme_advanced_statusbar_location' => 'bottom',
'theme_advanced_resizing' => true,
'theme_advanced_resize_horizontal' => false,
// 'browsers' => "$mce_browsers",
'dialog_type' => 'modal',
'convert_urls' => false,
'relative_urls' => false,
'remove_script_host' => false,
'fix_list_elements' => true,
'fix_table_elements' => true,
// 'fix_table_elements' => true,
'gecko_spellcheck' => true,
'entities' => '38,amp,60,lt,62,gt',
'accessibility_focus' => false,
@ -131,7 +125,7 @@ $initArray = array (
// pass-through the settings for compression and caching, so they can be changed with "tiny_mce_before_init"
'disk_cache' => true,
'compress' => true,
'del_old_cache' => true
'old_cache_max' => '3' // number of cache files to keep
);
if ( $valid_elements ) $initArray['valid_elements'] = $valid_elements;
@ -148,7 +142,7 @@ $mce_deprecated1 = ob_get_contents() || '';
ob_end_clean();
/*
// Do we need to support this? Most likely will breal TinyMCE 3...
// Do we need to support this? Most likely will break TinyMCE 3...
ob_start();
do_action('tinymce_before_init');
$mce_deprecated2 = ob_get_contents() || '';
@ -161,10 +155,10 @@ $cache_ext = '.js';
$disk_cache = ( ! isset($initArray['disk_cache']) || false == $initArray['disk_cache'] ) ? false : true;
$compress = ( ! isset($initArray['compress']) || false == $initArray['compress'] ) ? false : true;
$del_old_cache = ( ! isset($initArray['del_old_cache']) || false == $initArray['del_old_cache'] ) ? false : true;
$old_cache_max = ( isset($initArray['old_cache_max']) ) ? (int) $initArray['old_cache_max'] : 0;
$initArray['disk_cache'] = $initArray['compress'] = $initArray['del_old_cache'] = null;
unset( $initArray['disk_cache'], $initArray['compress'], $initArray['del_old_cache'] );
$initArray['disk_cache'] = $initArray['compress'] = $initArray['old_cache_max'] = null;
unset( $initArray['disk_cache'], $initArray['compress'], $initArray['old_cache_max'] );
$plugins = explode( ',', $initArray['plugins'] );
$theme = ( 'simple' == $initArray['theme'] ) ? 'simple' : 'advanced';
@ -188,13 +182,16 @@ if ( $compress && isset($_SERVER['HTTP_ACCEPT_ENCODING']) ) {
if ( $disk_cache && $cache_path ) {
$ver = isset($_GET['ver']) ? (int) $_GET['ver'] : '';
$cacheKey = $initArray['plugins'] . $language . $theme . $suffix . $ver;
$cacheKey = $suffix . $ver;
foreach ( $initArray as $v )
$cacheKey .= $v;
foreach ( $custom_js as $file )
$cacheKey .= $file;
$cacheKey = md5( $cacheKey );
$cache_file = $cache_path . '/tiny_mce_' . $cacheKey . $cache_ext;
$cache_file = $cache_path . '/tinymce_' . $cacheKey . $cache_ext;
}
cache_javascript_headers();
@ -209,13 +206,12 @@ if ( $disk_cache && file_exists($cache_file) ) {
}
foreach ( $initArray as $k => $v )
$mce_options .= $k . ':"' . $v . '", ';
$mce_options .= $k . ':"' . $v . '",';
$mce_options .= $mce_deprecated1;
$mce_options = rtrim( trim($mce_options), '\n\r,' );
$content = 'var tinyMCEPreInit = { suffix : "' . $suffix . '", base : "' . $baseurl . '" };';
$content .= 'var tinyMCE_GZ = { settings : { themes : "' . $theme . '", plugins : "' . $initArray['plugins'] . '", languages : "' . $language . '", debug : false, suffix : "' . $suffix . '" }, baseURL : "' . $baseurl . '" };';
$content .= 'var tinyMCEPreInit = { settings : { themes : "' . $theme . '", plugins : "' . $initArray['plugins'] . '", languages : "' . $language . '", debug : false }, base : "' . $baseurl . '", suffix : "' . $suffix . '" };';
// Load patch
$content .= getFileContents( 'tiny_mce_ext.js' );
@ -224,7 +220,7 @@ $content .= getFileContents( 'tiny_mce_ext.js' );
$content .= getFileContents( 'tiny_mce' . $suffix . '.js' );
// Patch loading functions
$content .= 'tinyMCE_GZ.start();';
$content .= 'tinyMCEPreInit.start();';
// Add all languages (WP)
include_once( dirname(__FILE__).'/langs/wp-langs.php' );
@ -247,26 +243,38 @@ $content .= $ext_plugins . 'tinyMCE.init({' . $mce_options . '});'; // $mce_depr
// Generate GZIP'd content
if ( '.gz' == $cache_ext ) {
header('Content-Encoding: ' . $enc);
$cache_data = gzencode( $content, 9, FORCE_GZIP );
} else
$cache_data = $content;
$content = gzencode( $content, 9, FORCE_GZIP );
}
// Stream to client
echo $cache_data;
echo $content;
// Write file
if ( '' != $cacheKey ) {
if ( $del_old_cache ) {
$old_key = getFileContents('tiny_mce_compressed_key');
if ( '' != $cacheKey && $cache_path ) {
if ( $old_cache_max ) {
$old_keys = getFileContents('tinymce_compressed_key' . $cache_ext);
if ( '' != $old_keys ) {
$keys_ar = explode( "\n", $old_keys );
if ( ($old_cache_max - 1) > count($old_keys_ar) )
$old_keys_rem = array_slice( $keys_ar, ($old_cache_max - 1) );
foreach ( $old_keys_rem as $key ) {
$key = trim($key);
if ( 32 != strlen($key) ) continue;
$old_cache = $cache_path . '/tinymce_' . $key . $cache_ext;
@unlink($old_cache);
}
array_unshift( $keys_ar, $cacheKey );
$keys_ar = array_slice( $keys_ar, 0, $old_cache_max );
$cacheKey = trim( implode( "\n", $keys_ar ) );
if ( '' != $old_key ) { // && $old_key != $cacheKey
$old_cache = $cache_path . '/tiny_mce_' . $old_key . $cache_ext;
@unlink($old_cache);
}
putFileContents( 'tiny_mce_compressed_key', $cacheKey );
}
putFileContents( $cache_file, $cache_data );
putFileContents( 'tinymce_compressed_key' . $cache_ext, $cacheKey );
}
putFileContents( $cache_file, $content );
}
?>

View File

@ -1,12 +1,11 @@
tinyMCE_GZ.start = function() {
tinyMCEPreInit.start = function() {
var t = this, each = tinymce.each, s = t.settings, sl = tinymce.ScriptLoader, ln = s.languages.split(',');
function load(u, sp) {
var o;
if (!sp)
u = t.baseURL + u;
u = t.base + u;
o = {url : u, state : 2};
sl.queue.push(o);
@ -22,7 +21,7 @@ tinyMCE_GZ.start = function() {
// Add themes with languages
each(s.themes.split(','), function(n) {
if (n) {
load('/themes/' + n + '/editor_template' + s.suffix + '.js');
load('/themes/' + n + '/editor_template' + t.suffix + '.js');
each (ln, function(c) {
if (c)
@ -34,7 +33,7 @@ tinyMCE_GZ.start = function() {
// Add plugins with languages
each(s.plugins.split(','), function(n) {
if (n && n.charAt(0) != '-') {
load('/plugins/' + n + '/editor_plugin' + s.suffix + '.js');
load('/plugins/' + n + '/editor_plugin' + t.suffix + '.js');
each (ln, function(c) {
if (c)

View File

@ -29,9 +29,16 @@ class WP_Scripts {
$this->add( 'colorpicker', '/wp-includes/js/colorpicker.js', false, '3517' );
// Modify this version when tinyMCE plugins are changed
$mce_config = apply_filters('tiny_mce_config_url', '/wp-includes/js/tinymce/tiny_mce_config.php');
$this->add( 'tiny_mce', $mce_config, false, '20080209' );
// Let a plugin replace the visual editor
$visual_editor = apply_filters('visual_editor', array('tiny_mce'));
$this->add( 'editor', false, $visual_editor, '20080218' );
$this->add( 'editor_functions', '/wp-admin/js/editor.js', false, '20080208' );
// Modify this version when tinyMCE plugins are changed.
$mce_version = apply_filters('tiny_mce_version', '20080209');
$this->add( 'tiny_mce', '/wp-includes/js/tinymce/tiny_mce_config.php', array('editor_functions'), $mce_version );
$this->localize( 'tiny_mce', 'wpTinyMCEConfig', array( 'defaultEditor' => wp_default_editor() ) );
$this->add( 'prototype', '/wp-includes/js/prototype.js', false, '1.6');
@ -474,12 +481,6 @@ function wp_prototype_before_jquery( $js_array ) {
return $js_array;
}
// These localizations require information that may not be loaded even by init
function wp_just_in_time_script_localization() {
wp_localize_script( 'tiny_mce', 'wpTinyMCEConfig', array( 'defaultEditor' => wp_default_editor() ) );
}
add_filter( 'wp_print_scripts', 'wp_just_in_time_script_localization' );
add_filter( 'print_scripts_array', 'wp_prototype_before_jquery' );
?>
?>