JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.6.4
[ckeditor.git] / _source / plugins / wysiwygarea / plugin.js
index 7657a19..1b81be2 100644 (file)
@@ -13,7 +13,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
        // Matching an empty paragraph at the end of document.\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
+       var notWhitespaceEval = CKEDITOR.dom.walker.whitespaces( true ),\r
+         notBogus = CKEDITOR.dom.walker.bogus( true ),\r
+         notEmpty = function( node ) { return notWhitespaceEval( node ) && notBogus( node ); };\r
 \r
        // Elements that could blink the cursor anchoring beside it, like hr, page-break. (#6554)\r
        function nonEditable( element )\r
@@ -267,16 +269,28 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        {\r
                                range.moveToPosition( lastElement, CKEDITOR.POSITION_AFTER_END );\r
 \r
-                               // If we're inserting a block element immediatelly followed by\r
-                               // another block element, the selection must move there. (#3100,#5436)\r
+                               // If we're inserting a block element immediately followed by\r
+                               // another block element, the selection must be optimized. (#3100,#5436,#8950)\r
                                if ( isBlock )\r
                                {\r
-                                       var next = lastElement.getNext( notWhitespaceEval ),\r
+                                       var next = lastElement.getNext( notEmpty ),\r
                                                nextName = next && next.type == CKEDITOR.NODE_ELEMENT && next.getName();\r
 \r
-                                       // Check if it's a block element that accepts text.\r
-                                       if ( nextName && CKEDITOR.dtd.$block[ nextName ] && CKEDITOR.dtd[ nextName ]['#'] )\r
+                                       // If the next one is a text block, move cursor to the start of it's content.\r
+                                       if ( nextName && CKEDITOR.dtd.$block[ nextName ] )\r
+                                       {\r
+                                               if ( CKEDITOR.dtd[ nextName ][ '#' ] )\r
+                                                       range.moveToElementEditStart( next );\r
+                                               // Otherwise move cursor to the before end of the last element.\r
+                                               else\r
+                                                       range.moveToElementEditEnd( lastElement );\r
+                                       }\r
+                                       // Open a new line if the block is inserted at the end of parent.\r
+                                       else if ( !next )\r
+                                       {\r
+                                               next = range.fixBlock( true, this.config.enterMode == CKEDITOR.ENTER_DIV ? 'div' : 'p' );\r
                                                range.moveToElementEditStart( next );\r
+                                       }\r
                                }\r
                        }\r
 \r
@@ -476,7 +490,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        var fixForBody = ( editor.config.enterMode != CKEDITOR.ENTER_BR && editor.config.autoParagraph !== false )\r
                                ? editor.config.enterMode == CKEDITOR.ENTER_DIV ? 'div' : 'p' : false;\r
 \r
-                       var frameLabel = editor.lang.editorTitle.replace( '%1', editor.name );\r
+                       var frameLabel = editor.lang.editorTitle.replace( '%1', editor.name ),\r
+                               frameDesc = editor.lang.editorHelp;\r
+\r
+                       if ( CKEDITOR.env.ie )\r
+                               frameLabel += ', ' + frameDesc;\r
 \r
                        var win = CKEDITOR.document.getWindow();\r
                        var contentDomReadyHandler;\r
@@ -520,10 +538,12 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                        :\r
                                                                '';\r
 \r
