Importation du code de ckeditor 4.3.4 en conservant les développements Plinn et en...
[ckeditor.git] / skins / ckeditor / _source / plugins / enterkey / plugin.js
diff --git a/skins/ckeditor/_source/plugins/enterkey/plugin.js b/skins/ckeditor/_source/plugins/enterkey/plugin.js
deleted file mode 100644 (file)
index 59a4f82..0000000
+++ /dev/null
@@ -1,413 +0,0 @@
-/*\r
-Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.\r
-For licensing, see LICENSE.html or http://ckeditor.com/license\r
-*/\r
-\r
-(function()\r
-{\r
-       CKEDITOR.plugins.add( 'enterkey',\r
-       {\r
-               requires : [ 'keystrokes', 'indent' ],\r
-\r
-               init : function( editor )\r
-               {\r
-                       editor.addCommand( 'enter', {\r
-                               modes : { wysiwyg:1 },\r
-                               editorFocus : false,\r
-                               exec : function( editor ){ enter( editor ); }\r
-                       });\r
-\r
-                       editor.addCommand( 'shiftEnter', {\r
-                               modes : { wysiwyg:1 },\r
-                               editorFocus : false,\r
-                               exec : function( editor ){ shiftEnter( editor ); }\r
-                       });\r
-\r
-                       var keystrokes = editor.keystrokeHandler.keystrokes;\r
-                       keystrokes[ 13 ] = 'enter';\r
-                       keystrokes[ CKEDITOR.SHIFT + 13 ] = 'shiftEnter';\r
-               }\r
-       });\r
-\r
-       CKEDITOR.plugins.enterkey =\r
-       {\r
-               enterBlock : function( editor, mode, range, forceMode )\r
-               {\r
-                       // Get the range for the current selection.\r
-                       range = range || getRange( editor );\r
-\r
-                       // We may not have valid ranges to work on, like when inside a\r
-                       // contenteditable=false element.\r
-                       if ( !range )\r
-                               return;\r
-\r
-                       var doc = range.document;\r
-\r
-                       var atBlockStart = range.checkStartOfBlock(),\r
-                               atBlockEnd = range.checkEndOfBlock(),\r
-                               path = new CKEDITOR.dom.elementPath( range.startContainer ),\r
-                               block = path.block;\r
-\r
-                       // Exit the list when we're inside an empty list item block. (#5376)\r
-                       if ( atBlockStart && atBlockEnd )\r
-                       {\r
-                               if ( block && ( block.is( 'li' ) || block.getParent().is( 'li' ) ) )\r
-                               {\r
-                                       editor.execCommand( 'outdent' );\r
-                                       return;\r
-                               }\r
-                       }\r
-                       // Don't split <pre> if we're in the middle of it, act as shift enter key.\r
-                       else if ( block && block.is( 'pre' ) )\r
-                       {\r
-                               if ( !atBlockEnd )\r
-                               {\r
-                                       enterBr( editor, mode, range, forceMode );\r
-                                       return;\r
-                               }\r
-                       }\r
-                       // Don't split caption blocks. (#7944)\r
-                       else if ( block && CKEDITOR.dtd.$captionBlock[ block.getName() ] )\r
-                       {\r
-                               enterBr( editor, mode, range, forceMode );\r
-                               return;\r
-                       }\r
-\r
-                       // Determine the block element to be used.\r
-                       var blockTag = ( mode == CKEDITOR.ENTER_DIV ? 'div' : 'p' );\r
-\r
-                       // Split the range.\r
-                       var splitInfo = range.splitBlock( blockTag );\r
-\r
-                       if ( !splitInfo )\r
-                               return;\r
-\r
-                       // Get the current blocks.\r
-                       var previousBlock       = splitInfo.previousBlock,\r
-                               nextBlock               = splitInfo.nextBlock;\r
-\r
-                       var isStartOfBlock      = splitInfo.wasStartOfBlock,\r
-                               isEndOfBlock    = splitInfo.wasEndOfBlock;\r
-\r
-                       var node;\r
-\r
-                       // If this is a block under a list item, split it as well. (#1647)\r
-                       if ( nextBlock )\r
-                       {\r
-                               node = nextBlock.getParent();\r
-                               if ( node.is( 'li' ) )\r
-                               {\r
-                                       nextBlock.breakParent( node );\r
-                                       nextBlock.move( nextBlock.getNext(), 1 );\r
-                               }\r
-                       }\r
-                       else if ( previousBlock && ( node = previousBlock.getParent() ) && node.is( 'li' ) )\r
-                       {\r
-                               previousBlock.breakParent( node );\r
-                               node = previousBlock.getNext();\r
-                               range.moveToElementEditStart( node );\r
-                               previousBlock.move( previousBlock.getPrevious() );\r
-                       }\r
-\r
-                       // If we have both the previous and next blocks, it means that the\r
-                       // boundaries were on separated blocks, or none of them where on the\r
-                       // block limits (start/end).\r
-                       if ( !isStartOfBlock && !isEndOfBlock )\r
-                       {\r
-                               // If the next block is an <li> with another list tree as the first\r
-                               // child, we'll need to append a filler (<br>/NBSP) or the list item\r
-                               // wouldn't be editable. (#1420)\r
-                               if ( nextBlock.is( 'li' )\r
-                                        && ( node = nextBlock.getFirst( CKEDITOR.dom.walker.invisible( true ) ) )\r
-                                        && node.is && node.is( 'ul', 'ol' ) )\r
-                                       ( CKEDITOR.env.ie ? doc.createText( '\xa0' ) : doc.createElement( 'br' ) ).insertBefore( node );\r
-\r
-                               // Move the selection to the end block.\r
-                               if ( nextBlock )\r
-                                       range.moveToElementEditStart( nextBlock );\r
-                       }\r
-                       else\r
-                       {\r
-                               var newBlock,\r
-                                       newBlockDir;\r
-\r
-                               if ( previousBlock )\r
-                               {\r
-                                       // Do not enter this block if it's a header tag, or we are in\r
-                                       // a Shift+Enter (#77). Create a new block element instead\r
-                                       // (later in the code).\r
-                                       if ( previousBlock.is( 'li' ) ||\r
-                                                       ! ( headerTagRegex.test( previousBlock.getName() ) || previousBlock.is( 'pre' ) ) )\r
-                                       {\r
-                                               // Otherwise, duplicate the previous block.\r
-                                               newBlock = previousBlock.clone();\r
-                                       }\r
-                               }\r
-                               else if ( nextBlock )\r
-                                       newBlock = nextBlock.clone();\r
-\r
-                               if ( !newBlock )\r
-                               {\r
-                                       // We have already created a new list item. (#6849)\r
-                                       if ( node && node.is( 'li' ) )\r
-                                               newBlock = node;\r
-                                       else\r
-                                       {\r
-                                               newBlock = doc.createElement( blockTag );\r
-                                               if ( previousBlock && ( newBlockDir = previousBlock.getDirection() ) )\r
-                                                       newBlock.setAttribute( 'dir', newBlockDir );\r
-                                       }\r
-                               }\r
-                               // Force the enter block unless we're talking of a list item.\r
-                               else if ( forceMode && !newBlock.is( 'li' ) )\r
-                                       newBlock.renameNode( blockTag );\r
-\r
-                               // Recreate the inline elements tree, which was available\r
-                               // before hitting enter, so the same styles will be available in\r
-                               // the new block.\r
-                               var elementPath = splitInfo.elementPath;\r
-                               if ( elementPath )\r
-                               {\r
-                                       for ( var i = 0, len = elementPath.elements.length ; i < len ; i++ )\r
-                                       {\r
-                                               var element = elementPath.elements[ i ];\r
-\r
-                                               if ( element.equals( elementPath.block ) || element.equals( elementPath.blockLimit ) )\r
-                                                       break;\r
-\r
-                                               if ( CKEDITOR.dtd.$removeEmpty[ element.getName() ] )\r
-                                               {\r
-                                                       element = element.clone();\r
-                                                       newBlock.moveChildren( element );\r
-                                                       newBlock.append( element );\r
-                                               }\r
-                                       }\r
-                               }\r
-\r
-                               if ( !CKEDITOR.env.ie )\r
-                                       newBlock.appendBogus();\r
-\r
-                               if ( !newBlock.getParent() )\r
-                                       range.insertNode( newBlock );\r
-\r
-                               // list item start number should not be duplicated (#7330), but we need\r
-                               // to remove the attribute after it's onto the DOM tree because of old IEs (#7581).\r
-                               newBlock.is( 'li' ) && newBlock.removeAttribute( 'value' );\r
-\r
-                               // This is tricky, but to make the new block visible correctly\r
-                               // we must select it.\r
-                               // The previousBlock check has been included because it may be\r
-                               // empty if we have fixed a block-less space (like ENTER into an\r
-                               // empty table cell).\r
-                               if ( CKEDITOR.env.ie && isStartOfBlock && ( !isEndOfBlock || !previousBlock.getChildCount() ) )\r
-                               {\r
-                                       // Move the selection to the new block.\r
-                                       range.moveToElementEditStart( isEndOfBlock ? previousBlock : newBlock );\r
-                                       range.select();\r
-                               }\r
-\r
-                               // Move the selection to the new block.\r
-                               range.moveToElementEditStart( isStartOfBlock && !isEndOfBlock ? nextBlock : newBlock );\r
-               }\r
-\r
-                       if ( !CKEDITOR.env.ie )\r
-                       {\r
-                               if ( nextBlock )\r
-                               {\r
-                                       // If we have split the block, adds a temporary span at the\r
-                                       // range position and scroll relatively to it.\r
-                                       var tmpNode = doc.createElement( 'span' );\r
-\r
-                                       // We need some content for Safari.\r
-                                       tmpNode.setHtml( '&nbsp;' );\r
-\r
-                                       range.insertNode( tmpNode );\r
-                                       tmpNode.scrollIntoView();\r
-                                       range.deleteContents();\r
-                               }\r
-                               else\r
-                               {\r
-                                       // We may use the above scroll logic for the new block case\r
-                                       // too, but it gives some weird result with Opera.\r
-                                       newBlock.scrollIntoView();\r
-                               }\r
-                       }\r
-\r
-                       range.select();\r
-               },\r
-\r
-               enterBr : function( editor, mode, range, forceMode )\r
-               {\r
-                       // Get the range for the current selection.\r
-                       range = range || getRange( editor );\r
-\r
-                       // We may not have valid ranges to work on, like when inside a\r
-                       // contenteditable=false element.\r
-                       if ( !range )\r
-                               return;\r
-\r
-                       var doc = range.document;\r
-\r
-                       // Determine the block element to be used.\r
-                       var blockTag = ( mode == CKEDITOR.ENTER_DIV ? 'div' : 'p' );\r
-\r
-                       var isEndOfBlock = range.checkEndOfBlock();\r
-\r
-                       var elementPath = new CKEDITOR.dom.elementPath( editor.getSelection().getStartElement() );\r
-\r
-                       var startBlock = elementPath.block,\r
-                               startBlockTag = startBlock && elementPath.block.getName();\r
-\r
-                       var isPre = false;\r
-\r
-                       if ( !forceMode && startBlockTag == 'li' )\r
-                       {\r
-                               enterBlock( editor, mode, range, forceMode );\r
-                               return;\r
-                       }\r
-\r
-                       // If we are at the end of a header block.\r
-                       if ( !forceMode && isEndOfBlock && headerTagRegex.test( startBlockTag ) )\r
-                       {\r
-                               var newBlock,\r
-                                       newBlockDir;\r
-\r
-                               if ( ( newBlockDir = startBlock.getDirection() ) )\r
-                               {\r
-                                       newBlock = doc.createElement( 'div' );\r
-                                       newBlock.setAttribute( 'dir', newBlockDir );\r
-                                       newBlock.insertAfter( startBlock );\r
-                                       range.setStart( newBlock, 0 );\r
-                               }\r
-                               else\r
-                               {\r
-                                       // Insert a <br> after the current paragraph.\r
-                                       doc.createElement( 'br' ).insertAfter( startBlock );\r
-\r
-                                       // A text node is required by Gecko only to make the cursor blink.\r
-                                       if ( CKEDITOR.env.gecko )\r
-                                               doc.createText( '' ).insertAfter( startBlock );\r
-\r
-                                       // IE has different behaviors regarding position.\r
-                                       range.setStartAt( startBlock.getNext(), CKEDITOR.env.ie ? CKEDITOR.POSITION_BEFORE_START : CKEDITOR.POSITION_AFTER_START );\r
-                               }\r
-                       }\r
-                       else\r
-                       {\r
-                               var lineBreak;\r
-\r
-                               isPre = ( startBlockTag == 'pre' );\r
-\r
-                               // Gecko prefers <br> as line-break inside <pre> (#4711).\r
-                               if ( isPre && !CKEDITOR.env.gecko )\r
-                                       lineBreak = doc.createText( CKEDITOR.env.ie ? '\r' : '\n' );\r
-                               else\r
-                                       lineBreak = doc.createElement( 'br' );\r
-\r
-                               range.deleteContents();\r
-                               range.insertNode( lineBreak );\r
-\r
-                               // IE has different behavior regarding position.\r
-                               if ( CKEDITOR.env.ie )\r
-                                       range.setStartAt( lineBreak, CKEDITOR.POSITION_AFTER_END );\r
-                               else\r
-                               {\r
-                                       // A text node is required by Gecko only to make the cursor blink.\r
-                                       // We need some text inside of it, so the bogus <br> is properly\r
-                                       // created.\r
-                                       doc.createText( '\ufeff' ).insertAfter( lineBreak );\r
-\r
-                                       // If we are at the end of a block, we must be sure the bogus node is available in that block.\r
-                                       if ( isEndOfBlock )\r
-                                               lineBreak.getParent().appendBogus();\r
-\r
-                                       // Now we can remove the text node contents, so the caret doesn't\r
-                                       // stop on it.\r
-                                       lineBreak.getNext().$.nodeValue = '';\r
-\r
-                                       range.setStartAt( lineBreak.getNext(), CKEDITOR.POSITION_AFTER_START );\r
-\r
-                                       // Scroll into view, for non IE.\r
-                                       var dummy = null;\r
-\r
-                                       // BR is not positioned in Opera and Webkit.\r
-                                       if ( !CKEDITOR.env.gecko )\r
-                                       {\r
-                                               dummy = doc.createElement( 'span' );\r
-                                               // We need have some contents for Webkit to position it\r
-                                               // under parent node. ( #3681)\r
-                                               dummy.setHtml('&nbsp;');\r
-                                       }\r
-                                       else\r
-                                               dummy = doc.createElement( 'br' );\r
-\r
-                                       dummy.insertBefore( lineBreak.getNext() );\r
-                                       dummy.scrollIntoView();\r
-                                       dummy.remove();\r
-                               }\r
-                       }\r
-\r
-                       // This collapse guarantees the cursor will be blinking.\r
-                       range.collapse( true );\r
-\r
-                       range.select( isPre );\r
-               }\r
-       };\r
-\r
-       var plugin = CKEDITOR.plugins.enterkey,\r
-               enterBr = plugin.enterBr,\r
-               enterBlock = plugin.enterBlock,\r
-               headerTagRegex = /^h[1-6]$/;\r
-\r
-       function shiftEnter( editor )\r
-       {\r
-               // Only effective within document.\r
-               if ( editor.mode != 'wysiwyg' )\r
-                       return false;\r
-\r
-               // On SHIFT+ENTER:\r
-               // 1. We want to enforce the mode to be respected, instead\r
-               // of cloning the current block. (#77)\r
-               return enter( editor, editor.config.shiftEnterMode, 1 );\r
-       }\r
-\r
-       function enter( editor, mode, forceMode )\r
-       {\r
-               forceMode = editor.config.forceEnterMode || forceMode;\r
-\r
-               // Only effective within document.\r
-               if ( editor.mode != 'wysiwyg' )\r
-                       return false;\r
-\r
-               if ( !mode )\r
-                       mode = editor.config.enterMode;\r
-\r
-               // Use setTimout so the keys get cancelled immediatelly.\r
-               setTimeout( function()\r
-                       {\r
-                               editor.fire( 'saveSnapshot' );  // Save undo step.\r
-                               if ( mode == CKEDITOR.ENTER_BR )\r
-                                       enterBr( editor, mode, null, forceMode );\r
-                               else\r
-                                       enterBlock( editor, mode, null, forceMode );\r
-\r
-                       }, 0 );\r
-\r
-               return true;\r
-       }\r
-\r
-       function getRange( editor )\r
-       {\r
-               // Get the selection ranges.\r
-               var ranges = editor.getSelection().getRanges( true );\r
-\r
-               // Delete the contents of all ranges except the first one.\r
-               for ( var i = ranges.length - 1 ; i > 0 ; i-- )\r
-               {\r
-                       ranges[ i ].deleteContents();\r
-               }\r
-\r
-               // Return the first range.\r
-               return ranges[ 0 ];\r
-       }\r
-})();\r