JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.4.1
[ckeditor.git] / _source / plugins / dialog / plugin.js
index 917d2dd..d708616 100644 (file)
@@ -68,6 +68,30 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
                return null;\r
        }\r
 \r
+\r
+       function clearOrRecoverTextInputValue( container, isRecover )\r
+       {\r
+               var inputs = container.$.getElementsByTagName( 'input' );\r
+               for ( var i = 0, length = inputs.length; i < length ; i++ )\r
+               {\r
+                       var item = new CKEDITOR.dom.element( inputs[ i ] );\r
+\r
+                       if ( item.getAttribute( 'type' ).toLowerCase() == 'text' )\r
+                       {\r
+                               if ( isRecover )\r
+                               {\r
+                                       item.setAttribute( 'value', item.getCustomData( 'fake_value' ) || '' );\r
+                                       item.removeCustomData( 'fake_value' );\r
+                               }\r
+                               else\r
+                               {\r
+                                       item.setCustomData( 'fake_value', item.getAttribute( 'value' ) );\r
+                                       item.setAttribute( 'value', '' );\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
        /**\r
         * This is the base class for runtime dialog objects. An instance of this\r
         * class represents a single named dialog for a single editor instance.\r
@@ -472,7 +496,10 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
 \r
                // Insert the tabs and contents.\r
                for ( var i = 0 ; i < definition.contents.length ; i++ )\r
-                       this.addPage( definition.contents[i] );\r
+               {\r
+                       var page = definition.contents[i];\r
+                       page && this.addPage( page );\r
+               }\r
 \r
                this.parts['tabs'].on( 'click', function( evt )\r
                                {\r
@@ -480,8 +507,10 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
                                        // If we aren't inside a tab, bail out.\r
                                        if ( target.hasClass( 'cke_dialog_tab' ) )\r
                                        {\r
+                                               // Get the ID of the tab, without the 'cke_' prefix and the unique number suffix.\r
                                                var id = target.$.id;\r
-                                               this.selectPage( id.substr( 0, id.lastIndexOf( '_' ) ) );\r
+                                               this.selectPage( id.substring( 4, id.lastIndexOf( '_' ) ) );\r
+\r
                                                if ( this._.tabBarMode )\r
                                                {\r
                                                        this._.tabBarMode = false;\r
@@ -680,12 +709,12 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
                        // First, set the dialog to an appropriate size.\r
                        this.resize( definition.minWidth, definition.minHeight );\r
 \r
-                       // Select the first tab by default.\r
-                       this.selectPage( this.definition.contents[0].id );\r
-\r
                        // Reset all inputs back to their default value.\r
                        this.reset();\r
 \r
+                       // Select the first tab by default.\r
+                       this.selectPage( this.definition.contents[0].id );\r
+\r
                        // Set z-index.\r
                        if ( CKEDITOR.dialog._.currentZIndex === null )\r
                                CKEDITOR.dialog._.currentZIndex = this._.editor.config.baseFloatZIndex;\r
@@ -757,7 +786,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
                        for ( var i in this._.contents )\r
                        {\r
                                for ( var j in this._.contents[i] )\r
-                                       fn( this._.contents[i][j]);\r
+                                       fn( this._.contents[i][j] );\r
                        }\r
                        return this;\r
                },\r
@@ -770,7 +799,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
                 */\r
                reset : (function()\r
                {\r
-                       var fn = function( widget ){ if ( widget.reset ) widget.reset(); };\r
+                       var fn = function( widget ){ if ( widget.reset ) widget.reset( 1 ); };\r
                        return function(){ this.foreach( fn ); return this; };\r
                })(),\r
 \r
@@ -881,7 +910,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
                        page.setAttribute( 'role', 'tabpanel' );\r
 \r
                        var env = CKEDITOR.env;\r
-                       var tabId = contents.id + '_' + CKEDITOR.tools.getNextNumber(),\r
+                       var tabId = 'cke_' + contents.id + '_' + CKEDITOR.tools.getNextNumber(),\r
                                 tab = CKEDITOR.dom.element.createFromHtml( [\r
                                        '<a class="cke_dialog_tab"',\r
                                                ( this._.pageCount > 0 ? ' cke_last' : 'cke_first' ),\r
@@ -963,7 +992,25 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
 \r
                        var selected = this._.tabs[id];\r
                        selected[0].addClass( 'cke_dialog_tab_selected' );\r
-                       selected[1].show();\r
+\r
+                       // [IE] a unvisible input[type='text'] will enlarge it's width\r
+                       // if it's value is long when it show( #5649 )\r
+                       // so we clear it's value before it shows and then recover it\r
+                       if ( CKEDITOR.env.ie6Compat || CKEDITOR.env.ie7Compat )\r
+                       {\r
+                               clearOrRecoverTextInputValue( selected[1] );\r
+                               selected[1].show();\r
+                               setTimeout( function()\r
+                               {\r
+                                       clearOrRecoverTextInputValue( selected[1], true );\r
+                               }, 0 );\r
+                       }\r
+                       else\r
+                       {\r
+                               selected[1].show();\r
+                       }\r
+\r
+\r
                        this._.currentTabId = id;\r
                        this._.currentTabIndex = CKEDITOR.tools.indexOf( this._.tabIdList, id );\r
                },\r
@@ -1386,7 +1433,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
                // Transform the contents entries in contentObjects.\r
                var contents = dialogDefinition.contents;\r
                for ( var i = 0, content ; ( content = contents[i] ) ; i++ )\r
-                       contents[ i ] = new contentObject( dialog, content );\r
+                       contents[ i ] = content && new contentObject( dialog, content );\r
 \r
                CKEDITOR.tools.extend( this, dialogDefinition );\r
        };\r
@@ -2051,7 +2098,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
                                        styles = ( stylesArg && stylesArg.call ? stylesArg( elementDefinition ) : stylesArg ) || {},\r
                                        attributes = ( attributesArg && attributesArg.call ? attributesArg( elementDefinition ) : attributesArg ) || {},\r
                                        innerHTML = ( contentsArg && contentsArg.call ? contentsArg.call( this, dialog, elementDefinition ) : contentsArg ) || '',\r
-                                       domId = this.domId = attributes.id || CKEDITOR.tools.getNextNumber() + '_uiElement',\r
+                                       domId = this.domId = attributes.id || CKEDITOR.tools.getNextId() + '_uiElement',\r
                                        id = this.id = elementDefinition.id,\r
                                        i;\r
 \r
@@ -2349,14 +2396,15 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
                /**\r
                 * Sets the value of this dialog UI object.\r
                 * @param {Object} value The new value.\r
+                * @param {Boolean} noChangeEvent Internal commit, to supress 'change' event on this element.\r
                 * @returns {CKEDITOR.dialog.uiElement} The current UI element.\r
                 * @example\r
                 * uiElement.setValue( 'Dingo' );\r
                 */\r
-               setValue : function( value )\r
+               setValue : function( value, noChangeEvent )\r
                {\r
                        this.getInputElement().setValue( value );\r
-                       this.fire( 'change', { value : value } );\r
+                       !noChangeEvent && this.fire( 'change', { value : value } );\r
                        return this;\r
                },\r
 \r