JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.0.1
[ckeditor.git] / _source / plugins / wysiwygarea / plugin.js
index 225f2f3..ab06245 100644 (file)
@@ -81,14 +81,24 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
                                // If we're inserting a block at dtd-violated position, split\r
                                // the parent blocks until we reach blockLimit.\r
-                               var parent, dtd;\r
-                               if ( this.config.enterMode != CKEDITOR.ENTER_BR && isBlock )\r
+                               var current, dtd;\r
+                               if ( isBlock )\r
                                {\r
-                                       while( ( parent = range.getCommonAncestor( false, true ) )\r
-                                                       && ( dtd = CKEDITOR.dtd[ parent.getName() ] )\r
+                                       while( ( current = range.getCommonAncestor( false, true ) )\r
+                                                       && ( dtd = CKEDITOR.dtd[ current.getName() ] )\r
                                                        && !( dtd && dtd [ elementName ] ) )\r
                                        {\r
-                                               range.splitBlock();\r
+                                               // If we're in an empty block which indicate a new paragraph,\r
+                                               // simply replace it with the inserting block.(#3664)\r
+                                               if ( range.checkStartOfBlock()\r
+                                                        && range.checkEndOfBlock() )\r
+                                               {\r
+                                                       range.setStartBefore( current );\r
+                                                       range.collapse( true );\r
+                                                       current.remove();\r
+                                               }\r
+                                               else\r
+                                                       range.splitBlock();\r
                                        }\r
                                }\r
 \r
@@ -122,6 +132,13 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                }\r
        }\r
 \r
