X-Git-Url: https://jasonwoof.com/gitweb/?p=ckeditor.git;a=blobdiff_plain;f=_source%2Fplugins%2Fdialog%2Fplugin.js;h=5615b11db6c473ade07a0554934a702f78814f74;hp=ee8d0e6d1c151dd8b668dc53e8275a0a9a423168;hb=8665a7c6c60586526e32e8941fe2896739b6ebfb;hpb=e7789c1ad838194d45eeee6ac2eb6e55f5cf35a1 diff --git a/_source/plugins/dialog/plugin.js b/_source/plugins/dialog/plugin.js index ee8d0e6..5615b11 100644 --- a/_source/plugins/dialog/plugin.js +++ b/_source/plugins/dialog/plugin.js @@ -248,6 +248,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; { if ( this.fire( 'cancel', { hide : true } ).hide !== false ) this.hide(); + evt.data.preventDefault(); }, this ); // Sort focus list according to tab order definitions. @@ -312,7 +313,8 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; if ( me != CKEDITOR.dialog._.currentTop ) return; - var keystroke = evt.data.getKeystroke(); + var keystroke = evt.data.getKeystroke(), + rtl = editor.lang.dir == 'rtl'; processed = 0; if ( keystroke == 9 || keystroke == CKEDITOR.SHIFT + 9 ) @@ -345,7 +347,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; else if ( ( keystroke == 37 || keystroke == 39 ) && me._.tabBarMode ) { // Arrow keys - used for changing tabs. - nextId = ( keystroke == 37 ? getPreviousVisibleTab.call( me ) : getNextVisibleTab.call( me ) ); + nextId = ( keystroke == ( rtl ? 39 : 37 ) ? getPreviousVisibleTab.call( me ) : getNextVisibleTab.call( me ) ); me.selectPage( nextId ); me._.tabs[ nextId ][ 0 ].focus(); processed = 1; @@ -381,11 +383,6 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; if ( CKEDITOR.env.opera || ( CKEDITOR.env.gecko && CKEDITOR.env.mac ) ) dialogElement.on( 'keypress', focusKeyPressHandler, this ); - if ( CKEDITOR.env.ie6Compat ) - { - var coverDoc = coverElement.getChild( 0 ).getFrameDocument(); - coverDoc.on( 'keydown', focusKeydownHandler, this, null, 0 ); - } } ); this.on( 'hide', function() { @@ -541,6 +538,12 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; CKEDITOR.dialog.prototype = { + destroy : function() + { + this.hide(); + this._.element.remove(); + }, + /** * Resizes the dialog. * @param {Number} width The width of the dialog in pixels. @@ -657,7 +660,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; if ( !( element.getParent() && element.getParent().equals( CKEDITOR.document.getBody() ) ) ) element.appendTo( CKEDITOR.document.getBody() ); else - return; + element.setStyle( 'display', 'block' ); // FIREFOX BUG: Fix vanishing caret for Firefox 2 or Gecko 1.8. if ( CKEDITOR.env.gecko && CKEDITOR.env.version < 10900 ) @@ -691,7 +694,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; { CKEDITOR.dialog._.currentTop = this; this._.parentDialog = null; - addCover( this._.editor ); + showCover( this._.editor ); element.on( 'keydown', accessKeyDownHandler ); element.on( CKEDITOR.env.opera ? 'keypress' : 'keyup', accessKeyUpHandler ); @@ -795,23 +798,24 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; */ hide : function() { + if ( !this.parts.dialog.isVisible() ) + return; + this.fire( 'hide', {} ); this._.editor.fire( 'dialogHide', this ); - - // Remove the dialog's element from the root document. var element = this._.element; - if ( !element.getParent() ) - return; - - element.remove(); + element.setStyle( 'display', 'none' ); this.parts.dialog.setStyle( 'visibility', 'hidden' ); - // Unregister all access keys associated with this dialog. unregisterAccessKey( this ); + // Close any child(top) dialogs first. + while( CKEDITOR.dialog._.currentTop != this ) + CKEDITOR.dialog._.currentTop.hide(); + // Maintain dialog ordering and remove cover if needed. if ( !this._.parentDialog ) - removeCover(); + hideCover(); else { var parentElement = this._.parentDialog.getElement().getFirst(); @@ -844,7 +848,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; else CKEDITOR.dialog._.currentZIndex -= 10; - + delete this._.parentDialog; // Reset the initial values of the dialog. this.foreach( function( contentObj ) { contentObj.resetInitValue && contentObj.resetInitValue(); } ); }, @@ -1577,7 +1581,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; if ( CKEDITOR.env.ie6Compat ) { - var coverDoc = coverElement.getChild( 0 ).getFrameDocument(); + var coverDoc = currentCover.getChild( 0 ).getFrameDocument(); coverDoc.removeListener( 'mousemove', mouseMoveHandler ); coverDoc.removeListener( 'mouseup', mouseUpHandler ); } @@ -1595,7 +1599,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; if ( CKEDITOR.env.ie6Compat ) { - var coverDoc = coverElement.getChild( 0 ).getFrameDocument(); + var coverDoc = currentCover.getChild( 0 ).getFrameDocument(); coverDoc.on( 'mousemove', mouseMoveHandler ); coverDoc.on( 'mouseup', mouseUpHandler ); } @@ -1653,7 +1657,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; if ( CKEDITOR.env.ie6Compat ) { - var coverDoc = coverElement.getChild( 0 ).getFrameDocument(); + var coverDoc = currentCover.getChild( 0 ).getFrameDocument(); coverDoc.on( 'mousemove', mouseMoveHandler, dialog, { part : partName } ); coverDoc.on( 'mouseup', mouseUpHandler, dialog, { part : partName } ); } @@ -1724,7 +1728,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; if ( CKEDITOR.env.ie6Compat ) { - var coverDoc = coverElement.getChild( 0 ).getFrameDocument(); + var coverDoc = currentCover.getChild( 0 ).getFrameDocument(); coverDoc.removeListener( 'mouseup', mouseUpHandler ); coverDoc.removeListener( 'mousemove', mouseMoveHandler ); } @@ -1748,25 +1752,33 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; } var resizeCover; - var coverElement; + // Caching resuable covers and allowing only one cover + // on screen. + var covers = {}, + currentCover; - var addCover = function( editor ) + function showCover( editor ) { var win = CKEDITOR.document.getWindow(); + var backgroundColorStyle = editor.config.dialog_backgroundCoverColor || 'white', + backgroundCoverOpacity = editor.config.dialog_backgroundCoverOpacity, + baseFloatZIndex = editor.config.baseFloatZIndex, + coverKey = CKEDITOR.tools.genKey( + backgroundColorStyle, + backgroundCoverOpacity, + baseFloatZIndex ), + coverElement = covers[ coverKey ]; if ( !coverElement ) { - var backgroundColorStyle = editor.config.dialog_backgroundCoverColor || 'white'; - var html = [ '
' + '" class="cke_dialog_background_cover">' ]; - if ( CKEDITOR.env.ie6Compat ) { // Support for custom document.domain in IE. @@ -1802,14 +1814,19 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; html.push( '
' ); coverElement = CKEDITOR.dom.element.createFromHtml( html.join( '' ) ); - } + coverElement.setOpacity( backgroundCoverOpacity != undefined ? backgroundCoverOpacity : 0.5 ); - var element = coverElement; + coverElement.appendTo( CKEDITOR.document.getBody() ); + covers[ coverKey ] = coverElement; + } + else + coverElement. show(); + currentCover = coverElement; var resizeFunc = function() { var size = win.getViewPaneSize(); - element.setStyles( + coverElement.setStyles( { width : size.width + 'px', height : size.height + 'px' @@ -1820,7 +1837,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; { var pos = win.getScrollPosition(), cursor = CKEDITOR.dialog._.currentTop; - element.setStyles( + coverElement.setStyles( { left : pos.x + 'px', top : pos.y + 'px' @@ -1852,20 +1869,15 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; }, 0 ); scrollFunc(); } + } - var opacity = editor.config.dialog_backgroundCoverOpacity; - element.setOpacity( typeof opacity != 'undefined' ? opacity : 0.5 ); - - element.appendTo( CKEDITOR.document.getBody() ); - }; - - var removeCover = function() + function hideCover() { - if ( !coverElement ) + if ( !currentCover ) return; var win = CKEDITOR.document.getWindow(); - coverElement.remove(); + currentCover.hide(); win.removeListener( 'resize', resizeCover ); if ( CKEDITOR.env.ie6Compat ) @@ -1877,7 +1889,14 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; }, 0 ); } resizeCover = null; - }; + } + + function removeCovers() + { + for ( var coverId in covers ) + covers[ coverId ].remove(); + covers = {}; + } var accessKeyProcessors = {}; @@ -2657,7 +2676,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; // undo support should dedicate to specific dialog implementation. canUndo: false, - editorFocus : CKEDITOR.env.ie + editorFocus : CKEDITOR.env.ie || CKEDITOR.env.webkit }; (function() @@ -2777,6 +2796,24 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; return this.functions( function( val ){ return val != value; }, msg ); } }; + + CKEDITOR.on( 'instanceDestroyed', function( evt ) + { + // Remove dialog cover on last instance destroy. + if ( CKEDITOR.tools.isEmpty( CKEDITOR.instances ) ) + { + var currentTopDialog; + while ( ( currentTopDialog = CKEDITOR.dialog._.currentTop ) ) + currentTopDialog.hide(); + removeCovers(); + } + + var dialogs = evt.editor._.storedDialogs; + for ( var name in dialogs ) + dialogs[ name ].destroy(); + + }); + })(); })();