Image captions from azaozz. see #6812

git-svn-id: https://develop.svn.wordpress.org/trunk@8239 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2008-07-02 18:41:11 +00:00
parent 458399dd51
commit 45ac770299
13 changed files with 365 additions and 93 deletions

View File

@ -64,7 +64,7 @@ header( 'Content-Type: application/x-javascript; charset=UTF-8' );
?> ?>
{ {
"betaManifestVersion" : 1, "betaManifestVersion" : 1,
"version" : "<?php echo $man_version; ?>_20080626", "version" : "<?php echo $man_version; ?>_20080701",
"entries" : [ "entries" : [
<?php echo $defaults; ?> <?php echo $defaults; ?>

View File

@ -62,6 +62,25 @@ function get_image_send_to_editor($id, $alt, $title, $align, $url='', $rel = fal
return $html; return $html;
} }
function image_add_caption( $html, $id, $alt, $title, $align, $url, $size ) {
if ( empty($alt) ) return $html;
$id = ( 0 < (int) $id ) ? 'attachment_' . $id : '';
preg_match( '/width="([0-9]+)/', $html, $matches );
if ( ! isset($matches[1]) ) return $html;
$width = $matches[1];
$html = preg_replace( '/align[^\s\'"]+\s?/', '', $html );
if ( empty($align) ) $align = 'none';
$shcode = '[wp_caption id="' . $id . '" align="align' . $align
. '" width="' . $width . '" caption="' . $alt . '"]' . $html . '[/wp_caption]';
return apply_filters( 'image_add_caption_shortcode', $shcode, $html );
}
add_filter( 'image_send_to_editor', 'image_add_caption', 20, 7 );
function media_send_to_editor($html) { function media_send_to_editor($html) {
?> ?>
<script type="text/javascript"> <script type="text/javascript">

View File

@ -52,6 +52,7 @@ switchEditors = {
// Fix some block element newline issues // Fix some block element newline issues
content = content.replace(new RegExp('\\s*<div', 'mg'), '\n<div'); content = content.replace(new RegExp('\\s*<div', 'mg'), '\n<div');
content = content.replace(new RegExp('</div>\\s*', 'mg'), '</div>\n'); content = content.replace(new RegExp('</div>\\s*', 'mg'), '</div>\n');
content = content.replace(new RegExp('\\s*\\[wp_caption([^\\[]+)\\[/wp_caption\\]\\s*', 'gi'), '\n\n[wp_caption$1[/wp_caption]\n\n');
var blocklist2 = 'blockquote|ul|ol|li|table|thead|tr|th|td|h[1-6]|pre'; var blocklist2 = 'blockquote|ul|ol|li|table|thead|tr|th|td|h[1-6]|pre';
content = content.replace(new RegExp('\\s*<(('+blocklist2+') ?[^>]*)\\s*>', 'mg'), '\n<$1>'); content = content.replace(new RegExp('\\s*<(('+blocklist2+') ?[^>]*)\\s*>', 'mg'), '\n<$1>');
@ -69,7 +70,7 @@ switchEditors = {
// Trim whitespace // Trim whitespace
content = content.replace(new RegExp('^\\s*', ''), ''); content = content.replace(new RegExp('^\\s*', ''), '');
content = content.replace(new RegExp('\\s*$', ''), ''); content = content.replace(new RegExp('[\\s\\u00a0]*$', ''), '');
// put back the line breaks in pre|script // put back the line breaks in pre|script
content = content.replace(/<wp_temp>/g, '\n'); content = content.replace(/<wp_temp>/g, '\n');
@ -164,6 +165,7 @@ switchEditors = {
pee = pee.replace(new RegExp('\\s*\\n', 'gi'), "<br />\n"); pee = pee.replace(new RegExp('\\s*\\n', 'gi'), "<br />\n");
pee = pee.replace(new RegExp('(</?(?:'+blocklist+')[^>]*>)\\s*<br />', 'gi'), "$1"); pee = pee.replace(new RegExp('(</?(?:'+blocklist+')[^>]*>)\\s*<br />', 'gi'), "$1");
pee = pee.replace(new RegExp('<br />(\\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)>)', 'gi'), '$1'); pee = pee.replace(new RegExp('<br />(\\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)>)', 'gi'), '$1');
pee = pee.replace(new RegExp('(?:<p>|<br ?/?>)*\\s*\\[wp_caption([^\\[]+)\\[/wp_caption\\]\\s*(?:</p>|<br ?/?>)*', 'gi'), '[wp_caption$1[/wp_caption]');
// pee = pee.replace(new RegExp('^((?:&nbsp;)*)\\s', 'mg'), '$1&nbsp;'); // pee = pee.replace(new RegExp('^((?:&nbsp;)*)\\s', 'mg'), '$1&nbsp;');
// Fix the pre|script tags // Fix the pre|script tags

View File

@ -6,6 +6,7 @@ function send_to_editor(h) {
ed.selection.moveToBookmark(tinymce.EditorManager.activeEditor.windowManager.bookmark); ed.selection.moveToBookmark(tinymce.EditorManager.activeEditor.windowManager.bookmark);
ed.execCommand('mceInsertContent', false, h); ed.execCommand('mceInsertContent', false, h);
ed.execCommand('mceCleanup');
} else } else
edInsertContent(edCanvas, h); edInsertContent(edCanvas, h);

View File

@ -319,3 +319,45 @@ ul.post-meta span.post-meta-key {
font-style: normal; font-style: normal;
text-transform: capitalize; text-transform: capitalize;
} }
/* Captions & aligment */
.aligncenter,
dl.aligncenter {
display: block;
margin-left: auto;
margin-right: auto;
}
.alignleft {
float: left;
}
.alignright {
float: right;
}
.wp_caption {
border: 1px solid #ddd;
text-align: center;
background-color: #f3f3f3;
padding-top: 4px;
margin: 10px;
-moz-border-radius: 3px;
-khtml-border-radius: 3px;
-webkit-border-radius: 3px;
border-radius: 3px;
}
.wp_caption img {
margin: 0;
padding: 0;
border: 0 none;
}
.wp_caption_dd {
font-size: 11px;
line-height: 17px;
padding: 0 4px 5px;
margin: 0;
}
/* End captions & aligment */

View File

@ -638,6 +638,41 @@ a img {
/* Captions */
.aligncenter,
dl.aligncenter {
display: block;
margin-left: auto;
margin-right: auto;
}
.wp_caption {
border: 1px solid #ddd;
text-align: center;
background-color: #f3f3f3;
padding-top: 4px;
margin: 10px;
-moz-border-radius: 3px;
-khtml-border-radius: 3px;
-webkit-border-radius: 3px;
border-radius: 3px;
}
.wp_caption img {
margin: 0;
padding: 0;
border: 0 none;
}
.wp_caption_dd {
font-size: 11px;
line-height: 17px;
padding: 0 4px 5px;
margin: 0;
}
/* End captions */
/* "Daisy, Daisy, give me your answer do. I'm half crazy all for the love of you. /* "Daisy, Daisy, give me your answer do. I'm half crazy all for the love of you.
It won't be a stylish marriage, I can't afford a carriage. It won't be a stylish marriage, I can't afford a carriage.
But you'll look sweet upon the seat of a bicycle built for two." */ But you'll look sweet upon the seat of a bicycle built for two." */

View File

@ -400,6 +400,7 @@ wp_page_alt:"' . mce_escape( __('Next page...') ) . '"
tinyMCE.addI18n("' . $language . '.wpeditimage",{ tinyMCE.addI18n("' . $language . '.wpeditimage",{
edit_img:"' . mce_escape( __('Edit Image') ) . '", edit_img:"' . mce_escape( __('Edit Image') ) . '",
del_img:"' . mce_escape( __('Delete Image') ) . '",
adv_settings:"' . mce_escape( __('Advanced Settings') ) . '", adv_settings:"' . mce_escape( __('Advanced Settings') ) . '",
none:"' . mce_escape( __('None') ) . '", none:"' . mce_escape( __('None') ) . '",
size:"' . mce_escape( __('Size') ) . '", size:"' . mce_escape( __('Size') ) . '",

View File

@ -34,27 +34,76 @@
}); });
ed.onMouseUp.add(function(ed, e) { ed.onMouseUp.add(function(ed, e) {
if ( tinymce.isOpera ) if ( ! tinymce.isOpera ) return;
ed.plugins.wpeditimage.showButtons(e); if ( e.target.nodeName == 'IMG' )
ed.plugins.wpeditimage.showButtons(e.target);
}); });
ed.onMouseDown.add(function(ed, e) { ed.onMouseDown.add(function(ed, e) {
if ( tinymce.isOpera ) return; if ( tinymce.isOpera || e.target.nodeName != 'IMG' ) {
ed.plugins.wpeditimage.showButtons(e); t.hideButtons();
}); return;
/* }
ed.onSetContent.add(function() { ed.plugins.wpeditimage.showButtons(e.target);
t._fixCenter(ed.getBody());
}); });
ed.onPreProcess.add(function(ed, o) { ed.onKeyPress.add(function(ed, e) {
if (o.set) var DL, DIV;
t._fixCenter(o.node);
if ( e.keyCode == 13 && (DL = ed.dom.getParent(ed.selection.getNode(), 'DL')) ) {
var P = ed.dom.create('p', {}, '&nbsp;');
if ( (DIV = DL.parentNode) && DIV.nodeName == 'DIV' )
ed.dom.insertAfter( P, DIV );
else ed.dom.insertAfter( P, DL );
tinymce.dom.Event.cancel(e);
ed.selection.select(P);
return false;
}
});
ed.onBeforeSetContent.add(function(ed, o) {
o.content = t._do_shcode(o.content);
});
ed.onPostProcess.add(function(ed, o) {
if (o.get) if (o.get)
ed.dom.removeClass(ed.dom.select('p', o.node), 'mce_iecenter'); o.content = t._get_shcode(o.content);
});
},
_do_shcode : function(co) {
return co.replace(/\[wp_caption([^\]]+)\]([\s\S]+?)\[\/wp_caption\][\s\u00a0]*/g, function(a,b,c){
var id = b.match(/id=['"]([^'"]+)/), cls = b.match(/align=['"]([^'"]+)/);
var w = b.match(/width=['"]([0-9]+)/), cap = b.match(/caption=['"]([^'"]+)/);
id = ( id && id[1] ) ? id[1] : '';
cls = ( cls && cls[1] ) ? cls[1] : 'alignnone';
w = ( w && w[1] ) ? w[1] : '';
cap = ( cap && cap[1] ) ? cap[1] : '';
if ( ! w || ! cap ) return c;
var div_cls = (cls == 'aligncenter') ? 'mceTemp mceIEcenter' : 'mceTemp';
return '<div class="'+div_cls+'"><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>';
});
},
_get_shcode : function(co) {
return co.replace(/<div class="mceTemp[^"]*">\s*<dl([^>]+)>\s*<dt[^>]+>([\s\S]+?)<\/dt>\s*<dd[^>]+>([^<]+)<\/dd>\s*<\/dl>\s*<\/div>\s*/g, function(a,b,c,cap){
var id = b.match(/id=['"]([^'"]+)/), cls = b.match(/class=['"]([^'"]+)/);
var 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] : '';
if ( ! w || ! cap ) return c;
cls = cls ? cls.match(/align[^ '"]+/) : '';
return '[wp_caption id="'+id+'" align="'+cls+'" width="'+w+'" caption="'+cap+'"]'+c+'[/wp_caption]';
}); });
*/
}, },
_fixCenter : function(c) { _fixCenter : function(c) {
@ -71,17 +120,15 @@
}); });
}, },
showButtons : function(e) { showButtons : function(n) {
var t = this, ed = tinyMCE.activeEditor, p1, p2, vp, DOM = tinymce.DOM, X, Y, el = e.target; var t = this, ed = tinyMCE.activeEditor, p1, p2, vp, DOM = tinymce.DOM, X, Y;
t.hideButtons(); if (ed.dom.getAttrib(n, 'class').indexOf('mceItem') != -1)
if (el.nodeName == 'IMG') {
if (ed.dom.getAttrib(el, 'class').indexOf('mceItem') != -1)
return; return;
vp = ed.dom.getViewPort(ed.getWin()); vp = ed.dom.getViewPort(ed.getWin());
p1 = DOM.getPos(ed.getContentAreaContainer()); p1 = DOM.getPos(ed.getContentAreaContainer());
p2 = ed.dom.getPos(el); p2 = ed.dom.getPos(n);
X = Math.max(p2.x - vp.x, 0) + p1.x; X = Math.max(p2.x - vp.x, 0) + p1.x;
Y = Math.max(p2.y - vp.y, 0) + p1.y; Y = Math.max(p2.y - vp.y, 0) + p1.y;
@ -93,10 +140,11 @@
}); });
t.btnsTout = window.setTimeout( function(){ed.plugins.wpeditimage.hideButtons();}, 5000 ); t.btnsTout = window.setTimeout( function(){ed.plugins.wpeditimage.hideButtons();}, 5000 );
}
}, },
hideButtons : function() { hideButtons : function() {
if ( tinymce.DOM.isHidden('wp_editbtns') ) return;
tinymce.DOM.hide('wp_editbtns'); tinymce.DOM.hide('wp_editbtns');
window.clearTimeout(this.btnsTout); window.clearTimeout(this.btnsTout);
}, },
@ -116,7 +164,7 @@
id : 'wp_editimgbtn', id : 'wp_editimgbtn',
width : '24', width : '24',
height : '24', height : '24',
title : 'Edit' title : ed.getLang('wpeditimage.edit_img')
}); });
wp_editimgbtn.onmousedown = function(e) { wp_editimgbtn.onmousedown = function(e) {
@ -131,15 +179,16 @@
id : 'wp_delimgbtn', id : 'wp_delimgbtn',
width : '24', width : '24',
height : '24', height : '24',
title : 'Delete' title : ed.getLang('wpeditimage.del_img')
}); });
wp_delimgbtn.onmousedown = function(e) { wp_delimgbtn.onmousedown = function(e) {
var ed = tinyMCE.activeEditor, el = ed.selection.getNode(), p; var ed = tinyMCE.activeEditor, el = ed.selection.getNode(), p;
if ( el.nodeName != 'IMG' || ed.dom.getAttrib(el, 'class').indexOf('mceItem') != -1 ) return; if ( el.nodeName == 'IMG' && ed.dom.getAttrib(el, 'class').indexOf('mceItem') == -1 ) {
if ( (p = ed.dom.getParent(el, 'div')) && ed.dom.hasClass(p, 'mceTemp') )
if ( (p = ed.dom.getParent(el, 'A')) && p.childNodes.length == 1) ed.dom.remove(p);
else if ( (p = ed.dom.getParent(el, 'A')) && p.childNodes.length == 1 )
ed.dom.remove(p); ed.dom.remove(p);
else ed.dom.remove(el); else ed.dom.remove(el);
@ -147,6 +196,7 @@
ed.execCommand('mceRepaint'); ed.execCommand('mceRepaint');
return false; return false;
} }
}
}, },
getInfo : function() { getInfo : function() {

View File

@ -95,6 +95,8 @@ var wpImage = {
current_size_sel : 's100', current_size_sel : 's100',
width : '', width : '',
height : '', height : '',
align : '',
img_alt : '',
setTabs : function(tab) { setTabs : function(tab) {
var t = this; var t = this;
@ -125,7 +127,7 @@ var wpImage = {
imgAlignCls : function(v) { imgAlignCls : function(v) {
var t = this, cls = t.I('img_classes').value; var t = this, cls = t.I('img_classes').value;
t.I('img_demo').className = v; t.I('img_demo').className = t.align = v;
cls = cls.replace( /align[^ "']+/gi, '' ); cls = cls.replace( /align[^ "']+/gi, '' );
cls += (' ' + v); cls += (' ' + v);
@ -243,7 +245,7 @@ var wpImage = {
}, },
setup : function() { setup : function() {
var t = this, h, c, el, id, link, fname, f = document.forms[0], ed = tinyMCEPopup.editor, d = t.I('img_demo'), dom = tinyMCEPopup.dom; var t = this, h, c, el, id, link, fname, f = document.forms[0], ed = tinyMCEPopup.editor, d = t.I('img_demo'), dom = tinyMCEPopup.dom, DL, caption;
document.dir = tinyMCEPopup.editor.getParam('directionality',''); document.dir = tinyMCEPopup.editor.getParam('directionality','');
tinyMCEPopup.restoreSelection(); tinyMCEPopup.restoreSelection();
el = ed.selection.getNode(); el = ed.selection.getNode();
@ -252,16 +254,32 @@ var wpImage = {
f.img_src.value = d.src = link = ed.dom.getAttrib(el, 'src'); f.img_src.value = d.src = link = ed.dom.getAttrib(el, 'src');
ed.dom.setStyle(el, 'float', ''); ed.dom.setStyle(el, 'float', '');
t.getImageData(); t.getImageData();
c = ed.dom.getAttrib(el, 'class');
caption = t.img_alt = ed.dom.getAttrib(el, 'alt');
if ( DL = dom.getParent(el, 'dl') ) {
var dlc = ed.dom.getAttrib(DL, 'class');
dlc = dlc.match(/align[^ "']+/i);
if ( ! dom.hasClass(el, dlc) )
c += ' '+dlc;
tinymce.each(DL.childNodes, function(e) {
if ( e.nodeName == 'DD' ) {
caption = e.innerHTML;
return;
}
});
}
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 = caption;
f.border.value = ed.dom.getAttrib(el, 'border'); f.border.value = ed.dom.getAttrib(el, 'border');
f.vspace.value = ed.dom.getAttrib(el, 'vspace'); f.vspace.value = ed.dom.getAttrib(el, 'vspace');
f.hspace.value = ed.dom.getAttrib(el, 'hspace'); f.hspace.value = ed.dom.getAttrib(el, 'hspace');
f.align.value = ed.dom.getAttrib(el, 'align'); f.align.value = ed.dom.getAttrib(el, 'align');
f.width.value = t.width = ed.dom.getAttrib(el, 'width'); f.width.value = t.width = ed.dom.getAttrib(el, 'width');
f.height.value = t.height = ed.dom.getAttrib(el, 'height'); f.height.value = t.height = ed.dom.getAttrib(el, 'height');
f.img_classes.value = c = ed.dom.getAttrib(el, 'class'); f.img_classes.value = c;
f.img_style.value = ed.dom.getAttrib(el, 'style'); f.img_style.value = ed.dom.getAttrib(el, 'style');
// Move attribs to styles // Move attribs to styles
@ -291,27 +309,20 @@ var wpImage = {
if ( c.indexOf('alignleft') != -1 ) { if ( c.indexOf('alignleft') != -1 ) {
t.I('alignleft').checked = "checked"; t.I('alignleft').checked = "checked";
d.className = "alignleft"; d.className = t.align = "alignleft";
} else if ( c.indexOf('aligncenter') != -1 ) { } else if ( c.indexOf('aligncenter') != -1 ) {
t.I('aligncenter').checked = "checked"; t.I('aligncenter').checked = "checked";
d.className = "aligncenter"; d.className = t.align = "aligncenter";
} else if ( c.indexOf('alignright') != -1 ) { } else if ( c.indexOf('alignright') != -1 ) {
t.I('alignright').checked = "checked"; t.I('alignright').checked = "checked";
d.className = "alignright"; d.className = t.align = "alignright";
} else if ( c.indexOf('alignnone') != -1 ) { } else if ( c.indexOf('alignnone') != -1 ) {
t.I('alignnone').checked = "checked"; t.I('alignnone').checked = "checked";
d.className = "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 = '';
/*
// Test if is attachment
if ( (id = c.match( /wp-image-([0-9]{1,6})/ )) && id[1] ) {
t.I('tab_attachment').href = tinymce.documentBaseURL + 'media.php?action=edit&attachment_id=' + id[1];
t.I('tab_attachment').style.display = 'inline';
}
*/
}, },
remove : function() { remove : function() {
@ -321,10 +332,11 @@ var wpImage = {
el = ed.selection.getNode(); el = ed.selection.getNode();
if (el.nodeName != 'IMG') return; if (el.nodeName != 'IMG') return;
if ( (p = ed.dom.getParent(el, 'A')) && p.childNodes.length == 1) if ( (p = ed.dom.getParent(el, 'div')) && ed.dom.hasClass(p, 'mceTemp') )
ed.dom.remove(p); ed.dom.remove(p);
else else if ( (p = ed.dom.getParent(el, 'A')) && p.childNodes.length == 1 )
ed.dom.remove(el); ed.dom.remove(p);
else ed.dom.remove(el);
ed.execCommand('mceRepaint'); ed.execCommand('mceRepaint');
tinyMCEPopup.close(); tinyMCEPopup.close();
@ -332,31 +344,37 @@ var wpImage = {
}, },
update : function() { update : function() {
var t = this, f = document.forms[0], nl = f.elements, ed = tinyMCEPopup.editor, el, P, A, v = f.img_classes.value; var t = this, f = document.forms[0], ed = tinyMCEPopup.editor, el, b, fixSafari = null, DL, P, A, DIV, do_caption = null, img_class = f.img_classes.value, html;
tinyMCEPopup.restoreSelection(); tinyMCEPopup.restoreSelection();
el = ed.selection.getNode(); el = ed.selection.getNode();
if (el.nodeName != 'IMG') return; if (el.nodeName != 'IMG') return;
if (f.img_src.value === '') t.remove(); if (f.img_src.value === '') {
t.remove();
A = ed.dom.getParent(el, 'A'); return;
P = ed.dom.getParent(el, 'p');
tinyMCEPopup.execCommand("mceBeginUndoLevel");
/* if ( tinymce.isIE ) {
if ( f.img_classes.value.indexOf('aligncenter') != -1 )
ed.dom.addClass(P, 'mce_iecenter');
else ed.dom.removeClass(P, 'mce_iecenter');
} }
*/
if ( f.img_alt.value != '' && f.width.value != '' ) {
do_caption = 1;
img_class = img_class.replace( /align[^ "']+\s?/gi, '' );
}
A = ed.dom.getParent(el, 'a');
P = ed.dom.getParent(el, 'p');
DL = ed.dom.getParent(el, 'dl');
DIV = ed.dom.getParent(el, 'div');
tinyMCEPopup.execCommand("mceBeginUndoLevel");
ed.dom.setAttribs(el, { ed.dom.setAttribs(el, {
src : f.img_src.value, src : f.img_src.value,
title : f.img_title.value, title : f.img_title.value,
alt : f.img_alt.value, alt : t.img_alt,
width : f.width.value, width : f.width.value,
height : f.height.value, height : f.height.value,
style : f.img_style.value, style : f.img_style.value,
'class' : '' //f.img_classes.value 'class' : img_class
}); });
if ( ! f.link_href.value ) { if ( ! f.link_href.value ) {
@ -368,11 +386,16 @@ var wpImage = {
} else { } else {
// Create new anchor elements // Create new anchor elements
if ( A == null ) { if ( A == null ) {
if ( ! f.link_href.value.match(/https?:\/\//) ) if ( ! f.link_href.value.match(/https?:\/\//) )
f.link_href.value = tinyMCEPopup.editor.documentBaseURI.toAbsolute(f.link_href.value); f.link_href.value = tinyMCEPopup.editor.documentBaseURI.toAbsolute(f.link_href.value);
if ( tinymce.isWebKit && ed.dom.hasClass(el, 'aligncenter') ) {
ed.dom.removeClass(el, 'aligncenter');
fixSafari = 1;
}
tinyMCEPopup.execCommand("CreateLink", false, "#mce_temp_url#", {skip_undo : 1}); tinyMCEPopup.execCommand("CreateLink", false, "#mce_temp_url#", {skip_undo : 1});
if ( fixSafari ) ed.dom.addClass(el, 'aligncenter');
tinymce.each(ed.dom.select("a"), function(n) { tinymce.each(ed.dom.select("a"), function(n) {
if (ed.dom.getAttrib(n, 'href') == '#mce_temp_url#') { if (ed.dom.getAttrib(n, 'href') == '#mce_temp_url#') {
@ -399,15 +422,63 @@ var wpImage = {
} }
} }
ed.dom.setAttrib(el, 'class', f.img_classes.value); if ( do_caption ) {
var id, cap_id = '', cap, DT, DD, cap_width = 10 + parseInt(f.width.value), align = t.align.substring(5), div_cls = (t.align == 'aligncenter') ? 'mceTemp mceIEcenter' : 'mceTemp';
if ( v.indexOf('aligncenter') != -1 ) { if ( DL ) {
ed.dom.setAttribs(DL, {
'class' : 'wp_caption '+t.align,
style : 'width: '+cap_width+'px;'
});
if ( DIV )
ed.dom.setAttrib(DIV, 'class', div_cls);
if ( (DT = ed.dom.getParent(el, 'dt')) && (DD = DT.nextSibling) && ed.dom.hasClass(DD, 'wp_caption_dd') )
ed.dom.setHTML(DD, f.img_alt.value);
} else {
if ( (id = f.img_classes.value.match( /wp-image-([0-9]{1,6})/ )) && id[1] )
cap_id = 'attachment_'+id[1];
if ( f.link_href.value ) html = ed.dom.getOuterHTML(ed.dom.getParent(el, 'a'));
else html = ed.dom.getOuterHTML(el);
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_alt.value+'</dd></dl>';
cap = ed.dom.create('div', {'class': div_cls}, html);
if ( P ) {
P.parentNode.insertBefore(cap, P);
ed.dom.remove(P);
}
}
tinyMCEPopup.execCommand("mceEndUndoLevel");
ed.execCommand('mceRepaint');
tinyMCEPopup.close();
return;
} else {
if ( DL ) {
if ( f.link_href.value ) html = ed.dom.getOuterHTML(ed.dom.getParent(el, 'a'));
else html = ed.dom.getOuterHTML(el);
P = ed.dom.create('p', {}, html);
DL.parentNode.insertBefore(P,DL);
ed.dom.remove(DL.childNodes);
ed.dom.remove(DL);
}
}
if ( f.img_classes.value.indexOf('aligncenter') != -1 ) {
if ( P && ( ! P.style || P.style.textAlign != 'center' ) ) if ( P && ( ! P.style || P.style.textAlign != 'center' ) )
ed.dom.setStyle(P, 'textAlign', 'center'); ed.dom.setStyle(P, 'textAlign', 'center');
} else { } else {
if ( P && P.style && P.style.textAlign == 'center' ) if ( P && P.style && P.style.textAlign == 'center' )
ed.dom.setStyle(P, 'textAlign', ''); ed.dom.setStyle(P, 'textAlign', '');
} }
tinyMCEPopup.execCommand("mceEndUndoLevel"); tinyMCEPopup.execCommand("mceEndUndoLevel");
ed.execCommand('mceRepaint'); ed.execCommand('mceRepaint');
tinyMCEPopup.close(); tinyMCEPopup.close();

View File

@ -1,4 +1,4 @@
body, td, pre {color:#000; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px; margin:8px;} body, td {color:#000; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px; margin:8px;}
body {background:#FFF;} body {background:#FFF;}
body.mceForceColors {background:#FFF; color:#000;} body.mceForceColors {background:#FFF; color:#000;}
h1 {font-size: 2em} h1 {font-size: 2em}
@ -17,7 +17,3 @@ ins {border-bottom:1px solid green; text-decoration: none; color:green}
del {color:red; text-decoration:line-through} del {color:red; text-decoration:line-through}
cite {border-bottom:1px dashed blue} cite {border-bottom:1px dashed blue}
acronym {border-bottom:1px dotted #CCC; cursor:help} acronym {border-bottom:1px dotted #CCC; cursor:help}
p.mce_iecenter {
text-align: center;
}

View File

@ -1,6 +1,7 @@
/* This file contains the CSS data for the editable area(iframe) of TinyMCE */ /* This file contains the CSS data for the editable area(iframe) of TinyMCE */
.aligncenter { .aligncenter,
dl.aligncenter {
display: block; display: block;
margin-left: auto; margin-left: auto;
margin-right: auto; margin-right: auto;
@ -14,6 +15,31 @@
float: right; float: right;
} }
.wp_caption {
border: 1px solid #ddd;
text-align: center;
background-color: #f3f3f3;
padding-top: 4px;
margin: 10px;
-moz-border-radius: 3px;
-khtml-border-radius: 3px;
-webkit-border-radius: 3px;
border-radius: 3px;
}
.wp_caption img {
margin: 0;
padding: 0;
border: 0 none;
}
.wp_caption_dd {
font-size: 11px;
line-height: 17px;
padding: 0 4px 5px;
margin: 0;
}
body.mceContentBody { body.mceContentBody {
background: #fff; background: #fff;
color: #000; color: #000;
@ -63,3 +89,7 @@ a.mceItemAnchor {
padding-left: 12px; padding-left: 12px;
background: url(img/items.gif) no-repeat bottom left; background: url(img/items.gif) no-repeat bottom left;
} }
.mceIEcenter {
text-align: center;
}

View File

@ -350,6 +350,31 @@ function wp_get_attachment_image($attachment_id, $size='thumbnail', $icon = fals
return $html; return $html;
} }
add_shortcode('wp_caption', 'wp_caption_shortcode');
function wp_caption_shortcode($attr, $content = null) {
// Allow plugins/themes to override the default caption template.
$output = apply_filters('wp_caption_shortcode', '', $attr, $content);
if ( $output != '' )
return $output;
extract(shortcode_atts(array(
'id' => '',
'align' => 'alignnone',
'width' => '',
'caption' => ''
), $attr));
if ( 1 > (int) $width || empty($caption) )
return $content;
if ( $id ) $id = 'id="' . $id . '" ';
return '<dl ' . $id . 'class="wp_caption ' . $align . '" style="width: ' . (10 + (int) $width) . 'px">'
. '<dt class="wp_caption_dt">' . $content . '</dt><dd class="wp_caption_dd">' . $caption . '</dd></dl>';
}
add_shortcode('gallery', 'gallery_shortcode'); add_shortcode('gallery', 'gallery_shortcode');
function gallery_shortcode($attr) { function gallery_shortcode($attr) {

View File

@ -34,10 +34,10 @@ function wp_default_scripts( &$scripts ) {
$visual_editor = apply_filters('visual_editor', array('tiny_mce')); $visual_editor = apply_filters('visual_editor', array('tiny_mce'));
$scripts->add( 'editor', false, $visual_editor, '20080321' ); $scripts->add( 'editor', false, $visual_editor, '20080321' );
$scripts->add( 'editor_functions', '/wp-admin/js/editor.js', false, '20080325' ); $scripts->add( 'editor_functions', '/wp-admin/js/editor.js', false, '20080701' );
// Modify this version when tinyMCE plugins are changed. // Modify this version when tinyMCE plugins are changed.
$mce_version = apply_filters('tiny_mce_version', '20080626'); $mce_version = apply_filters('tiny_mce_version', '20080701');
$scripts->add( 'tiny_mce', '/wp-includes/js/tinymce/tiny_mce_config.php', array('editor_functions'), $mce_version ); $scripts->add( 'tiny_mce', '/wp-includes/js/tinymce/tiny_mce_config.php', array('editor_functions'), $mce_version );
$scripts->add( 'prototype', '/wp-includes/js/prototype.js', false, '1.6'); $scripts->add( 'prototype', '/wp-includes/js/prototype.js', false, '1.6');
@ -159,7 +159,7 @@ function wp_default_scripts( &$scripts ) {
'edit' => __('Edit'), 'edit' => __('Edit'),
) ); ) );
$scripts->add( 'admin-gallery', '/wp-admin/js/gallery.js', array( 'jquery-ui-sortable' ), '20080520' ); $scripts->add( 'admin-gallery', '/wp-admin/js/gallery.js', array( 'jquery-ui-sortable' ), '20080520' );
$scripts->add( 'media-upload', '/wp-admin/js/media-upload.js', array( 'thickbox' ), '20080625' ); $scripts->add( 'media-upload', '/wp-admin/js/media-upload.js', array( 'thickbox' ), '20080701' );
$scripts->localize( 'upload', 'uploadL10n', array( $scripts->localize( 'upload', 'uploadL10n', array(
'browseTitle' => attribute_escape(__('Browse your files')), 'browseTitle' => attribute_escape(__('Browse your files')),
'back' => __('&laquo; Back'), 'back' => __('&laquo; Back'),