Hide text while editor is loading, show html editor on error

git-svn-id: http://svn.automattic.com/wordpress/trunk@11171 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
azaozz 2009-05-04 10:34:50 +00:00
parent cce77d198a
commit bf88b244cd
7 changed files with 68 additions and 61 deletions

View File

@ -40,7 +40,7 @@ var pagenow = '<?php echo substr($pagenow, 0, -4); ?>';
<?php <?php
if ( in_array( $pagenow, array('post.php', 'post-new.php', 'page.php', 'page-new.php') ) ) { if ( in_array( $pagenow, array('post.php', 'post-new.php', 'page.php', 'page-new.php') ) ) {
add_action( 'admin_print_footer_scripts', 'wp_tiny_mce', 5 ); add_action( 'admin_print_footer_scripts', 'wp_tiny_mce', 25 );
wp_enqueue_script('quicktags'); wp_enqueue_script('quicktags');
} }

View File

@ -1282,8 +1282,8 @@ function wp_tiny_mce( $teeny = false ) {
// TinyMCE init settings // TinyMCE init settings
$initArray = array ( $initArray = array (
'mode' => 'none', 'mode' => 'specific_textareas',
'onpageload' => 'switchEditors.edInit', 'editor_selector' => 'theEditor',
'width' => '100%', 'width' => '100%',
'theme' => 'advanced', 'theme' => 'advanced',
'skin' => 'wp_theme', 'skin' => 'wp_theme',
@ -1334,7 +1334,7 @@ function wp_tiny_mce( $teeny = false ) {
$language = $initArray['language']; $language = $initArray['language'];
$zip = $compress_scripts ? 1 : 0; $zip = $compress_scripts ? 1 : 0;
$ver = apply_filters('tiny_mce_version', '3211'); $ver = apply_filters('tiny_mce_version', '323');
if ( 'en' != $language ) if ( 'en' != $language )
include_once(ABSPATH . WPINC . '/js/tinymce/langs/wp-langs.php'); include_once(ABSPATH . WPINC . '/js/tinymce/langs/wp-langs.php');

View File

@ -1,4 +1,16 @@
jQuery(document).ready(function($){
var h = wpCookies.getHash('TinyMCE_content_size');
if ( getUserSetting( 'editor' ) == 'html' ) {
if ( h )
$('#content').css('height', h.ch - 15 + 'px');
} else {
$('#content').css('color', 'white');
$('#quicktags').hide();
}
});
var switchEditors = { var switchEditors = {
mode : '', mode : '',
@ -8,18 +20,6 @@ var switchEditors = {
}, },
edInit : function() { edInit : function() {
var h = tinymce.util.Cookie.getHash("TinyMCE_content_size");
// Activate TinyMCE if it's the user's default editor
if ( getUserSetting( 'editor' ) == 'html' ) {
if ( h )
try { this.I('content').style.height = h.ch - 30 + 'px'; } catch(e){};
} else {
try {
this.I("quicktags").style.display = "none";
} catch(e){};
tinyMCE.execCommand("mceAddControl", false, "content");
}
}, },
saveCallback : function(el, content, body) { saveCallback : function(el, content, body) {
@ -94,43 +94,44 @@ var switchEditors = {
id = id || 'content'; id = id || 'content';
mode = mode || this.mode || ''; mode = mode || this.mode || '';
var ed = tinyMCE.get(id) || false, qt = this.I('quicktags'), H = this.I('edButtonHTML'), P = this.I('edButtonPreview'), ta = this.I(id); var ed, qt = this.I('quicktags'), H = this.I('edButtonHTML'), P = this.I('edButtonPreview'), ta = this.I(id);
try { ed = tinyMCE.get(id); }
catch(e) { ed = false; }
if ( 'tinymce' == mode ) { if ( 'tinymce' == mode ) {
if ( ed && ! ed.isHidden() ) if ( ed && ! ed.isHidden() )
return false; return false;
setUserSetting( 'editor', 'tinymce' );
this.mode = 'html'; this.mode = 'html';
ta.style.color = '#fff';
P.className = 'active'; P.className = 'active';
H.className = ''; H.className = '';
edCloseAllTags(); // :-( edCloseAllTags(); // :-(
qt.style.display = 'none'; qt.style.display = 'none';
ta.value = this.wpautop(ta.value); ta.value = this.wpautop(ta.value);
if ( ed ) ed.show(); if ( ed ) {
else tinyMCE.execCommand("mceAddControl", false, id); ed.show();
} else {
setUserSetting( 'editor', 'tinymce' ); try{tinyMCE.execCommand("mceAddControl", false, id);}
catch(e){}
}
} else { } else {
if ( ! ed || ed.isHidden() ) setUserSetting( 'editor', 'html' );
return false; ta.style.color = '#000';
this.mode = 'tinymce'; this.mode = 'tinymce';
H.className = 'active'; H.className = 'active';
P.className = ''; P.className = '';
ta.style.height = ed.getContentAreaContainer().offsetHeight + 6 + 'px'; if ( ed && !ed.isHidden() ) {
ta.style.height = ed.getContentAreaContainer().offsetHeight + 24 + 'px';
ed.hide();
}
ed.hide();
qt.style.display = 'block'; qt.style.display = 'block';
ta.style.color = '';
setUserSetting( 'editor', 'html' );
} }
return false; return false;
}, },

View File

@ -1 +1 @@
var switchEditors={mode:"",I:function(a){return document.getElementById(a)},edInit:function(){var a=tinymce.util.Cookie.getHash("TinyMCE_content_size");if(getUserSetting("editor")=="html"){if(a){try{this.I("content").style.height=a.ch-30+"px"}catch(b){}}}else{try{this.I("quicktags").style.display="none"}catch(b){}tinyMCE.execCommand("mceAddControl",false,"content")}},saveCallback:function(b,c,a){if(tinyMCE.activeEditor.isHidden()){c=this.I(b).value}else{c=this.pre_wpautop(c)}return c},pre_wpautop:function(b){var c,a;b=b.replace(/<(pre|script)[^>]*>[\s\S]+?<\/\1>/g,function(d){d=d.replace(/<br ?\/?>[\r\n]*/g,"<wp_temp>");return d.replace(/<\/?p( [^>]*)?>[\r\n]*/g,"<wp_temp>")});c="blockquote|ul|ol|li|table|thead|tbody|tr|th|td|div|h[1-6]|p";b=b.replace(new RegExp("\\s*</("+c+")>\\s*","mg"),"</$1>\n");b=b.replace(new RegExp("\\s*<(("+c+")[^>]*)>","mg"),"\n<$1>");b=b.replace(new RegExp("(<p [^>]+>.*?)</p>","mg"),"$1</p#>");b=b.replace(new RegExp("<div([^>]*)>\\s*<p>","mgi"),"<div$1>\n\n");b=b.replace(new RegExp("\\s*<p>","mgi"),"");b=b.replace(new RegExp("\\s*</p>\\s*","mgi"),"\n\n");b=b.replace(new RegExp("\\n\\s*\\n","mgi"),"\n\n");b=b.replace(new RegExp("\\s*<br ?/?>\\s*","gi"),"\n");b=b.replace(new RegExp("\\s*<div","mg"),"\n<div");b=b.replace(new RegExp("</div>\\s*","mg"),"</div>\n");b=b.replace(new RegExp("\\s*\\[caption([^\\[]+)\\[/caption\\]\\s*","gi"),"\n\n[caption$1[/caption]\n\n");b=b.replace(new RegExp("caption\\]\\n\\n+\\[caption","g"),"caption]\n\n[caption");a="blockquote|ul|ol|li|table|thead|tr|th|td|h[1-6]|pre";b=b.replace(new RegExp("\\s*<(("+a+") ?[^>]*)\\s*>","mg"),"\n<$1>");b=b.replace(new RegExp("\\s*</("+a+")>\\s*","mg"),"</$1>\n");b=b.replace(new RegExp("<li([^>]*)>","g"),"\t<li$1>");if(b.indexOf("<object")!=-1){b=b.replace(/<object[\s\S]+?<\/object>/g,function(d){return d.replace(/[\r\n]+/g,"")})}b=b.replace(new RegExp("</p#>","g"),"</p>\n");b=b.replace(new RegExp("\\s*(<p [^>]+>.*</p>)","mg"),"\n$1");b=b.replace(new RegExp("^\\s*",""),"");b=b.replace(new RegExp("[\\s\\u00a0]*$",""),"");b=b.replace(/<wp_temp>/g,"\n");return b},go:function(g,e){g=g||"content";e=e||this.mode||"";var b=tinyMCE.get(g)||false,f=this.I("quicktags"),c=this.I("edButtonHTML"),d=this.I("edButtonPreview"),a=this.I(g);if("tinymce"==e){if(b&&!b.isHidden()){return false}this.mode="html";a.style.color="#fff";d.className="active";c.className="";edCloseAllTags();f.style.display="none";a.value=this.wpautop(a.value);if(b){b.show()}else{tinyMCE.execCommand("mceAddControl",false,g)}setUserSetting("editor","tinymce")}else{if(!b||b.isHidden()){return false}this.mode="tinymce";c.className="active";d.className="";a.style.height=b.getContentAreaContainer().offsetHeight+6+"px";b.hide();f.style.display="block";a.style.color="";setUserSetting("editor","html")}return false},wpautop:function(a){var b="table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|address|math|p|h[1-6]";if(a.indexOf("<object")!=-1){a=a.replace(/<object[\s\S]+?<\/object>/g,function(c){return c.replace(/[\r\n]+/g,"")})}a=a.replace(/<[^<>]+>/g,function(c){return c.replace(/[\r\n]+/g," ")});a=a+"\n\n";a=a.replace(new RegExp("<br />\\s*<br />","gi"),"\n\n");a=a.replace(new RegExp("(<(?:"+b+")[^>]*>)","gi"),"\n$1");a=a.replace(new RegExp("(</(?:"+b+")>)","gi"),"$1\n\n");a=a.replace(new RegExp("\\r\\n|\\r","g"),"\n");a=a.replace(new RegExp("\\n\\s*\\n+","g"),"\n\n");a=a.replace(new RegExp("([\\s\\S]+?)\\n\\n","mg"),"<p>$1</p>\n");a=a.replace(new RegExp("<p>\\s*?</p>","gi"),"");a=a.replace(new RegExp("<p>\\s*(</?(?:"+b+")[^>]*>)\\s*</p>","gi"),"$1");a=a.replace(new RegExp("<p>(<li.+?)</p>","gi"),"$1");a=a.replace(new RegExp("<p>\\s*<blockquote([^>]*)>","gi"),"<blockquote$1><p>");a=a.replace(new RegExp("</blockquote>\\s*</p>","gi"),"</p></blockquote>");a=a.replace(new RegExp("<p>\\s*(</?(?:"+b+")[^>]*>)","gi"),"$1");a=a.replace(new RegExp("(</?(?:"+b+")[^>]*>)\\s*</p>","gi"),"$1");a=a.replace(new RegExp("\\s*\\n","gi"),"<br />\n");a=a.replace(new RegExp("(</?(?:"+b+")[^>]*>)\\s*<br />","gi"),"$1");a=a.replace(new RegExp("<br />(\\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)>)","gi"),"$1");a=a.replace(new RegExp("(?:<p>|<br ?/?>)*\\s*\\[caption([^\\[]+)\\[/caption\\]\\s*(?:</p>|<br ?/?>)*","gi"),"[caption$1[/caption]");a=a.replace(/<(pre|script)[^>]*>[\s\S]+?<\/\1>/g,function(c){c=c.replace(/<br ?\/?>[\r\n]*/g,"\n");return c.replace(/<\/?p( [^>]*)?>[\r\n]*/g,"\n")});return a}}; jQuery(document).ready(function(b){var a=wpCookies.getHash("TinyMCE_content_size");if(getUserSetting("editor")=="html"){if(a){b("#content").css("height",a.ch-15+"px")}}else{b("#content").css("color","white");b("#quicktags").hide()}});var switchEditors={mode:"",I:function(a){return document.getElementById(a)},edInit:function(){},saveCallback:function(b,c,a){if(tinyMCE.activeEditor.isHidden()){c=this.I(b).value}else{c=this.pre_wpautop(c)}return c},pre_wpautop:function(b){var c,a;b=b.replace(/<(pre|script)[^>]*>[\s\S]+?<\/\1>/g,function(d){d=d.replace(/<br ?\/?>[\r\n]*/g,"<wp_temp>");return d.replace(/<\/?p( [^>]*)?>[\r\n]*/g,"<wp_temp>")});c="blockquote|ul|ol|li|table|thead|tbody|tr|th|td|div|h[1-6]|p";b=b.replace(new RegExp("\\s*</("+c+")>\\s*","mg"),"</$1>\n");b=b.replace(new RegExp("\\s*<(("+c+")[^>]*)>","mg"),"\n<$1>");b=b.replace(new RegExp("(<p [^>]+>.*?)</p>","mg"),"$1</p#>");b=b.replace(new RegExp("<div([^>]*)>\\s*<p>","mgi"),"<div$1>\n\n");b=b.replace(new RegExp("\\s*<p>","mgi"),"");b=b.replace(new RegExp("\\s*</p>\\s*","mgi"),"\n\n");b=b.replace(new RegExp("\\n\\s*\\n","mgi"),"\n\n");b=b.replace(new RegExp("\\s*<br ?/?>\\s*","gi"),"\n");b=b.replace(new RegExp("\\s*<div","mg"),"\n<div");b=b.replace(new RegExp("</div>\\s*","mg"),"</div>\n");b=b.replace(new RegExp("\\s*\\[caption([^\\[]+)\\[/caption\\]\\s*","gi"),"\n\n[caption$1[/caption]\n\n");b=b.replace(new RegExp("caption\\]\\n\\n+\\[caption","g"),"caption]\n\n[caption");a="blockquote|ul|ol|li|table|thead|tr|th|td|h[1-6]|pre";b=b.replace(new RegExp("\\s*<(("+a+") ?[^>]*)\\s*>","mg"),"\n<$1>");b=b.replace(new RegExp("\\s*</("+a+")>\\s*","mg"),"</$1>\n");b=b.replace(new RegExp("<li([^>]*)>","g"),"\t<li$1>");if(b.indexOf("<object")!=-1){b=b.replace(/<object[\s\S]+?<\/object>/g,function(d){return d.replace(/[\r\n]+/g,"")})}b=b.replace(new RegExp("</p#>","g"),"</p>\n");b=b.replace(new RegExp("\\s*(<p [^>]+>.*</p>)","mg"),"\n$1");b=b.replace(new RegExp("^\\s*",""),"");b=b.replace(new RegExp("[\\s\\u00a0]*$",""),"");b=b.replace(/<wp_temp>/g,"\n");return b},go:function(i,g){i=i||"content";g=g||this.mode||"";var b,h=this.I("quicktags"),c=this.I("edButtonHTML"),d=this.I("edButtonPreview"),a=this.I(i);try{b=tinyMCE.get(i)}catch(f){b=false}if("tinymce"==g){if(b&&!b.isHidden()){return false}setUserSetting("editor","tinymce");this.mode="html";d.className="active";c.className="";edCloseAllTags();h.style.display="none";a.value=this.wpautop(a.value);if(b){b.show()}else{try{tinyMCE.execCommand("mceAddControl",false,i)}catch(f){}}}else{setUserSetting("editor","html");a.style.color="#000";this.mode="tinymce";c.className="active";d.className="";if(b&&!b.isHidden()){a.style.height=b.getContentAreaContainer().offsetHeight+24+"px";b.hide()}h.style.display="block"}return false},wpautop:function(a){var b="table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|address|math|p|h[1-6]";if(a.indexOf("<object")!=-1){a=a.replace(/<object[\s\S]+?<\/object>/g,function(c){return c.replace(/[\r\n]+/g,"")})}a=a.replace(/<[^<>]+>/g,function(c){return c.replace(/[\r\n]+/g," ")});a=a+"\n\n";a=a.replace(new RegExp("<br />\\s*<br />","gi"),"\n\n");a=a.replace(new RegExp("(<(?:"+b+")[^>]*>)","gi"),"\n$1");a=a.replace(new RegExp("(</(?:"+b+")>)","gi"),"$1\n\n");a=a.replace(new RegExp("\\r\\n|\\r","g"),"\n");a=a.replace(new RegExp("\\n\\s*\\n+","g"),"\n\n");a=a.replace(new RegExp("([\\s\\S]+?)\\n\\n","mg"),"<p>$1</p>\n");a=a.replace(new RegExp("<p>\\s*?</p>","gi"),"");a=a.replace(new RegExp("<p>\\s*(</?(?:"+b+")[^>]*>)\\s*</p>","gi"),"$1");a=a.replace(new RegExp("<p>(<li.+?)</p>","gi"),"$1");a=a.replace(new RegExp("<p>\\s*<blockquote([^>]*)>","gi"),"<blockquote$1><p>");a=a.replace(new RegExp("</blockquote>\\s*</p>","gi"),"</p></blockquote>");a=a.replace(new RegExp("<p>\\s*(</?(?:"+b+")[^>]*>)","gi"),"$1");a=a.replace(new RegExp("(</?(?:"+b+")[^>]*>)\\s*</p>","gi"),"$1");a=a.replace(new RegExp("\\s*\\n","gi"),"<br />\n");a=a.replace(new RegExp("(</?(?:"+b+")[^>]*>)\\s*<br />","gi"),"$1");a=a.replace(new RegExp("<br />(\\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)>)","gi"),"$1");a=a.replace(new RegExp("(?:<p>|<br ?/?>)*\\s*\\[caption([^\\[]+)\\[/caption\\]\\s*(?:</p>|<br ?/?>)*","gi"),"[caption$1[/caption]");a=a.replace(/<(pre|script)[^>]*>[\s\S]+?<\/\1>/g,function(c){c=c.replace(/<br ?\/?>[\r\n]*/g,"\n");return c.replace(/<\/?p( [^>]*)?>[\r\n]*/g,"\n")});return a}};

View File

@ -1806,9 +1806,8 @@ input#link_url {
border-style: none none solid; border-style: none none solid;
} }
#poststuff #edButtonPreview, #edButtonPreview,
#poststuff #edButtonHTML { #edButtonHTML {
display: block;
height: 18px; height: 18px;
margin: 5px 5px 0 0; margin: 5px 5px 0 0;
padding: 4px 5px 2px; padding: 4px 5px 2px;
@ -1825,6 +1824,10 @@ input#link_url {
border-top-left-radius: 3px; border-top-left-radius: 3px;
} }
.js .theEditor {
color: white;
}
#poststuff #edButtonHTML { #poststuff #edButtonHTML {
margin-right: 15px; margin-right: 15px;
} }

