JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.3
[ckeditor.git] / _source / plugins / wysiwygarea / plugin.js
index a6b0639..ed278c7 100644 (file)
@@ -319,7 +319,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                        // for other browers, the 'src' attribute should be left empty to\r
                                                        // trigger iframe's 'load' event.\r
                                                        ' src="' + ( CKEDITOR.env.ie ? 'javascript:void(function(){' + encodeURIComponent( srcScript ) + '}())' : '' ) + '"' +\r
-                                                       ' tabIndex="' + editor.tabIndex + '"' +\r
+                                                       ' tabIndex="' + ( CKEDITOR.env.webkit? -1 : editor.tabIndex ) + '"' +\r
                                                        ' allowTransparency="true"' +\r
                                                        '></iframe>' );\r
 \r
@@ -380,30 +380,42 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                }\r
                                                else\r
                                                {\r
-                                                       // Gecko need a key event to 'wake up' the editing\r
-                                                       // ability when document is empty.(#3864)\r
-                                                       if ( CKEDITOR.env.gecko && !body.childNodes.length )\r
+                                                       // Avoid opening design mode in a frame window thread,\r
+                                                       // which will cause host page scrolling.(#4397)\r
+                                                       setTimeout( function()\r
                                                        {\r
-                                                               setTimeout( function()\r
-                                                               {\r
-                                                                       restoreDirty( editor );\r
-\r
-                                                                       // Simulating keyboard character input by dispatching a keydown of white-space text.\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
-\r
-                                                                       // Restore the original document status by placing the cursor before a bogus br created (#5021).\r
-                                                                       domDocument.createElement( 'br', { attributes: { '_moz_editor_bogus_node' : 'TRUE', '_moz_dirty' : "" } } )\r
-                                                                               .replace( domDocument.getBody().getFirst() );\r
-                                                                       var nativeRange = new CKEDITOR.dom.range( domDocument );\r
-                                                                       nativeRange.setStartAt( new CKEDITOR.dom.element( body ) , CKEDITOR.POSITION_AFTER_START );\r
-                                                                       nativeRange.select();\r
-                                                               }, 0 );\r
-                                                       }\r
+                                                               // Prefer 'contentEditable' instead of 'designMode'. (#3593)\r
+                                                               if ( CKEDITOR.env.gecko && CKEDITOR.env.version >= 10900\r
+                                                                               || CKEDITOR.env.opera )\r
+                                                                       domDocument.$.body.contentEditable = true;\r
+                                                               else if ( CKEDITOR.env.webkit )\r
+                                                                       domDocument.$.body.parentNode.contentEditable = true;\r
+                                                               else\r
+                                                                       domDocument.$.designMode = 'on';\r
+                                                       }, 0 );\r
+                                               }\r
 \r
-                                                       domDocument.designMode = 'on';\r
+                                               // Gecko need a key event to 'wake up' the editing\r
+                                               // ability when document is empty.(#3864)\r
+                                               if ( CKEDITOR.env.gecko && !body.childNodes.length )\r
+                                               {\r
+                                                       setTimeout( function()\r
+                                                       {\r
+                                                               restoreDirty( editor );\r
+\r
+                                                               // Simulating keyboard character input by dispatching a keydown of white-space text.\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
+\r
+                                                               // Restore the original document status by placing the cursor before a bogus br created (#5021).\r
+                                                               domDocument.createElement( 'br', { attributes: { '_moz_editor_bogus_node' : 'TRUE', '_moz_dirty' : "" } } )\r
+                                                                       .replace( domDocument.getBody().getFirst() );\r
+                                                               var nativeRange = new CKEDITOR.dom.range( domDocument );\r
+                                                               nativeRange.setStartAt( new CKEDITOR.dom.element( body ) , CKEDITOR.POSITION_AFTER_START );\r
+                                                               nativeRange.select();\r
+                                                       }, 0 );\r
                                                }\r
 \r
                                                // IE, Opera and Safari may not support it and throw\r
@@ -414,6 +426,14 @@ 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
+                                               domDocument.on( 'dblclick', function( evt )\r
+                                               {\r
+                                                       var element = evt.data.getTarget(),\r
+                                                               data = { element : element, dialog : '' };\r
+                                                       editor.fire( 'doubleclick', data );\r
+                                                       data.dialog && editor.openDialog( data.dialog );\r
+                                               });\r
+\r
                                                // Gecko/Webkit need some help when selecting control type elements. (#3448)\r
                                                if ( !( CKEDITOR.env.ie || CKEDITOR.env.opera) )\r
                                                {\r
@@ -446,7 +466,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                // IE standard compliant in editing frame doesn't focus the editor when\r
                                                // clicking outside actual content, manually apply the focus. (#1659)\r
                                                if ( CKEDITOR.env.ie\r
-                                                       && domDocument.$.compatMode == 'CSS1Compat' )\r
+                                                       && domDocument.$.compatMode == 'CSS1Compat'\r
+                                                               || CKEDITOR.env.gecko\r
+                                                               || CKEDITOR.env.opera )\r
                                                {\r
                                                        var htmlElement = domDocument.getDocumentElement();\r
                                                        htmlElement.on( 'mousedown', function( evt )\r
@@ -455,20 +477,35 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                // have to use here a temporary element to 'redirect'\r
                                                                // the focus.\r
                                                                if ( evt.data.getTarget().equals( htmlElement ) )\r
-                                                                       ieFocusGrabber.focus();\r
+                                                               {\r
+                                                                       CKEDITOR.env.gecko && blinkCursor();\r
+                                                                       focusGrabber.focus();\r
+                                                               }\r
                                                        } );\r
                                                }\r
 \r
