--- popups_reference.js +++ popups_reference.js @@ -33,25 +33,37 @@ Drupal.behaviors.popups_reference = function(context) { var $wrapper = $('#' + rel); // Unbind namespaced event, so bindings don't pile up every click. $(document).unbind('popups_form_success.popups_reference'); - + // Bind to the popups API custom form_success event. $(document).bind('popups_form_success.popups_reference', function() { - // Info about the new node was placed in a cookie when it was created. - var nid = popups_reference_get_cookie_value('PopupRefNid'); - var title = decodeURIComponent(popups_reference_get_cookie_value('PopupRefTitle')); - $wrapper.find('select').val(nid); // Select - $wrapper.find(':radio[value=' + nid + ']').select(); // Radio buttons - // Get the first empty autocomplete field to fill (http://drupal.org/node/388406). $emptyAutos = $wrapper.find('input.form-autocomplete').filter(function(i) { return !$(this).val(); }); - if ($emptyAutos.length) { - $emptyAutos.eq(0).val(title); - } - else { // There are no empty fields, use the first one. - $wrapper.find('input.form-autocomplete:first').val(title); + $moreButton = $wrapper.find('.content-add-more input.form-submit'); + + if (!$emptyAutos.length) { + $moreButton.triggerHandler('mousedown'); } + + $moreButton.fadeTo(1000, 2, function() { + // Info about the new node was placed in a cookie when it was created. + var nid = popups_reference_get_cookie_value('PopupRefNid'); + var title = decodeURIComponent(popups_reference_get_cookie_value('PopupRefTitle')); + $wrapper.find('select').val(nid); // Select + $wrapper.find(':radio[value=' + nid + ']').select(); // Radio buttons + + var autoText = title + ' [nid:' + nid + ']'; + $emptyAutos = $wrapper.find('input.form-autocomplete').filter(function(i) { + return !$(this).val(); + }); + if ($emptyAutos.length) { + $emptyAutos.eq(0).val(autoText); + } + else { // There are no empty fields, use the first one. + $wrapper.find('input.form-autocomplete:first').val(autoText); + } + }); }); }); });