+                                               var labelId = CKEDITOR.tools.getNextId();\r
                                                iframe = CKEDITOR.dom.element.createFromHtml( '<iframe' +\r
                                                        ' style="width:100%;height:100%"' +\r
                                                        ' frameBorder="0"' +\r
-                                                       ' title="' + frameLabel + '"' +\r
+                                                       ' aria-describedby="' + labelId + '"' +\r
+                                                       ' title="' + frameLabel + '"' +\r
                                                        ' src="' + src + '"' +\r
                                                        ' tabIndex="' + ( CKEDITOR.env.webkit? -1 : editor.tabIndex ) + '"' +\r
                                                        ' allowTransparency="true"' +\r
@@ -549,6 +569,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                if ( document.location.protocol == 'chrome:' )\r
                                                        CKEDITOR.event.useCapture = false;\r
 \r
+                                               mainElement.append( CKEDITOR.dom.element.createFromHtml(\r
+                                                       '<span id="' + labelId + '" class="cke_voice_label">' + frameDesc + '</span>'));\r
+\r
                                                mainElement.append( iframe );\r
 \r
                                                // Webkit: iframe size doesn't auto fit well. (#7360)\r
@@ -556,8 +579,12 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                {\r
                                                        onResize = function()\r
                                                        {\r
+                                                               // Hide the iframe to get real size of the holder. (#8941)\r
+                                                               mainElement.setStyle( 'width', '100%' );\r
                                                                iframe.hide();\r
+\r
                                                                iframe.setSize( 'width', mainElement.getSize( 'width' ) );\r
+                                                               mainElement.removeStyle( 'width' );\r
                                                                iframe.show();\r
                                                        };\r
 \r
@@ -718,9 +745,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                        {\r
                                                                var doc = editor.document;\r
 \r
-                                                               if ( editable && CKEDITOR.env.gecko && CKEDITOR.env.version >= 10900 )\r
-                                                                       blinkCursor();\r
-                                                               else if ( CKEDITOR.env.opera )\r
+                                                               if ( CKEDITOR.env.gecko || 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
@@ -751,7 +776,12 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                        {\r
                                                                var sel = editor.getSelection(),\r
                                                                        selected = sel.getSelectedElement(),\r
-                                                                       range  = sel.getRanges()[ 0 ];\r
+                                                                       range = sel.getRanges()[ 0 ],\r
+                                                                       path = new CKEDITOR.dom.elementPath( range.startContainer ),\r
+                                                                       block,\r
+                                                                       parent,\r
+                                                                       next,\r
+                                                                       rtl = keyCode == 8;\r
 \r
                                                                // Override keystrokes which should have deletion behavior\r
                                                                //  on fully selected element . (#4047) (#7645)\r
@@ -770,7 +800,52 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                        editor.fire( 'saveSnapshot' );\r
 \r
                                                                        evt.data.preventDefault();\r
-                                                                       return;\r
+                                                               }\r
+                                                               else\r
+                                                               {\r
+                                                                       // Handle the following special cases: (#6217)\r
+                                                                       // 1. Del/Backspace key before/after table;\r
+                                                                       // 2. Backspace Key after start of table.\r
+                                                                       if ( ( block = path.block ) &&\r
+                                                                                range[ rtl ? 'checkStartOfBlock' : 'checkEndOfBlock' ]() &&\r
+                                                                                ( next = block[ rtl ? 'getPrevious' : 'getNext' ]( notWhitespaceEval ) ) &&\r
+                                                                                next.is( 'table' ) )\r
+                                                                       {\r
+                                                                               editor.fire( 'saveSnapshot' );\r
+\r
+                                                                               // Remove the current empty block.\r
+                                                                               if ( range[ rtl ? 'checkEndOfBlock' : 'checkStartOfBlock' ]() )\r
+                                                                                       block.remove();\r
+\r
+                                                                               // Move cursor to the beginning/end of table cell.\r
+                                                                               range[ 'moveToElementEdit' + ( rtl ? 'End' : 'Start' ) ]( next );\r
+                                                                               range.select();\r
+\r
+                                                                               editor.fire( 'saveSnapshot' );\r
+\r
+                                                                               evt.data.preventDefault();\r
+                                                                       }\r
+                                                                       else if ( path.blockLimit.is( 'td' ) &&\r
+                                                                                         ( parent = path.blockLimit.getAscendant( 'table' ) ) &&\r
+                                                                                         range.checkBoundaryOfElement( parent, rtl ? CKEDITOR.START : CKEDITOR.END ) &&\r
+                                                                                         ( next = parent[ rtl ? 'getPrevious' : 'getNext' ]( notWhitespaceEval ) ) )\r
+                                                                       {\r
+                                                                               editor.fire( 'saveSnapshot' );\r
+\r
+                                                                               // Move cursor to the end of previous block.\r
+                                                                               range[ 'moveToElementEdit' + ( rtl ? 'End' : 'Start' ) ]( next );\r
+\r
+                                                                               // Remove any previous empty block.\r
+                                                                               if ( range.checkStartOfBlock() && range.checkEndOfBlock() )\r
+                                                                                       next.remove();\r
+                                                                               else\r
+                                                                                       range.select();\r
+\r
+                                                                               editor.fire( 'saveSnapshot' );\r
+\r
+                                                                               evt.data.preventDefault();\r
+                                                                       }\r
+\r
                                                                }\r
                                                        }\r
 \r
@@ -868,6 +943,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                        editor.fire( 'dataReady' );\r
                                                                }, 0 );\r
 \r
+                                                               // Enable dragging of position:absolute elements in IE.\r
+                                                               try { editor.document.$.execCommand ( '2D-position', false, true); } catch(e) {}\r
+\r
                                                                // IE, Opera and Safari may not support it and throw errors.\r
                                                                try { editor.document.$.execCommand( 'enableInlineTableEditing', false, !editor.config.disableNativeTableHandles ); } catch(e) {}\r
                                                                if ( editor.config.disableObjectResizing )\r
@@ -1112,6 +1190,15 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                        isPendingFocus = true;\r
                                                                else if ( win )\r
                                                                {\r
+                                                                       var sel = editor.getSelection(),\r
+                                                                               ieSel = sel && sel.getNative();\r
+\r
+                                                                       // IE considers control-type element as separate\r
+                                                                       // focus host when selected, avoid destroying the\r
+                                                                       // selection in such case. (#5812) (#8949)\r
+                                                                       if ( ieSel && ieSel.type == 'Control' )\r
+                                                                               return;\r
+\r
                                                                        // AIR needs a while to focus when moving from a link.\r
                                                                        CKEDITOR.env.air ? setTimeout( function () { win.focus(); }, 0 ) : win.focus();\r
                                                                        editor.selectionChange();\r
@@ -1142,14 +1229,15 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                        }, null, null, 1 );\r
                                });\r
 \r
