mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-24 18:18:01 +01:00
Add or remove class=aligncenter when aligning images in TinyMCE. Props azaozz. fixes #6645 for trunk
git-svn-id: http://svn.automattic.com/wordpress/trunk@7687 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
c92c2be2af
commit
f8cea0117c
@ -89,20 +89,45 @@
|
|||||||
cmd : 'WP_Adv'
|
cmd : 'WP_Adv'
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add class "alignleft" or "alignright" when selecting align for images.
|
// Add class "alignleft", "alignright" and "aligncenter" when selecting align for images.
|
||||||
|
ed.onExecCommand.add(function( editor, cmd ) {
|
||||||
|
var node, bl, dom = editor.dom;
|
||||||
|
|
||||||
|
if ( 'JustifyCenter' == cmd ) {
|
||||||
|
if ( ( node = editor.selection.getNode() ) && node.nodeName == 'IMG' ) {
|
||||||
|
if ( ! dom.hasClass( node, "aligncenter" ) && ( bl = editor.forceBlocks.getParentBlock(node) ) && bl.childNodes.length == 1 )
|
||||||
|
dom.setStyle(bl, 'text-align', '');
|
||||||
|
}
|
||||||
|
editor.execCommand('mceRepaint');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
ed.onBeforeExecCommand.add(function( editor, cmd ) {
|
ed.onBeforeExecCommand.add(function( editor, cmd ) {
|
||||||
var node, dir, xdir;
|
var node, dir, xdir, bl, dom = editor.dom;
|
||||||
|
|
||||||
if ( ( cmd.indexOf('Justify') != -1 ) && ( node = editor.selection.getNode() ) ) {
|
if ( ( cmd.indexOf('Justify') != -1 ) && ( node = editor.selection.getNode() ) ) {
|
||||||
if ( node.nodeName !== 'IMG' ) return;
|
if ( 'JustifyFull' == cmd || node.nodeName !== 'IMG' ) return;
|
||||||
dir = cmd.substring(7).toLowerCase();
|
dir = cmd.substring(7).toLowerCase();
|
||||||
if ( 'JustifyCenter' == cmd || editor.queryCommandState( cmd ) ) {
|
|
||||||
editor.dom.removeClass( node, "alignleft" );
|
if ( editor.queryCommandState( cmd ) ) {
|
||||||
editor.dom.removeClass( node, "alignright" );
|
dom.removeClass( node, "alignleft" );
|
||||||
|
dom.removeClass( node, "alignright" );
|
||||||
|
dom.removeClass( node, "aligncenter" );
|
||||||
|
} else if ( 'JustifyCenter' == cmd ) {
|
||||||
|
dom.removeClass( node, "alignleft" );
|
||||||
|
dom.removeClass( node, "alignright" );
|
||||||
|
|
||||||
|
if ( dom.hasClass( node, "aligncenter" ) ) {
|
||||||
|
dom.removeClass( node, "aligncenter" );
|
||||||
|
if ( ( bl = editor.forceBlocks.getParentBlock(node) ) && bl.childNodes.length == 1 && tinymce.isGecko )
|
||||||
|
editor.selection.select(bl.firstChild);
|
||||||
|
} else dom.addClass( node, "aligncenter" );
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
xdir = ( dir == 'left' ) ? 'right' : 'left';
|
xdir = ( dir == 'left' ) ? 'right' : 'left';
|
||||||
editor.dom.removeClass( node, "align"+xdir );
|
dom.removeClass( node, "aligncenter" );
|
||||||
editor.dom.addClass( node, "align"+dir );
|
dom.removeClass( node, "align"+xdir );
|
||||||
|
dom.addClass( node, "align"+dir );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -190,9 +215,7 @@
|
|||||||
if (o.get)
|
if (o.get)
|
||||||
o.content = o.content.replace(/<img[^>]+>/g, function(im) {
|
o.content = o.content.replace(/<img[^>]+>/g, function(im) {
|
||||||
if (im.indexOf('class="mceWPmore') !== -1) {
|
if (im.indexOf('class="mceWPmore') !== -1) {
|
||||||
var m;
|
var m, moretext = (m = im.match(/alt="(.*?)"/)) ? m[1] : '';
|
||||||
var moretext = (m = im.match(/alt="(.*?)"/)) ? m[1] : '';
|
|
||||||
|
|
||||||
im = '<!--more'+moretext+'-->';
|
im = '<!--more'+moretext+'-->';
|
||||||
}
|
}
|
||||||
if (im.indexOf('class="mceWPnextpage') !== -1)
|
if (im.indexOf('class="mceWPnextpage') !== -1)
|
||||||
|
@ -108,7 +108,7 @@ var ImageDialog = {
|
|||||||
// Handle align
|
// Handle align
|
||||||
v = getSelectValue(f, 'align');
|
v = getSelectValue(f, 'align');
|
||||||
cls = f.class_name.value || '';
|
cls = f.class_name.value || '';
|
||||||
cls = cls ? cls.replace(/alignright\s*|alignleft\s*/g, '') : '';
|
cls = cls ? cls.replace(/alignright\s*|alignleft\s*|aligncenter\s*/g, '') : '';
|
||||||
cls = cls ? cls.replace(/^\s*(.+?)\s*$/, '$1') : '';
|
cls = cls ? cls.replace(/^\s*(.+?)\s*$/, '$1') : '';
|
||||||
if (v) {
|
if (v) {
|
||||||
if (v == 'left' || v == 'right') {
|
if (v == 'left' || v == 'right') {
|
||||||
|
@ -1,5 +1,19 @@
|
|||||||
/* 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 {
|
||||||
|
display: block;
|
||||||
|
margin-left: auto;
|
||||||
|
margin-right: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.alignleft {
|
||||||
|
float: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.alignright {
|
||||||
|
float: right;
|
||||||
|
}
|
||||||
|
|
||||||
body.mceContentBody {
|
body.mceContentBody {
|
||||||
background: #fff;
|
background: #fff;
|
||||||
color: #000;
|
color: #000;
|
||||||
|
Loading…
Reference in New Issue
Block a user