Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

save support in source mode #822

Merged
merged 6 commits into from
Sep 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Fixed Issues:
* [#719](https://github.com/ckeditor/ckeditor-dev/issues/719): Fixed: Image inserted using [Enhanced Image](https://ckeditor.com/addon/image2) plugin could be resized when editor is in read-only mode.
* [#577](https://github.com/ckeditor/ckeditor-dev/issues/577): Fixed: "Delete Columns" command provided by [Table Tools](https://ckeditor.com/addon/tabletools) plugin throws an error while trying to delete columns.
* [#867](https://github.com/ckeditor/ckeditor-dev/issues/867): Fixed: Typing into selected table throws an error.
* [#817](https://github.com/ckeditor/ckeditor-dev/issues/817): Fixed: [Save](https://ckeditor.com/addon/save) plugin does not work in [Source Mode](https://ckeditor.com/addon/sourcearea).

Other Changes:

Expand Down
3 changes: 2 additions & 1 deletion plugins/save/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
( function() {
var saveCmd = {
readOnly: 1,
modes: { wysiwyg: 1,source: 1 },

exec: function( editor ) {
if ( editor.fire( 'save' ) ) {
Expand Down Expand Up @@ -45,7 +46,7 @@
return;

var command = editor.addCommand( pluginName, saveCmd );
command.modes = { wysiwyg: !!( editor.element.$.form ) };
command.startDisabled = !( editor.element.$.form );

editor.ui.addButton && editor.ui.addButton( 'Save', {
label: editor.lang.save.toolbar,
Expand Down
9 changes: 9 additions & 0 deletions tests/plugins/save/manual/sourcemode.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<form>
<textarea id="editor1">editor</textarea>
</form>

<script>
CKEDITOR.replace( 'editor1', {
startupMode: 'source'
} );
</script>
13 changes: 13 additions & 0 deletions tests/plugins/save/manual/sourcemode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@bender-ui: collapsed
@bender-tags: 817, 4.7.3, bug
@bender-ckeditor-plugins: wysiwygarea, save, sourcearea, toolbar

**Procedure:**

1. Check if "Save" button is enabled.
2. Switch to WYSIWYG mode.
3. Check if "Save" button is enabled.

**Expected result:**

* "Save" button should be enabled in both modes.
8 changes: 6 additions & 2 deletions tests/plugins/save/save.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<form id="form">
<textarea id="editor">editor</textarea>
<form id="form1">
<textarea id="editor1">editor</textarea>
</form>

<form id="form2">
<textarea id="editor2">editor</textarea>
</form>
41 changes: 25 additions & 16 deletions tests/plugins/save/save.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
/* bender-tags: editor */
/* bender-ckeditor-plugins: toolbar,save,wysiwygarea */
/* bender-ckeditor-plugins: toolbar,save,wysiwygarea,sourcearea */

bender.test( {
'test save event': function() {
var editor = CKEDITOR.replace( 'editor' ),
count = 0;
function saveTest( editor ) {
var count = 0;

editor.on( 'instanceReady', function() {
editor.execCommand( 'save' );
editor.on( 'instanceReady', function() {
editor.execCommand( 'save' );

setTimeout( function() {
resume( function() {
assert.areSame( 1, count, 'save was fired once' );
} );
setTimeout( function() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if afterCommandExec could be used here instead of setTimeout.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately no, save plugin doesn't fire afterCommandExec

resume( function() {
assert.areSame( 1, count, 'save was fired once' );
} );
} );
} );

editor.on( 'save', function() {
count++;
return false;
} );
editor.on( 'save', function() {
count++;
return false;
} );

wait();
}

bender.test( {
'test save event in WYSIWYG mode': function() {
var editor = CKEDITOR.replace( 'editor1' );
saveTest( editor );
},

wait();
'test save event in source mode': function() {
var editor = CKEDITOR.replace( 'editor2' , { startupMode: 'source' } );
saveTest( editor );
}
} );