+       // DOM modification here should not bother dirty flag.(#4385)\r
+       function restoreDirty( editor )\r
+       {\r
+               if( !editor.checkDirty() )\r
+                       setTimeout( function(){ editor.resetDirty(); } );\r
+       }\r
+\r
        /**\r
         *  Auto-fixing block-less content by wrapping paragraph (#3190), prevent\r
         *  non-exitable-block by padding extra br.(#3189)\r
@@ -143,6 +160,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                         && blockLimit.getName() == 'body'\r
                         && !path.block )\r
                {\r
+                       restoreDirty( editor );\r
                        var bms = selection.createBookmarks(),\r
                                fixedBlock = range.fixBlock( true,\r
                                        editor.config.enterMode == CKEDITOR.ENTER_DIV ? 'div' : 'p'  );\r
@@ -193,6 +211,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                var lastNode = body.getLast( CKEDITOR.dom.walker.whitespaces( true ) );\r
                if ( lastNode && lastNode.getName && ( lastNode.getName() in nonExitableElementNames ) )\r
                {\r
+                       restoreDirty( editor );\r
                        var paddingBlock = editor.document.createElement(\r
                                        ( CKEDITOR.env.ie && enterMode != CKEDITOR.ENTER_BR ) ?\r
                                                '<br _cke_bogus="true" />' : 'br' );\r
@@ -363,26 +382,6 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                domWindow       = editor.window         = new CKEDITOR.dom.window( domWindow );\r
                                                domDocument     = editor.document       = new CKEDITOR.dom.document( domDocument );\r
 \r
-                                               // Gecko need a key event to 'wake up' the editing\r
-                                               // ability when document is empty.(#3864)\r
-                                               var firstNode = domDocument.getBody().getFirst();\r
-                                               if ( CKEDITOR.env.gecko\r
-                                                       && firstNode && firstNode.is\r
-                                                       && firstNode.is( 'br' ) && firstNode.hasAttribute( '_moz_editor_bogus_node' ) )\r
-                                               {\r
-                                                       var keyEventSimulate = domDocument.$.createEvent( "KeyEvents" );\r
-                                                       keyEventSimulate.initKeyEvent( 'keypress', true, true, domWindow.$, false,\r
-                                                               false, false, false, 0, 32 );\r
-                                                       domDocument.$.dispatchEvent( keyEventSimulate );\r
-                                                       var bogusText = domDocument.getBody().getFirst() ;\r
-                                                       // Compensate the line maintaining <br> if enterMode is not block.\r
-                                                       if ( editor.config.enterMode == CKEDITOR.ENTER_BR )\r
-                                                               domDocument.createElement( 'br', { attributes: { '_moz_dirty' : "" } } )\r
-                                                                       .replace( bogusText );\r
-                                                       else\r
-                                                               bogusText.remove();\r
-                                               }\r
-\r
                                                // Gecko/Webkit need some help when selecting control type elements. (#3448)\r
                                                if ( !( CKEDITOR.env.ie || CKEDITOR.env.opera) )\r
                                                {\r
@@ -412,7 +411,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                        } );\r
                                                }\r
 \r
-                                               var focusTarget = ( CKEDITOR.env.ie || CKEDITOR.env.safari ) ?\r
+                                               var focusTarget = ( CKEDITOR.env.ie || CKEDITOR.env.webkit ) ?\r
                                                                domWindow : domDocument;\r
 \r
                                                focusTarget.on( 'blur', function()\r
@@ -422,6 +421,32 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
                                                focusTarget.on( 'focus', function()\r
                                                        {\r
+                                                               // Gecko need a key event to 'wake up' the editing\r
+                                                               // ability when document is empty.(#3864)\r
+                                                               if ( CKEDITOR.env.gecko )\r
+                                                               {\r
+                                                                       var first = body;\r
+                                                                       while( first.firstChild )\r
+                                                                               first = first.firstChild;\r
+\r
+                                                                       if( !first.nextSibling\r
+                                                                               && ( 'BR' == first.tagName )\r
+                                                                               && first.hasAttribute( '_moz_editor_bogus_node' ) )\r
+                                                                       {\r
+                                                                               var keyEventSimulate = domDocument.$.createEvent( "KeyEvents" );\r
+                                                                               keyEventSimulate.initKeyEvent( 'keypress', true, true, domWindow.$, false,\r
+                                                                                       false, false, false, 0, 32 );\r
+                                                                               domDocument.$.dispatchEvent( keyEventSimulate );\r
+                                                                               var bogusText = domDocument.getBody().getFirst() ;\r
+                                                                               // Compensate the line maintaining <br> if enterMode is not block.\r
+                                                                               if ( editor.config.enterMode == CKEDITOR.ENTER_BR )\r
+                                                                                       domDocument.createElement( 'br', { attributes: { '_moz_dirty' : "" } } )\r
+                                                                                               .replace( bogusText );\r
+                                                                               else\r
+                                                                                       bogusText.remove();\r
+                                                                       }\r
+                                                               }\r
+\r
                                                                editor.focusManager.focus();\r
                                                        });\r
 \r
@@ -429,6 +454,26 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                if ( keystrokeHandler )\r
                                                        keystrokeHandler.attach( domDocument );\r
 \r
+                                               // Cancel default action for backspace in IE on control types. (#4047)\r
+                                               if ( CKEDITOR.env.ie )\r
+                                               {\r
+                                                       editor.on( 'key', function( event )\r
+                                                       {\r
+                                                               // Backspace.\r
+                                                               var control = event.data.keyCode == 8\r
+                                                                                         && editor.getSelection().getSelectedElement();\r
+                                                               if ( control )\r
+                                                               {\r
+                                                                       // Make undo snapshot.\r
+                                                                       editor.fire( 'saveSnapshot' );\r
+                                                                       // Remove manually.\r
+                                                                       control.remove();\r
+                                                                       editor.fire( 'saveSnapshot' );\r
+                                                                       event.cancel();\r
+                                                               }\r
+                                                       } );\r
+                                               }\r
+\r
                                                // Adds the document body as a context menu target.\r
                                                if ( editor.contextMenu )\r
                                                        editor.contextMenu.addTarget( domDocument );\r
@@ -451,6 +496,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                        editor.focus();\r
                                                                        isPendingFocus = false;\r
                                                                }\r
+                                                               setTimeout( function()\r
+                                                               {\r
+                                                                       editor.fire( 'dataReady' );\r
+                                                               }, 0 );\r
 \r
                                                                /*\r
                                                                 * IE BUG: IE might have rendered the iframe with invisible contents.\r
@@ -511,7 +560,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                        editor.config.docType +\r
                                                                        '<html dir="' + editor.config.contentsLangDirection + '">' +\r
                                                                        '<head>' +\r
-                                                                               '<link href="' + editor.config.contentsCss + '" type="text/css" rel="stylesheet" _fcktemp="true"/>' +\r
+                                                                               '<link type="text/css" rel="stylesheet" href="' +\r
+                                                                               [].concat( editor.config.contentsCss ).join( '"><link type="text/css" rel="stylesheet" href="' ) +\r
+                                                                               '">' +\r
                                                                                '<style type="text/css" _fcktemp="true">' +\r
                                                                                        editor._.styles.join( '\n' ) +\r
                                                                                '</style>'+\r