/*\r
-Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.\r
+Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved.\r
For licensing, see LICENSE.html or http://ckeditor.com/license\r
*/\r
\r
var definition = CKEDITOR.dialog._.dialogDefinitions[ dialogName ],\r
defaultDefinition = CKEDITOR.tools.clone( defaultDialogDefinition ),\r
buttonsOrder = editor.config.dialog_buttonsOrder || 'OS',\r
- dir = editor.lang.dir;\r
+ dir = editor.lang.dir,\r
+ tabsToRemove = {},\r
+ i,\r
+ processed;\r
\r
if ( ( buttonsOrder == 'OS' && CKEDITOR.env.mac ) || // The buttons in MacOS Apps are in reverse order (#4750)\r
( buttonsOrder == 'rtl' && dir == 'ltr' ) ||\r
}\r
, editor ).definition;\r
\r
- var tabsToRemove = {};\r
// Cache tabs that should be removed.\r
if ( !( 'removeDialogTabs' in editor._ ) && editor.config.removeDialogTabs )\r
{\r
focusList[ i ].focusIndex = i;\r
}\r
\r
- function changeFocus( forward )\r
+ function changeFocus( offset )\r
{\r
- var focusList = me._.focusList,\r
- offset = forward ? 1 : -1;\r
+ var focusList = me._.focusList;\r
+ offset = offset || 0;\r
+\r
if ( focusList.length < 1 )\r
return;\r
\r
\r
var startIndex = ( current + offset + focusList.length ) % focusList.length,\r
currentIndex = startIndex;\r
- while ( !focusList[ currentIndex ].isFocusable() )\r
+ while ( offset && !focusList[ currentIndex ].isFocusable() )\r
{\r
currentIndex = ( currentIndex + offset + focusList.length ) % focusList.length;\r
if ( currentIndex == startIndex )\r
break;\r
}\r
+\r
focusList[ currentIndex ].focus();\r
\r
// Select whole field content.\r
\r
this.changeFocus = changeFocus;\r
\r
- var processed;\r
\r
function focusKeydownHandler( evt )\r
{\r
else\r
{\r
// Change the focus of inputs.\r
- changeFocus( !shiftPressed );\r
+ changeFocus( shiftPressed ? -1 : 1 );\r
}\r
\r
processed = 1;\r
this.selectPage( this._.currentTabId );\r
this._.tabBarMode = false;\r
this._.currentFocusIndex = -1;\r
- changeFocus( true );\r
+ changeFocus( 1 );\r
processed = 1;\r
}\r
\r
}\r
// Focus the first field in layout order.\r
else\r
- changeFocus( true );\r
+ changeFocus( 1 );\r
\r
/*\r
* IE BUG: If the initial focus went into a non-text element (e.g. button),\r
( new CKEDITOR.dom.text( definition.title, CKEDITOR.document ) ).appendTo( this.parts.title );\r
\r
// Insert the tabs and contents.\r
- for ( var i = 0 ; i < definition.contents.length ; i++ )\r
+ for ( i = 0 ; i < definition.contents.length ; i++ )\r
{\r
var page = definition.contents[i];\r
page && this.addPage( page );\r
{\r
this._.tabBarMode = false;\r
this._.currentFocusIndex = -1;\r
- changeFocus( true );\r
+ changeFocus( 1 );\r
}\r
evt.data.preventDefault();\r
}\r
this._.element.getFirst().setStyle( 'z-index', CKEDITOR.dialog._.currentZIndex += 10 );\r
\r
// Maintain the dialog ordering and dialog cover.\r
- // Also register key handlers if first dialog.\r
if ( CKEDITOR.dialog._.currentTop === null )\r
{\r
CKEDITOR.dialog._.currentTop = this;\r
this._.parentDialog = null;\r
showCover( this._.editor );\r
\r
- element.on( 'keydown', accessKeyDownHandler );\r
- element.on( CKEDITOR.env.opera ? 'keypress' : 'keyup', accessKeyUpHandler );\r
-\r
- // Prevent some keys from bubbling up. (#4269)\r
- for ( var event in { keyup :1, keydown :1, keypress :1 } )\r
- element.on( event, preventKeyBubbling );\r
}\r
else\r
{\r
CKEDITOR.dialog._.currentTop = this;\r
}\r
\r
+ element.on( 'keydown', accessKeyDownHandler );\r
+ element.on( CKEDITOR.env.opera ? 'keypress' : 'keyup', accessKeyUpHandler );\r
+\r
+ // Prevent some keys from bubbling up. (#4269)\r
+ for ( var event in { keyup :1, keydown :1, keypress :1 } )\r
+ element.on( event, preventKeyBubbling );\r
+\r
// Register the Esc hotkeys.\r
registerAccessKey( this, this, '\x1b', null, function()\r
{\r
- this.getButton( 'cancel' ) && this.getButton( 'cancel' ).click();\r
+ var button = this.getButton( 'cancel' );\r
+ // If there's a Cancel button, click it, else just fire the cancel event and hide the dialog\r
+ if ( button )\r
+ button.click();\r
+ else\r
+ {\r
+ if ( this.fire( 'cancel', { hide : true } ).hide !== false )\r
+ this.hide();\r
+ }\r
} );\r
\r
// Reset the hasFocus state.\r
{\r
// Special treatment for Opera. (#8031)\r
CKEDITOR.env.opera ?\r
- CKEDITOR.tools.setTimeout( function() { editor.openDialog( this.dialogName ) }, 0, this )\r
+ CKEDITOR.tools.setTimeout( function() { editor.openDialog( this.dialogName ); }, 0, this )\r
: editor.openDialog( this.dialogName );\r
},\r
\r