JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.5.4
[ckeditor.git] / _source / plugins / wysiwygarea / plugin.js
index 76501cc..d63550d 100644 (file)
@@ -10,19 +10,15 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
 (function()\r
 {\r
-       // List of elements in which has no way to move editing focus outside.\r
-       var nonExitableElementNames = { table:1,pre:1 };\r
-\r
        // Matching an empty paragraph at the end of document.\r
-       var emptyParagraphRegexp = /(^|<body\b[^>]*>)\s*<(p|div|address|h\d|center)[^>]*>\s*(?:<br[^>]*>|&nbsp;|\u00A0|&#160;)?\s*(:?<\/\2>)?\s*(?=$|<\/body>)/gi;\r
+       var emptyParagraphRegexp = /(^|<body\b[^>]*>)\s*<(p|div|address|h\d|center|pre)[^>]*>\s*(?:<br[^>]*>|&nbsp;|\u00A0|&#160;)?\s*(:?<\/\2>)?\s*(?=$|<\/body>)/gi;\r
 \r
        var notWhitespaceEval = CKEDITOR.dom.walker.whitespaces( true );\r
 \r
-       // Elements that could have empty new line around, including table, pre-formatted block, hr, page-break. (#6554)\r
-       function nonExitable( element )\r
+       // Elements that could blink the cursor anchoring beside it, like hr, page-break. (#6554)\r
+       function nonEditable( element )\r
        {\r
-               return ( element.getName() in nonExitableElementNames )\r
-                               || element.isBlockBoundary() && CKEDITOR.dtd.$empty[ element.getName() ];\r
+               return element.isBlockBoundary() && CKEDITOR.dtd.$empty[ element.getName() ];\r
        }\r
 \r
 \r
@@ -313,9 +309,13 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                var win = editor.window,\r
                        doc = editor.document,\r
                        body = editor.document.getBody(),\r
+                       bodyFirstChild = body.getFirst(),\r
                        bodyChildsNum = body.getChildren().count();\r
 \r
-               if ( !bodyChildsNum || ( bodyChildsNum == 1&& body.getFirst().hasAttribute( '_moz_editor_bogus_node' ) ) )\r
+               if ( !bodyChildsNum\r
+                       || bodyChildsNum == 1\r
+                               && bodyFirstChild.type == CKEDITOR.NODE_ELEMENT\r
+                               && bodyFirstChild.hasAttribute( '_moz_editor_bogus_node' ) )\r
                {\r
                        restoreDirty( editor );\r
 \r
@@ -362,8 +362,18 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        activateEditing( editor );\r
 \r
                        // Ensure bogus br could help to move cursor (out of styles) to the end of block. (#7041)\r
-                       var pathBlock = path.block || path.blockLimit;\r
-                       if ( pathBlock && !pathBlock.getBogus() )\r
+                       var pathBlock = path.block || path.blockLimit,\r
+                               lastNode = pathBlock && pathBlock.getLast( isNotEmpty );\r
+\r
+                       // Check some specialities of the current path block:\r
+                       // 1. It is really displayed as block; (#7221)\r
+                       // 2. It doesn't end with one inner block; (#7467)\r
+                       // 3. It doesn't have bogus br yet.\r
+                       if ( pathBlock\r
+                                       && pathBlock.isBlockBoundary()\r
+                                       && !( lastNode && lastNode.type == CKEDITOR.NODE_ELEMENT && lastNode.isBlockBoundary() )\r
+                                       && !pathBlock.is( 'pre' )\r
+                                       && !pathBlock.getBogus() )\r
                        {\r
                                editor.fire( 'updateSnapshot' );\r
                                restoreDirty( editor );\r
@@ -399,7 +409,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                var element = fixedBlock.getNext( isNotWhitespace );\r
                                if ( element &&\r
                                         element.type == CKEDITOR.NODE_ELEMENT &&\r
-                                        !nonExitable( element ) )\r
+                                        !nonEditable( element ) )\r
                                {\r
                                        range.moveToElementEditStart( element );\r
                                        fixedBlock.remove();\r
@@ -409,7 +419,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                        element = fixedBlock.getPrevious( isNotWhitespace );\r
                                        if ( element &&\r
                                                 element.type == CKEDITOR.NODE_ELEMENT &&\r
-                                                !nonExitable( element ) )\r
+                                                !nonEditable( element ) )\r
                                        {\r
                                                range.moveToElementEditEnd( element );\r
                                                fixedBlock.remove();\r
@@ -418,31 +428,17 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        }\r
 \r
                        range.select();\r
-                       // Notify non-IE that selection has changed.\r
-                       if ( !CKEDITOR.env.ie )\r
-                       {\r
-                               // Make sure next selection change is correct.  (#6811)\r
-                               editor.forceNextSelectionCheck();\r
-                               editor.selectionChange();\r
-                       }\r
+                       // Cancel this selection change in favor of the next (correct).  (#6811)\r
+                       evt.cancel();\r
                }\r
 \r
-               // All browsers are incapable to moving cursor out of certain non-exitable\r
-               // blocks (e.g. table, list, pre) at the end of document, make this happen by\r
-               // place a bogus node there, which would be later removed by dataprocessor.\r
-               var walkerRange = new CKEDITOR.dom.range( editor.document ),\r
-                       walker = new CKEDITOR.dom.walker( walkerRange );\r
-               walkerRange.selectNodeContents( body );\r
-               walker.evaluator = function( node )\r
-               {\r
-                       return node.type == CKEDITOR.NODE_ELEMENT && ( node.getName() in nonExitableElementNames );\r
-               };\r
-               walker.guard = function( node, isMoveout )\r
-               {\r
-                       return !( ( node.type == CKEDITOR.NODE_TEXT && isNotWhitespace( node ) ) || isMoveout );\r
-               };\r
-\r
-               if ( walker.previous() )\r
+               // Browsers are incapable of moving cursor out of certain block elements (e.g. table, div, pre)\r
+               // at the end of document, makes it unable to continue adding content, we have to make this\r
+               // easier by opening an new empty paragraph.\r
+               var testRange = new CKEDITOR.dom.range( editor.document );\r
+               testRange.moveToElementEditEnd( editor.document.getBody() );\r
+               var testPath = new CKEDITOR.dom.elementPath( testRange.startContainer );\r
+               if ( !testPath.blockLimit.is( 'body') )\r
                {\r
                        editor.fire( 'updateSnapshot' );\r
                        restoreDirty( editor );\r
@@ -450,7 +446,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
                        var paddingBlock;\r
                        if ( enterMode != CKEDITOR.ENTER_BR )\r
-                               paddingBlock = body.append( new CKEDITOR.dom.element( enterMode == CKEDITOR.ENTER_P ? 'p' : 'div' ) );\r
+                               paddingBlock = body.append( editor.document.createElement( enterMode == CKEDITOR.ENTER_P ? 'p' : 'div' ) );\r
                        else\r
                                paddingBlock = body;\r
 \r
@@ -687,6 +683,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                // Webkit: avoid from editing form control elements content.\r
                                                if ( CKEDITOR.env.webkit )\r
                                                {\r
+                                                       // Mark that cursor will right blinking (#7113).\r
+                                                       domDocument.on( 'mousedown', function() { wasFocused = 1; } );\r
                                                        // Prevent from tick checkbox/radiobox/select\r
                                                        domDocument.on( 'click', function( ev )\r
                                                        {\r
@@ -807,6 +805,30 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                        }\r
                                                                } );\r
                                                        }\r
+\r
+                                                       // Prevent IE from leaving new paragraph after deleting all contents in body. (#6966)\r
+                                                       editor.config.enterMode != CKEDITOR.ENTER_P\r
+                                                               && domDocument.on( 'selectionchange', function()\r
+                                                               {\r
+                                                                       var body = domDocument.getBody(),\r
+                                                                               range = editor.getSelection().getRanges()[ 0 ];\r
+\r
+                                                                       if ( body.getHtml().match( /^<p>&nbsp;<\/p>$/i )\r
+                                                                               && range.startContainer.equals( body ) )\r
+                                                                       {\r
+                                                                               // Avoid the ambiguity from a real user cursor position.\r
+                                                                               setTimeout( function ()\r
+                                                                               {\r
+                                                                                       range = editor.getSelection().getRanges()[ 0 ];\r
+                                                                                       if ( !range.startContainer.equals ( 'body' ) )\r
+                                                                                       {\r
+                                                                                               body.getFirst().remove( 1 );\r
+                                                                                               range.moveToElementEditEnd( body );\r
+                                                                                               range.select( 1 );\r
+                                                                                       }\r
+                                                                               }, 0 );\r
+                                                                       }\r
+                                                               });\r
                                                }\r
 \r
                                                // Adds the document body as a context menu target.\r
@@ -902,6 +924,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                        loadData : function( data )\r
                                                        {\r
                                                                isLoadingData = true;\r
+                                                               editor._.dataStore = { id : 1 };\r
 \r
                                                                var config = editor.config,\r
                                                                        fullPage = config.fullPage,\r
@@ -981,6 +1004,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                                '</html>';\r
                                                                }\r
 \r
+                                                               // Distinguish bogus to normal BR at the end of document for Mozilla. (#5293).\r
+                                                               if ( CKEDITOR.env.gecko )\r
+                                                                       data = data.replace( /<br \/>(?=\s*<\/(:?html|body)>)/, '$&<br type="_moz" />' );\r
+\r
                                                                data += activationScript;\r
 \r
 \r
@@ -1000,6 +1027,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                        ? doc.getDocumentElement().getOuterHtml()\r
                                                                        : doc.getBody().getHtml();\r
 \r
+                                                               // BR at the end of document is bogus node for Mozilla. (#5293).\r
+                                                               if ( CKEDITOR.env.gecko )\r
+                                                                       data = data.replace( /<br>(?=\s*(:?$|<\/body>))/, '' );\r
+\r
                                                                if ( editor.dataProcessor )\r
                                                                        data = editor.dataProcessor.toDataFormat( data, fixForBody );\r
 \r
@@ -1096,9 +1127,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                        editor.document.$.title = frameLabel;\r
                                });\r
 \r
-                       // IE8 stricts mode doesn't have 'contentEditable' in effect\r
+                       // IE>=8 stricts mode doesn't have 'contentEditable' in effect\r
                        // on element unless it has layout. (#5562)\r
-                       if ( CKEDITOR.env.ie8Compat )\r
+                       if ( CKEDITOR.document.$.documentMode >= 8 )\r
                        {\r
                                editor.addCss( 'html.CSS1Compat [contenteditable=false]{ min-height:0 !important;}' );\r
 \r
@@ -1236,14 +1267,12 @@ CKEDITOR.config.disableObjectResizing = false;
 CKEDITOR.config.disableNativeTableHandles = true;\r
 \r
 /**\r
- * Disables the built-in spell checker while typing natively available in the\r
- * browser (currently Firefox and Safari only).<br /><br />\r
+ * Disables the built-in words spell checker if browser provides one.<br /><br />\r
  *\r
- * Even if word suggestions will not appear in the CKEditor context menu, this\r
- * feature is useful to help quickly identifying misspelled words.<br /><br />\r
+ * <strong>Note:</strong> Although word suggestions provided by browsers (natively) will not appear in CKEditor's default context menu,\r
+ * users can always reach the native context menu by holding the <em>Ctrl</em> key when right-clicking if {@link CKEDITOR.config.browserContextMenuOnCtrl}\r
+ * is enabled or you're simply not using the context menu plugin.\r
  *\r
- * This setting is currently compatible with Firefox only due to limitations in\r
- * other browsers.\r
  * @type Boolean\r
  * @default true\r
  * @example\r