Mercurial > defr > drupal > popups_reference
comparison popups_reference.js @ 0:56772e0a00ae
Import of dev version (2009-01-19)
author | Franck Deroche <franck@defr.org> |
---|---|
date | Wed, 21 Jan 2009 11:19:01 +0100 |
parents | |
children | ece8e4be4d6f e1318a313b1d |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:56772e0a00ae |
---|---|
1 // $Id: popups_reference.js,v 1.1.2.1 2009/01/18 22:40:33 starbow Exp $ | |
2 | |
3 /** | |
4 * Popups: Add and Reference behavior | |
5 * | |
6 * Adds the behavior of selecting the newly created node. | |
7 */ | |
8 | |
9 /** | |
10 * Parse the cookies to find a value. | |
11 * | |
12 * @param name of cookie value. | |
13 */ | |
14 function popups_reference_get_cookie_value(name) { | |
15 name += '='; | |
16 var cookies = document.cookie.split(';'); | |
17 for (var i=0; i < cookies.length; i++) { | |
18 var cookie = jQuery.trim(cookies[i]); | |
19 if (cookie.indexOf(name) === 0) { | |
20 return cookie.substring(name.length, cookie.length); | |
21 } | |
22 } | |
23 } | |
24 | |
25 /** | |
26 * Attach the behavior. | |
27 */ | |
28 Drupal.behaviors.popups_reference = function(context) { | |
29 $('.popups-reference', context).not('.popups-reference-processed').each(function() { | |
30 $(this).addClass('popups-reference-processed'); // Don't re-add to processed links. | |
31 $(this).click(function() { | |
32 var rel = $(this).attr('rel'); // Rel attribute of the clicked link is the wrapper id. | |
33 var $wrapper = $('#' + rel); | |
34 // Unbind namespaced event, so bindings don't pile up every click. | |
35 $(document).unbind('popups_form_success.popups_reference'); | |
36 | |
37 // Bind to the popups API custom form_success event. | |
38 $(document).bind('popups_form_success.popups_reference', function() { | |
39 // Info about the new node was placed in a cookie when it was created. | |
40 var nid = popups_reference_get_cookie_value('PopupRefNid'); | |
41 var title = popups_reference_get_cookie_value('PopupRefTitle'); | |
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 | |
45 }); | |
46 }); | |
47 }); | |
48 }; | |
49 |