HTML in image captions, first run, see #18311

git-svn-id: http://svn.automattic.com/wordpress/trunk@19982 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
azaozz 2012-02-24 01:58:18 +00:00
parent a1d2e646ab
commit 73c87020c7
14 changed files with 510 additions and 188 deletions

View File

@ -3873,6 +3873,43 @@ abbr.required {
padding-left: 15px; padding-left: 15px;
} }
.media-item .edit-caption-controls {
margin: 5px 0;
width: 460px;
}
.media-item .edit-caption-controls label {
margin: 5px 0;
display: block;
}
.media-item .edit-caption-controls label span {
width: 100px;
float: left;
line-height: 22px;
}
.media-item .edit-caption-controls input[type="text"] {
width: 335px;
}
.media-item .caption-insert-link-buttons {
text-align: right;
margin: 5px 12px;
}
.media-item .caption-insert-link-wrap {
padding: 5px 0 5px 12px;
background-color: #f8f8f8;
border: 1px solid #eee;
-webkit-border-radius: 3px;
border-radius: 3px;
}
.media-item .post_excerpt textarea {
height: 60px;
}
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
14.1 - Media Library 14.1 - Media Library
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/

View File

@ -149,22 +149,28 @@ function image_add_caption( $html, $id, $caption, $title, $align, $url, $size, $
$width = $matches[1]; $width = $matches[1];
$caption = str_replace( array( '>', '<', '"', "'" ), $caption = preg_replace_callback( '/<[a-zA-Z][^<>]+>/', '_cleanup_image_add_caption', $caption );
array( '&gt;', '&lt;', '&quot;', '&#039;' ), $caption = str_replace( '"', '&quot;', $caption );
$caption
);
$html = preg_replace( '/(class=["\'][^\'"]*)align(none|left|right|center)\s?/', '$1', $html ); $html = preg_replace( '/(class=["\'][^\'"]*)align(none|left|right|center)\s?/', '$1', $html );
if ( empty($align) ) if ( empty($align) )
$align = 'none'; $align = 'none';
$shcode = '[caption id="' . $id . '" align="align' . $align $shcode = '[caption id="' . $id . '" align="align' . $align
. '" width="' . $width . '" caption="' . addslashes($caption) . '"]' . $html . '[/caption]'; . '" width="' . $width . '" caption="' . $caption . '"]' . $html . '[/caption]';
return apply_filters( 'image_add_caption_shortcode', $shcode, $html ); return apply_filters( 'image_add_caption_shortcode', $shcode, $html );
} }
add_filter( 'image_send_to_editor', 'image_add_caption', 20, 8 ); add_filter( 'image_send_to_editor', 'image_add_caption', 20, 8 );
// Private, preg_replace callback used in image_add_caption()
function _cleanup_image_add_caption($str) {
if ( isset($str[0]) )
return str_replace( '"', "'", $str[0] );
return '';
}
/** /**
* {@internal Missing Short Description}} * {@internal Missing Short Description}}
* *
@ -776,12 +782,33 @@ function image_link_input_fields($post, $url_type = '') {
return " return "
<input type='text' class='text urlfield' name='attachments[$post->ID][url]' value='" . esc_attr($url) . "' /><br /> <input type='text' class='text urlfield' name='attachments[$post->ID][url]' value='" . esc_attr($url) . "' /><br />
<button type='button' class='button urlnone' title=''>" . __('None') . "</button> <button type='button' class='button urlnone' data-link-url=''>" . __('None') . "</button>
<button type='button' class='button urlfile' title='" . esc_attr($file) . "'>" . __('File URL') . "</button> <button type='button' class='button urlfile' data-link-url='" . esc_attr($file) . "'>" . __('File URL') . "</button>
<button type='button' class='button urlpost' title='" . esc_attr($link) . "'>" . __('Attachment Post URL') . "</button> <button type='button' class='button urlpost' data-link-url='" . esc_attr($link) . "'>" . __('Attachment Post URL') . "</button>
"; ";
} }
function wp_caption_input_textarea($edit_post) {
// post data is already escaped
$name = "attachments[{$edit_post->ID}][post_excerpt]";
return '
<textarea class="code" name="' . $name . '" id="' . $name . '">' . $edit_post->post_excerpt . '</textarea>
<div class="edit-caption-controls hide-if-no-js">
<input type="button" class="button caption-insert-link" value="' . esc_attr__('Insert Link') . '" />
<div class="caption-insert-link-wrap hidden">
<label><span>' . __('Link URL') . '</span>
<input type="text" value="" class="caption-insert-link-url" /></label>
<label><span>' . __('Linked text') . '</span>
<input type="text" value="" class="caption-insert-link-text" /></label>
<div class="caption-insert-link-buttons">
<input type="button" class="button caption-cancel" value="' . esc_attr__('Cancel') . '" />
<input type="button" class="button-primary caption-save" value="' . esc_attr__('Insert') . '" />
<br class="clear" />
</div></div></div>
';
}
/** /**
* {@internal Missing Short Description}} * {@internal Missing Short Description}}
* *
@ -924,8 +951,9 @@ function get_attachment_fields_to_edit($post, $errors = null) {
), ),
'image_alt' => array(), 'image_alt' => array(),
'post_excerpt' => array( 'post_excerpt' => array(
'label' => __('Caption'), 'label' => __('Default Caption'),
'value' => $edit_post->post_excerpt 'input' => 'html',
'html' => wp_caption_input_textarea($edit_post)
), ),
'post_content' => array( 'post_content' => array(
'label' => __('Description'), 'label' => __('Description'),
@ -1202,9 +1230,11 @@ function get_media_item( $attachment_id, $args = null ) {
if ( !empty( $field[ $field['input'] ] ) ) if ( !empty( $field[ $field['input'] ] ) )
$item .= $field[ $field['input'] ]; $item .= $field[ $field['input'] ];
elseif ( $field['input'] == 'textarea' ) { elseif ( $field['input'] == 'textarea' ) {
if ( user_can_richedit() ) { // textarea_escaped when user_can_richedit() = false if ( 'post_content' == $id && user_can_richedit() ) {
$field['value'] = esc_textarea( $field['value'] ); // sanitize_post() skips the post_content when user_can_richedit
$field['value'] = htmlspecialchars( $field['value'], ENT_QUOTES );
} }
// post_excerpt is already escaped by sanitize_post() in get_attachment_fields_to_edit()
$item .= "<textarea id='$name' name='$name' $aria_required>" . $field['value'] . '</textarea>'; $item .= "<textarea id='$name' name='$name' $aria_required>" . $field['value'] . '</textarea>';
} else { } else {
$item .= "<input type='text' class='text' id='$name' name='$name' value='" . esc_attr( $field['value'] ) . "' $aria_required />"; $item .= "<input type='text' class='text' id='$name' name='$name' value='" . esc_attr( $field['value'] ) . "' $aria_required />";
@ -1513,8 +1543,13 @@ var addExtImage = {
alt = f.alt.value.replace(/'/g, '&#039;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;'); alt = f.alt.value.replace(/'/g, '&#039;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
<?php if ( ! apply_filters( 'disable_captions', '' ) ) { ?> <?php if ( ! apply_filters( 'disable_captions', '' ) ) { ?>
if ( f.caption.value ) if ( f.caption.value ) {
caption = f.caption.value.replace(/'/g, '&#039;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;'); caption = f.caption.value.replace(/<[a-z][^<>]+>/g, function(a){
return a.replace(/"/g, "'");
});
caption = caption.replace(/"/g, '&quot;');
}
<?php } ?> <?php } ?>
cls = caption ? '' : ' class="'+t.align+'"'; cls = caption ? '' : ' class="'+t.align+'"';

View File

@ -25,8 +25,8 @@ function send_to_editor(h) {
ed.selection.moveToBookmark(ed.windowManager.insertimagebookmark); ed.selection.moveToBookmark(ed.windowManager.insertimagebookmark);
if ( h.indexOf('[caption') === 0 ) { if ( h.indexOf('[caption') === 0 ) {
if ( ed.plugins.wpeditimage ) if ( ed.wpSetImgCaption )
h = ed.plugins.wpeditimage._do_shcode(h); h = ed.wpSetImgCaption(h);
} else if ( h.indexOf('[gallery') === 0 ) { } else if ( h.indexOf('[gallery') === 0 ) {
if ( ed.plugins.wpgallery ) if ( ed.plugins.wpgallery )
h = ed.plugins.wpgallery._do_gallery(h); h = ed.plugins.wpgallery._do_gallery(h);

View File

@ -1188,14 +1188,14 @@ function force_balance_tags( $text ) {
/** /**
* Acts on text which is about to be edited. * Acts on text which is about to be edited.
* *
* Unless $richedit is set, it is simply a holder for the 'format_to_edit' * The $content is run through esc_textarea(), which uses htmlspecialchars()
* filter. If $richedit is set true htmlspecialchars(), through esc_textarea(), * to convert special characters to HTML entities. If $richedit is set to true,
* will be run on the content, converting special characters to HTML entities. * it is simply a holder for the 'format_to_edit' filter.
* *
* @since 0.71 * @since 0.71
* *
* @param string $content The text about to be edited. * @param string $content The text about to be edited.
* @param bool $richedit Whether the $content should pass through htmlspecialchars(). Default false. * @param bool $richedit Whether the $content should not pass through htmlspecialchars(). Default false (meaning it will be passed).
* @return string The text after the filter (and possibly htmlspecialchars()) has been run. * @return string The text after the filter (and possibly htmlspecialchars()) has been run.
*/ */
function format_to_edit( $content, $richedit = false ) { function format_to_edit( $content, $richedit = false ) {

View File

@ -338,10 +338,43 @@ function uploadSizeError( up, file, over100mb ) {
} }
jQuery(document).ready(function($){ jQuery(document).ready(function($){
$('.media-upload-form').bind('click.uploader', function(e) { var insert_link, bookmark;
var target = $(e.target), tr, c;
if ( target.is('input[type="radio"]') ) { // remember the last used image size and alignment $('.media-upload-form').bind('click.uploader', function(e) {
var target = $(e.target), tr, c, el, textarea, sel, text, startPos, endPos;
if ( target.hasClass('caption-insert-link') ) {
el = target.siblings('div.caption-insert-link-wrap'), textarea = target.parent().siblings('textarea').get(0);
if ( document.selection ) {
textarea.focus();
sel = document.selection.createRange();
bookmark = sel.getBookmark();
if ( sel.text )
el.find('.caption-insert-link-text').val(sel.text);
} else if ( textarea.selectionStart || textarea.selectionStart == '0' ) {
text = textarea.value;
startPos = textarea.selectionStart;
endPos = textarea.selectionEnd;
if ( startPos != endPos )
el.find('.caption-insert-link-text').val( text.substring(startPos, endPos) );
}
target.hide();
el.show();
el.find('.caption-insert-link-url').focus();
} else if ( target.hasClass('caption-cancel') || target.hasClass('caption-save') ) {
el = target.closest('div.caption-insert-link-wrap');
if ( target.hasClass('caption-save') )
insert_link( el.closest('.edit-caption-controls').siblings('textarea'), el );
el.hide();
el.siblings('.caption-insert-link').show();
} else if ( target.is('input[type="radio"]') ) { // remember the last used image size and alignment
tr = target.closest('tr'); tr = target.closest('tr');
if ( $(tr).hasClass('align') ) if ( $(tr).hasClass('align') )
@ -355,7 +388,7 @@ jQuery(document).ready(function($){
if ( c && c[1] ) { if ( c && c[1] ) {
setUserSetting('urlbutton', c[1]); setUserSetting('urlbutton', c[1]);
target.siblings('.urlfield').val( target.attr('title') ); target.siblings('.urlfield').val( target.data('link-url') );
} }
} else if ( target.is('a.dismiss') ) { } else if ( target.is('a.dismiss') ) {
target.parents('.media-item').fadeOut(200, function(){ target.parents('.media-item').fadeOut(200, function(){
@ -364,11 +397,11 @@ jQuery(document).ready(function($){
} else if ( target.is('.upload-flash-bypass a') || target.is('a.uploader-html') ) { // switch uploader to html4 } else if ( target.is('.upload-flash-bypass a') || target.is('a.uploader-html') ) { // switch uploader to html4
$('#media-items, p.submit, span.big-file-warning').css('display', 'none'); $('#media-items, p.submit, span.big-file-warning').css('display', 'none');
switchUploader(0); switchUploader(0);
return false; e.preventDefault();
} else if ( target.is('.upload-html-bypass a') ) { // switch uploader to multi-file } else if ( target.is('.upload-html-bypass a') ) { // switch uploader to multi-file
$('#media-items, p.submit, span.big-file-warning').css('display', ''); $('#media-items, p.submit, span.big-file-warning').css('display', '');
switchUploader(1); switchUploader(1);
return false; e.preventDefault();
} else if ( target.is('a.describe-toggle-on') ) { // Show } else if ( target.is('a.describe-toggle-on') ) { // Show
target.parent().addClass('open'); target.parent().addClass('open');
target.siblings('.slidetoggle').fadeIn(250, function(){ target.siblings('.slidetoggle').fadeIn(250, function(){
@ -386,15 +419,54 @@ jQuery(document).ready(function($){
} }
} }
}); });
return false; e.preventDefault();
} else if ( target.is('a.describe-toggle-off') ) { // Hide } else if ( target.is('a.describe-toggle-off') ) { // Hide
target.siblings('.slidetoggle').fadeOut(250, function(){ target.siblings('.slidetoggle').fadeOut(250, function(){
target.parent().removeClass('open'); target.parent().removeClass('open');
}); });
return false; e.preventDefault();
} }
}); });
insert_link = function(textarea, parent) {
var sel, content, startPos, endPos, scrollTop, text,
url = parent.find('.caption-insert-link-url'), link_text = parent.find('.caption-insert-link-text');
if ( !url.length || !link_text.length )
return;
textarea = textarea.get(0);
content = "<a href='"+url.val()+"'>"+link_text.val()+"</a>";
if ( document.selection ) {
textarea.focus();
sel = document.selection.createRange();
if ( bookmark ) {
sel.moveToBookmark( bookmark );
bookmark = '';
}
sel.text = content;
textarea.focus();
} else if ( textarea.selectionStart || textarea.selectionStart == '0' ) {
text = textarea.value;
startPos = textarea.selectionStart;
endPos = textarea.selectionEnd;
scrollTop = textarea.scrollTop;
textarea.value = text.substring(0, startPos) + content + text.substring(endPos, text.length);
textarea.focus();
textarea.selectionStart = startPos + content.length;
textarea.selectionEnd = startPos + content.length;
textarea.scrollTop = scrollTop;
}
url.val('');
link_text.val('');
};
// init and set the uploader // init and set the uploader
uploader_init = function() { uploader_init = function() {
uploader = new plupload.Uploader(wpUploaderInit); uploader = new plupload.Uploader(wpUploaderInit);

View File

@ -12,7 +12,7 @@ not_set:"-- Not set --",
clipboard_msg:"Copy/Cut/Paste is not available in Mozilla and Firefox.", clipboard_msg:"Copy/Cut/Paste is not available in Mozilla and Firefox.",
clipboard_no_support:"Currently not supported by your browser, use keyboard shortcuts instead.", clipboard_no_support:"Currently not supported by your browser, use keyboard shortcuts instead.",
popup_blocked:"Sorry, but we have noticed that your popup-blocker has disabled a window that provides application functionality. You will need to disable popup blocking on this site in order to fully utilize this tool.", popup_blocked:"Sorry, but we have noticed that your popup-blocker has disabled a window that provides application functionality. You will need to disable popup blocking on this site in order to fully utilize this tool.",
invalid_data:"Error: Invalid values entered, these are marked in red.", invalid_data:"ERROR: Invalid values entered, these are marked in red.",
invalid_data_number:"{#field} must be a number", invalid_data_number:"{#field} must be a number",
invalid_data_min:"{#field} must be a number greater than {#min}", invalid_data_min:"{#field} must be a number greater than {#min}",
invalid_data_size:"{#field} must be a number or percentage", invalid_data_size:"{#field} must be a number or percentage",
@ -240,8 +240,8 @@ code:"Code",
samp:"Code sample", samp:"Code sample",
dt:"Definition term ", dt:"Definition term ",
dd:"Definition description", dd:"Definition description",
bold_desc:"Bold (Ctrl / Alt + Shift + B)", bold_desc:"Bold (Ctrl + B)",
italic_desc:"Italic (Ctrl / Alt + Shift + I)", italic_desc:"Italic (Ctrl + I)",
underline_desc:"Underline", underline_desc:"Underline",
striketrough_desc:"Strikethrough (Alt + Shift + D)", striketrough_desc:"Strikethrough (Alt + Shift + D)",
justifyleft_desc:"Align Left (Alt + Shift + L)", justifyleft_desc:"Align Left (Alt + Shift + L)",
@ -266,6 +266,7 @@ removeformat_desc:"Remove formatting",
forecolor_desc:"Select text color", forecolor_desc:"Select text color",
backcolor_desc:"Select background color", backcolor_desc:"Select background color",
charmap_desc:"Insert custom character", charmap_desc:"Insert custom character",
charmap_usage:"Use left and right arrows to navigate.",
visualaid_desc:"Toggle guidelines/invisible elements", visualaid_desc:"Toggle guidelines/invisible elements",
anchor_desc:"Insert/edit anchor", anchor_desc:"Insert/edit anchor",
cut_desc:"Cut", cut_desc:"Cut",
@ -498,5 +499,7 @@ s120:"120%",
s130:"130%", s130:"130%",
img_title:"Title", img_title:"Title",
caption:"Caption", caption:"Caption",
insert_link:"Insert link",
linked_text:"Linked text",
alt:"Alternate Text" alt:"Alternate Text"
}); });

View File

@ -275,6 +275,7 @@ removeformat_desc:"' . mce_escape( __('Remove formatting') ) . '",
forecolor_desc:"' . mce_escape( __('Select text color') ) . '", forecolor_desc:"' . mce_escape( __('Select text color') ) . '",
backcolor_desc:"' . mce_escape( __('Select background color') ) . '", backcolor_desc:"' . mce_escape( __('Select background color') ) . '",
charmap_desc:"' . mce_escape( __('Insert custom character') ) . '", charmap_desc:"' . mce_escape( __('Insert custom character') ) . '",
charmap_usage:"' . mce_escape( __('Use left and right arrows to navigate.') ) . '",
visualaid_desc:"' . mce_escape( __('Toggle guidelines/invisible elements') ) . '", visualaid_desc:"' . mce_escape( __('Toggle guidelines/invisible elements') ) . '",
anchor_desc:"' . mce_escape( __('Insert/edit anchor') ) . '", anchor_desc:"' . mce_escape( __('Insert/edit anchor') ) . '",
cut_desc:"' . mce_escape( __('Cut') ) . '", cut_desc:"' . mce_escape( __('Cut') ) . '",
@ -507,6 +508,8 @@ s120:"' . mce_escape( __('120%') ) . '",
s130:"' . mce_escape( __('130%') ) . '", s130:"' . mce_escape( __('130%') ) . '",
img_title:"' . mce_escape( __('Title') ) . '", img_title:"' . mce_escape( __('Title') ) . '",
caption:"' . mce_escape( __('Caption') ) . '", caption:"' . mce_escape( __('Caption') ) . '",
insert_link:"' . mce_escape( __('Insert link') ) . '",
linked_text:"' . mce_escape( __('Linked text') ) . '",
alt:"' . mce_escape( __('Alternate Text') ) . '" alt:"' . mce_escape( __('Alternate Text') ) . '"
}); });
'; ';

View File

@ -1,68 +0,0 @@
body#media-upload ul#sidemenu {
left: auto;
right: 0;
}
#basic .align .field label {
display: block;
float: right;
padding: 0 24px 0 0;
margin: 5px 3px 5px 5px;
}
.align .field input {
display: block;
float: right;
margin: 5px 15px 5px 0;
}
tr.image-size label {
margin: 0;
}
tr.image-size input {
margin: 3px 15px 0 5px;
}
.image-align-none-label,
.image-align-left-label,
.image-align-center-label,
.image-align-right-label {
background-position: center right;
}
#media-upload .describe th.label {
text-align: right;
}
.show-align,
.alignright,
#img_size {
float: left;
}
tr.image-size label,
tr.image-size input,
#img_dim label,
#img_dim input,
#img_prop label,
#img_prop input,
#img_size_div,
.alignleft {
float: right;
}
#img_dim label,
#img_prop label {
margin: 5px 0pt;
}
#img_dim input,
#img_prop input {
margin: 0 5px 0 10px;
}
#img_size_title {
text-align: left;
}

