comparison noderef_view.js @ 7:281e131cb6c3

Change location of the out-of-space warning and way to pick the wrapper Previously the warning was screwed when the user pressed the "Add more" button (the possibilites were: warning above the label which looked strange, warning below the the add more button but that would then expand to contain the whole field or warning between the textfields and the add more button but the warning would disaspear when the button was clicked). It's now conveniently placed under the "Search" link. A class is also added to the <div /> wrapping the textfields, so we use that to find the wrapper instead of walking the DOM tree.
author Franck Deroche <franck@defr.org>
date Tue, 27 Jan 2009 11:54:25 +0100
parents e3f85c9247b7
children 1f9c278126f9
comparison
equal deleted inserted replaced
6:e3f85c9247b7 7:281e131cb6c3
5 Drupal.behaviors.noderef_view = function(context) { 5 Drupal.behaviors.noderef_view = function(context) {
6 $('.noderef-view-wrapper div[id$="-wrapper"]:first-child').addClass('noderef-view-items'); 6 $('.noderef-view-wrapper div[id$="-wrapper"]:first-child').addClass('noderef-view-items');
7 $('.noderef_view_link', context).each(function(i, obj) { 7 $('.noderef_view_link', context).each(function(i, obj) {
8 $(obj).addClass('noderef_view_link_processed').click(function() { 8 $(obj).addClass('noderef_view_link_processed').click(function() {
9 // Get the wrapper 9 // Get the wrapper
10 var wrapper = $(this).prev(); 10 var wrapper = $(this)
11 while (!wrapper.is('div')) { 11 .parent()
12 wrapper = wrapper.prev(); 12 .find('.noderef-view-items')
13 } 13 .filter(':first');
14 var element = $(this);
14 15
15 // Hide existing "No space left" message 16 // Hide existing "No space left" message
16 $('div.noderef_nospace', wrapper).fadeOut(); 17 $('div.noderef_outofspace', element.parent()).fadeOut();
17 18
18 // Suppress behavior if it was previsously attached 19 // Suppress behavior if it was previsously attached
19 $(document).unbind('popups_form_success.noderef_view'); 20 $(document).unbind('popups_form_success.noderef_view');
20 21
21 // And now bind it. This code will be executed after successful 22 // And now bind it. This code will be executed after successful
40 } 41 }
41 } 42 }
42 if (left.length) { 43 if (left.length) {
43 message = Drupal.t('No space left for value(s): @titles', 44 message = Drupal.t('No space left for value(s): @titles',
44 { '@titles': left.join(', ')}); 45 { '@titles': left.join(', ')});
45 wrapper.append('<div class="warning noderef_nospace">'+ message +'</div>'); 46 text = $('<br /><div>'+ message + '<div>')
47 .css('display', 'inline')
48 .addClass('warning')
49 .addClass('noderef_outofspace');
50 element.after(text);
46 } 51 }
47 }); 52 });
48 }); 53 });
49 }); 54 });
50 } 55 }