Skip to content

Commit 24f7406

Browse files
committed
Merge branch 't/11004b'
2 parents bb0ed1c + cfe7d02 commit 24f7406

File tree

3 files changed

+71
-17
lines changed

3 files changed

+71
-17
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Fixed Issues:
2323
* [#11390](http://dev.ckeditor.com/ticket/11390): All [XML](http://docs.ckeditor.com/#!/api/CKEDITOR.xml) plugin's methods work now on IE10+.
2424
* [#11542](http://dev.ckeditor.com/ticket/11542): [IE11] Fixed: Blurry toolbar icons when right-to-left UI language is set.
2525
* [#11504](http://dev.ckeditor.com/ticket/11504): Fixed: When `config.fullPage` is set `true`, entities are not encoded in editor's output.
26+
* [#11004](http://dev.ckeditor.com/ticket/11004): Integrated [Enhanced Image](http://ckeditor.com/addon/image2) dialog with [Advanced Content Filter](http://docs.ckeditor.com/#!/guide/dev_advanced_content_filter).
2627

2728
## CKEditor 4.3.2
2829

plugins/image2/dialogs/image2.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ CKEDITOR.dialog.add( 'image2', function( editor ) {
3838

3939
helpers = CKEDITOR.plugins.image2,
4040

41+
// Content restrictions defined by the widget which
42+
// impact on dialog structure and presence of fields.
43+
features = editor.widgets.registered.image.features,
44+
4145
// Functions inherited from image2 plugin.
4246
checkHasNaturalRatio = helpers.checkHasNaturalRatio,
4347
getNatural = helpers.getNatural,
@@ -428,7 +432,7 @@ CKEDITOR.dialog.add( 'image2', function( editor ) {
428432
{
429433
type: 'hbox',
430434
widths: [ '25%', '25%', '50%' ],
431-
requiredContent: 'img[width,height]',
435+
requiredContent: features.dimension.requiredContent,
432436
children: [
433437
{
434438
type: 'text',
@@ -482,6 +486,7 @@ CKEDITOR.dialog.add( 'image2', function( editor ) {
482486
{
483487
type: 'hbox',
484488
id: 'alignment',
489+
requiredContent: features.align.requiredContent,
485490
children: [
486491
{
487492
id: 'align',
@@ -505,6 +510,7 @@ CKEDITOR.dialog.add( 'image2', function( editor ) {
505510
id: 'hasCaption',
506511
type: 'checkbox',
507512
label: lang.captioned,
513+
requiredContent: features.caption.requiredContent,
508514
setup: function( widget ) {
509515
this.setValue( widget.data.hasCaption );
510516
},

plugins/image2/plugin.js

Lines changed: 63 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,22 @@
132132
}
133133
},
134134

135+
requiredContent: 'img[src,alt]',
136+
137+
// Note: The following may not cover all the possible cases since
138+
// requiredContent supports a single tag only.
139+
features: {
140+
dimension: {
141+
requiredContent: 'img[width,height]'
142+
},
143+
align: {
144+
requiredContent: 'img{float}'
145+
},
146+
caption: {
147+
requiredContent: 'figcaption'
148+
}
149+
},
150+
135151
// This widget converts style-driven dimensions to attributes.
136152
contentTransformations: [
137153
[ 'img[width]: sizeToAttribute' ]
@@ -162,7 +178,16 @@
162178
doc = editor.document,
163179
editable = editor.editable(),
164180
oldState = widget.oldData,
165-
newState = widget.data;
181+
newState = widget.data,
182+
features = this.features;
183+
184+
// Image can't be captioned when figcaption is disallowed (#11004).
185+
if ( newState.hasCaption && !editor.filter.checkFeature( features.caption ) )
186+
newState.hasCaption = false;
187+
188+
// Image can't be aligned when floating is disallowed (#11004).
189+
if ( newState.align != 'none' && !editor.filter.checkFeature( features.align ) )
190+
newState.align = 'none';
166191

167192
// Convert the internal form of the widget from the old state to the new one.
168193
widget.shiftState( {
@@ -229,7 +254,9 @@
229254
} );
230255

231256
// Set dimensions of the image according to gathered data.
232-
setDimensions( widget );
257+
// Do it only when the attributes are allowed (#11004).
258+
if ( editor.filter.checkFeature( features.dimension ) )
259+
setDimensions( widget );
233260

234261
// Cache current data.
235262
widget.oldData = CKEDITOR.tools.extend( {}, widget.data );
@@ -265,7 +292,9 @@
265292
this.setData( data );
266293

267294
// Setup dynamic image resizing with mouse.
268-
setupResizer( this );
295+
// Don't initialize resizer when dimensions are disallowed (#11004).
296+
if ( editor.filter.checkFeature( this.features.dimension ) )
297+
setupResizer( this );
269298

270299
this.shiftState = helpers.stateShifter( this.editor );
271300

@@ -593,9 +622,13 @@
593622
// Only block widgets have one.
594623
if ( !this.inline ) {
595624
var resizeWrapper = el.getFirst( 'span' ),
596-
img = resizeWrapper.getFirst( 'img' );
625+
img;
597626

598-
resizeWrapper.replaceWith( img );
627+
if ( resizeWrapper ) {
628+
img = resizeWrapper.getFirst( 'img' );
629+
resizeWrapper.replaceWith( img );
630+
} else
631+
img = el.getFirst( 'img' );
599632
}
600633

601634
if ( align && align != 'none' ) {
@@ -702,7 +735,9 @@
702735
var editor = widget.editor,
703736
editable = editor.editable(),
704737
doc = editor.document,
705-
resizer = doc.createElement( 'span' );
738+
739+
// Store the resizer in a widget for testing (#11004).
740+
resizer = widget.resizer = doc.createElement( 'span' );
706741

707742
resizer.addClass( 'cke_image_resizer' );
708743
resizer.setAttribute( 'title', editor.lang.image2.resizer );
@@ -925,7 +960,8 @@
925960
// @param {CKEDITOR.editor} editor
926961
// @param {String} value 'left', 'right', 'center' or 'block'
927962
function alignCommandIntegrator( editor ) {
928-
var execCallbacks = [];
963+
var execCallbacks = [],
964+
enabled;
929965

930966
return function( value ) {
931967
var command = editor.getCommand( 'justify' + value );
@@ -964,14 +1000,25 @@
9641000
if ( !widget )
9651001
return;
9661002

967-
this.setState(
968-
( widget.data.align == value ) ?
969-
CKEDITOR.TRISTATE_ON
970-
:
971-
( value in allowed ) ?
972-
CKEDITOR.TRISTATE_OFF
973-
:
974-
CKEDITOR.TRISTATE_DISABLED );
1003+
// Cache "enabled" on first use. This is because filter#checkFeature may
1004+
// not be available during plugin's afterInit in the future — a moment when
1005+
// alignCommandIntegrator is called.
1006+
if ( enabled == undefined )
1007+
enabled = editor.filter.checkFeature( editor.widgets.registered.image.features.align );
1008+
1009+
// Don't allow justify commands when widget alignment is disabled (#11004).
1010+
if ( !enabled )
1011+
this.setState( CKEDITOR.TRISTATE_DISABLED );
1012+
else {
1013+
this.setState(
1014+
( widget.data.align == value ) ?
1015+
CKEDITOR.TRISTATE_ON
1016+
:
1017+
( value in allowed ) ?
1018+
CKEDITOR.TRISTATE_OFF
1019+
:
1020+
CKEDITOR.TRISTATE_DISABLED );
1021+
}
9751022

9761023
evt.cancel();
9771024
} );
@@ -991,4 +1038,4 @@
9911038

9921039
return null;
9931040
}
994-
} )();
1041+
} )();

0 commit comments

Comments
 (0)