X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fdialog%2Fplugin.js;h=706c92b61f017e806f7888dfdaaab8fe362ef14e;hb=941b0a9ba4e673e292510d80a5a86806994b8ea6;hp=b41cd1078eaea0ac89b745cac675fe60b4ca6e9d;hpb=8761695d9b70afe75905deaac88f78c1f8aeb32d;p=ckeditor.git diff --git a/_source/plugins/dialog/plugin.js b/_source/plugins/dialog/plugin.js index b41cd10..706c92b 100644 --- a/_source/plugins/dialog/plugin.js +++ b/_source/plugins/dialog/plugin.js @@ -1,5 +1,5 @@ /* -Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved. +Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ @@ -7,11 +7,6 @@ For licensing, see LICENSE.html or http://ckeditor.com/license * @fileOverview The floating dialog plugin. */ -CKEDITOR.plugins.add( 'dialog', - { - requires : [ 'dialogui' ] - }); - /** * No resize for this dialog. * @constant @@ -73,9 +68,6 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; return null; } - // Stores dialog related data from skin definitions. e.g. margin sizes. - var skinData = {}; - /** * This is the base class for runtime dialog objects. An instance of this * class represents a single named dialog for a single editor instance. @@ -89,11 +81,6 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; { // Load the dialog definition. var definition = CKEDITOR.dialog._.dialogDefinitions[ dialogName ]; - if ( !definition ) - { - console.log( 'Error: The dialog "' + dialogName + '" is not defined.' ); - return; - } // Completes the definition with the default values. definition = CKEDITOR.tools.extend( definition( editor ), defaultDialogDefinition ); @@ -264,11 +251,12 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; if ( focusList.length < 1 ) return; - var currentIndex = ( me._.currentFocusIndex + offset + focusList.length ) % focusList.length; + var startIndex = ( me._.currentFocusIndex + offset + focusList.length ) % focusList.length, + currentIndex = startIndex; while ( !focusList[ currentIndex ].isFocusable() ) { currentIndex = ( currentIndex + offset + focusList.length ) % focusList.length; - if ( currentIndex == me._.currentFocusIndex ) + if ( currentIndex == startIndex ) break; } focusList[ currentIndex ].focus(); @@ -278,14 +266,17 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; focusList[ currentIndex ].select(); } + var processed; + function focusKeydownHandler( evt ) { // If I'm not the top dialog, ignore. if ( me != CKEDITOR.dialog._.currentTop ) return; - var keystroke = evt.data.getKeystroke(), - processed = false; + var keystroke = evt.data.getKeystroke(); + + processed = 0; if ( keystroke == 9 || keystroke == CKEDITOR.SHIFT + 9 ) { var shiftPressed = ( keystroke == CKEDITOR.SHIFT + 9 ); @@ -304,14 +295,14 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; changeFocus( !shiftPressed ); } - processed = true; + processed = 1; } else if ( keystroke == CKEDITOR.ALT + 121 && !me._.tabBarMode ) { // Alt-F10 puts focus into the current tab item in the tab bar. me._.tabBarMode = true; me._.tabs[ me._.currentTabId ][ 0 ].focus(); - processed = true; + processed = 1; } else if ( ( keystroke == 37 || keystroke == 39 ) && me._.tabBarMode ) { @@ -319,7 +310,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; nextId = ( keystroke == 37 ? getPreviousVisibleTab.call( me ) : getNextVisibleTab.call( me ) ); me.selectPage( nextId ); me._.tabs[ nextId ][ 0 ].focus(); - processed = true; + processed = 1; } if ( processed ) @@ -329,10 +320,19 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; } } + function focusKeyPressHandler( evt ) + { + processed && evt.data.preventDefault(); + } + // Add the dialog keyboard handlers. this.on( 'show', function() { CKEDITOR.document.on( 'keydown', focusKeydownHandler, this, null, 0 ); + // Some browsers instead, don't cancel key events in the keydown, but in the + // keypress. So we must do a longer trip in those cases. (#4531) + if ( CKEDITOR.env.opera || ( CKEDITOR.env.gecko && CKEDITOR.env.mac ) ) + CKEDITOR.document.on( 'keypress', focusKeyPressHandler, this ); if ( CKEDITOR.env.ie6Compat ) { @@ -343,6 +343,8 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; this.on( 'hide', function() { CKEDITOR.document.removeListener( 'keydown', focusKeydownHandler ); + if ( CKEDITOR.env.opera || ( CKEDITOR.env.gecko && CKEDITOR.env.mac ) ) + CKEDITOR.document.removeListener( 'keypress', focusKeyPressHandler ); } ); this.on( 'iframeAdded', function( evt ) { @@ -447,12 +449,13 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; }; // Focusable interface. Use it via dialog.addFocusable. - function Focusable( dialog, element, index ) { + function Focusable( dialog, element, index ) + { this.element = element; this.focusIndex = index; this.isFocusable = function() { - return true; + return !element.getAttribute( 'disabled' ) && element.isVisible(); }; this.focus = function() { @@ -580,8 +583,12 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; */ show : function() { - if ( this._.editor.mode == 'wysiwyg' && CKEDITOR.env.ie ) - this._.editor.getSelection().lock(); + var editor = this._.editor; + if ( editor.mode == 'wysiwyg' && CKEDITOR.env.ie ) + { + var selection = editor.getSelection(); + selection && selection.lock(); + } // Insert the dialog's element to the root document. var element = this._.element; @@ -625,12 +632,12 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; this._.parentDialog = null; addCover( this._.editor ); - CKEDITOR.document.on( 'keydown', accessKeyDownHandler ); - CKEDITOR.document.on( 'keyup', accessKeyUpHandler ); + element.on( 'keydown', accessKeyDownHandler ); + element.on( CKEDITOR.env.opera ? 'keypress' : 'keyup', accessKeyUpHandler ); // Prevent some keys from bubbling up. (#4269) for ( var event in { keyup :1, keydown :1, keypress :1 } ) - CKEDITOR.document.on( event, preventKeyBubbling ); + element.on( event, preventKeyBubbling ); } else { @@ -664,6 +671,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; // Execute onLoad for the first show. this.fireOnce( 'load', {} ); this.fire( 'show', {} ); + this._.editor.fire( 'dialogShow', this ); // Save the initial values of the dialog. this.foreach( function( contentObj ) { contentObj.setInitValue && contentObj.setInitValue(); } ); @@ -727,6 +735,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; hide : function() { this.fire( 'hide', {} ); + this._.editor.fire( 'dialogHide', this ); // Remove the dialog's element from the root document. var element = this._.element; @@ -755,19 +764,21 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; CKEDITOR.dialog._.currentZIndex = null; // Remove access key handlers. - CKEDITOR.document.removeListener( 'keydown', accessKeyDownHandler ); - CKEDITOR.document.removeListener( 'keyup', accessKeyUpHandler ); - CKEDITOR.document.removeListener( 'keypress', accessKeyUpHandler ); + element.removeListener( 'keydown', accessKeyDownHandler ); + element.removeListener( CKEDITOR.env.opera ? 'keypress' : 'keyup', accessKeyUpHandler ); // Remove bubbling-prevention handler. (#4269) for ( var event in { keyup :1, keydown :1, keypress :1 } ) - CKEDITOR.document.removeListener( event, preventKeyBubbling ); + element.removeListener( event, preventKeyBubbling ); var editor = this._.editor; editor.focus(); if ( editor.mode == 'wysiwyg' && CKEDITOR.env.ie ) - editor.getSelection().unlock( true ); + { + var selection = editor.getSelection(); + selection && selection.unlock( true ); + } } else CKEDITOR.dialog._.currentZIndex -= 10; @@ -794,7 +805,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; children : contents.elements, expand : !!contents.expand, padding : contents.padding, - style : contents.style || 'width: 100%; height: 100%;' + style : contents.style || 'width: 100%;' }, pageHtml ); // Create the HTML for the tab and the content block. @@ -1437,7 +1448,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; element = dialog.getElement().getFirst(), editor = dialog.getParentEditor(), magnetDistance = editor.config.dialog_magnetDistance, - margins = skinData[ editor.skinName ].margins || [ 0, 0, 0, 0 ]; + margins = editor.skin.margins || [ 0, 0, 0, 0 ]; if ( typeof magnetDistance == 'undefined' ) magnetDistance = 20; @@ -1515,7 +1526,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; minWidth = definition.minWidth || 0, minHeight = definition.minHeight || 0, resizable = definition.resizable, - margins = skinData[ dialog.getParentEditor().skinName ].margins || [ 0, 0, 0, 0 ]; + margins = dialog.getParentEditor().skin.margins || [ 0, 0, 0, 0 ]; function topSizer( coords, dy ) { @@ -1661,11 +1672,13 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; if ( !coverElement ) { + var backgroundColorStyle = editor.config.dialog_backgroundCoverColor || 'white'; + var html = [ '
' ]; @@ -1673,7 +1686,8 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; if ( CKEDITOR.env.ie6Compat ) { // Support for custom document.domain in IE. - var isCustomDomain = CKEDITOR.env.isCustomDomain(); + var isCustomDomain = CKEDITOR.env.isCustomDomain(), + iframeHtml = ''; html.push( '