View File

@ -356,3 +356,112 @@ div#media-upload-error {
background-color: #222222; background-color: #222222;
color: #CFCFCF; color: #CFCFCF;
} }
#img-edit .edit-caption-controls {
margin: 5px 0;
}
#img-edit .edit-caption-controls label {
margin: 5px 0;
display: block;
}
#img-edit .edit-caption-controls label span {
width: 100px;
float: left;
line-height: 22px;
}
#img-edit .edit-caption-controls input[type="text"] {
width: 335px;
}
#img-edit .caption-insert-link-buttons {
text-align: right;
margin: 5px 12px;
}
#img-edit .caption-insert-link-wrap {
padding: 5px 0 5px 12px;
background-color: #f8f8f8;
border: 1px solid #eee;
-webkit-border-radius: 3px;
border-radius: 3px;
}
#img-edit #img_cap_text {
font: normal 12px/18px monospace;
}
.hidden {
display: none;
}
/* RTL */
body#media-upload.rtl ul#sidemenu {
left: auto;
right: 0;
}
.rtl #basic .align .field label {
display: block;
float: right;
padding: 0 24px 0 0;
margin: 5px 3px 5px 5px;
}
.rtl .align .field input {
display: block;
float: right;
margin: 5px 15px 5px 0;
}
.rtl tr.image-size label {
margin: 0;
}
.rtl tr.image-size input {
margin: 3px 15px 0 5px;
}
.rtl .image-align-none-label,
.rtl .image-align-left-label,
.rtl .image-align-center-label,
.rtl .image-align-right-label {
background-position: center right;
}
#media-upload.rtl .describe th.label {
text-align: right;
}
.rtl .show-align,
.rtl .alignright,
.rtl #img_size {
float: left;
}
.rtl tr.image-size label,
.rtl tr.image-size input,
.rtl #img_dim label,
.rtl #img_dim input,
.rtl #img_prop label,
.rtl #img_prop input,
.rtl #img_size_div,
.rtl .alignleft {
float: right;
}
.rtl #img_dim label,
.rtl #img_prop label {
margin: 5px 0pt;
}
.rtl #img_dim input,
.rtl #img_prop input {
margin: 0 5px 0 10px;
}
.rtl #img_size_title {
text-align: left;
}