-                       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
                                {\r
                                        var title = editor.document.getElementsByTag( 'title' ).getItem( 0 );\r
                                        title.data( 'cke-title', editor.document.$.title );\r
-                                       editor.document.$.title = frameLabel;\r
+\r
+                                       // [IE] JAWS will not recognize the aria label we used on the iframe\r
+                                       // unless the frame window title string is used as the voice label,\r
+                                       // backup the original one and restore it on output.\r
+                                       CKEDITOR.env.ie && ( editor.document.$.title = frameLabel );\r
                                });\r
 \r
                        editor.on( 'readOnly', function()\r
@@ -1177,7 +1265,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        else if ( CKEDITOR.env.gecko )\r
                        {\r
                                editor.addCss( 'html { height: 100% !important; }' );\r
-                               editor.addCss( 'img:-moz-broken { -moz-force-broken-image-icon : 1;     width : 24px; height : 24px; }' );\r
+                               editor.addCss( 'img:-moz-broken { -moz-force-broken-image-icon : 1;     min-width : 24px; min-height : 24px; }' );\r
                        }\r
                        // Remove the margin to avoid mouse confusion. (#8835)\r
                        else if ( CKEDITOR.env.ie && CKEDITOR.env.version < 8 && editor.config.contentsLangDirection == 'ltr' )\r
@@ -1191,37 +1279,6 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        // Use correct cursor for these elements\r
                        editor.addCss( 'img, input, textarea { cursor: default;}' );\r
 \r
-                       // Switch on design mode for a short while and close it after then.\r
-                       function blinkCursor( retry )\r
-                       {\r
-                               if ( editor.readOnly )\r
-                                       return;\r
-\r
-                               CKEDITOR.tools.tryThese(\r
-                                       function()\r
-                                       {\r
-                                               editor.document.$.designMode = 'on';\r
-                                               setTimeout( function()\r
-                                               {\r
-                                                       editor.document.$.designMode = 'off';\r
-                                                       if ( CKEDITOR.currentInstance == editor )\r
-                                                               editor.document.getBody().focus();\r
-                                               }, 50 );\r
-                                       },\r
-                                       function()\r
-                                       {\r
-                                               // The above call is known to fail when parent DOM\r
-                                               // tree layout changes may break design mode. (#5782)\r
-                                               // Refresh the 'contentEditable' is a cue to this.\r
-                                               editor.document.$.designMode = 'off';\r
-                                               var body = editor.document.getBody();\r
-                                               body.setAttribute( 'contentEditable', false );\r
-                                               body.setAttribute( 'contentEditable', true );\r
-                                               // Try it again once..\r
-                                               !retry && blinkCursor( 1 );\r
-                                       });\r
-                       }\r
-\r
                        // Disable form elements editing mode provided by some browers. (#5746)\r
                        editor.on( 'insertElement', function ( evt )\r
                        {\r