From 164e0defba5d4e5f43682d5de80c0e0cf31a9a69 Mon Sep 17 00:00:00 2001 From: Marek Lewandowski Date: Thu, 9 Nov 2017 13:20:30 +0100 Subject: [PATCH 1/6] Added manual test for skipping notifications in uploadwidget. --- .../uploadwidget/manual/skipnotification.html | 21 +++++++++++++++++++ .../uploadwidget/manual/skipnotification.md | 15 +++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 tests/plugins/uploadwidget/manual/skipnotification.html create mode 100644 tests/plugins/uploadwidget/manual/skipnotification.md diff --git a/tests/plugins/uploadwidget/manual/skipnotification.html b/tests/plugins/uploadwidget/manual/skipnotification.html new file mode 100644 index 00000000000..34342098284 --- /dev/null +++ b/tests/plugins/uploadwidget/manual/skipnotification.html @@ -0,0 +1,21 @@ + + + diff --git a/tests/plugins/uploadwidget/manual/skipnotification.md b/tests/plugins/uploadwidget/manual/skipnotification.md new file mode 100644 index 00000000000..e3125253c35 --- /dev/null +++ b/tests/plugins/uploadwidget/manual/skipnotification.md @@ -0,0 +1,15 @@ +@bender-tags: 4.8.0, feature, 1145 +@bender-ui: collapsed +@bender-ckeditor-plugins: wysiwygarea, toolbar, undo, uploadwidget, image, uploadimage, elementspath +@bender-include: _helpers/xhr.js + +## Skipping Notifications + +1. Paste an image into editor. + +## Expected + +* No progress/success notification are shown. +* Image is changed to Lena (after ~4 secs). + +**Note:** This test use upload mock which will show you *Lena* instead of the real uploaded image. From c7158c321fb82c944a29875984cf6643309d9422 Mon Sep 17 00:00:00 2001 From: Marek Lewandowski Date: Thu, 9 Nov 2017 13:43:46 +0100 Subject: [PATCH 2/6] Added unit test for uploadWidgetDefinition.skipNotifications. --- tests/plugins/uploadwidget/uploadwidget.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/plugins/uploadwidget/uploadwidget.js b/tests/plugins/uploadwidget/uploadwidget.js index edfc08c9dcc..e637ab8cef0 100644 --- a/tests/plugins/uploadwidget/uploadwidget.js +++ b/tests/plugins/uploadwidget/uploadwidget.js @@ -622,6 +622,23 @@ wait(); }, + 'test uploadWidgetDefinition.skipNotifications': function() { + var editor = mockEditorForPaste(); + + addTestUploadWidget( editor, 'bindNotificationsWidget', { + skipNotifications: true + } ); + + resumeAfter( editor, 'paste', function() { + var spy = CKEDITOR.fileTools.bindNotifications; + assert.areSame( 0, spy.callCount, 'CKEDITOR.fileTools.bindNotifications call count' ); + } ); + + pasteFiles( editor, [ bender.tools.getTestPngFile() ] ); + + wait(); + }, + 'test undo and redo': function() { var bot = this.editorBot, editor = bot.editor, From 7dde6be928d21182f6efaff546538d5f90386f09 Mon Sep 17 00:00:00 2001 From: Marek Lewandowski Date: Thu, 9 Nov 2017 14:07:30 +0100 Subject: [PATCH 3/6] In order to have a good manual test I had to fix #1068 too. --- plugins/uploadwidget/plugin.js | 14 +++++++++- tests/plugins/uploadwidget/uploadwidget.js | 31 +++++++++++++++++++++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/plugins/uploadwidget/plugin.js b/plugins/uploadwidget/plugin.js index c6273c8a246..22cc8014267 100644 --- a/plugins/uploadwidget/plugin.js +++ b/plugins/uploadwidget/plugin.js @@ -173,6 +173,8 @@ if ( def.fileToElement ) { editor.on( 'paste', function( evt ) { var data = evt.data, + // Fetch runtime widget definition as it might get changed in editor#widgetDefinition event. + def = editor.widgets.registered[ name ], dataTransfer = data.dataTransfer, filesCount = dataTransfer.getFilesCount(), loadMethod = def.loadMethod || 'loadAndUpload', @@ -195,7 +197,7 @@ CKEDITOR.fileTools.markElement( el, name, loader.id ); - if ( loadMethod == 'loadAndUpload' || loadMethod == 'upload' ) { + if ( ( loadMethod == 'loadAndUpload' || loadMethod == 'upload' ) && !def.skipNotifications ) { CKEDITOR.fileTools.bindNotifications( editor, loader ); } @@ -383,6 +385,16 @@ * @property {String} [loadMethod=loadAndUpload] */ + /** + * Indicates whether default notification handling should be skipped. + * + * By default upload widget will use [Notification](https://ckeditor.com/cke4/addon/notification) plugin to provide + * feedback for upload progress and eventual success / error message. + * + * @since 4.8.0 + * @property {Boolean} [skipNotifications=false] + */ + /** * A function called when the {@link CKEDITOR.fileTools.fileLoader#status status} of the upload changes to `loading`. * diff --git a/tests/plugins/uploadwidget/uploadwidget.js b/tests/plugins/uploadwidget/uploadwidget.js index e637ab8cef0..1aa220e905e 100644 --- a/tests/plugins/uploadwidget/uploadwidget.js +++ b/tests/plugins/uploadwidget/uploadwidget.js @@ -61,7 +61,11 @@ function mockEditorForPaste() { var editor = { widgets: { - add: function() {} + add: function( name, def ) { + // Note that widget system makes a duplicate of a definition. + this.registered[ name ] = CKEDITOR.tools.prototypedCopy( def ); + }, + registered: {} }, lang: {}, config: {} @@ -507,6 +511,31 @@ wait(); }, + 'test supports definition changes at a runtime': function() { + var editor = mockEditorForPaste(); + + addTestUploadWidget( editor, 'runtimeDefChanges', { + supportedTypes: /image\/png/, + + loadMethod: 'upload', + + fileToElement: function() { + return new CKEDITOR.dom.element( 'span' ); + } + } ); + + // Change supported type, so that paste does not match. + editor.widgets.registered.runtimeDefChanges.supportedTypes = /text\/plain/; + + resumeAfter( editor, 'paste', function() { + assert.areSame( 0, uploadCount, 'Upload call count' ); + } ); + + pasteFiles( editor, [ bender.tools.getTestPngFile( 'test1.png' ) ] ); + + wait(); + }, + 'test paste multiple files': function() { var editor = mockEditorForPaste(); From 9df5444d85c14e702bfe0cf623428cb87bb597e8 Mon Sep 17 00:00:00 2001 From: Marek Lewandowski Date: Thu, 9 Nov 2017 14:14:48 +0100 Subject: [PATCH 4/6] Added issue references. --- tests/plugins/uploadwidget/uploadwidget.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/plugins/uploadwidget/uploadwidget.js b/tests/plugins/uploadwidget/uploadwidget.js index 1aa220e905e..c7e7c581846 100644 --- a/tests/plugins/uploadwidget/uploadwidget.js +++ b/tests/plugins/uploadwidget/uploadwidget.js @@ -511,6 +511,7 @@ wait(); }, + // (#1068). 'test supports definition changes at a runtime': function() { var editor = mockEditorForPaste(); @@ -651,6 +652,7 @@ wait(); }, + // (#1145). 'test uploadWidgetDefinition.skipNotifications': function() { var editor = mockEditorForPaste(); From ec93f8c7cae975011534f223b03f00b47a6ccb0f Mon Sep 17 00:00:00 2001 From: Tomasz Jakut Date: Thu, 9 Nov 2017 16:41:27 +0100 Subject: [PATCH 5/6] Update manual test description. --- tests/plugins/uploadwidget/manual/skipnotification.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/plugins/uploadwidget/manual/skipnotification.md b/tests/plugins/uploadwidget/manual/skipnotification.md index e3125253c35..5a1a55aa579 100644 --- a/tests/plugins/uploadwidget/manual/skipnotification.md +++ b/tests/plugins/uploadwidget/manual/skipnotification.md @@ -5,7 +5,7 @@ ## Skipping Notifications -1. Paste an image into editor. +1. Paste or drag and drop an image into editor. ## Expected From d568cda8b6eb9c55a06fb7706d90c462b0313940 Mon Sep 17 00:00:00 2001 From: Tomasz Jakut Date: Thu, 9 Nov 2017 16:50:01 +0100 Subject: [PATCH 6/6] Update changelog [ci skip]. --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 1a1a91a8766..f6b06c42998 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -28,11 +28,13 @@ Fixed Issues: * [#1008](https://github.com/ckeditor/ckeditor-dev/issues/1008): Fixed: Shorthand Hex colors from the [`config.colorButton_colors`](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.config-cfg-colorButton_colors) option are not correctly highlighted in the [Color Button](https://ckeditor.com/cke4/addon/colorbutton) Text Color or Background Color panel. * [#1094](https://github.com/ckeditor/ckeditor-dev/issues/1094): Fixed: Widget definition [`upcast`](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.plugins.widget.definition-property-upcasts) methods are called for every element. * [#1057](https://github.com/ckeditor/ckeditor-dev/issues/1057): Fixed: The [Notification](https://ckeditor.com/addon/notification) plugin overwrites Web Notifications API due to leakage to the global scope. +* [#1068](https://github.com/ckeditor/ckeditor-dev/issues/1068): Fixed: Upload widget paste listener ignores changes to the `uploadWidgetDefinition`. API Changes: * [#1097](https://github.com/ckeditor/ckeditor-dev/issues/1097): Widget [`upcast`](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.plugins.widget.definition-property-upcast) methods are now called in the [widget definition's](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.plugins.widget-property-definition) context. * [#1118](https://github.com/ckeditor/ckeditor-dev/issues/1118): Added the `show` option in the [`balloonPanel.attach`](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.ui.balloonPanel-method-attach) method, allowing to attach a hidden [Balloon Panel](https://ckeditor.com/cke4/addon/balloonpanel) instance. +* [#1145(]https://github.com/ckeditor/ckeditor-dev/issues/1145): Added the `skipNotifications` option to the [`CKEDITOR.fileTools.uploadWidgetDefinition`](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.fileTools.uploadWidgetDefinition-property-skipNotifications), allowing to switch off default notifications displayed by upload widgets. Other Changes: