Skip to content
Permalink
Browse files

Merge branch 't/11753'

  • Loading branch information...
adelura committed Jun 16, 2014
2 parents a8fe468 + e14c014 commit a2facd8f7cf0e75b908402e75463c9fd5bf05ec9
Showing with 88 additions and 3 deletions.
  1. +1 −0 CHANGES.md
  2. +4 −0 core/selection.js
  3. +21 −3 plugins/widget/plugin.js
  4. +62 −0 tests/plugins/widget/checkdirty.js
@@ -13,6 +13,7 @@ New Features:

Fixed Issues:

* [#11753](http://dev.ckeditor.com/ticket/11753): Fixed: Issue with wrong checkDirty value.
* [#11830](http://dev.ckeditor.com/ticket/11830): Fixed: Issue with passing arguments into CKBuilder.
* [#11757](http://dev.ckeditor.com/ticket/11757): Fixed: Imperfections in the [Moono](http://ckeditor.com/addon/moono) skin. Thanks to [danyaPostfactum](https://github.com/danyaPostfactum)!
* [#10091](http://dev.ckeditor.com/ticket/10091): Blockquote should be treated like an object by the styles system. Thanks to [dan-james-deeson](https://github.com/dan-james-deeson)!
@@ -278,9 +278,13 @@
var hiddenEl = editor._.hiddenSelectionContainer;

if ( hiddenEl ) {
var isDirty = editor.checkDirty();

editor.fire( 'lockSnapshot' );
hiddenEl.remove();
editor.fire( 'unlockSnapshot' );

!isDirty && editor.resetDirty();
}

delete editor._.hiddenSelectionContainer;
@@ -1196,9 +1196,14 @@

// Fake the selection before focusing editor, to avoid unpreventable viewports scrolling
// on Webkit/Blink/IE which is done because there's no selection or selection was somewhere else than widget.
if ( sel )
if ( sel ) {
var isDirty = this.editor.checkDirty();

sel.fake( this.wrapper );

!isDirty && this.editor.resetDirty();
}

// Always focus editor (not only when focusManger.hasFocus is false) (because of #10483).
this.editor.focus();
},
@@ -1701,9 +1706,13 @@
widgetsRepo.focused = null;

if ( widget.isInited() ) {
var isDirty = widget.editor.checkDirty();

// Widget could be destroyed in the meantime - e.g. data could be set.
widgetsRepo.fire( 'widgetBlurred', { widget: widget } );
widget.setFocused( false );

!isDirty && widget.editor.resetDirty();
}
}

@@ -2631,7 +2640,7 @@

commit: function() {
var focusedChanged = widgetsRepo.focused !== focused,
widget;
widget, isDirty;

widgetsRepo.editor.fire( 'lockSnapshot' );

@@ -2641,14 +2650,23 @@
while ( ( widget = toBeDeselected.pop() ) ) {
currentlySelected.splice( CKEDITOR.tools.indexOf( currentlySelected, widget ), 1 );
// Widget could be destroyed in the meantime - e.g. data could be set.
if ( widget.isInited() )
if ( widget.isInited() ) {
isDirty = widget.editor.checkDirty();

widget.setSelected( false );

!isDirty && widget.editor.resetDirty();
}
}

if ( focusedChanged && focused ) {
isDirty = widgetsRepo.editor.checkDirty();

widgetsRepo.focused = focused;
widgetsRepo.fire( 'widgetFocused', { widget: focused } );
focused.setFocused( true );

!isDirty && widgetsRepo.editor.resetDirty();
}

while ( ( widget = toBeSelected.pop() ) ) {
@@ -0,0 +1,62 @@
/* bender-ckeditor-plugins: widget */

(function() {
'use strict';

bender.test( {
'async:init': function() {
var tc = this;

bender.tools.setUpEditors( {
editor: {
name: 'editor1',
startupData: '<b id="one" data-widget="testwidget">foo</b><b id="two" data-widget="testwidget">foo</b>',
config: {
allowedContent: true,
on: {
pluginsLoaded: function( evt ) {
var ed = evt.editor;

ed.widgets.add( 'testwidget', {} );
}
}
}
}
}, function( editors, bots ) {
tc.editor = bots.editor.editor;

tc.callback();
} );
},

'test check dirty is false after widget focus': function() {
var widget = this.editor.widgets.instances[ 1 ];

assert.isFalse( this.editor.checkDirty() );
widget.focus();
assert.isFalse( this.editor.checkDirty() );
},

'test check dirty is true after modifications': function() {
var widget = this.editor.widgets.instances[ 1 ];

assert.isFalse( this.editor.checkDirty() );

// Clear selection
var range = this.editor.createRange();
var lastElement = this.editor.document.getById( 'two' );
range.moveToPosition( lastElement, CKEDITOR.POSITION_BEFORE_END );
this.editor.getSelection().selectRanges( [ range ] );

assert.isFalse( this.editor.checkDirty() );

// Make some changes in editor
widget.addClass( 'test' );

assert.isTrue( this.editor.checkDirty() );
widget.focus();
assert.isTrue( this.editor.checkDirty() );
}
} );

})();

0 comments on commit a2facd8

Please sign in to comment.
You can’t perform that action at this time.