Ticket #4997: 4997.patch

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

Proposed patch

  • _source/plugins/dialogui/plugin.js

     
    12331233                                 * @returns {String} The value of the action.
    12341234                                 * @example
    12351235                                 */
    1236                                 getAction : function( action )
     1236                                getAction : function()
    12371237                                {
    12381238                                        return this.getInputElement().getParent().$.action;
    12391239                                },
    12401240
    12411241                                /**
     1242                                 * The events must be applied on the inner input element, and
     1243                                 * that must be done when the iframe & form has been loaded
     1244                                 */
     1245                                registerEvents : function( definition )
     1246                                {
     1247                                        var regex = /^on([A-Z]\w+)/,
     1248                                                match;
     1249
     1250                                        var registerDomEvent = function( uiElement, dialog, eventName, func )
     1251                                        {
     1252                                                uiElement.on( 'formLoaded', function()
     1253                                                {
     1254                                                        uiElement.getInputElement().on( eventName, func, uiElement );
     1255                                                });
     1256                                        };
     1257
     1258                                        for ( var i in definition )
     1259                                        {
     1260                                                if ( !( match = i.match( regex ) ) )
     1261                                                        continue;
     1262                                                if ( this.eventProcessors[i] )
     1263                                                        this.eventProcessors[i].call( this, this._.dialog, definition[i] );
     1264                                                else
     1265                                                        registerDomEvent( this, this._.dialog, match[1].toLowerCase(), definition[i] );
     1266                                        }
     1267
     1268                                        return this;
     1269                                },
     1270
     1271                                /**
    12421272                                 * Redraws the file input and resets the file path in the file input.
    12431273                                 * The redraw logic is necessary because non-IE browsers tend to clear
    12441274                                 * the <iframe> containing the file input after closing the dialog.
     
    12491279                                        var frameElement = CKEDITOR.document.getById( this._.frameId ),
    12501280                                                frameDocument = frameElement.getFrameDocument(),
    12511281                                                elementDefinition = this._.definition,
    1252                                                 buttons = this._.buttons;
     1282                                                buttons = this._.buttons,
     1283                                                callNumber = this.formLoadedNumber;
    12531284
     1285                                        // The callback function for the iframe, but we must call tools.addFunction only once
     1286                                        // so we store the function number in this.formLoadedNumber
     1287                                        if (!callNumber)
     1288                                                callNumber = this.formLoadedNumber = CKEDITOR.tools.addFunction(
     1289                                                        function()
     1290                                                        {
     1291                                                                // Now we can apply the events to the input type=file
     1292                                                                this.fire( 'formLoaded' ) ;
     1293                                                        }, this ) ;
     1294
     1295
    12541296                                        function generateFormField()
    12551297                                        {
    12561298                                                frameDocument.$.open();
     
    12731315                                                                CKEDITOR.tools.htmlEncode( size > 0 ? size : "" ),
    12741316                                                                '" />',
    12751317                                                                '</form>',
    1276                                                                 '</body></html>' ].join( '' ) );
     1318                                                                '</body></html>',
     1319                                                                '<script>window.parent.CKEDITOR.tools.callFunction(' + callNumber + ');</script>' ].join( '' ) );
    12771320
    12781321                                                frameDocument.$.close();
    12791322
     
    12901333
    12911334                                getValue : function()
    12921335                                {
    1293                                         // The file path returned from the input tag is incomplete anyway, so it's
    1294                                         // safe to ignore it and prevent the confirmation dialog from appearing.
    1295                                         // (Part of #3465)
    1296                                         return '';
     1336                                        return this.getInputElement().$.value;
    12971337                                },
    12981338
     1339                                /***
     1340                                 * The default value of input type="file" is an empty string, but during initialization
     1341                                 * of this UI element, the iframe still isn't ready so it can't be read from that object
     1342                                 * Setting it manually prevents later issues about the current value ("") being different
     1343                                 * of the initial value (undefined as it asked for .value of a div)
     1344                                 */
     1345                                setInitValue : function()
     1346                                {
     1347                                        this._.initValue = '';
     1348                                },
     1349
    12991350                                /**
    13001351                                 * Defines the onChange event for UI element definitions.
    13011352                                 * @field
    13021353                                 * @type Object
    13031354                                 * @example
    13041355                                 */
    1305                                 eventProcessors : commonEventProcessors,
     1356                                eventProcessors :
     1357                                {
     1358                                        onChange : function( dialog, func )
     1359                                        {
     1360                                                // If this method is called several times (I'm not sure about how this can happen but the default
     1361                                                // onChange processor includes this protection)
     1362                                                // In order to reapply to the new element, the property is deleted at the beggining of the registerEvents method
     1363                                                if ( !this._.domOnChangeRegistered )
     1364                                                {
     1365                                                        // By listening for the formLoaded event, this handler will get reapplied when a new
     1366                                                        // form is created
     1367                                                        this.on( 'formLoaded', function()
     1368                                                        {
     1369                                                                this.getInputElement().on( 'change', function(){ this.fire( 'change', { value : this.getValue() } ); }, this );
     1370                                                        }, this );
     1371                                                        this._.domOnChangeRegistered = true;
     1372                                                }
    13061373
     1374                                                this.on( 'change', func );
     1375                                        }
     1376                                },
     1377
    13071378                                keyboardFocusable : true
    13081379                        }, true );
    13091380
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy