Skip to content

Commit b01618f

Browse files
committed
Merge branch 't/12377'
2 parents 665e3b9 + 2e13326 commit b01618f

File tree

3 files changed

+106
-15
lines changed

3 files changed

+106
-15
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Fixed Issues:
77

88
* [#10804](http://dev.ckeditor.com/ticket/10804): Fixed: `CKEDITOR_GETURL` isn't used with some plugins it should be used. Thanks to [Thomas Andraschko](https://github.com/tandraschko)!
99
* [#9137](http://dev.ckeditor.com/ticket/9137): Fixed: `base` tag is not created when `head` has an attribute. Thanks to [naoki.fujikawa](https://github.com/naoki-fujikawa)!
10+
* [#12377](http://dev.ckeditor.com/ticket/12377): Fixed: Errors thrown in the image plugin when removing preview from dialog definition. Thanks to [Axinet](https://github.com/Axinet)!
1011
* [#12315](http://dev.ckeditor.com/ticket/12315): Fixed: Marked [`config.autoParagraph`](http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-autoParagraph) as deprecated.
1112
* [#12113](http://dev.ckeditor.com/ticket/12113): Fixed: Code snippet should be presented in elements path as "codesnippet".
1213
* [#12311](http://dev.ckeditor.com/ticket/12311): Fixed: Remove format should also remove `<cite>` elements.

plugins/image/dialogs/image.js

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,17 @@
194194

195195
var onImgLoadEvent = function() {
196196
// Image is ready.
197-
var original = this.originalElement;
197+
var original = this.originalElement,
198+
loader = CKEDITOR.document.getById( imagePreviewLoaderId );
199+
198200
original.setCustomData( 'isReady', 'true' );
199201
original.removeListener( 'load', onImgLoadEvent );
200202
original.removeListener( 'error', onImgLoadErrorEvent );
201203
original.removeListener( 'abort', onImgLoadErrorEvent );
202204

203-
// Hide loader
204-
CKEDITOR.document.getById( imagePreviewLoaderId ).setStyle( 'display', 'none' );
205+
// Hide loader.
206+
if ( loader )
207+
loader.setStyle( 'display', 'none' );
205208

206209
// New image -> new domensions
207210
if ( !this.dontResetSize )
@@ -218,7 +221,9 @@
218221

219222
var onImgLoadErrorEvent = function() {
220223
// Error. Image is not loaded.
221-
var original = this.originalElement;
224+
var original = this.originalElement,
225+
loader = CKEDITOR.document.getById( imagePreviewLoaderId );
226+
222227
original.removeListener( 'load', onImgLoadEvent );
223228
original.removeListener( 'error', onImgLoadErrorEvent );
224229
original.removeListener( 'abort', onImgLoadErrorEvent );
@@ -229,8 +234,10 @@
229234
if ( this.preview )
230235
this.preview.setAttribute( 'src', noimage );
231236

232-
// Hide loader
233-
CKEDITOR.document.getById( imagePreviewLoaderId ).setStyle( 'display', 'none' );
237+
// Hide loader.
238+
if ( loader )
239+
loader.setStyle( 'display', 'none' );
240+
234241
switchLockRatio( this, false ); // Unlock.
235242
};
236243

@@ -264,10 +271,13 @@
264271
var editor = this.getParentEditor(),
265272
sel = editor.getSelection(),
266273
element = sel && sel.getSelectedElement(),
267-
link = element && editor.elementPath( element ).contains( 'a', 1 );
274+
link = element && editor.elementPath( element ).contains( 'a', 1 ),
275+
loader = CKEDITOR.document.getById( imagePreviewLoaderId );
276+
277+
// Hide loader.
278+
if ( loader )
279+
loader.setStyle( 'display', 'none' );
268280

269-
//Hide loader.
270-
CKEDITOR.document.getById( imagePreviewLoaderId ).setStyle( 'display', 'none' );
271281
// Create the preview before setup the dialog contents.
272282
previewPreloader = new CKEDITOR.dom.element( 'img', editor.document );
273283
this.preview = CKEDITOR.document.getById( previewImageId );
@@ -464,10 +474,12 @@
464474
dialog = this.getDialog();
465475
var original = dialog.originalElement;
466476

467-
dialog.preview.removeStyle( 'display' );
477+
if ( dialog.preview ) {
478+
dialog.preview.removeStyle( 'display' );
479+
}
468480

469481
original.setCustomData( 'isReady', 'false' );
470-
// Show loader
482+
// Show loader.
471483
var loader = CKEDITOR.document.getById( imagePreviewLoaderId );
472484
if ( loader )
473485
loader.setStyle( 'display', '' );
@@ -477,10 +489,12 @@
477489
original.on( 'abort', onImgLoadErrorEvent, dialog );
478490
original.setAttribute( 'src', newUrl );
479491

480-
// Query the preloader to figure out the url impacted by based href.
481-
previewPreloader.setAttribute( 'src', newUrl );
482-
dialog.preview.setAttribute( 'src', previewPreloader.$.src );
483-
updatePreview( dialog );
492+
if ( dialog.preview ) {
493+
// Query the preloader to figure out the url impacted by based href.
494+
previewPreloader.setAttribute( 'src', newUrl );
495+
dialog.preview.setAttribute( 'src', previewPreloader.$.src );
496+
updatePreview( dialog );
497+
}
484498
}
485499
// Dont show preview if no URL given.
486500
else if ( dialog.preview ) {

tests/tickets/12377/1.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/* bender-tags: editor,unit,image */
2+
/* bender-ckeditor-plugins: image,toolbar */
3+
4+
(function() {
5+
'use strict';
6+
7+
bender.editor = {};
8+
9+
bender.test( {
10+
'test image dialog with removed preview and basic panel - image loaded': function() {
11+
var bot = this.editorBot,
12+
editor = this.editor,
13+
src = '%BASE_PATH%_assets/img.gif',
14+
src2 = '%BASE_PATH%_assets/logo.png';
15+
16+
bot.setHtmlWithSelection( '<p>[<img alt="foo" src="' + src + '" />]</p>' );
17+
18+
CKEDITOR.on( 'dialogDefinition', function( evt ) {
19+
var dialogName = evt.data.name;
20+
var dialogDefinition = evt.data.definition;
21+
22+
if ( dialogName == 'image' ) {
23+
var infoTab = dialogDefinition.getContents( 'info' );
24+
infoTab.remove( 'basic' );
25+
infoTab.remove( 'htmlPreview' );
26+
}
27+
} );
28+
29+
bot.dialog( 'image', function( dialog ) {
30+
assert.areSame( src, dialog.getValueOf( 'info', 'txtUrl' ) );
31+
32+
dialog.setValueOf( 'info', 'txtUrl', src2 );
33+
dialog.getContentElement( 'info', 'txtAlt' ).focus();
34+
35+
// Focus will be moved asynchronously. IE8 might complain too.
36+
wait( function() {
37+
dialog.getButton( 'ok' ).click();
38+
assert.areSame( '<p><img alt="foo" src="' + src2 + '" /></p>', bot.getData() );
39+
}, 50 );
40+
} );
41+
},
42+
43+
'test image dialog with removed preview and basic panel - image load error': function() {
44+
var bot = this.editorBot,
45+
editor = this.editor,
46+
src = 'img404.gif',
47+
src2 = 'anotherimg404.gif';
48+
49+
bot.setHtmlWithSelection( '<p>[<img alt="foo" src="' + src + '" />]</p>' );
50+
51+
CKEDITOR.on( 'dialogDefinition', function( evt ) {
52+
var dialogName = evt.data.name;
53+
var dialogDefinition = evt.data.definition;
54+
55+
if ( dialogName == 'image' ) {
56+
var infoTab = dialogDefinition.getContents( 'info' );
57+
infoTab.remove( 'basic' );
58+
infoTab.remove( 'htmlPreview' );
59+
}
60+
} );
61+
62+
bot.dialog( 'image', function( dialog ) {
63+
assert.areSame( src, dialog.getValueOf( 'info', 'txtUrl' ) );
64+
65+
dialog.setValueOf( 'info', 'txtUrl', src2 );
66+
dialog.getContentElement( 'info', 'txtAlt' ).focus();
67+
68+
// Focus will be moved asynchronously. IE8 might complain too.
69+
wait( function() {
70+
dialog.getButton( 'ok' ).click();
71+
assert.areSame( '<p><img alt="foo" src="' + src2 + '" /></p>', bot.getData() );
72+
}, 50 );
73+
} );
74+
}
75+
} );
76+
})();

0 commit comments

Comments
 (0)