View File

@ -1,22 +1,20 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title></title> <title></title>
<script type="text/javascript" src="js/editimage.js?ver=327"></script> <link rel="stylesheet" href="css/editimage.css?ver=348" type="text/css" media="all" />
<script type="text/javascript" src="../../utils/form_utils.js?ver=3223"></script> <script type="text/javascript" src="js/editimage.js?ver=348"></script>
<script type="text/javascript" src="../../utils/form_utils.js?ver=348"></script>
<link rel="stylesheet" href="css/editimage.css?ver=327" type="text/css" media="all" />
<script type="text/javascript">
if ( 'rtl' == tinyMCEPopup.editor.getParam('directionality','') )
document.write('<link rel="stylesheet" href="css/editimage-rtl.css?ver=3223" type="text/css" media="all" />');
</script>
<base target="_self" /> <base target="_self" />
</head> </head>
<body id="media-upload" style="display:none;"> <body id="media-upload" style="display:none;">
<script type="text/javascript">
if ( 'rtl' == tinyMCEPopup.editor.getParam('directionality','') )
document.body.className += ' rtl';
</script>
<div id="media-upload-header"> <div id="media-upload-header">
<ul id="sidemenu"> <ul id="sidemenu">
<li><a href="javascript:;" id="tab_basic" class="current" onclick="wpImage.setTabs(this);">{#wpeditimage.edit_img}</a></li> <li><a href="javascript:;" id="tab_basic" class="current" onclick="wpImage.setTabs(this);">{#wpeditimage.edit_img}</a></li>
@ -103,7 +101,23 @@ if ( 'rtl' == tinyMCEPopup.editor.getParam('directionality','') )
</label> </label>
</th> </th>
<td class="field"> <td class="field">
<input type="text" id="img_cap" name="img_cap" value="" size="60" /> <textarea id="img_cap_text"></textarea>
<div class="edit-caption-controls">
<input type="button" class="button caption-insert-link" value="{#wpeditimage.insert_link}" />
<div class="caption-insert-link-wrap hidden">
<label><span>{#advanced_dlg.link_url}</span>
<input type="text" value="" class="caption-insert-link-url" /></label>
<label><span>{#wpeditimage.linked_text}</span>
<input type="text" value="" class="caption-insert-link-text" /></label>
<div class="caption-insert-link-buttons">
<input type="button" class="button caption-cancel" value="{#cancel}" />
<input type="button" class="button-primary caption-save" value="{#insert}" />
<br class="clear" />
</div></div></div>
</td> </td>
</tr> </tr>

View File

@ -1,11 +1,14 @@
(function() { (function() {
tinymce.create('tinymce.plugins.wpEditImage', { tinymce.create('tinymce.plugins.wpEditImage', {
url: '',
editor: {},
init : function(ed, url) { init: function(ed, url) {
var t = this, mouse = {}; var t = this, mouse = {};
t.url = url; t.url = url;
t.editor = ed;
t._createButtons(); t._createButtons();
// Register the command so that it can be invoked by using tinyMCE.activeEditor.execCommand('...'); // Register the command so that it can be invoked by using tinyMCE.activeEditor.execCommand('...');
@ -28,9 +31,12 @@
}); });
ed.onInit.add(function(ed) { ed.onInit.add(function(ed) {
tinymce.dom.Event.add(ed.getBody(), 'dragstart', function(e) { ed.dom.events.add(ed.getBody(), 'dragstart', function(e) {
if ( !tinymce.isGecko && e.target.nodeName == 'IMG' && ed.dom.getParent(e.target, 'dl.wp-caption') ) var parent;
return tinymce.dom.Event.cancel(e);
if ( e.target.nodeName == 'IMG' && ( parent = ed.dom.getParent(e.target, 'div.mceTemp') ) ) {
ed.selection.select(parent);
}
}); });
}); });
@ -44,21 +50,16 @@
if ( 'IMG' == n.nodeName ) { if ( 'IMG' == n.nodeName ) {
window.setTimeout(function(){ window.setTimeout(function(){
var DL, width; var DL = ed.dom.getParent(n, 'dl.wp-caption'), width;
if ( n.width != mouse.img_w || n.height != mouse.img_h ) if ( n.width != mouse.img_w || n.height != mouse.img_h )
n.className = n.className.replace(/size-[^ "']+/, ''); n.className = n.className.replace(/size-[^ "']+/, '');
if ( ed.dom.getParent(n, 'div.mceTemp') ) { if ( DL ) {
DL = ed.dom.getParent(n, 'dl.wp-caption'); width = ed.dom.getAttrib(n, 'width') || n.width;
width = parseInt(width, 10);
if ( DL ) { ed.dom.setStyle(DL, 'width', 10 + width);
width = ed.dom.getAttrib(n, 'width') || n.width; ed.execCommand('mceRepaint');
width = parseInt(width, 10);
ed.dom.setStyle(DL, 'width', 10 + width);
ed.execCommand('mceRepaint');
}
} }
}, 100); }, 100);
} }
@ -82,79 +83,104 @@
} }
}); });
// when pressing Return inside a caption move the cursor to a new parapraph under it // when pressing Return inside a caption move the caret to a new parapraph under it
ed.onKeyPress.add(function(ed, e) { ed.onKeyPress.add(function(ed, e) {
var n, DL, DIV, P; var n, DL, DIV, P;
if ( e.keyCode == 13 ) { if ( e.keyCode == 13 ) {
n = ed.selection.getNode(); n = ed.selection.getNode();
DL = ed.dom.getParent(n, 'dl.wp-caption'); DL = ed.dom.getParent(n, 'dl.wp-caption');
DIV = ed.dom.getParent(DL, 'div.mceTemp');
if ( DL && DIV ) { if ( DL )
P = ed.dom.create('p', {}, '&nbsp;'); DIV = ed.dom.getParent(DL, 'div.mceTemp');
if ( DIV ) {
P = ed.dom.create('p', {}, '<br>');
ed.dom.insertAfter( P, DIV ); ed.dom.insertAfter( P, DIV );
ed.selection.select(P.firstChild);
if ( P.firstChild ) if ( tinymce.isIE ) {
ed.selection.select(P.firstChild); ed.selection.setContent('');
else } else {
ed.selection.select(P); ed.selection.setContent('<br _moz_dirty="">');
ed.selection.setCursorLocation(P, 0);
}
tinymce.dom.Event.cancel(e); ed.dom.events.cancel(e);
return false; return false;
} }
} }
}); });
ed.onBeforeSetContent.add(function(ed, o) { ed.onBeforeSetContent.add(function(ed, o) {
o.content = t._do_shcode(o.content); o.content = ed.wpSetImgCaption(o.content);
}); });
ed.onPostProcess.add(function(ed, o) { ed.onPostProcess.add(function(ed, o) {
if (o.get) if (o.get)
o.content = t._get_shcode(o.content); o.content = ed.wpGetImgCaption(o.content);
}); });
ed.wpSetImgCaption = function(content) {
return t._do_shcode(content);
};
ed.wpGetImgCaption = function(content) {
return t._get_shcode(content);
};
}, },
_do_shcode : function(co) { _do_shcode : function(content) {
return co.replace(/(?:<p>)?\[(?:wp_)?caption([^\]]+)\]([\s\S]+?)\[\/(?:wp_)?caption\](?:<\/p>)?[\s\u00a0]*/g, function(a,b,c){ return content.replace(/(?:<p>)?\[(?:wp_)?caption([^\]]+)\]([\s\S]+?)\[\/(?:wp_)?caption\](?:<\/p>)?/g, function(a,b,c){
var id, cls, w, cap, div_cls; var id, cls, w, cap, div_cls;
b = b.replace(/\\'|\\&#39;|\\&#039;/g, '&#39;').replace(/\\"|\\&quot;/g, '&quot;'); id = b.match(/id=['"]([^'"]+)['"] ?/);
c = c.replace(/\\&#39;|\\&#039;/g, '&#39;').replace(/\\&quot;/g, '&quot;'); b = b.replace(id[0], '');
id = b.match(/id=['"]([^'"]+)/i);
cls = b.match(/align=['"]([^'"]+)/i); cls = b.match(/align=['"]([^'"]+)['"] ?/);
w = b.match(/width=['"]([0-9]+)/); b = b.replace(cls[0], '');
cap = b.match(/caption=['"]([^'"]+)/i);
w = b.match(/width=['"]([0-9]+)['"] ?/);
b = b.replace(w[0], '');
cap = tinymce.trim(b).replace(/caption=['"]/, '').replace(/['"]$/, '');
id = ( id && id[1] ) ? id[1] : ''; id = ( id && id[1] ) ? id[1] : '';
cls = ( cls && cls[1] ) ? cls[1] : 'alignnone'; cls = ( cls && cls[1] ) ? cls[1] : 'alignnone';
w = ( w && w[1] ) ? w[1] : ''; w = ( w && w[1] ) ? w[1] : '';
cap = ( cap && cap[1] ) ? cap[1] : '';
if ( ! w || ! cap ) return c; if ( !w || !cap )
return c;
div_cls = (cls == 'aligncenter') ? 'mceTemp mceIEcenter' : 'mceTemp'; div_cls = (cls == 'aligncenter') ? 'mceTemp mceIEcenter' : 'mceTemp';
return '<div class="'+div_cls+'" draggable><dl id="'+id+'" class="wp-caption '+cls+'" style="width: '+(10+parseInt(w))+ return '<div class="'+div_cls+'" draggable="true"><dl id="'+id+'" class="wp-caption '+cls+'" style="width: '+( 10 + parseInt(w) )+
'px"><dt class="wp-caption-dt">'+c+'</dt><dd class="wp-caption-dd">'+cap+'</dd></dl></div>'; 'px"><dt class="wp-caption-dt">'+c+'</dt><dd class="wp-caption-dd">'+cap+'</dd></dl></div>';
}); });
}, },
_get_shcode : function(co) { _get_shcode : function(content) {
return co.replace(/<div class="mceTemp[^"]*">\s*<dl([^>]+)>\s*<dt[^>]+>([\s\S]+?)<\/dt>\s*<dd[^>]+>(.+?)<\/dd>\s*<\/dl>\s*<\/div>\s*/gi, function(a,b,c,cap){ return content.replace(/<div class="mceTemp[^"]*">\s*<dl ([^>]+)>\s*<dt [^>]+>([\s\S]+?)<\/dt>\s*<dd [^>]+>([\s\S]+?)<\/dd>\s*<\/dl>\s*<\/div>/gi, function(a,b,c,cap){
var id, cls, w; var id, cls, w;
id = b.match(/id=['"]([^'"]+)/i); w = c.match(/width="([0-9]+)"/);
cls = b.match(/class=['"]([^'"]+)/i);
w = c.match(/width=['"]([0-9]+)/);
id = ( id && id[1] ) ? id[1] : '';
cls = ( cls && cls[1] ) ? cls[1] : 'alignnone';
w = ( w && w[1] ) ? w[1] : ''; w = ( w && w[1] ) ? w[1] : '';
if ( ! w || ! cap ) return c; if ( !w || !cap )
cls = cls.match(/align[^ '"]+/) || 'alignnone'; return c;
cap = cap.replace(/<\S[^<>]*>/gi, '').replace(/'/g, '&#39;').replace(/"/g, '&quot;');
id = b.match(/id="([^"]+)"/);
id = ( id && id[1] ) ? id[1] : '';
cls = b.match(/class="([^"]+)"/);
cls = ( cls && cls[1] ) ? cls[1] : '';
cls = cls.match(/align[a-z]+/) || 'alignnone';
cap = cap.replace(/<[a-z][^<>]+>/g, function(a){
return a.replace(/"/g, "'");
});
cap = cap.replace(/"/g, '&quot;');
return '[caption id="'+id+'" align="'+cls+'" width="'+w+'" caption="'+cap+'"]'+c+'[/caption]'; return '[caption id="'+id+'" align="'+cls+'" width="'+w+'" caption="'+cap+'"]'+c+'[/caption]';
}); });

View File

@ -21,6 +21,7 @@ tinyMCEPopup = {
tinyMCE = w.tinyMCE; tinyMCE = w.tinyMCE;
t.editor = tinymce.EditorManager.activeEditor; t.editor = tinymce.EditorManager.activeEditor;
t.params = t.editor.windowManager.params; t.params = t.editor.windowManager.params;
t.events = new tinymce.dom.EventUtils();
// Setup local DOM // Setup local DOM
t.dom = t.editor.windowManager.createInstance('tinymce.dom.DOMUtils', document); t.dom = t.editor.windowManager.createInstance('tinymce.dom.DOMUtils', document);
@ -36,16 +37,16 @@ tinyMCEPopup = {
}, },
close : function() { close : function() {
var t = this, win = t.getWin(); var t = this;
// To avoid domain relaxing issue in Opera // To avoid domain relaxing issue in Opera
function close() { function close() {
win.tb_remove(); t.editor.windowManager.close(window);
tinymce = tinyMCE = t.editor = t.dom = t.dom.doc = null; // Cleanup tinymce = tinyMCE = t.editor = t.params = t.dom = t.dom.doc = null; // Cleanup
}; };
if (tinymce.isOpera) if (tinymce.isOpera)
win.setTimeout(close, 0); t.getWin().setTimeout(close, 0);
else else
close(); close();
}, },
@ -74,12 +75,14 @@ tinyMCEPopup.init();
wpImage = { wpImage = {
preInit : function() { preInit : function() {
// import colors stylesheet from parent // import colors stylesheet from parent
var win = tinyMCEPopup.getWin(), styles = win.document.styleSheets, url, i; var ed = tinyMCEPopup.editor, win = tinyMCEPopup.getWin(), styles = win.document.styleSheets, url, i;
for ( i = 0; i < styles.length; i++ ) { for ( i = 0; i < styles.length; i++ ) {
url = styles.item(i).href; url = styles.item(i).href;
if ( url && url.indexOf('colors') != -1 ) if ( url && url.indexOf('colors') != -1 ) {
document.write( '<link rel="stylesheet" href="'+url+'" type="text/css" media="all" />' ); document.getElementsByTagName('head')[0].appendChild( ed.dom.create('link', {rel:'stylesheet', href: url}) );
break;
}
} }
}, },
@ -242,7 +245,7 @@ wpImage = {
setup : function() { setup : function() {
var t = this, c, el, link, fname, f = document.forms[0], ed = tinyMCEPopup.editor, var t = this, c, el, link, fname, f = document.forms[0], ed = tinyMCEPopup.editor,
d = t.I('img_demo'), dom = tinyMCEPopup.dom, DL, caption = '', dlc, pa; d = t.I('img_demo'), dom = tinyMCEPopup.dom, DL, DD, caption = '', dlc, pa, bookmark, insert_link;
document.dir = tinyMCEPopup.editor.getParam('directionality',''); document.dir = tinyMCEPopup.editor.getParam('directionality','');
@ -267,15 +270,12 @@ wpImage = {
tinymce.trim(c); tinymce.trim(c);
} }
tinymce.each(DL.childNodes, function(e) { DD = ed.dom.select('dd.wp-caption-dd', DL);
if ( e.nodeName == 'DD' && dom.hasClass(e, 'wp-caption-dd') ) { if ( DD && DD[0] )
caption = e.innerHTML; caption = ed.serializer.serialize(DD[0]).replace(/^<p>/, '').replace(/<\/p>$/, '');
return;
}
});
} }
f.img_cap.value = caption; f.img_cap_text.value = caption;
f.img_title.value = ed.dom.getAttrib(el, 'title'); f.img_title.value = ed.dom.getAttrib(el, 'title');
f.img_alt.value = ed.dom.getAttrib(el, 'alt'); f.img_alt.value = ed.dom.getAttrib(el, 'alt');
f.border.value = ed.dom.getAttrib(el, 'border'); f.border.value = ed.dom.getAttrib(el, 'border');
@ -326,8 +326,83 @@ wpImage = {
d.className = t.align = "alignnone"; d.className = t.align = "alignnone";
} }
if ( t.width && t.preloadImg.width ) t.showSizeSet(); if ( t.width && t.preloadImg.width )
t.showSizeSet();
document.body.style.display = ''; document.body.style.display = '';
tinyMCEPopup.events.add(document.body, 'click', function(e) {
var target = e.target, parent = target.parentNode, tr, c, el, textarea, sel, text, startPos, endPos;
if ( dom.hasClass(target, 'caption-insert-link') ) {
el = dom.select('div.caption-insert-link-wrap', parent)[0], textarea = dom.select('#img_cap_text')[0];
if ( document.selection ) {
textarea.focus();
sel = document.selection.createRange();
bookmark = sel.getBookmark();
if ( sel.text )
dom.select('.caption-insert-link-text', el)[0].value = sel.text;
} else if ( textarea.selectionStart || textarea.selectionStart == '0' ) {
text = textarea.value;
startPos = textarea.selectionStart;
endPos = textarea.selectionEnd;
if ( startPos != endPos )
dom.select('.caption-insert-link-text', el)[0].value = text.substring(startPos, endPos);
}
dom.hide(target);
dom.show(el);
dom.select('.caption-insert-link-url', el)[0].focus();
} else if ( dom.hasClass(target, 'caption-cancel') || dom.hasClass(target, 'caption-save') ) {
if ( dom.hasClass(target, 'caption-save') )
insert_link();
dom.hide( dom.select('.caption-insert-link-wrap') );
dom.show( dom.select('.caption-insert-link') );
}
});
insert_link = function() {
var sel, content, startPos, endPos, scrollTop, text, textarea = dom.select('#img_cap_text')[0],
url = dom.select('.caption-insert-link-url')[0], link_text = dom.select('.caption-insert-link-text')[0];
if ( !url || !link_text )
return;
content = "<a href='"+url.value+"'>"+link_text.value+"</a>";
if ( document.selection ) {
textarea.focus();
sel = document.selection.createRange();
if ( bookmark ) {
sel.moveToBookmark( bookmark );
bookmark = '';
}
sel.text = content;
textarea.focus();
} else if ( textarea.selectionStart || textarea.selectionStart == '0' ) {
text = textarea.value;
startPos = textarea.selectionStart;
endPos = textarea.selectionEnd;
scrollTop = textarea.scrollTop;
textarea.value = text.substring(0, startPos) + content + text.substring(endPos, text.length);
textarea.focus();
textarea.selectionStart = startPos + content.length;
textarea.selectionEnd = startPos + content.length;
textarea.scrollTop = scrollTop;
}
url.value = '';
link_text.value = '';
};
}, },
remove : function() { remove : function() {
@ -362,7 +437,7 @@ wpImage = {
return; return;
} }
if ( f.img_cap.value != '' && f.width.value != '' ) { if ( f.img_cap_text.value != '' && f.width.value != '' ) {
do_caption = 1; do_caption = 1;
img_class = img_class.replace( /align[^ "']+\s?/gi, '' ); img_class = img_class.replace( /align[^ "']+\s?/gi, '' );
} }
@ -440,7 +515,7 @@ wpImage = {
ed.dom.setAttrib(DIV, 'class', div_cls); ed.dom.setAttrib(DIV, 'class', div_cls);
if ( (DT = ed.dom.getParent(el, 'dt')) && (DD = DT.nextSibling) && ed.dom.hasClass(DD, 'wp-caption-dd') ) if ( (DT = ed.dom.getParent(el, 'dt')) && (DD = DT.nextSibling) && ed.dom.hasClass(DD, 'wp-caption-dd') )
ed.dom.setHTML(DD, f.img_cap.value); ed.dom.setHTML(DD, f.img_cap_text.value);
} else { } else {
if ( (id = f.img_classes.value.match( /wp-image-([0-9]{1,6})/ )) && id[1] ) if ( (id = f.img_classes.value.match( /wp-image-([0-9]{1,6})/ )) && id[1] )
@ -457,7 +532,7 @@ wpImage = {
} else html = ed.dom.getOuterHTML(el); } else html = ed.dom.getOuterHTML(el);
html = '<dl id="'+cap_id+'" class="wp-caption '+t.align+'" style="width: '+cap_width+ html = '<dl id="'+cap_id+'" class="wp-caption '+t.align+'" style="width: '+cap_width+
'px"><dt class="wp-caption-dt">'+html+'</dt><dd class="wp-caption-dd">'+f.img_cap.value+'</dd></dl>'; 'px"><dt class="wp-caption-dt">'+html+'</dt><dd class="wp-caption-dd">'+f.img_cap_text.value+'</dd></dl>';
cap = ed.dom.create('div', {'class': div_cls}, html); cap = ed.dom.create('div', {'class': div_cls}, html);
@ -614,3 +689,4 @@ wpImage = {
window.onload = function(){wpImage.init();} window.onload = function(){wpImage.init();}
wpImage.preInit(); wpImage.preInit();

File diff suppressed because one or more lines are too long

View File

@ -1,8 +1,4 @@
body {
font: 13px/19px Georgia, "Times New Roman", "Bitstream Charter", Times, serif;
margin: 10px;
color: #000;
}
body.mceForceColors {background:#FFF; color:#000;} body.mceForceColors {background:#FFF; color:#000;}
body.mceBrowserDefaults {background:transparent; color:inherit; font-size:inherit; font-family:inherit;} body.mceBrowserDefaults {background:transparent; color:inherit; font-size:inherit; font-family:inherit;}
td {color:#000; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px; margin:8px;} td {color:#000; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px; margin:8px;}
@ -41,6 +37,24 @@ font[face=mceinline] {font-family:inherit !important}
.mcePageBreak {display:block;border:0;width:100%;height:12px;border-top:1px dotted #ccc;margin-top:15px;background:#fff url(../../img/pagebreak.gif) no-repeat center top;} .mcePageBreak {display:block;border:0;width:100%;height:12px;border-top:1px dotted #ccc;margin-top:15px;background:#fff url(../../img/pagebreak.gif) no-repeat center top;}
/* WordPress styles */ /* WordPress styles */
body {
font-family: sans-serif;
font-size: 13px;
line-height: 19px;
color: #333;
margin: 10px;
min-height: 100%;
}
br[data-mce-bogus] {
line-height: 1em;
margin-top: -1em;
}
br[data-mce-bogus]:only-child {
line-height: inherit;
margin-top: inherit;
}
.aligncenter, .aligncenter,
dl.aligncenter { dl.aligncenter {
@ -75,6 +89,7 @@ dl.aligncenter {
margin: 0; margin: 0;
padding: 0; padding: 0;
border: 0 none; border: 0 none;
-webkit-user-drag: none;
} }
.wp-caption-dd { .wp-caption-dd {