Skip to content

Commit

Permalink
Merge branch 't/11027' into major
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Jasiun committed Nov 4, 2013
2 parents d792be6 + 57f8477 commit 7b210e8
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -5,6 +5,7 @@ CKEditor 4 Changelog

New Features:

* [#11027](http://dev.ckeditor.com/ticket/11027): Fixed block commands break on widget issue; added contentDomInvalidated event.
* [#10886](http://dev.ckeditor.com/ticket/10886): Widgets: added tooltip to the drag handler.
* [#10895](http://dev.ckeditor.com/ticket/10895): Image2: added support for server file browsers.
* [#11057](http://dev.ckeditor.com/ticket/11057): Fixed: Regression in #10212 test.
Expand Down
11 changes: 11 additions & 0 deletions core/editor.js
Expand Up @@ -1754,4 +1754,15 @@ CKEDITOR.ELEMENT_MODE_INLINE = 3;
*
* @event contentDomUnload
* @param {CKEDITOR.editor} editor This editor instance.
*/

/**
* The event fired when contents DOM changes and some of the references as well as
* native DOM event listeners could be lost.
* This event is useful when it is important to keep track of references
* to elements in the editable contents from code.
*
* @since 4.3
* @event contentDomInvalidated
* @param {CKEDITOR.editor} editor This editor instance.
*/
3 changes: 3 additions & 0 deletions core/selection.js
Expand Up @@ -1958,6 +1958,9 @@
fake: function( element ) {
var editor = this.root.editor;

// Cleanup after previous selection - e.g. remove hidden sel container.
this.reset();

hideSelection( editor );

// Set this value after executing hiseSelection, because it may
Expand Down
2 changes: 1 addition & 1 deletion plugins/blockquote/plugin.js
Expand Up @@ -16,7 +16,7 @@
exec: function( editor ) {
var state = editor.getCommand( 'blockquote' ).state,
selection = editor.getSelection(),
range = selection && selection.getRanges( true )[ 0 ];
range = selection && selection.getRanges()[ 0 ];

if ( !range )
return;
Expand Down
8 changes: 5 additions & 3 deletions plugins/indentblock/plugin.js
Expand Up @@ -138,7 +138,7 @@

exec: function( editor ) {
var selection = editor.getSelection(),
range = selection && selection.getRanges( 1 )[ 0 ],
range = selection && selection.getRanges()[ 0 ],
nearestListBlock;

// If there's some list in the path, then it will be
Expand All @@ -156,8 +156,10 @@
iterator.enforceRealBlocks = true;
iterator.enlargeBr = enterMode != CKEDITOR.ENTER_BR;

while ( ( block = iterator.getNextParagraph( enterMode == CKEDITOR.ENTER_P ? 'p' : 'div' ) ) )
indentElement.call( this, block, classes );
while ( ( block = iterator.getNextParagraph( enterMode == CKEDITOR.ENTER_P ? 'p' : 'div' ) ) ) {
if ( !block.isReadOnly() )
indentElement.call( this, block, classes );
}
}

return true;
Expand Down
5 changes: 4 additions & 1 deletion plugins/indentlist/plugin.js
Expand Up @@ -221,11 +221,14 @@
}
}

if ( newList )
editor.fire( 'contentDomInvalidated' );

return true;
}

var selection = editor.getSelection(),
ranges = selection && selection.getRanges( 1 ),
ranges = selection && selection.getRanges(),
iterator = ranges.createIterator(),
range;

Expand Down
5 changes: 4 additions & 1 deletion plugins/justify/plugin.js
Expand Up @@ -134,7 +134,7 @@
return;

var bookmarks = selection.createBookmarks(),
ranges = selection.getRanges( true );
ranges = selection.getRanges();

var cssClassName = this.cssClassName,
iterator, block;
Expand All @@ -147,6 +147,9 @@
iterator.enlargeBr = enterMode != CKEDITOR.ENTER_BR;

while ( ( block = iterator.getNextParagraph( enterMode == CKEDITOR.ENTER_P ? 'p' : 'div' ) ) ) {
if ( block.isReadOnly() )
continue;

block.removeAttribute( 'align' );
block.removeStyle( 'text-align' );

Expand Down
6 changes: 5 additions & 1 deletion plugins/list/plugin.js
Expand Up @@ -291,6 +291,8 @@
listsCreated.push( child );
}
newList.listNode.replace( groupObj.root );

editor.fire( 'contentDomInvalidated' );
}

var headerTagRegex = /^h[1-6]$/;
Expand Down Expand Up @@ -443,6 +445,8 @@
compensateBrs();

docFragment.replace( groupObj.root );

editor.fire( 'contentDomInvalidated' );
}

function listCommand( name, type ) {
Expand Down Expand Up @@ -476,7 +480,7 @@
var doc = editor.document,
config = editor.config,
selection = editor.getSelection(),
ranges = selection && selection.getRanges( true );
ranges = selection && selection.getRanges();

// Midas lists rule #1 says we can create a list even in an empty document.
// But DOM iterator wouldn't run if the document is really empty.
Expand Down
26 changes: 18 additions & 8 deletions plugins/undo/plugin.js
Expand Up @@ -181,20 +181,25 @@
* @class CKEDITOR.plugins.undo.Image
* @constructor Creates an Image class instance.
* @param {CKEDITOR.editor} editor The editor instance on which the image is created.
* @param {Boolean} [contentsOnly] If set to `true` image will contain only contents, without selection.
*/
var Image = CKEDITOR.plugins.undo.Image = function( editor ) {
var Image = CKEDITOR.plugins.undo.Image = function( editor, contentsOnly ) {
this.editor = editor;

editor.fire( 'beforeUndoImage' );

var contents = editor.getSnapshot(),
selection = contents && editor.getSelection();
var contents = editor.getSnapshot();

// In IE, we need to remove the expando attributes.
CKEDITOR.env.ie && contents && ( contents = contents.replace( /\s+data-cke-expando=".*?"/g, '' ) );
if ( CKEDITOR.env.ie && contents )
contents = contents.replace( /\s+data-cke-expando=".*?"/g, '' );

this.contents = contents;
this.bookmarks = selection && selection.createBookmarks2( true );

if ( !contentsOnly ) {
var selection = contents && editor.getSelection();
this.bookmarks = selection && selection.createBookmarks2( true );
}

editor.fire( 'afterUndoImage' );
};
Expand Down Expand Up @@ -614,7 +619,12 @@
*/
lock: function() {
if ( !this.locked ) {
var imageBefore = new Image( this.editor );
// Make a contents image. Don't include bookmarks, because:
// * we don't compare them,
// * there's a chance that DOM has been changed since
// locked (e.g. fake) selection was made, so createBookmark2 could fail.
// http://dev.ckeditor.com/ticket/11027#comment:3
var imageBefore = new Image( this.editor, true );

// If current editor content matches the tip of snapshot stack,
// the stack tip must be updated by unlock, to include any changes made
Expand All @@ -640,12 +650,12 @@
// Decrease level of lock and check if equals 0, what means that undoM is completely unlocked.
if ( !--this.locked.level ) {
var updateImage = this.locked.update,
newImage = new Image( this.editor );
newImage = new Image( this.editor, true );

this.locked = null;

if ( updateImage && !updateImage.equalsContent( newImage ) )
this.update( newImage );
this.update();
}
}
}
Expand Down
40 changes: 30 additions & 10 deletions plugins/widget/plugin.js
Expand Up @@ -256,24 +256,40 @@
/**
* Checks if all widget instances are still present in the DOM.
* Destroys those instances that are not present.
* Reinitializes widgets on widget wrappers for which widget instances
* cannot be found.
*
* This method is triggered by the {@link #event-checkWidgets} event.
*/
checkWidgets: function() {
if ( this.editor.mode != 'wysiwyg' )
return;

var toBeDestroyed = [],
editable = this.editor.editable(),
var editable = this.editor.editable(),
instances = this.instances,
id;
i, count, wrapper;

if ( !editable )
return;

for ( id in instances ) {
if ( !editable.contains( instances[ id ].wrapper ) )
this.destroy( instances[ id ], true );
// Remove widgets which have no corresponding elements in DOM.
for ( i in instances ) {
if ( !editable.contains( instances[ i ].wrapper ) )
this.destroy( instances[ i ], true );
}

var wrappers = editable.find( '.cke_widget_wrapper' );

// Create widgets on existing wrappers if they do not exists.
for ( i = 0, count = wrappers.count(); i < count; i++ ) {
wrapper = wrappers.getItem( i );

if ( !this.getByElement( wrapper, true ) ) {
// Add cke_widget_new class because otherwise
// widget will not be created on such wrapper.
wrapper.addClass( 'cke_widget_new' );
this.initOn( wrapper.getFirst( isWidgetElement2 ) );
}
}
},

Expand Down Expand Up @@ -416,7 +432,7 @@
* Initializes a widget on a given element if the widget has not been initialized on it yet.
*
* @param {CKEDITOR.dom.element} element The future widget element.
* @param {String/CKEDITOR.plugins.widget.definition} widgetDef Name of a widget or a widget definition.
* @param {String/CKEDITOR.plugins.widget.definition} [widgetDef] Name of a widget or a widget definition.
* The widget definition should be previously registered by using the
* {@link CKEDITOR.plugins.widget.repository#add} method.
* @param [startupData] Widget startup data (has precedence over default one).
Expand Down Expand Up @@ -2154,9 +2170,7 @@
// * keyup.
function setupWidgetsObserver( widgetsRepo ) {
var editor = widgetsRepo.editor,
buffer = CKEDITOR.tools.eventsBuffer( widgetsRepo.MIN_WIDGETS_CHECK_INTERVAL, function() {
widgetsRepo.fire( 'checkWidgets' );
} ),
buffer = CKEDITOR.tools.eventsBuffer( widgetsRepo.MIN_WIDGETS_CHECK_INTERVAL, checkWidgets ),
ignoredKeys = { 16:1,17:1,18:1,37:1,38:1,39:1,40:1,225:1 }; // SHIFT,CTRL,ALT,LEFT,UP,RIGHT,DOWN,RIGHT ALT(FF)

editor.on( 'contentDom', function() {
Expand All @@ -2172,6 +2186,12 @@
editor.on( 'contentDomUnload', buffer.reset );

widgetsRepo.on( 'checkWidgets', widgetsRepo.checkWidgets, widgetsRepo );

editor.on( 'contentDomInvalidated', checkWidgets );

function checkWidgets() {
widgetsRepo.fire( 'checkWidgets' );
}
}

// Helper for coordinating which widgets should be
Expand Down

0 comments on commit 7b210e8

Please sign in to comment.