Ticket #4997: 4997_2.patch

File 4997_2.patch, 5.1 KB (added by Alfonso Martínez de Lizarrondo, 14 years ago)

Updated patch

  • _source/plugins/dialogui/plugin.js

     
    13231323                                 * @returns {String} The value of the action.
    13241324                                 * @example
    13251325                                 */
    1326                                 getAction : function( action )
     1326                                getAction : function()
    13271327                                {
    13281328                                        return this.getInputElement().getParent().$.action;
    13291329                                },
    13301330
    13311331                                /**
     1332                                 * The events must be applied on the inner input element, and
     1333                                 * that must be done when the iframe & form has been loaded
     1334                                 */
     1335                                registerEvents : function( definition )
     1336                                {
     1337                                        var regex = /^on([A-Z]\w+)/,
     1338                                                match;
     1339
     1340                                        var registerDomEvent = function( uiElement, dialog, eventName, func )
     1341                                        {
     1342                                                uiElement.on( 'formLoaded', function()
     1343                                                {
     1344                                                        uiElement.getInputElement().on( eventName, func, uiElement );
     1345                                                });
     1346                                        };
     1347
     1348                                        for ( var i in definition )
     1349                                        {
     1350                                                if ( !( match = i.match( regex ) ) )
     1351                                                        continue;
     1352
     1353                                                if ( this.eventProcessors[i] )
     1354                                                        this.eventProcessors[i].call( this, this._.dialog, definition[i] );
     1355                                                else
     1356                                                        registerDomEvent( this, this._.dialog, match[1].toLowerCase(), definition[i] );
     1357                                        }
     1358
     1359                                        return this;
     1360                                },
     1361
     1362                                /**
    13321363                                 * Redraws the file input and resets the file path in the file input.
    13331364                                 * The redraw logic is necessary because non-IE browsers tend to clear
    13341365                                 * the <iframe> containing the file input after closing the dialog.
     
    13391370                                        var frameElement = CKEDITOR.document.getById( this._.frameId ),
    13401371                                                frameDocument = frameElement.getFrameDocument(),
    13411372                                                elementDefinition = this._.definition,
    1342                                                 buttons = this._.buttons;
     1373                                                buttons = this._.buttons,
     1374                                                callNumber = this.formLoadedNumber,
     1375                                                unloadNumber = this.formUnloadNumber;
    13431376
     1377                                        // The callback function for the iframe, but we must call tools.addFunction only once
     1378                                        // so we store the function number in this.formLoadedNumber
     1379                                        if (!callNumber)
     1380                                        {
     1381                                                callNumber = this.formLoadedNumber = CKEDITOR.tools.addFunction(
     1382                                                        function()
     1383                                                        {
     1384                                                                // Now we can apply the events to the input type=file
     1385                                                                this.fire( 'formLoaded' ) ;
     1386                                                        }, this ) ;
     1387
     1388                                                // Remove listeners attached to the content of the iframe (the file input)
     1389                                                unloadNumber = this.formUnloadNumber = CKEDITOR.tools.addFunction(
     1390                                                        function()
     1391                                                        {
     1392                                                                this.getInputElement().clearCustomData();
     1393                                                        }, this ) ;
     1394
     1395                                                this.getDialog()._.editor.on( 'destroy', function()
     1396                                                                {
     1397                                                                        CKEDITOR.tools.removeFunction( callNumber );
     1398                                                                        CKEDITOR.tools.removeFunction( unloadNumber );
     1399                                                                } );
     1400                                        }
     1401
    13441402                                        function generateFormField()
    13451403                                        {
    13461404                                                frameDocument.$.open();
     
    13631421                                                                CKEDITOR.tools.htmlEncode( size > 0 ? size : "" ),
    13641422                                                                '" />',
    13651423                                                                '</form>',
    1366                                                                 '</body></html>' ].join( '' ) );
     1424                                                                '</body></html>',
     1425                                                                '<script>window.parent.CKEDITOR.tools.callFunction(' + callNumber + ');',
     1426                                                                'window.onbeforeunload = function() {window.parent.CKEDITOR.tools.callFunction(' + unloadNumber + ')}</script>' ].join( '' ) );
    13671427
    13681428                                                frameDocument.$.close();
    13691429
     
    13801440
    13811441                                getValue : function()
    13821442                                {
    1383                                         // The file path returned from the input tag is incomplete anyway, so it's
    1384                                         // safe to ignore it and prevent the confirmation dialog from appearing.
    1385                                         // (Part of #3465)
    1386                                         return '';
     1443                                        return this.getInputElement().$.value;
    13871444                                },
    13881445
     1446                                /***
     1447                                 * The default value of input type="file" is an empty string, but during initialization
     1448                                 * of this UI element, the iframe still isn't ready so it can't be read from that object
     1449                                 * Setting it manually prevents later issues about the current value ("") being different
     1450                                 * of the initial value (undefined as it asked for .value of a div)
     1451                                 */
     1452                                setInitValue : function()
     1453                                {
     1454                                        this._.initValue = '';
     1455                                },
     1456
    13891457                                /**
    13901458                                 * Defines the onChange event for UI element definitions.
    13911459                                 * @field
    13921460                                 * @type Object
    13931461                                 * @example
    13941462                                 */
    1395                                 eventProcessors : commonEventProcessors,
     1463                                eventProcessors :
     1464                                {
     1465                                        onChange : function( dialog, func )
     1466                                        {
     1467                                                // If this method is called several times (I'm not sure about how this can happen but the default
     1468                                                // onChange processor includes this protection)
     1469                                                // In order to reapply to the new element, the property is deleted at the beggining of the registerEvents method
     1470                                                if ( !this._.domOnChangeRegistered )
     1471                                                {
     1472                                                        // By listening for the formLoaded event, this handler will get reapplied when a new
     1473                                                        // form is created
     1474                                                        this.on( 'formLoaded', function()
     1475                                                        {
     1476                                                                this.getInputElement().on( 'change', function(){ this.fire( 'change', { value : this.getValue() } ); }, this );
     1477                                                        }, this );
     1478                                                        this._.domOnChangeRegistered = true;
     1479                                                }
    13961480
     1481                                                this.on( 'change', func );
     1482                                        }
     1483                                },
     1484
    13971485                                keyboardFocusable : true
    13981486                        }, true );
    13991487
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy