JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.4.2
[ckeditor.git] / _source / plugins / wysiwygarea / plugin.js
index e626aad..5ea1f1a 100644 (file)
@@ -14,7 +14,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
        var nonExitableElementNames = { table:1,pre:1 };\r
 \r
        // Matching an empty paragraph at the end of document.\r
-       var emptyParagraphRegexp = /\s*<(p|div|address|h\d|center)[^>]*>\s*(?:<br[^>]*>|&nbsp;|\u00A0|&#160;)?\s*(:?<\/\1>)?(?=\s*$|<\/body>)/gi;\r
+       var emptyParagraphRegexp = /(^|<body\b[^>]*>)\s*<(p|div|address|h\d|center)[^>]*>\s*(?:<br[^>]*>|&nbsp;|\u00A0|&#160;)?\s*(:?<\/\2>)?\s*(?=$|<\/body>)/gi;\r
 \r
        var notWhitespaceEval = CKEDITOR.dom.walker.whitespaces( true );\r
 \r
@@ -92,6 +92,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                var marker = this.document.getById( 'cke_paste_marker' );\r
                                marker.scrollIntoView();\r
                                marker.remove();\r
+                               marker = null;\r
                        }\r
 \r
                        CKEDITOR.tools.setTimeout( function()\r
@@ -132,14 +133,14 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                // Remove the original contents.\r
                                range.deleteContents();\r
 \r
-                               clone = !i && element || element.clone( true );\r
+                               clone = !i && element || element.clone( 1 );\r
 \r
                                // If we're inserting a block at dtd-violated position, split\r
                                // the parent blocks until we reach blockLimit.\r
                                var current, dtd;\r
                                if ( isBlock )\r
                                {\r
-                                       while ( ( current = range.getCommonAncestor( false, true ) )\r
+                                       while ( ( current = range.getCommonAncestor( 0, 1 ) )\r
                                                        && ( dtd = CKEDITOR.dtd[ current.getName() ] )\r
                                                        && !( dtd && dtd [ elementName ] ) )\r
                                        {\r
@@ -530,7 +531,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
                                                CKEDITOR.env.gecko && CKEDITOR.tools.setTimeout( activateEditing, 0, null, editor );\r
 \r
-                                               domWindow       = editor.window         = new CKEDITOR.dom.window( domWindow );\r
+                                               domWindow       = editor.window = new CKEDITOR.dom.window( domWindow );\r
                                                domDocument     = editor.document       = new CKEDITOR.dom.document( domDocument );\r
 \r
                                                domDocument.on( 'dblclick', function( evt )\r
@@ -542,7 +543,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                });\r
 \r
                                                // Gecko/Webkit need some help when selecting control type elements. (#3448)\r
-                                               if ( !( CKEDITOR.env.ie || CKEDITOR.env.opera) )\r
+                                               if ( !( CKEDITOR.env.ie || CKEDITOR.env.opera ) )\r
                                                {\r
                                                        domDocument.on( 'mousedown', function( ev )\r
                                                        {\r
@@ -625,6 +626,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                editor.focusManager.blur();\r
                                                        });\r
 \r
+                                               var wasFocused;\r
+\r
                                                domWindow.on( 'focus', function()\r
                                                        {\r
                                                                var doc = editor.document;\r
@@ -633,6 +636,15 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                        blinkCursor();\r
                                                                else if ( CKEDITOR.env.opera )\r
                                                                        doc.getBody().focus();\r
+                                                               // Webkit needs focus for the first time on the HTML element. (#6153)\r
+                                                               else if ( CKEDITOR.env.webkit )\r
+                                                               {\r
+                                                                       if ( !wasFocused )\r
+                                                                       {\r
+                                                                               editor.document.getDocumentElement().focus();\r
+                                                                               wasFocused = 1;\r
+                                                                       }\r
+                                                               }\r
 \r
                                                                editor.focusManager.focus();\r
                                                        });\r
@@ -873,9 +885,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                if ( editor.dataProcessor )\r
                                                                        data = editor.dataProcessor.toDataFormat( data, fixForBody );\r
 \r
-                                                               // Strip the last blank paragraph within document.\r
+                                                               // Reset empty if the document contains only one empty paragraph.\r
                                                                if ( config.ignoreEmptyParagraph )\r
-                                                                       data = data.replace( emptyParagraphRegexp, '' );\r
+                                                                       data = data.replace( emptyParagraphRegexp, function( match, lookback ) { return lookback; } );\r
 \r
                                                                if ( docType )\r
                                                                        data = docType + '\n' + data;\r
@@ -930,6 +942,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                // Temporary solution caused by #6025, supposed be unified by #6154.\r
                                                                else if ( CKEDITOR.env.opera && editor.document )\r
                                                                {\r
+                                                                       // Required for Opera when switching focus\r
+                                                                       // from another iframe, e.g. panels. (#6444)\r
+                                                                       var iframe = editor.window.$.frameElement;\r
+                                                                       iframe.blur(), iframe.focus();\r
                                                                        editor.document.getBody().focus();\r
 \r
                                                                        editor.selectionChange();\r
@@ -952,7 +968,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        var titleBackup;\r
                        // Setting voice label as window title, backup the original one\r
                        // and restore it before running into use.\r
-                       editor.on( 'contentDom', function ()\r
+                       editor.on( 'contentDom', function()\r
                                {\r
                                        var title = editor.document.getElementsByTag( 'title' ).getItem( 0 );\r
                                        title.setAttribute( '_cke_title', editor.document.$.title );\r
@@ -970,6 +986,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                        selectors.push( 'html.CSS1Compat ' + tag + '[contenteditable=false]' );\r
                                editor.addCss( selectors.join( ',' ) + '{ display:inline-block;}' );\r
                        }\r
+                       // Set the HTML style to 100% to have the text cursor in affect (#6341)\r
+                       else if ( CKEDITOR.env.gecko )\r
+                               editor.addCss( 'html { height: 100% !important; }' );\r
 \r
                        // Switch on design mode for a short while and close it after then.\r
                        function blinkCursor( retry )\r
@@ -978,10 +997,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                        function()\r
                                        {\r
                                                editor.document.$.designMode = 'on';\r
-                                               setTimeout( function ()\r
+                                               setTimeout( function()\r
                                                {\r
                                                        editor.document.$.designMode = 'off';\r
-                                                       editor.document.getBody().focus();\r
+                                                       if ( CKEDITOR.currentInstance == editor )\r
+                                                               editor.document.getBody().focus();\r
                                                }, 50 );\r
                                        },\r
                                        function()\r
@@ -1043,7 +1063,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
        // Fixing Firefox 'Back-Forward Cache' break design mode. (#4514)\r
        if ( CKEDITOR.env.gecko )\r
        {\r
-               ( function ()\r
+               (function()\r
                {\r
                        var body = document.body;\r
 \r