Mercurial > defr > drupal > popups_reference
comparison popups_reference.js @ 5:e1318a313b1d
Popups: AddnReference 1.3
author | Franck Deroche <franck@defr.org> |
---|---|
date | Thu, 19 Mar 2009 11:34:01 +0100 |
parents | 56772e0a00ae |
children | 990f71344a66 |
comparison
equal
deleted
inserted
replaced
0:56772e0a00ae | 5:e1318a313b1d |
---|---|
1 // $Id: popups_reference.js,v 1.1.2.1 2009/01/18 22:40:33 starbow Exp $ | 1 // $Id: popups_reference.js,v 1.1.2.3 2009/03/06 01:54:08 starbow Exp $ |
2 | 2 |
3 /** | 3 /** |
4 * Popups: Add and Reference behavior | 4 * Popups: Add and Reference behavior |
5 * | 5 * |
6 * Adds the behavior of selecting the newly created node. | 6 * Adds the behavior of selecting the newly created node. |
36 | 36 |
37 // Bind to the popups API custom form_success event. | 37 // Bind to the popups API custom form_success event. |
38 $(document).bind('popups_form_success.popups_reference', function() { | 38 $(document).bind('popups_form_success.popups_reference', function() { |
39 // Info about the new node was placed in a cookie when it was created. | 39 // Info about the new node was placed in a cookie when it was created. |
40 var nid = popups_reference_get_cookie_value('PopupRefNid'); | 40 var nid = popups_reference_get_cookie_value('PopupRefNid'); |
41 var title = popups_reference_get_cookie_value('PopupRefTitle'); | 41 var title = decodeURIComponent(popups_reference_get_cookie_value('PopupRefTitle')); |
42 $wrapper.find('select').val(nid); // Select | 42 $wrapper.find('select').val(nid); // Select |
43 $wrapper.find('input.form-autocomplete').val(title); // Autocomplete | |
44 $wrapper.find(':radio[value=' + nid + ']').select(); // Radio buttons | 43 $wrapper.find(':radio[value=' + nid + ']').select(); // Radio buttons |
44 | |
45 // Get the first empty autocomplete field to fill (http://drupal.org/node/388406). | |
46 $emptyAutos = $wrapper.find('input.form-autocomplete').filter(function(i) { | |
47 return !$(this).val(); | |
48 }); | |
49 if ($emptyAutos.length) { | |
50 $emptyAutos.eq(0).val(title); | |
51 } | |
52 else { // There are no empty fields, use the first one. | |
53 $wrapper.find('input.form-autocomplete:first').val(title); | |
54 } | |
45 }); | 55 }); |
46 }); | 56 }); |
47 }); | 57 }); |
48 }; | 58 }; |
49 | 59 |