X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fwysiwygarea%2Fplugin.js;h=deff9758a0d97424141adbdd2a8d417ef65ad35d;hb=refs%2Ftags%2Fv3.3.2;hp=5a0aca8a52abf45008298dbc85dc4a19ee8b63b7;hpb=66f4ae0bf0280ed56bf7c0f4ab175424dd1d47a0;p=ckeditor.git diff --git a/_source/plugins/wysiwygarea/plugin.js b/_source/plugins/wysiwygarea/plugin.js index 5a0aca8..deff975 100644 --- a/_source/plugins/wysiwygarea/plugin.js +++ b/_source/plugins/wysiwygarea/plugin.js @@ -14,7 +14,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license var nonExitableElementNames = { table:1,pre:1 }; // Matching an empty paragraph at the end of document. - var emptyParagraphRegexp = /\s*<(p|div|address|h\d|center)[^>]*>\s*(?:]*>| |\u00A0| )?\s*(:?<\/\1>)?\s*(?=$|<\/body>)/gi; + var emptyParagraphRegexp = /\s*<(p|div|address|h\d|center|li)[^>]*>\s*(?:]*>| |\u00A0| )?\s*(:?<\/\1>)?\s*(?=$|<\/body>)/gi; + + var notWhitespaceEval = CKEDITOR.dom.walker.whitespaces( true ); function onInsertHtml( evt ) { @@ -47,6 +49,15 @@ For licensing, see LICENSE.html or http://ckeditor.com/license else this.document.$.execCommand( 'inserthtml', false, data ); + // Webkit does not scroll to the cursor position after pasting (#5558) + if ( CKEDITOR.env.webkit ) + { + this.document.$.execCommand( 'inserthtml', false, '' ); + var marker = this.document.getById( 'cke_paste_marker' ); + marker.scrollIntoView(); + marker.remove(); + } + CKEDITOR.tools.setTimeout( function() { this.fire( 'saveSnapshot' ); @@ -121,9 +132,17 @@ For licensing, see LICENSE.html or http://ckeditor.com/license range.moveToPosition( lastElement, CKEDITOR.POSITION_AFTER_END ); - var next = lastElement.getNextSourceNode( true ); - if ( next && next.type == CKEDITOR.NODE_ELEMENT ) - range.moveToElementEditStart( next ); + // If we're inserting a block element immediatelly followed by + // another block element, the selection must move there. (#3100,#5436) + if ( isBlock ) + { + var next = lastElement.getNext( notWhitespaceEval ), + nextName = next && next.type == CKEDITOR.NODE_ELEMENT && next.getName(); + + // Check if it's a block element that accepts text. + if ( nextName && CKEDITOR.dtd.$block[ nextName ] && CKEDITOR.dtd[ nextName ]['#'] ) + range.moveToElementEditStart( next ); + } selection.selectRanges( [ range ] ); @@ -177,6 +196,34 @@ For licensing, see LICENSE.html or http://ckeditor.com/license isNotWhitespace = CKEDITOR.dom.walker.whitespaces( true ); + // Gecko need a key event to 'wake up' the editing + // ability when document is empty.(#3864, #5781) + function activateEditing( editor ) + { + var win = editor.window, + doc = editor.document, + body = editor.document.getBody(), + bodyChildsNum = body.getChildren().count(); + + if ( !bodyChildsNum || ( bodyChildsNum == 1&& body.getFirst().hasAttribute( '_moz_editor_bogus_node' ) ) ) + { + restoreDirty( editor ); + + // Simulating keyboard character input by dispatching a keydown of white-space text. + var keyEventSimulate = doc.$.createEvent( "KeyEvents" ); + keyEventSimulate.initKeyEvent( 'keypress', true, true, win.$, false, + false, false, false, 0, 32 ); + doc.$.dispatchEvent( keyEventSimulate ); + + // Restore the original document status by placing the cursor before a bogus br created (#5021). + bodyChildsNum && body.getFirst().remove(); + doc.getBody().appendBogus(); + var nativeRange = new CKEDITOR.dom.range( doc ); + nativeRange.setStartAt( body , CKEDITOR.POSITION_AFTER_START ); + nativeRange.select(); + } + } + /** * Auto-fixing block-less content by wrapping paragraph (#3190), prevent * non-exitable-block by padding extra br.(#3189) @@ -191,6 +238,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license body = editor.document.getBody(), enterMode = editor.config.enterMode; + CKEDITOR.env.gecko && activateEditing( editor ); + // When enterMode set to block, we'll establing new paragraph only if we're // selecting inline contents right under body. (#3657) if ( enterMode != CKEDITOR.ENTER_BR @@ -216,20 +265,25 @@ For licensing, see LICENSE.html or http://ckeditor.com/license // block, we should revert the fix and move into the existed one. (#3684) if ( isBlankParagraph( fixedBlock ) ) { - var previousElement = fixedBlock.getPrevious( isNotWhitespace ), - nextElement = fixedBlock.getNext( isNotWhitespace ); - - if ( previousElement && previousElement.getName - && !( previousElement.getName() in nonExitableElementNames ) - && isBlankParagraph( previousElement ) - && range.moveToElementEditStart( previousElement ) - || nextElement && nextElement.getName - && !( nextElement.getName() in nonExitableElementNames ) - && isBlankParagraph( nextElement ) - && range.moveToElementEditStart( nextElement ) ) + var element = fixedBlock.getNext( isNotWhitespace ); + if ( element && + element.type == CKEDITOR.NODE_ELEMENT && + !nonExitableElementNames[ element.getName() ] ) { + range.moveToElementEditStart( element ); fixedBlock.remove(); } + else + { + element = fixedBlock.getPrevious( isNotWhitespace ); + if ( element && + element.type == CKEDITOR.NODE_ELEMENT && + !nonExitableElementNames[ element.getName() ] ) + { + range.moveToElementEditEnd( element ); + fixedBlock.remove(); + } + } } range.select(); @@ -395,33 +449,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license }, 0 ); } - // Gecko need a key event to 'wake up' the editing - // ability when document is empty.(#3864) - if ( CKEDITOR.env.gecko && !body.childNodes.length ) - { - setTimeout( function() - { - restoreDirty( editor ); - - // Simulating keyboard character input by dispatching a keydown of white-space text. - var keyEventSimulate = domDocument.$.createEvent( "KeyEvents" ); - keyEventSimulate.initKeyEvent( 'keypress', true, true, domWindow.$, false, - false, false, false, 0, 32 ); - domDocument.$.dispatchEvent( keyEventSimulate ); - - // Restore the original document status by placing the cursor before a bogus br created (#5021). - domDocument.createElement( 'br', { attributes: { '_moz_editor_bogus_node' : 'TRUE', '_moz_dirty' : "" } } ) - .replace( domDocument.getBody().getFirst() ); - var nativeRange = new CKEDITOR.dom.range( domDocument ); - nativeRange.setStartAt( new CKEDITOR.dom.element( body ) , CKEDITOR.POSITION_AFTER_START ); - nativeRange.select(); - }, 0 ); - } - - // IE, Opera and Safari may not support it and throw - // errors. - try { domDocument.execCommand( 'enableObjectResizing', false, !editor.config.disableObjectResizing ) ; } catch(e) {} - try { domDocument.execCommand( 'enableInlineTableEditing', false, !editor.config.disableNativeTableHandles ) ; } catch(e) {} + CKEDITOR.env.gecko && CKEDITOR.tools.setTimeout( activateEditing, 0, null, editor ); domWindow = editor.window = new CKEDITOR.dom.window( domWindow ); domDocument = editor.document = new CKEDITOR.dom.document( domDocument ); @@ -445,6 +473,26 @@ For licensing, see LICENSE.html or http://ckeditor.com/license } ); } + if ( CKEDITOR.env.gecko ) + { + domDocument.on( 'mouseup', function( ev ) + { + if ( ev.data.$.button == 2 ) + { + var target = ev.data.getTarget(); + + // Prevent right click from selecting an empty block even + // when selection is anchored inside it. (#5845) + if ( !target.getOuterHtml().replace( emptyParagraphRegexp, '' ) ) + { + var range = new CKEDITOR.dom.range( domDocument ); + range.moveToElementEditStart( target ); + range.select( true ); + } + } + } ); + } + // Webkit: avoid from editing form control elements content. if ( CKEDITOR.env.webkit ) { @@ -498,17 +546,6 @@ For licensing, see LICENSE.html or http://ckeditor.com/license blinkCursor(); else if ( CKEDITOR.env.opera ) doc.getBody().focus(); - else if ( CKEDITOR.env.webkit ) - { - // Selection will get lost after move focus - // to document element, save it first. - var sel = editor.getSelection(), - type = sel.getType(), - range = ( type != CKEDITOR.SELECTION_NONE ) && sel.getRanges()[ 0 ]; - - doc.getDocumentElement().focus(); - range && range.select(); - } editor.focusManager.focus(); }); @@ -596,6 +633,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license editor.fire( 'dataReady' ); }, 0 ); + // IE, Opera and Safari may not support it and throw errors. + try { editor.document.$.execCommand( 'enableObjectResizing', false, !editor.config.disableObjectResizing ) ; } catch(e) {} + try { editor.document.$.execCommand( 'enableInlineTableEditing', false, !editor.config.disableNativeTableHandles ) ; } catch(e) {} + /* * IE BUG: IE might have rendered the iframe with invisible contents. * (#3623). Push some inconsequential CSS style changes to force IE to @@ -777,6 +818,13 @@ For licensing, see LICENSE.html or http://ckeditor.com/license editor.document.clearCustomData(); iframe.clearCustomData(); + + /* + * IE BUG: When destroying editor DOM with the selection remains inside + * editing area would break IE7/8's selection system, we have to put the editing + * iframe offline first. (#3812 and #5441) + */ + iframe.remove(); }, unload : function( holderElement ) @@ -882,7 +930,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license editor.on( 'insertElement', function ( evt ) { var element = evt.data; - if ( element.type = CKEDITOR.NODE_ELEMENT + if ( element.type == CKEDITOR.NODE_ELEMENT && ( element.is( 'input' ) || element.is( 'textarea' ) ) ) { element.setAttribute( 'contentEditable', false );