JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.4.1
[ckeditor.git] / _source / plugins / wysiwygarea / plugin.js
index 0a35305..e626aad 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|li)[^>]*>\s*(?:<br[^>]*>|&nbsp;|\u00A0|&#160;)?\s*(:?<\/\1>)?\s*(?=$|<\/body>)/gi;\r
+       var emptyParagraphRegexp = /\s*<(p|div|address|h\d|center)[^>]*>\s*(?:<br[^>]*>|&nbsp;|\u00A0|&#160;)?\s*(:?<\/\1>)?(?=\s*$|<\/body>)/gi;\r
 \r
        var notWhitespaceEval = CKEDITOR.dom.walker.whitespaces( true );\r
 \r
@@ -73,7 +73,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                        }\r
                                }\r
 \r
-                               $sel.createRange().pasteHTML( data );\r
+                               try\r
+                               {\r
+                                       $sel.createRange().pasteHTML( data );\r
+                               }\r
+                               catch (e) {}\r
 \r
                                if ( selIsLocked )\r
                                        this.getSelection().lock();\r
@@ -198,7 +202,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
        function restoreDirty( editor )\r
        {\r
                if ( !editor.checkDirty() )\r
-                       setTimeout( function(){ editor.resetDirty(); } );\r
+                       setTimeout( function(){ editor.resetDirty(); }, 0 );\r
        }\r
 \r
        var isNotWhitespace = CKEDITOR.dom.walker.whitespaces( true ),\r
@@ -244,12 +248,21 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                {\r
                        restoreDirty( editor );\r
 \r
+                       // Memorize scroll position to restore it later (#4472).\r
+                       var hostDocument = editor.element.getDocument();\r
+                       var hostDocumentElement = hostDocument.getDocumentElement();\r
+                       var scrollTop = hostDocumentElement.$.scrollTop;\r
+                       var scrollLeft = hostDocumentElement.$.scrollLeft;\r
+\r
                        // Simulating keyboard character input by dispatching a keydown of white-space text.\r
                        var keyEventSimulate = doc.$.createEvent( "KeyEvents" );\r
                        keyEventSimulate.initKeyEvent( 'keypress', true, true, win.$, false,\r
                                false, false, false, 0, 32 );\r
                        doc.$.dispatchEvent( keyEventSimulate );\r
 \r
+                       if ( scrollTop != hostDocumentElement.$.scrollTop || scrollLeft != hostDocumentElement.$.scrollLeft )\r
+                               hostDocument.getWindow().$.scrollTo( scrollLeft, scrollTop );\r
+\r
                        // Restore the original document status by placing the cursor before a bogus br created (#5021).\r
                        bodyChildsNum && body.getFirst().remove();\r
                        doc.getBody().appendBogus();\r
@@ -412,8 +425,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                        ' allowTransparency="true"' +\r
                                                        '></iframe>' );\r
 \r
-                                               // #5689 Running inside of Firefox chrome the load event doesn't bubble like in a normal page\r
-                                               if (document.location.protocol == 'chrome:')\r
+                                               // Running inside of Firefox chrome the load event doesn't bubble like in a normal page (#5689)\r
+                                               if ( document.location.protocol == 'chrome:' )\r
                                                        CKEDITOR.event.useCapture = true;\r
 \r
                                                // With FF, it's better to load the data on iframe.load. (#3894,#4058)\r
@@ -430,11 +443,34 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                doc.close();\r
                                                        });\r
 \r
-                                               // #5689 Reset adjustment back to default\r
-                                               if (document.location.protocol == 'chrome:')\r
+                                               // Reset adjustment back to default (#5689)\r
+                                               if ( document.location.protocol == 'chrome:' )\r
                                                        CKEDITOR.event.useCapture = false;\r
 \r
+                                               // The container must be visible when creating the iframe in FF (#5956)\r
+                                               var element = editor.element,\r
+                                                       isHidden = CKEDITOR.env.gecko && !element.isVisible(),\r
+                                                       previousStyles = {};\r
+                                               if ( isHidden )\r
+                                               {\r
+                                                       element.show();\r
+                                                       previousStyles = {\r
+                                                               position : element.getStyle( 'position' ),\r
+                                                               top : element.getStyle( 'top' )\r
+                                                       };\r
+                                                       element.setStyles( { position : 'absolute', top : '-3000px' } );\r
+                                               }\r
+\r
                                                mainElement.append( iframe );\r
+\r
+                                               if ( isHidden )\r
+                                               {\r
+                                                       setTimeout( function()\r
+                                                       {\r
+                                                               element.hide();\r
+                                                               element.setStyles( previousStyles );\r
+                                                       }, 1000 );\r
+                                               }\r
                                        };\r
 \r
                                        // The script that launches the bootstrap logic on 'domReady', so the document\r