JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.6.3
[ckeditor.git] / _source / plugins / dialog / plugin.js
index 13ee0ef..eee4916 100644 (file)
@@ -1,5 +1,5 @@
 /*\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
@@ -138,7 +138,10 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
                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
@@ -219,7 +222,6 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
                        }\r
                        , editor ).definition;\r
 \r
-               var tabsToRemove = {};\r
                // Cache tabs that should be removed.\r
                if ( !( 'removeDialogTabs' in editor._ ) && editor.config.removeDialogTabs )\r
                {\r
@@ -358,10 +360,11 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
                                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
@@ -377,12 +380,13 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
 \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
@@ -392,7 +396,6 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
 \r
                this.changeFocus = changeFocus;\r
 \r
-               var processed;\r
 \r
                function focusKeydownHandler( evt )\r
                {\r
@@ -419,7 +422,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
                                else\r
                                {\r
                                        // Change the focus of inputs.\r
-                                       changeFocus( !shiftPressed );\r
+                                       changeFocus( shiftPressed ? -1 : 1 );\r
                                }\r
 \r
                                processed = 1;\r
@@ -444,7 +447,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
                                this.selectPage( this._.currentTabId );\r
                                this._.tabBarMode = false;\r
                                this._.currentFocusIndex = -1;\r
-                               changeFocus( true );\r
+                               changeFocus( 1 );\r
                                processed = 1;\r
                        }\r
 \r
@@ -512,7 +515,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
                                        }\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
@@ -558,7 +561,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
                ( 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
@@ -578,7 +581,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
                                                {\r
                                                        this._.tabBarMode = false;\r
                                                        this._.currentFocusIndex = -1;\r
-                                                       changeFocus( true );\r
+                                                       changeFocus( 1 );\r
                                                }\r
                                                evt.data.preventDefault();\r
                                        }\r
@@ -794,19 +797,12 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
                        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
@@ -816,10 +812,25 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
                                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
@@ -2935,7 +2946,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
                {\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