Mercurial > defr > drupal > noderef_view
comparison noderef_view.js @ 0:a3c1e224e807
Import initial du module noderef_view
| author | Franck Deroche <franck@defr.org> |
|---|---|
| date | Fri, 23 Jan 2009 14:52:03 +0100 |
| parents | |
| children | 25a0c2fcbcfb |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:a3c1e224e807 |
|---|---|
| 1 // vim: set ts=2 sw=2 expandtab syntax=php: | |
| 2 /** | |
| 3 * Attach the noderef_view behavior. | |
| 4 */ | |
| 5 Drupal.behaviors.noderef_view = function(context) { | |
| 6 $('.noderef_view_link', context).each(function(i, obj) { | |
| 7 $(obj).addClass('noderef_view_link_processed').click(function() { | |
| 8 // Get the wrapper | |
| 9 var id = $(this).attr('rel'); | |
| 10 var wrapper = $('#' + id); | |
| 11 | |
| 12 // Suppress behavior if it was previsously attached | |
| 13 $(document).unbind('popups_form_success.noderef_view'); | |
| 14 | |
| 15 // And now bind it. This code will be executed after successful | |
| 16 // completion of the popup select form | |
| 17 $(document).bind('popups_form_success.noderef_view', function() { | |
| 18 selection = noderef_view_get_selection(); | |
| 19 for(nid in selection) { | |
| 20 // Autocomplete field | |
| 21 $('input.form-autocomplete:not([value])', wrapper) | |
| 22 .filter(':first') | |
| 23 .val(selection[nid]); | |
| 24 // Select field | |
| 25 $('select', wrapper).val(nid); | |
| 26 // Radio field | |
| 27 $('input:radio[value='+ nid + '], input:checkbox[value='+ nid +']', wrapper).attr('checked', 'checked'); | |
| 28 } | |
| 29 }); | |
| 30 }); | |
| 31 }); | |
| 32 } | |
| 33 | |
| 34 /** | |
| 35 * Helper function to extract the references values | |
| 36 */ | |
| 37 function noderef_view_get_selection() { | |
| 38 var cookies = document.cookie.split(';'), selection = {}; | |
| 39 for(var i = 0; i < cookies.length; i++) { | |
| 40 var cookie = $.trim(cookies[i]).split('='); | |
| 41 if (cookie[0].indexOf('noderef[') == 0) { | |
| 42 var nid = cookie[0].replace(/noderef\[(\d+)\]/, "$1"); | |
| 43 var title = decodeURIComponent(cookie[1]); | |
| 44 selection[nid] = title; | |
| 45 } | |
| 46 } | |
| 47 return selection; | |
| 48 } |
