X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fwysiwygarea%2Fplugin.js;h=d6ab1d8f209e6a4a4d49276014a3011738d847e2;hb=e73319a12b56100b29ef456fd74114fe5519e01c;hp=d837ea7afe4cb0852f96eb10a3d80e7363ce2e2c;hpb=4e70ea24db840898be8cc21c950363a52a2a6aba;p=ckeditor.git diff --git a/_source/plugins/wysiwygarea/plugin.js b/_source/plugins/wysiwygarea/plugin.js index d837ea7..d6ab1d8 100644 --- a/_source/plugins/wysiwygarea/plugin.js +++ b/_source/plugins/wysiwygarea/plugin.js @@ -51,6 +51,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license if ( this.dataProcessor ) data = this.dataProcessor.toHtml( data ); + if ( !data ) + return; + // HTML insertion only considers the first range. var selection = this.getSelection(), range = selection.getRanges()[ 0 ]; @@ -58,6 +61,26 @@ For licensing, see LICENSE.html or http://ckeditor.com/license if ( range.checkReadOnly() ) return; + // Opera: force block splitting when pasted content contains block. (#7801) + if ( CKEDITOR.env.opera ) + { + var path = new CKEDITOR.dom.elementPath( range.startContainer ); + if ( path.block ) + { + var nodes = CKEDITOR.htmlParser.fragment.fromHtml( data, false ).children; + for ( var i = 0, count = nodes.length; i < count; i++ ) + { + if ( nodes[ i ]._.isBlockLike ) + { + range.splitBlock( this.enterMode == CKEDITOR.ENTER_DIV ? 'div' : 'p' ); + range.insertNode( range.document.createText( '' ) ); + range.select(); + break; + } + } + } + } + if ( CKEDITOR.env.ie ) { var selIsLocked = selection.isLocked; @@ -89,11 +112,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license } } - try - { - $sel.createRange().pasteHTML( data ); - } - catch (e) {} + $sel.createRange().pasteHTML( data ); if ( selIsLocked ) this.getSelection().lock(); @@ -375,8 +394,6 @@ For licensing, see LICENSE.html or http://ckeditor.com/license && !pathBlock.is( 'pre' ) && !pathBlock.getBogus() ) { - editor.fire( 'updateSnapshot' ); - restoreDirty( editor ); pathBlock.appendBogus(); } } @@ -389,10 +406,6 @@ For licensing, see LICENSE.html or http://ckeditor.com/license && blockLimit.getName() == 'body' && !path.block ) { - editor.fire( 'updateSnapshot' ); - restoreDirty( editor ); - CKEDITOR.env.ie && restoreSelection( selection ); - var fixedBlock = range.fixBlock( true, editor.config.enterMode == CKEDITOR.ENTER_DIV ? 'div' : 'p' ); @@ -441,10 +454,6 @@ For licensing, see LICENSE.html or http://ckeditor.com/license var testPath = new CKEDITOR.dom.elementPath( testRange.startContainer ); if ( !testPath.blockLimit.is( 'body') ) { - editor.fire( 'updateSnapshot' ); - restoreDirty( editor ); - CKEDITOR.env.ie && restoreSelection( selection ); - var paddingBlock; if ( enterMode != CKEDITOR.ENTER_BR ) paddingBlock = body.append( editor.document.createElement( enterMode == CKEDITOR.ENTER_P ? 'p' : 'div' ) ); @@ -536,30 +545,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license if ( document.location.protocol == 'chrome:' ) CKEDITOR.event.useCapture = false; - // The container must be visible when creating the iframe in FF (#5956) - var element = editor.element, - isHidden = CKEDITOR.env.gecko && !element.isVisible(), - previousStyles = {}; - if ( isHidden ) - { - element.show(); - previousStyles = { - position : element.getStyle( 'position' ), - top : element.getStyle( 'top' ) - }; - element.setStyles( { position : 'absolute', top : '-3000px' } ); - } - mainElement.append( iframe ); - - if ( isHidden ) - { - setTimeout( function() - { - element.hide(); - element.setStyles( previousStyles ); - }, 1000 ); - } }; // The script that launches the bootstrap logic on 'domReady', so the document @@ -759,80 +745,82 @@ For licensing, see LICENSE.html or http://ckeditor.com/license keystrokeHandler.blockedKeystrokes[ 8 ] = !editable; keystrokeHandler.attach( domDocument ); - if ( CKEDITOR.env.ie ) + domDocument.getDocumentElement().addClass( domDocument.$.compatMode ); + // Override keystroke behaviors. + editable && domDocument.on( 'keydown', function( evt ) { - domDocument.getDocumentElement().addClass( domDocument.$.compatMode ); - // Override keystrokes which should have deletion behavior - // on control types in IE . (#4047) - editable && domDocument.on( 'keydown', function( evt ) + var keyCode = evt.data.getKeystroke(); + + // Backspace OR Delete. + if ( keyCode in { 8 : 1, 46 : 1 } ) { - var keyCode = evt.data.getKeystroke(); + var sel = editor.getSelection(), + selected = sel.getSelectedElement(), + range = sel.getRanges()[ 0 ]; - // Backspace OR Delete. - if ( keyCode in { 8 : 1, 46 : 1 } ) + // Override keystrokes which should have deletion behavior + // on fully selected element . (#4047) (#7645) + if ( selected ) { - var sel = editor.getSelection(), - control = sel.getSelectedElement(); - - if ( control ) - { - // Make undo snapshot. - editor.fire( 'saveSnapshot' ); + // Make undo snapshot. + editor.fire( 'saveSnapshot' ); - // Delete any element that 'hasLayout' (e.g. hr,table) in IE8 will - // break up the selection, safely manage it here. (#4795) - var bookmark = sel.getRanges()[ 0 ].createBookmark(); - // Remove the control manually. - control.remove(); - sel.selectBookmarks( [ bookmark ] ); + // Delete any element that 'hasLayout' (e.g. hr,table) in IE8 will + // break up the selection, safely manage it here. (#4795) + range.moveToPosition( selected, CKEDITOR.POSITION_BEFORE_START ); + // Remove the control manually. + selected.remove(); + range.select(); - editor.fire( 'saveSnapshot' ); + editor.fire( 'saveSnapshot' ); - evt.data.preventDefault(); - } + evt.data.preventDefault(); + return; } - } ); + } + } ); - // PageUp/PageDown scrolling is broken in document - // with standard doctype, manually fix it. (#4736) - if ( domDocument.$.compatMode == 'CSS1Compat' ) + // PageUp/PageDown scrolling is broken in document + // with standard doctype, manually fix it. (#4736) + if ( CKEDITOR.env.ie && domDocument.$.compatMode == 'CSS1Compat' ) + { + var pageUpDownKeys = { 33 : 1, 34 : 1 }; + domDocument.on( 'keydown', function( evt ) { - var pageUpDownKeys = { 33 : 1, 34 : 1 }; - domDocument.on( 'keydown', function( evt ) + if ( evt.data.getKeystroke() in pageUpDownKeys ) { - if ( evt.data.getKeystroke() in pageUpDownKeys ) + setTimeout( function () { - setTimeout( function () - { - editor.getSelection().scrollIntoView(); - }, 0 ); - } - } ); - } + editor.getSelection().scrollIntoView(); + }, 0 ); + } + } ); + } - // Prevent IE from leaving new paragraph after deleting all contents in body. (#6966) - editor.config.enterMode != CKEDITOR.ENTER_P - && domDocument.on( 'selectionchange', function() - { - var body = domDocument.getBody(), - range = editor.getSelection().getRanges()[ 0 ]; + // Prevent IE from leaving new paragraph after deleting all contents in body. (#6966) + if ( CKEDITOR.env.ie && editor.config.enterMode != CKEDITOR.ENTER_P ) + { + domDocument.on( 'selectionchange', function() + { + var body = domDocument.getBody(), + range = editor.getSelection().getRanges()[ 0 ]; - if ( body.getHtml().match( /^

 <\/p>$/i ) - && range.startContainer.equals( body ) ) + if ( body.getHtml().match( /^

 <\/p>$/i ) + && range.startContainer.equals( body ) ) + { + // Avoid the ambiguity from a real user cursor position. + setTimeout( function () { - // Avoid the ambiguity from a real user cursor position. - setTimeout( function () + range = editor.getSelection().getRanges()[ 0 ]; + if ( !range.startContainer.equals ( 'body' ) ) { - range = editor.getSelection().getRanges()[ 0 ]; - if ( !range.startContainer.equals ( 'body' ) ) - { - body.getFirst().remove( 1 ); - range.moveToElementEditEnd( body ); - range.select( 1 ); - } - }, 0 ); - } - }); + body.getFirst().remove( 1 ); + range.moveToElementEditEnd( body ); + range.select( 1 ); + } + }, 0 ); + } + }); } // Adds the document body as a context menu target. @@ -846,7 +834,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license if ( fireMode ) { editor.mode = 'wysiwyg'; - editor.fire( 'mode' ); + editor.fire( 'mode', { previousMode : editor._.previousMode } ); fireMode = false; } @@ -1101,18 +1089,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license if ( isLoadingData ) isPendingFocus = true; - // Temporary solution caused by #6025, supposed be unified by #6154. - else if ( CKEDITOR.env.opera && editor.document ) - { - // Required for Opera when switching focus - // from another iframe, e.g. panels. (#6444) - var iframe = editor.window.$.frameElement; - iframe.blur(), iframe.focus(); - editor.document.getBody().focus(); - - editor.selectionChange(); - } - else if ( !CKEDITOR.env.opera && win ) + else if ( win ) { // AIR needs a while to focus when moving from a link. CKEDITOR.env.air ? setTimeout( function () { win.focus(); }, 0 ) : win.focus(); @@ -1125,7 +1102,23 @@ For licensing, see LICENSE.html or http://ckeditor.com/license editor.on( 'insertElement', onInsert( doInsertElement ), null, null, 20 ); editor.on( 'insertText', onInsert( doInsertText ), null, null, 20 ); // Auto fixing on some document structure weakness to enhance usabilities. (#3190 and #3189) - editor.on( 'selectionChange', onSelectionChangeFixBody, null, null, 1 ); + editor.on( 'selectionChange', function( evt ) + { + if ( editor.readOnly ) + return; + + var sel = editor.getSelection(); + // Do it only when selection is not locked. (#8222) + if ( sel && !sel.isLocked ) + { + var isDirty = editor.checkDirty(); + editor.fire( 'saveSnapshot', { contentOnly : 1 } ); + onSelectionChangeFixBody.call( this, evt ); + editor.fire( 'updateSnapshot' ); + !isDirty && editor.resetDirty(); + } + + }, null, null, 1 ); }); var titleBackup; @@ -1239,9 +1232,12 @@ For licensing, see LICENSE.html or http://ckeditor.com/license { // We should flag that the element was locked by our code so // it'll be editable by the editor functions (#6046). - if ( !element.isReadOnly() ) + var readonly = element.getAttribute( 'contenteditable' ) == 'false'; + if ( !readonly ) + { element.data( 'cke-editable', element.hasAttribute( 'contenteditable' ) ? 'true' : '1' ); - element.setAttribute( 'contentEditable', false ); + element.setAttribute( 'contenteditable', false ); + } } });