Fix wplink when TinyMCE is not loaded, fix image insertion when wpActiveEditor is not set, see #17144

git-svn-id: http://svn.automattic.com/wordpress/trunk@18766 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
azaozz 2011-09-24 04:43:19 +00:00
parent ef11d05989
commit eb8878fbfc
7 changed files with 87 additions and 66 deletions

View File

@ -3,18 +3,18 @@
var wpActiveEditor;
function send_to_editor(h) {
var ed;
var ed, mce = typeof(tinymce) != 'undefined', qt = typeof(QTags) != 'undefined';
if ( !wpActiveEditor ) {
if ( typeof(tinymce) != 'undefined' && tinymce.activeEditor ) {
if ( mce && tinymce.activeEditor ) {
ed = tinymce.activeEditor;
wpActiveEditor = ed.id;
} else {
} else if ( !qt ) {
return false;
}
}
if ( !ed && typeof(tinymce) != 'undefined' && wpActiveEditor )
if ( !ed && mce && wpActiveEditor )
ed = tinymce.get(wpActiveEditor);
if ( ed && !ed.isHidden() ) {
@ -34,13 +34,13 @@ function send_to_editor(h) {
}
ed.execCommand('mceInsertContent', false, h);
} else if ( typeof(QTags) != 'undefined' ) {
} else if ( qt ) {
QTags.insertContent(h);
} else {
document.getElementById(wpActiveEditor).value += h;
}
tb_remove();
try{tb_remove();}catch(e){};
}
// thickbox settings

View File

@ -1 +1 @@
var wpActiveEditor;function send_to_editor(b){var a;if(!wpActiveEditor){if(typeof(tinymce)!="undefined"&&tinymce.activeEditor){a=tinymce.activeEditor;wpActiveEditor=a.id}else{return false}}if(!a&&typeof(tinymce)!="undefined"&&wpActiveEditor){a=tinymce.get(wpActiveEditor)}if(a&&!a.isHidden()){if(tinymce.isIE&&a.windowManager.insertimagebookmark){a.selection.moveToBookmark(a.windowManager.insertimagebookmark)}if(b.indexOf("[caption")===0){if(a.plugins.wpeditimage){b=a.plugins.wpeditimage._do_shcode(b)}}else{if(b.indexOf("[gallery")===0){if(a.plugins.wpgallery){b=a.plugins.wpgallery._do_gallery(b)}}else{if(b.indexOf("[embed")===0){if(a.plugins.wordpress){b=a.plugins.wordpress._setEmbed(b)}}}}a.execCommand("mceInsertContent",false,b)}else{if(typeof(QTags)!="undefined"){QTags.insertContent(b)}else{document.getElementById(wpActiveEditor).value+=b}}tb_remove()}var tb_position;(function(a){tb_position=function(){var f=a("#TB_window"),e=a(window).width(),d=a(window).height(),c=(720<e)?720:e,b=0;if(a("body.admin-bar").length){b=28}if(f.size()){f.width(c-50).height(d-45-b);a("#TB_iframeContent").width(c-50).height(d-75-b);f.css({"margin-left":"-"+parseInt(((c-50)/2),10)+"px"});if(typeof document.body.style.maxWidth!="undefined"){f.css({top:20+b+"px","margin-top":"0"})}}return a("a.thickbox").each(function(){var g=a(this).attr("href");if(!g){return}g=g.replace(/&width=[0-9]+/g,"");g=g.replace(/&height=[0-9]+/g,"");a(this).attr("href",g+"&width="+(c-80)+"&height="+(d-85-b))})};a(window).resize(function(){tb_position()});a(document).ready(function(b){b("a.thickbox").click(function(){var c;if(typeof(tinymce)!="undefined"&&tinymce.isIE&&(c=tinymce.get(wpActiveEditor))&&!c.isHidden()){c.focus();c.windowManager.insertimagebookmark=c.selection.getBookmark()}})})})(jQuery);
var wpActiveEditor;function send_to_editor(c){var b,a=typeof(tinymce)!="undefined",f=typeof(QTags)!="undefined";if(!wpActiveEditor){if(a&&tinymce.activeEditor){b=tinymce.activeEditor;wpActiveEditor=b.id}else{if(!f){return false}}}if(!b&&a&&wpActiveEditor){b=tinymce.get(wpActiveEditor)}if(b&&!b.isHidden()){if(tinymce.isIE&&b.windowManager.insertimagebookmark){b.selection.moveToBookmark(b.windowManager.insertimagebookmark)}if(c.indexOf("[caption")===0){if(b.plugins.wpeditimage){c=b.plugins.wpeditimage._do_shcode(c)}}else{if(c.indexOf("[gallery")===0){if(b.plugins.wpgallery){c=b.plugins.wpgallery._do_gallery(c)}}else{if(c.indexOf("[embed")===0){if(b.plugins.wordpress){c=b.plugins.wordpress._setEmbed(c)}}}}b.execCommand("mceInsertContent",false,c)}else{if(f){QTags.insertContent(c)}else{document.getElementById(wpActiveEditor).value+=c}}try{tb_remove()}catch(d){}}var tb_position;(function(a){tb_position=function(){var f=a("#TB_window"),e=a(window).width(),d=a(window).height(),c=(720<e)?720:e,b=0;if(a("body.admin-bar").length){b=28}if(f.size()){f.width(c-50).height(d-45-b);a("#TB_iframeContent").width(c-50).height(d-75-b);f.css({"margin-left":"-"+parseInt(((c-50)/2),10)+"px"});if(typeof document.body.style.maxWidth!="undefined"){f.css({top:20+b+"px","margin-top":"0"})}}return a("a.thickbox").each(function(){var g=a(this).attr("href");if(!g){return}g=g.replace(/&width=[0-9]+/g,"");g=g.replace(/&height=[0-9]+/g,"");a(this).attr("href",g+"&width="+(c-80)+"&height="+(d-85-b))})};a(window).resize(function(){tb_position()});a(document).ready(function(b){b("a.thickbox").click(function(){var c;if(typeof(tinymce)!="undefined"&&tinymce.isIE&&(c=tinymce.get(wpActiveEditor))&&!c.isHidden()){c.focus();c.windowManager.insertimagebookmark=c.selection.getBookmark()}})})})(jQuery);

View File

@ -1,6 +1,6 @@
<?php
/**
* Adds the TinyMCE editor used on the Write and Edit screens.
* Adds the WordPress editor used on the Write and Edit screens.
*
* @package WordPress
* @since 3.3
@ -16,6 +16,7 @@ class WP_Editor {
var $mce_settings = array();
var $qt_settings = array();
var $plugins = array();
var $qt_buttons = array();
var $mce_locale;
var $ext_plugins;
var $baseurl;
@ -48,7 +49,7 @@ class WP_Editor {
'editor_css' => '', // intended for extra styles for both visual and HTML editors buttons, needs to include the <style> tags, can use "scoped".
'editor_class' => '', // add extra class(es) to the editor textarea
'teeny' => false, // output the minimal editor config used in Press This
'dfw' => false, // replace the default fullscreen with DFW (needs specific css)
'dfw' => false, // replace the default fullscreen with DFW (needs specific DOM elements and css)
'tinymce' => true, // load TinyMCE, can be used to pass settings directly to TinyMCE using an array()
'quicktags' => true // load Quicktags, can be used to pass settings directly to Quicktags using an array()
) );
@ -64,7 +65,7 @@ class WP_Editor {
if ( !current_user_can( 'upload_files' ) )
$set['media_buttons'] = false;
if ( $this->can_richedit && $this->this_quicktags && $this->this_tinymce ) {
if ( $this->this_quicktags && $this->this_tinymce ) {
$switch_class = 'html-active';
if ( 'html' == $this->default_editor ) {
@ -98,7 +99,7 @@ class WP_Editor {
echo "</div>\n";
}
$the_editor = apply_filters('the_editor', '<div id="wp-' . $editor_id . '-editor-container" class="wp-editor-container"><textarea' . $editor_class . $rows . $tabindex . '" cols="40" name="' . $set['textarea_name'] . '" id="' . $editor_id . '">%s</textarea></div>');
$the_editor = apply_filters('the_editor', '<div id="wp-' . $editor_id . '-editor-container" class="wp-editor-container"><textarea' . $editor_class . $rows . $tabindex . ' cols="40" name="' . $set['textarea_name'] . '" id="' . $editor_id . '">%s</textarea></div>');
$content = apply_filters('the_editor_content', $content);
printf($the_editor, $content);
@ -114,24 +115,40 @@ class WP_Editor {
$this->editor_settings($editor_id, $set);
}
function editor_settings($editor_id, $settings) {
function editor_settings($editor_id, $set) {
global $editor_styles;
$first_run = false;
if ( $this->this_quicktags ) {
$qtbuttons = apply_filters( 'quicktags_buttons', array(), $editor_id );
$qtbuttons_disabled = apply_filters( 'quicktags_disabled_buttons', array(), $editor_id );
$qt_buttons = array();
$qtInit = array(
'id' => $editor_id,
'buttons' => implode($qtbuttons, ','),
'disabled_buttons' => implode($qtbuttons_disabled, ',')
'buttons' => '',
'disabled_buttons' => ''
);
if ( is_array($settings['quicktags']) )
$qtInit = array_merge($qtInit, $settings['quicktags']);
if ( is_array($set['quicktags']) )
$qtInit = array_merge($qtInit, $set['quicktags']);
$qtInit = apply_filters( 'quicktags_settings', $qtInit, $editor_id );
$this->qt_settings[$editor_id] = $qtInit;
if ( !empty($qtInit['buttons']) || !empty($qtInit['disabled_buttons']) ) {
if ( strpos( ',' . $qtInit['buttons'] . ',', ',link,' ) !== false )
$qt_buttons[] = 'link';
if ( strpos( ',' . $qtInit['disabled_buttons'] . ',', ',link,' ) !== false )
$qt_buttons = array();
} else {
$qt_buttons[] = 'link';
}
if ( $set['dfw'] )
$qt_buttons[] = 'fullscreen';
$this->qt_buttons = array_merge( $this->qt_buttons, $qt_buttons );
}
if ( $this->this_tinymce ) {
@ -143,7 +160,7 @@ class WP_Editor {
$plugins = array( 'inlinepopups', 'spellchecker', 'tabfocus', 'paste', 'media', 'fullscreen', 'wordpress', 'wpeditimage', 'wpgallery', 'wplink', 'wpdialogs' );
$first_run = true;
if ( $settings['teeny'] ) {
if ( $set['teeny'] ) {
$this->plugins = $plugins = apply_filters( 'teeny_mce_plugins', array('inlinepopups', 'fullscreen', 'wordpress', 'wplink', 'wpdialogs'), $editor_id );
$ext_plugins = '';
} else {
@ -192,7 +209,7 @@ class WP_Editor {
$plugurl = dirname($url);
$strings = $str1 = $str2 = '';
if ( ! in_array($name, $loaded_langs) ) {
$path = str_replace( WP_CONTENT_URL, '', $plugurl );
$path = str_replace( content_url(), '', $plugurl );
$path = WP_CONTENT_DIR . $path . '/langs/';
if ( function_exists('realpath') )
@ -230,7 +247,7 @@ class WP_Editor {
$plugins = array_unique( apply_filters('tiny_mce_plugins', $plugins) );
}
if ( $settings['dfw'] )
if ( $set['dfw'] )
$plugins[] = 'wpfullscreen';
$this->plugins = $plugins;
@ -325,7 +342,7 @@ class WP_Editor {
$this->first_init['content_css'] = $mce_css;
}
if ( $settings['teeny'] ) {
if ( $set['teeny'] ) {
$mce_buttons = apply_filters( 'teeny_mce_buttons', array('bold', 'italic', 'underline', 'blockquote', 'separator', 'strikethrough', 'bullist', 'numlist', 'justifyleft', 'justifycenter', 'justifyright', 'undo', 'redo', 'link', 'unlink', 'fullscreen'), $editor_id );
$mce_buttons_2 = $mce_buttons_3 = $mce_buttons_4 = array();
} else {
@ -335,7 +352,7 @@ class WP_Editor {
$mce_buttons_4 = apply_filters('mce_buttons_4', array(), $editor_id);
}
if ( $settings['dfw'] ) {
if ( $set['dfw'] ) {
function replace_fullscreen(&$val) {
if ( $val == 'fullscreen' )
$val = 'wp_fullscreen';
@ -349,9 +366,9 @@ class WP_Editor {
$mceInit = array (
'elements' => $editor_id,
'wpautop' => (bool) $settings['wpautop'],
'remove_linebreaks' => (bool) $settings['wpautop'],
'apply_source_formatting' => (bool) !$settings['wpautop'],
'wpautop' => (bool) $set['wpautop'],
'remove_linebreaks' => (bool) $set['wpautop'],
'apply_source_formatting' => (bool) !$set['wpautop'],
'theme_advanced_buttons1' => implode($mce_buttons, ','),
'theme_advanced_buttons2' => implode($mce_buttons_2, ','),
'theme_advanced_buttons3' => implode($mce_buttons_3, ','),
@ -361,14 +378,14 @@ class WP_Editor {
if ( $first_run )
$mceInit = array_merge($this->first_init, $mceInit);
if ( is_array($settings['tinymce']) )
$mceInit = array_merge($mceInit, $settings['tinymce']);
if ( is_array($set['tinymce']) )
$mceInit = array_merge($mceInit, $set['tinymce']);
// For people who really REALLY know what they're doing with TinyMCE
// You can modify initArray to add, remove, change elements of the config before tinyMCE.init
// Setting "valid_elements", "invalid_elements" and "extended_valid_elements" can be done through this filter.
// Best is to use the default cleanup by not specifying valid_elements, as TinyMCE contains full set of XHTML 1.0.
if ( $settings['teeny'] ) {
if ( $set['teeny'] ) {
$mceInit = apply_filters('teeny_mce_before_init', $mceInit, $editor_id);
} else {
$mceInit = apply_filters('tiny_mce_before_init', $mceInit, $editor_id);
@ -422,16 +439,22 @@ class WP_Editor {
}
function enqueue_scripts() {
wp_enqueue_script('quicktags');
wp_enqueue_script('word-count');
wp_enqueue_script('wplink');
wp_enqueue_script('editor');
wp_enqueue_style('editor-buttons');
wp_enqueue_script('wpdialogs-popup');
wp_enqueue_style('wp-jquery-ui-dialog');
if ( $this->this_tinymce )
wp_enqueue_script('editor');
if ( in_array('wpfullscreen', $this->plugins, true) )
if ( $this->this_quicktags )
wp_enqueue_script('quicktags');
if ( in_array('wplink', $this->plugins, true) || in_array('link', $this->qt_buttons, true) ) {
wp_enqueue_script('wplink');
wp_enqueue_script('wpdialogs-popup');
wp_enqueue_style('wp-jquery-ui-dialog');
}
if ( in_array('wpfullscreen', $this->plugins, true) || in_array('fullscreen', $this->qt_buttons, true) )
wp_enqueue_script('wp-fullscreen');
add_thickbox();
@ -464,9 +487,9 @@ class WP_Editor {
if ( $tmce_on ) {
foreach ( $this->mce_settings as $editor_id => $init ) {
$options = $this->_parse_init( $init );
$mceInit .= "'$editor_id':{$options},\n";
$mceInit .= "'$editor_id':{$options},";
}
$mceInit = '{' . trim($mceInit, '\n,') . '}';
$mceInit = '{' . trim($mceInit, ',') . '}';
} else {
$mceInit = '{}';
}
@ -474,9 +497,9 @@ class WP_Editor {
if ( !empty($this->qt_settings) ) {
foreach ( $this->qt_settings as $editor_id => $init ) {
$options = $this->_parse_init( $init );
$qtInit .= "'$editor_id':{$options},\n";
$qtInit .= "'$editor_id':{$options},";
}
$qtInit = '{' . trim($qtInit, '\n,') . '}';
$qtInit = '{' . trim($qtInit, ',') . '}';
} else {
$qtInit = '{}';
}
@ -563,10 +586,10 @@ class WP_Editor {
</script>
<?php
if ( in_array( 'wplink', $this->plugins, true ) )
if ( in_array('wplink', $this->plugins, true) || in_array('link', $this->qt_buttons, true) )
$this->wp_link_dialog();
if ( in_array( 'wpfullscreen', $this->plugins, true ) )
if ( in_array('wpfullscreen', $this->plugins, true) || in_array('fullscreen', $this->qt_buttons, true) )
$this->wp_fullscreen_html();
do_action('after_wp_tiny_mce', $this->mce_settings);

View File

@ -26,7 +26,26 @@
// by Alex King
// http://www.alexking.org/
var QTags, edButtons = [], edCanvas;
var QTags, edButtons = [], edCanvas,
/**
* Back-compat
*
* Define all former global functions so plugins that hack quicktags.js directly don't cause fatal errors.
*/
edAddTag = function(){},
edCheckOpenTags = function(){},
edCloseAllTags = function(){},
edInsertImage = function(){},
edInsertLink = function(){},
edInsertTag = function(){},
edLink = function(){},
edQuickLink = function(){},
edRemoveTag = function(){},
edShowButton = function(){},
edShowLinks = function(){},
edSpell = function(){},
edToolbar = function(){};
/**
* Initialize new instance of the Quicktags editor
@ -55,25 +74,6 @@ function edButton(id, display, tagStart, tagEnd, access, open) {
return QTags.addButton( id, display, tagStart, tagEnd, access, '', -1 );
}
/**
* Back-compat
*
* Define all former global functions so plugins that hack quicktags.js directly don't cause fatal errors.
*/
var edAddTag = function(){},
edCheckOpenTags = function(){},
edCloseAllTags = function(){},
edInsertImage = function(){},
edInsertLink = function(){},
edInsertTag = function(){},
edLink = function(){},
edQuickLink = function(){},
edRemoveTag = function(){},
edShowButton = function(){},
edShowLinks = function(){},
edSpell = function(){},
edToolbar = function(){};
(function(){
// private stuff is prefixed with an underscore
var _domReady = function(func) {

File diff suppressed because one or more lines are too long

View File

@ -62,9 +62,7 @@ dl.aligncenter {
text-align: center;
background-color: #f3f3f3;
padding-top: 4px;
margin: 10px;
-moz-border-radius: 3px;
-khtml-border-radius: 3px;
margin: 10px 0;
-webkit-border-radius: 3px;
border-radius: 3px;
}

View File

@ -276,7 +276,7 @@ function wp_default_scripts( &$scripts ) {
$scripts->add( 'word-count', "/wp-admin/js/word-count$suffix.js", array( 'jquery' ), '20110515', 1 );
$scripts->add( 'media-upload', "/wp-admin/js/media-upload$suffix.js", array( 'thickbox' ), '20110805', 1 );
$scripts->add( 'media-upload', "/wp-admin/js/media-upload$suffix.js", array( 'thickbox' ), '20110922', 1 );
if ( is_admin() ) {
$scripts->add( 'ajaxcat', "/wp-admin/js/cat$suffix.js", array( 'wp-lists' ), '20090102' );