JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.0.2
[ckeditor.git] / _source / plugins / dialog / plugin.js
index b41cd10..75067d6 100644 (file)
@@ -89,11 +89,6 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
        {\r
                // Load the dialog definition.\r
                var definition = CKEDITOR.dialog._.dialogDefinitions[ dialogName ];\r
-               if ( !definition )\r
-               {\r
-                       console.log( 'Error: The dialog "' + dialogName + '" is not defined.' );\r
-                       return;\r
-               }\r
 \r
                // Completes the definition with the default values.\r
                definition = CKEDITOR.tools.extend( definition( editor ), defaultDialogDefinition );\r
@@ -264,11 +259,12 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
                        if ( focusList.length < 1 )\r
                                return;\r
 \r
-                       var currentIndex = ( me._.currentFocusIndex + offset + focusList.length ) % focusList.length;\r
+                       var startIndex = ( me._.currentFocusIndex + offset + focusList.length ) % focusList.length,\r
+                               currentIndex = startIndex;\r
                        while ( !focusList[ currentIndex ].isFocusable() )\r
                        {\r
                                currentIndex = ( currentIndex + offset + focusList.length ) % focusList.length;\r
-                               if ( currentIndex == me._.currentFocusIndex )\r
+                               if ( currentIndex == startIndex )\r
                                        break;\r
                        }\r
                        focusList[ currentIndex ].focus();\r
@@ -278,14 +274,17 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
                                focusList[ currentIndex ].select();\r
                }\r
 \r
+               var processed;\r
+\r
                function focusKeydownHandler( evt )\r
                {\r
                        // If I'm not the top dialog, ignore.\r
                        if ( me != CKEDITOR.dialog._.currentTop )\r
                                return;\r
 \r
-                       var keystroke = evt.data.getKeystroke(),\r
-                               processed = false;\r
+                       var keystroke = evt.data.getKeystroke();\r
+\r
+                       processed = 0;\r
                        if ( keystroke == 9 || keystroke == CKEDITOR.SHIFT + 9 )\r
                        {\r
                                var shiftPressed = ( keystroke == CKEDITOR.SHIFT + 9 );\r
@@ -304,14 +303,14 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
                                        changeFocus( !shiftPressed );\r
                                }\r
 \r
-                               processed = true;\r
+                               processed = 1;\r
                        }\r
                        else if ( keystroke == CKEDITOR.ALT + 121 && !me._.tabBarMode )\r
                        {\r
                                // Alt-F10 puts focus into the current tab item in the tab bar.\r
                                me._.tabBarMode = true;\r
                                me._.tabs[ me._.currentTabId ][ 0 ].focus();\r
-                               processed = true;\r
+                               processed = 1;\r
                        }\r
                        else if ( ( keystroke == 37 || keystroke == 39 ) && me._.tabBarMode )\r
                        {\r
@@ -319,7 +318,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
                                nextId = ( keystroke == 37 ? getPreviousVisibleTab.call( me ) : getNextVisibleTab.call( me ) );\r
                                me.selectPage( nextId );\r
                                me._.tabs[ nextId ][ 0 ].focus();\r
-                               processed = true;\r
+                               processed = 1;\r
                        }\r
 \r
                        if ( processed )\r
@@ -329,10 +328,19 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
                        }\r
                }\r
 \r