-                                               var focusTarget = ( CKEDITOR.env.ie || CKEDITOR.env.webkit ) ?\r
-                                                               domWindow : domDocument;\r
-\r
-                                               focusTarget.on( 'blur', function()\r
+                                               domWindow.on( 'blur', function()\r
                                                        {\r
                                                                editor.focusManager.blur();\r
                                                        });\r
 \r
-                                               focusTarget.on( 'focus', function()\r
+                                               domWindow.on( 'focus', function()\r
                                                        {\r
+                                                               var doc = editor.document;\r
+                                                               if ( CKEDITOR.env.gecko || CKEDITOR.env.opera )\r
+                                                                       doc.getBody().focus();\r
+                                                               else if ( CKEDITOR.env.webkit )\r
+                                                               {\r
+                                                                       // Selection will get lost after move focus\r
+                                                                       // to document element, save it first.\r
+                                                                       var sel = editor.getSelection(),\r
+                                                                                       type = sel.getType(),\r
+                                                                                       range = ( type != CKEDITOR.SELECTION_NONE ) && sel.getRanges()[ 0 ];\r
+\r
+                                                                       doc.getDocumentElement().focus();\r
+                                                                       range && range.select();\r
+                                                               }\r
+\r
                                                                editor.focusManager.focus();\r
                                                        });\r
 \r
@@ -478,6 +515,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
                                                if ( CKEDITOR.env.ie )\r
                                                {\r
+                                                       domDocument.getDocumentElement().addClass( domDocument.$.compatMode );\r
                                                        // Override keystrokes which should have deletion behavior\r
                                                        //  on control types in IE . (#4047)\r
                                                        domDocument.on( 'keydown', function( evt )\r
@@ -753,6 +791,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                else if ( editor.window )\r
                                                                {\r
                                                                        editor.window.focus();\r
+\r
                                                                        editor.selectionChange();\r
                                                                }\r
                                                        }\r
@@ -774,18 +813,32 @@ 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
+                       // on element unless it has layout. (#5562)\r
+                       if ( CKEDITOR.env.ie8 )\r
+                               editor.addCss( 'html.CSS1Compat [contenteditable=false]{ min-height:0 !important;}' );\r
+\r
+                       // Switch on design mode for a short while and close it after then.\r
+                       function blinkCursor()\r
+                       {\r
+                               editor.document.$.designMode = 'on';\r
+                               setTimeout( function ()\r
+                               {\r
+                                       editor.document.$.designMode = 'off';\r
+                               }, 50 );\r
+                       }\r
 \r
                        // Create an invisible element to grab focus.\r
-                       if ( CKEDITOR.env.ie )\r
+                       if ( CKEDITOR.env.gecko || CKEDITOR.env.ie || CKEDITOR.env.opera )\r
                        {\r
-                               var ieFocusGrabber;\r
+                               var focusGrabber;\r
                                editor.on( 'uiReady', function()\r
                                {\r
-                                       ieFocusGrabber = editor.container.append( CKEDITOR.dom.element.createFromHtml(\r
+                                       focusGrabber = editor.container.append( CKEDITOR.dom.element.createFromHtml(\r
                                                // Use 'span' instead of anything else to fly under the screen-reader radar. (#5049)\r
                                                '<span tabindex="-1" style="position:absolute; left:-10000" role="presentation"></span>' ) );\r
 \r
-                                       ieFocusGrabber.on( 'focus', function()\r
+                                       focusGrabber.on( 'focus', function()\r
                                                {\r
                                                        editor.focus();\r
                                                } );\r
@@ -793,9 +846,21 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                editor.on( 'destroy', function()\r
                                {\r
                                        CKEDITOR.tools.removeFunction( contentDomReadyHandler );\r
-                                       ieFocusGrabber.clearCustomData();\r
+                                       focusGrabber.clearCustomData();\r
                                } );\r
                        }\r
+\r
+                       // Disable form elements editing mode provided by some browers. (#5746)\r
+                       editor.on( 'insertElement', function ( evt )\r
+                       {\r
+                               var element = evt.data;\r
+                               if ( element.type = CKEDITOR.NODE_ELEMENT\r
+                                               && ( element.is( 'input' ) || element.is( 'textarea' ) ) )\r
+                               {\r
+                                       element.setAttribute( 'contentEditable', false );\r
+                               }\r
+                       });\r
+\r
                }\r
        });\r
 \r