Ticket #4997: 4997_2.patch
File 4997_2.patch, 5.1 KB (added by , 13 years ago) |
---|
-
_source/plugins/dialogui/plugin.js
1323 1323 * @returns {String} The value of the action. 1324 1324 * @example 1325 1325 */ 1326 getAction : function( action)1326 getAction : function() 1327 1327 { 1328 1328 return this.getInputElement().getParent().$.action; 1329 1329 }, 1330 1330 1331 1331 /** 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 /** 1332 1363 * Redraws the file input and resets the file path in the file input. 1333 1364 * The redraw logic is necessary because non-IE browsers tend to clear 1334 1365 * the <iframe> containing the file input after closing the dialog. … … 1339 1370 var frameElement = CKEDITOR.document.getById( this._.frameId ), 1340 1371 frameDocument = frameElement.getFrameDocument(), 1341 1372 elementDefinition = this._.definition, 1342 buttons = this._.buttons; 1373 buttons = this._.buttons, 1374 callNumber = this.formLoadedNumber, 1375 unloadNumber = this.formUnloadNumber; 1343 1376 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 1344 1402 function generateFormField() 1345 1403 { 1346 1404 frameDocument.$.open(); … … 1363 1421 CKEDITOR.tools.htmlEncode( size > 0 ? size : "" ), 1364 1422 '" />', 1365 1423 '</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( '' ) ); 1367 1427 1368 1428 frameDocument.$.close(); 1369 1429 … … 1380 1440 1381 1441 getValue : function() 1382 1442 { 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; 1387 1444 }, 1388 1445 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 1389 1457 /** 1390 1458 * Defines the onChange event for UI element definitions. 1391 1459 * @field 1392 1460 * @type Object 1393 1461 * @example 1394 1462 */ 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 } 1396 1480 1481 this.on( 'change', func ); 1482 } 1483 }, 1484 1397 1485 keyboardFocusable : true 1398 1486 }, true ); 1399 1487