View File

@ -1619,49 +1619,52 @@ function the_editor($content, $id = 'content', $prev_id = 'title', $media_button
$media_buttons = false; $media_buttons = false;
$richedit = user_can_richedit(); $richedit = user_can_richedit();
$rows = "rows='$rows'"; $class = '';
if ( $richedit || $media_buttons ) { ?> if ( $richedit || $media_buttons ) { ?>
<div id="editor-toolbar"> <div id="editor-toolbar">
<?php if ( $richedit ) { <?php
if ( $richedit ) {
$wp_default_editor = wp_default_editor(); ?> $wp_default_editor = wp_default_editor(); ?>
<div class="zerosize"><input accesskey="e" type="button" onclick="switchEditors.go('<?php echo $id; ?>')" /></div> <div class="zerosize"><input accesskey="e" type="button" onclick="switchEditors.go('<?php echo $id; ?>')" /></div>
<?php if ( 'html' == $wp_default_editor ) { <?php if ( 'html' == $wp_default_editor ) {
add_filter('the_editor_content', 'wp_htmledit_pre'); ?> add_filter('the_editor_content', 'wp_htmledit_pre'); ?>
<a id="edButtonHTML" class="active" onclick="switchEditors.go('<?php echo $id; ?>', 'html');"><?php _e('HTML'); ?></a> <a id="edButtonHTML" class="active hide-if-no-js" onclick="switchEditors.go('<?php echo $id; ?>', 'html');"><?php _e('HTML'); ?></a>
<a id="edButtonPreview" onclick="switchEditors.go('<?php echo $id; ?>', 'tinymce');"><?php _e('Visual'); ?></a> <a id="edButtonPreview" class="hide-if-no-js" onclick="switchEditors.go('<?php echo $id; ?>', 'tinymce');"><?php _e('Visual'); ?></a>
<?php } else { <?php } else {
$class = " class='theEditor'";
add_filter('the_editor_content', 'wp_richedit_pre'); ?> add_filter('the_editor_content', 'wp_richedit_pre'); ?>
<a id="edButtonHTML" onclick="switchEditors.go('<?php echo $id; ?>', 'html');"><?php _e('HTML'); ?></a> <a id="edButtonHTML" class="hide-if-no-js" onclick="switchEditors.go('<?php echo $id; ?>', 'html');"><?php _e('HTML'); ?></a>
<a id="edButtonPreview" class="active" onclick="switchEditors.go('<?php echo $id; ?>', 'tinymce');"><?php _e('Visual'); ?></a> <a id="edButtonPreview" class="active hide-if-no-js" onclick="switchEditors.go('<?php echo $id; ?>', 'tinymce');"><?php _e('Visual'); ?></a>
<?php } <?php }
} }
if ( $media_buttons ) { ?> if ( $media_buttons ) { ?>
<div id="media-buttons" class="hide-if-no-js"> <div id="media-buttons" class="hide-if-no-js">
<?php do_action( 'media_buttons' ); ?> <?php do_action( 'media_buttons' ); ?>
</div> </div>
<?php } ?> <?php
} ?>
</div> </div>
<?php } ?> <?php
}
<div id="quicktags"> ?>
<?php wp_print_scripts( 'quicktags' ); ?> <div id="quicktags"><?php
wp_print_scripts( 'quicktags' ); ?>
<script type="text/javascript">edToolbar()</script> <script type="text/javascript">edToolbar()</script>
</div> </div>
<?php $the_editor = apply_filters('the_editor', "<div id='editorcontainer'><textarea $rows cols='40' name='$id' tabindex='$tab_index' id='$id'>%s</textarea></div>\n"); <?php
$the_editor = apply_filters('the_editor', "<div id='editorcontainer'><textarea rows='$rows'$class cols='40' name='$id' tabindex='$tab_index' id='$id'>%s</textarea></div>\n");
$the_editor_content = apply_filters('the_editor_content', $content); $the_editor_content = apply_filters('the_editor_content', $content);
printf($the_editor, $the_editor_content); printf($the_editor, $the_editor_content);
?> ?>
<script type="text/javascript"> <script type="text/javascript">
/* <![CDATA[ */
edCanvas = document.getElementById('<?php echo $id; ?>'); edCanvas = document.getElementById('<?php echo $id; ?>');
/* ]]> */
</script> </script>
<?php <?php
} }
/** /**

View File

@ -88,7 +88,7 @@ function wp_default_scripts( &$scripts ) {
// Modify this version when tinyMCE plugins are changed. // Modify this version when tinyMCE plugins are changed.
function mce_version() { function mce_version() {
return '20090424'; return '20090503';
} }
add_filter( 'tiny_mce_version', 'mce_version' ); add_filter( 'tiny_mce_version', 'mce_version' );