+               function focusKeyPressHandler( evt )\r
+               {\r
+                       processed && evt.data.preventDefault();\r
+               }\r
+\r
                // Add the dialog keyboard handlers.\r
                this.on( 'show', function()\r
                        {\r
                                CKEDITOR.document.on( 'keydown', focusKeydownHandler, this, null, 0 );\r
+                               // Some browsers instead, don't cancel key events in the keydown, but in the\r
+                               // keypress. So we must do a longer trip in those cases. (#4531)\r
+                               if ( CKEDITOR.env.opera || ( CKEDITOR.env.gecko && CKEDITOR.env.mac ) )\r
+                                       CKEDITOR.document.on( 'keypress', focusKeyPressHandler, this );\r
 \r
                                if ( CKEDITOR.env.ie6Compat )\r
                                {\r
@@ -343,6 +351,8 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
                this.on( 'hide', function()\r
                        {\r
                                CKEDITOR.document.removeListener( 'keydown', focusKeydownHandler );\r
+                               if ( CKEDITOR.env.opera || ( CKEDITOR.env.gecko && CKEDITOR.env.mac ) )\r
+                                       CKEDITOR.document.removeListener( 'keypress', focusKeyPressHandler );\r
                        } );\r
                this.on( 'iframeAdded', function( evt )\r
                        {\r
@@ -447,12 +457,13 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
        };\r
 \r
        // Focusable interface. Use it via dialog.addFocusable.\r
-       function Focusable( dialog, element, index ) {\r
+       function Focusable( dialog, element, index )\r
+       {\r
                this.element = element;\r
                this.focusIndex = index;\r
                this.isFocusable = function()\r
                {\r
-                       return true;\r
+                       return !element.getAttribute( 'disabled' ) && element.isVisible();\r
                };\r
                this.focus = function()\r
                {\r
@@ -580,8 +591,12 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
                 */\r
                show : function()\r
                {\r
-                       if ( this._.editor.mode == 'wysiwyg' && CKEDITOR.env.ie )\r
-                               this._.editor.getSelection().lock();\r
+                       var editor = this._.editor;\r
+                       if ( editor.mode == 'wysiwyg' && CKEDITOR.env.ie )\r
+                       {\r
+                               var selection = editor.getSelection();\r
+                               selection && selection.lock();\r
+                       }\r
 \r
                        // Insert the dialog's element to the root document.\r
                        var element = this._.element;\r
@@ -625,12 +640,12 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
                                this._.parentDialog = null;\r
                                addCover( this._.editor );\r
 \r
-                               CKEDITOR.document.on( 'keydown', accessKeyDownHandler );\r
-                               CKEDITOR.document.on( 'keyup', accessKeyUpHandler );\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
-                                       CKEDITOR.document.on( event, preventKeyBubbling );\r
+                                       element.on( event, preventKeyBubbling );\r
                        }\r
                        else\r
                        {\r
@@ -755,19 +770,21 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
                                CKEDITOR.dialog._.currentZIndex = null;\r
 \r
                                // Remove access key handlers.\r
-                               CKEDITOR.document.removeListener( 'keydown', accessKeyDownHandler );\r
-                               CKEDITOR.document.removeListener( 'keyup', accessKeyUpHandler );\r
-                               CKEDITOR.document.removeListener( 'keypress', accessKeyUpHandler );\r
+                               element.removeListener( 'keydown', accessKeyDownHandler );\r
+                               element.removeListener( CKEDITOR.env.opera ? 'keypress' : 'keyup', accessKeyUpHandler );\r
 \r
                                // Remove bubbling-prevention handler. (#4269)\r
                                for ( var event in { keyup :1, keydown :1, keypress :1 } )\r
-                                       CKEDITOR.document.removeListener( event, preventKeyBubbling );\r
+                                       element.removeListener( event, preventKeyBubbling );\r
 \r
                                var editor = this._.editor;\r
                                editor.focus();\r
 \r
                                if ( editor.mode == 'wysiwyg' && CKEDITOR.env.ie )\r
-                                       editor.getSelection().unlock( true );\r
+                               {\r
+                                       var selection = editor.getSelection();\r
+                                       selection && selection.unlock( true );\r
+                               }\r
                        }\r
                        else\r
                                CKEDITOR.dialog._.currentZIndex -= 10;\r
@@ -794,7 +811,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
                                                        children : contents.elements,\r
                                                        expand : !!contents.expand,\r
                                                        padding : contents.padding,\r
-                                                       style : contents.style || 'width: 100%; height: 100%;'\r
+                                                       style : contents.style || 'width: 100%;'\r
                                                }, pageHtml );\r
 \r
                        // Create the HTML for the tab and the content block.\r
@@ -1661,11 +1678,13 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
 \r
                if ( !coverElement )\r
                {\r
+                       var backgroundColorStyle = editor.config.dialog_backgroundCoverColor || 'white';\r
+\r
                        var html = [\r
                                        '<div style="position: ', ( CKEDITOR.env.ie6Compat ? 'absolute' : 'fixed' ),\r
                                        '; z-index: ', editor.config.baseFloatZIndex,\r
                                        '; top: 0px; left: 0px; ',\r
-                                       'background-color: ', editor.config.dialog_backgroundCoverColor || 'white',\r
+                                       ( !CKEDITOR.env.ie6Compat ? 'background-color: ' + backgroundColorStyle : '' ),\r
                                        '" id="cke_dialog_background_cover">'\r
                                ];\r
 \r
@@ -1673,7 +1692,8 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
                        if ( CKEDITOR.env.ie6Compat )\r
                        {\r
                                // Support for custom document.domain in IE.\r
-                               var isCustomDomain = CKEDITOR.env.isCustomDomain();\r
+                               var isCustomDomain = CKEDITOR.env.isCustomDomain(),\r
+                                       iframeHtml = '<html><body style=\\\'background-color:' + backgroundColorStyle + ';\\\'></body></html>';\r
 \r
                                html.push(\r
                                        '<iframe' +\r
@@ -1682,15 +1702,12 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
                                                ' id="cke_dialog_background_iframe"' +\r
                                                ' src="javascript:' );\r
 \r
-                               html.push(\r
-                                               isCustomDomain ?\r
-                                                       'void((function(){' +\r
+                               html.push( 'void((function(){' +\r
                                                                'document.open();' +\r
-                                                               'document.domain=\'' + document.domain + '\';' +\r
+                                                               ( isCustomDomain ? 'document.domain=\'' + document.domain + '\';' : '' ) +\r
+                                                               'document.write( \'' + iframeHtml + '\' );' +\r
                                                                'document.close();' +\r
-                                                       '})())'\r
-                                               :\r
-                                                       '\'\'' );\r
+                                                       '})())' );\r
 \r
                                html.push(\r
                                                '"' +\r
@@ -1814,8 +1831,11 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
                        return;\r
 \r
                keyProcessor = keyProcessor[keyProcessor.length - 1];\r
-               keyProcessor.keyup && keyProcessor.keyup.call( keyProcessor.uiElement, keyProcessor.dialog, keyProcessor.key );\r
-               evt.data.preventDefault();\r
+               if ( keyProcessor.keyup )\r
+               {\r
+                       keyProcessor.keyup.call( keyProcessor.uiElement, keyProcessor.dialog, keyProcessor.key );\r
+                       evt.data.preventDefault();\r
+               }\r
        };\r
 \r
        var registerAccessKey = function( uiElement, dialog, key, downFunc, upFunc )\r
@@ -2448,7 +2468,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
                 */\r
                isVisible : function()\r
                {\r
-                       return !!this.getInputElement().$.offsetHeight;\r
+                       return this.getInputElement().isVisible();\r
                },\r
 \r
                /**\r