var container = editor.elementPath( element ).blockLimit;\r
\r
// Never consider read-only (i.e. contenteditable=false) element as\r
- // a first div limit (#11083).\r
+ // a first div limit (http://dev.ckeditor.com/ticket/11083).\r
if ( container.isReadOnly() )\r
container = container.getParent();\r
\r
var ancestor, divElement;\r
\r
for ( i = 0; i < blockGroups.length; i++ ) {\r
+ // Sometimes we could get empty block group if all elements inside it\r
+ // don't have parent's nodes (http://dev.ckeditor.com/ticket/13585).\r
+ if ( !blockGroups[ i ].length ) {\r
+ continue;\r
+ }\r
+\r
var currentNode = blockGroups[ i ][ 0 ];\r
\r
// Calculate the common parent node of all contained elements.\r
ancestor = currentNode.getParent();\r
- for ( j = 1; j < blockGroups[ i ].length; j++ )\r
+ for ( j = 1; j < blockGroups[ i ].length; j++ ) {\r
ancestor = ancestor.getCommonAncestor( blockGroups[ i ][ j ] );\r
+ }\r
+\r
+ // If there is no ancestor, mark editable as one (http://dev.ckeditor.com/ticket/13585).\r
+ if ( !ancestor ) {\r
+ ancestor = editor.editable();\r
+ }\r
\r
divElement = new CKEDITOR.dom.element( 'div', editor.document );\r
\r
for ( j = 0; j < blockGroups[ i ].length; j++ ) {\r
currentNode = blockGroups[ i ][ j ];\r
\r
- while ( !currentNode.getParent().equals( ancestor ) )\r
+ // Check if the currentNode has a parent before attempting to operate on it (http://dev.ckeditor.com/ticket/13585).\r
+ while ( currentNode.getParent() && !currentNode.getParent().equals( ancestor ) ) {\r
currentNode = currentNode.getParent();\r
+ }\r
\r
// This could introduce some duplicated elements in array.\r
blockGroups[ i ][ j ] = currentNode;\r
currentNode.is && CKEDITOR.dom.element.setMarker( database, currentNode, 'block_processed', true );\r
\r
// Establish new container, wrapping all elements in this group.\r
- if ( !j )\r
+ if ( !j ) {\r
divElement.insertBefore( currentNode );\r
+ }\r
\r
divElement.append( currentNode );\r
}\r
lastDivLimit = limit;\r
groups.push( [] );\r
}\r
- groups[ groups.length - 1 ].push( block );\r
+\r
+ // Sometimes we got nodes that are not inside the DOM, which causes error (http://dev.ckeditor.com/ticket/13585).\r
+ if ( block.getParent() ) {\r
+ groups[ groups.length - 1 ].push( block );\r
+ }\r
}\r
+\r
return groups;\r
}\r
\r
// it if no options are available at all.\r
stylesField[ stylesField.items.length > 1 ? 'enable' : 'disable' ]();\r
\r
- // Now setup the field value manually if dialog was opened on element. (#9689)\r
+ // Now setup the field value manually if dialog was opened on element. (http://dev.ckeditor.com/ticket/9689)\r
setTimeout( function() {\r
dialog._element && stylesField.setup( dialog._element );\r
}, 0 );\r
this.hide();\r
},\r
onHide: function() {\r
- // Remove style only when editing existing DIV. (#6315)\r
+ // Remove style only when editing existing DIV. (http://dev.ckeditor.com/ticket/6315)\r
if ( command == 'editdiv' )\r
this._element.removeCustomData( 'elementStyle' );\r
delete this._element;\r