app/assets/javascripts/ckeditor/_source/plugins/wysiwygarea/plugin.js in refinerycms-ckeditor-0.1.4 vs app/assets/javascripts/ckeditor/_source/plugins/wysiwygarea/plugin.js in refinerycms-ckeditor-0.2.0

- old
+ new

@@ -1,7 +1,7 @@ /* -Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ /** * @fileOverview The "wysiwygarea" plugin. It registers the "wysiwyg" editing @@ -28,14 +28,24 @@ { if ( this.mode == 'wysiwyg' ) { this.focus(); + // Since the insertion might happen from within dialog or menu + // where the editor selection might be locked at the moment, + // update the locked selection. + var selection = this.getSelection(), + selIsLocked = selection.isLocked; + + selIsLocked && selection.unlock(); + this.fire( 'saveSnapshot' ); insertFunc.call( this, evt.data ); + selIsLocked && this.getSelection().lock(); + // Save snaps after the whole execution completed. // This's a workaround for make DOM modification's happened after // 'insertElement' to be included either, e.g. Form-based dialogs' 'commitContents' // call. CKEDITOR.tools.setTimeout( function() @@ -81,15 +91,10 @@ } } if ( CKEDITOR.env.ie ) { - var selIsLocked = selection.isLocked; - - if ( selIsLocked ) - selection.unlock(); - var $sel = selection.getNative(); // Delete control selections to avoid IE bugs on pasteHTML. if ( $sel.type == 'Control' ) $sel.clear(); @@ -111,13 +116,10 @@ range.deleteContents(); } } $sel.createRange().pasteHTML( data ); - - if ( selIsLocked ) - this.getSelection().lock(); } else this.document.$.execCommand( 'inserthtml', false, data ); // Webkit does not scroll to the cursor position after pasting (#5558) @@ -474,19 +476,21 @@ var fixForBody = ( editor.config.enterMode != CKEDITOR.ENTER_BR && editor.config.autoParagraph !== false ) ? editor.config.enterMode == CKEDITOR.ENTER_DIV ? 'div' : 'p' : false; var frameLabel = editor.lang.editorTitle.replace( '%1', editor.name ); + var win = CKEDITOR.document.getWindow(); var contentDomReadyHandler; editor.on( 'editingBlockReady', function() { var mainElement, iframe, isLoadingData, isPendingFocus, frameLoaded, - fireMode; + fireMode, + onResize; // Support for custom document.domain in IE. var isCustomDomain = CKEDITOR.env.isCustomDomain(); @@ -544,10 +548,23 @@ // Reset adjustment back to default (#5689) if ( document.location.protocol == 'chrome:' ) CKEDITOR.event.useCapture = false; mainElement.append( iframe ); + + // Webkit: iframe size doesn't auto fit well. (#7360) + if ( CKEDITOR.env.webkit ) + { + onResize = function() + { + iframe.hide(); + iframe.setSize( 'width', mainElement.getSize( 'width' ) ); + iframe.show(); + }; + + win.on( 'resize', onResize ); + } }; // The script that launches the bootstrap logic on 'domReady', so the document // is fully editable even before the editing iframe is fully loaded (#4455). contentDomReadyHandler = CKEDITOR.tools.addFunction( contentDomReady ); @@ -687,32 +704,10 @@ if ( ev.data.getTarget().is( 'input', 'textarea' ) ) ev.data.preventDefault(); } ); } - // IE standard compliant in editing frame doesn't focus the editor when - // clicking outside actual content, manually apply the focus. (#1659) - if ( editable && - CKEDITOR.env.ie && domDocument.$.compatMode == 'CSS1Compat' - || CKEDITOR.env.gecko - || CKEDITOR.env.opera ) - { - var htmlElement = domDocument.getDocumentElement(); - htmlElement.on( 'mousedown', function( evt ) - { - // Setting focus directly on editor doesn't work, we - // have to use here a temporary element to 'redirect' - // the focus. - if ( evt.data.getTarget().equals( htmlElement ) ) - { - if ( CKEDITOR.env.gecko && CKEDITOR.env.version >= 10900 ) - blinkCursor(); - focusGrabber.focus(); - } - } ); - } - var focusTarget = CKEDITOR.env.ie ? iframe : domWindow; focusTarget.on( 'blur', function() { editor.focusManager.blur(); }); @@ -776,10 +771,32 @@ evt.data.preventDefault(); return; } } + + // PageUp OR PageDown + if ( keyCode == 33 || keyCode == 34 ) + { + if ( CKEDITOR.env.gecko ) + { + var body = domDocument.getBody(); + + // Page up/down cause editor selection to leak + // outside of editable thus we try to intercept + // the behavior, while it affects only happen + // when editor contents are not overflowed. (#7955) + if ( domWindow.$.innerHeight > body.$.offsetHeight ) + { + range = new CKEDITOR.dom.range( domDocument ); + range[ keyCode == 33 ? 'moveToElementEditStart' : 'moveToElementEditEnd']( body ); + range.select(); + evt.data.preventDefault(); + } + } + + } } ); // PageUp/PageDown scrolling is broken in document // with standard doctype, manually fix it. (#4736) if ( CKEDITOR.env.ie && domDocument.$.compatMode == 'CSS1Compat' ) @@ -801,13 +818,14 @@ if ( CKEDITOR.env.ie && editor.config.enterMode != CKEDITOR.ENTER_P ) { domDocument.on( 'selectionchange', function() { var body = domDocument.getBody(), - range = editor.getSelection().getRanges()[ 0 ]; + sel = editor.getSelection(), + range = sel && sel.getRanges()[ 0 ]; - if ( body.getHtml().match( /^<p>&nbsp;<\/p>$/i ) + if ( range && body.getHtml().match( /^<p>&nbsp;<\/p>$/i ) && range.startContainer.equals( body ) ) { // Avoid the ambiguity from a real user cursor position. setTimeout( function () { @@ -1076,10 +1094,13 @@ unload : function( holderElement ) { this.onDispose(); + if ( onResize ) + win.removeListener( 'resize', onResize ); + editor.window = editor.document = iframe = mainElement = isPendingFocus = null; editor.fire( 'contentDomUnload' ); }, @@ -1156,10 +1177,13 @@ else if ( CKEDITOR.env.gecko ) { editor.addCss( 'html { height: 100% !important; }' ); editor.addCss( 'img:-moz-broken { -moz-force-broken-image-icon : 1; width : 24px; height : 24px; }' ); } + // Remove the margin to avoid mouse confusion. (#8835) + else if ( CKEDITOR.env.ie && CKEDITOR.env.version < 8 && editor.config.contentsLangDirection == 'ltr' ) + editor.addCss( 'body{margin-right:0;}' ); /* #3658: [IE6] Editor document has horizontal scrollbar on long lines To prevent this misbehavior, we show the scrollbar always */ /* #6341: The text cursor must be set on the editor area. */ /* #6632: Avoid having "text" shape of cursor in IE7 scrollbars.*/ @@ -1194,34 +1218,9 @@ body.setAttribute( 'contentEditable', false ); body.setAttribute( 'contentEditable', true ); // Try it again once.. !retry && blinkCursor( 1 ); }); - } - - // Create an invisible element to grab focus. - if ( CKEDITOR.env.gecko || CKEDITOR.env.ie || CKEDITOR.env.opera ) - { - var focusGrabber; - editor.on( 'uiReady', function() - { - focusGrabber = editor.container.append( CKEDITOR.dom.element.createFromHtml( - // Use 'span' instead of anything else to fly under the screen-reader radar. (#5049) - '<span tabindex="-1" style="position:absolute;" role="presentation"></span>' ) ); - - focusGrabber.on( 'focus', function() - { - editor.focus(); - } ); - - editor.focusGrabber = focusGrabber; - } ); - editor.on( 'destroy', function() - { - CKEDITOR.tools.removeFunction( contentDomReadyHandler ); - focusGrabber.clearCustomData(); - delete editor.focusGrabber; - } ); } // Disable form elements editing mode provided by some browers. (#5746) editor.on( 'insertElement', function ( evt ) {