132
132
}
133
133
} ,
134
134
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
+
135
151
// This widget converts style-driven dimensions to attributes.
136
152
contentTransformations : [
137
153
[ 'img[width]: sizeToAttribute' ]
162
178
doc = editor . document ,
163
179
editable = editor . editable ( ) ,
164
180
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' ;
166
191
167
192
// Convert the internal form of the widget from the old state to the new one.
168
193
widget . shiftState ( {
229
254
} ) ;
230
255
231
256
// 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 ) ;
233
260
234
261
// Cache current data.
235
262
widget . oldData = CKEDITOR . tools . extend ( { } , widget . data ) ;
265
292
this . setData ( data ) ;
266
293
267
294
// 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 ) ;
269
298
270
299
this . shiftState = helpers . stateShifter ( this . editor ) ;
271
300
593
622
// Only block widgets have one.
594
623
if ( ! this . inline ) {
595
624
var resizeWrapper = el . getFirst ( 'span' ) ,
596
- img = resizeWrapper . getFirst ( 'img' ) ;
625
+ img ;
597
626
598
- resizeWrapper . replaceWith ( img ) ;
627
+ if ( resizeWrapper ) {
628
+ img = resizeWrapper . getFirst ( 'img' ) ;
629
+ resizeWrapper . replaceWith ( img ) ;
630
+ } else
631
+ img = el . getFirst ( 'img' ) ;
599
632
}
600
633
601
634
if ( align && align != 'none' ) {
702
735
var editor = widget . editor ,
703
736
editable = editor . editable ( ) ,
704
737
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' ) ;
706
741
707
742
resizer . addClass ( 'cke_image_resizer' ) ;
708
743
resizer . setAttribute ( 'title' , editor . lang . image2 . resizer ) ;
925
960
// @param {CKEDITOR.editor } editor
926
961
// @param {String } value 'left', 'right', 'center' or 'block'
927
962
function alignCommandIntegrator ( editor ) {
928
- var execCallbacks = [ ] ;
963
+ var execCallbacks = [ ] ,
964
+ enabled ;
929
965
930
966
return function ( value ) {
931
967
var command = editor . getCommand ( 'justify' + value ) ;
964
1000
if ( ! widget )
965
1001
return ;
966
1002
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
+ }
975
1022
976
1023
evt . cancel ( ) ;
977
1024
} ) ;
991
1038
992
1039
return null ;
993
1040
}
994
- } ) ( ) ;
1041
+ } ) ( ) ;
0 commit comments