| Project: | Popups: Add and Reference |
| Version: | 6.x-2.0-alpha1 |
| Component: | Code |
| Category: | task |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs work |
Issue Summary
Drupal.behaviors.popups_reference = function(context) {
$('.popups-reference', context).not('.popups-reference-processed').each(function() {
//$(this).addClass('popups-reference-processed'); // Don't re-add to processed links.
$(this).click(function() {
var rel = $(this).attr('rel'); // Rel attribute of the clicked link is the wrapper id.
var wrapper = $(this).parent().parent();
// 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(obj, popup) {
// 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').append('<option value="' + nid + '" >' + title + '</option>').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);
}
});
});
});
};The relevant line here is "var wrapper = $(this).parent().parent();"
If the alter function removes the need to add a number to the class selector
popups-reference-0 to popups-reference
The javascript could look like this
"var wrapper = $(this).parent('.popups-reference');"
this way, there is no need to use a id counter after each popups-reference and then solve one problem I had with multigroup module (cck 3.x)
When a cck group is added, it doesn't recall the alter form because it use a cached form. In other words the counter doesn't get incremented or always stays at 0 because multigroup only add a new group at a time.
I also added a line which will add a new option to select field so it can select it.
Comments
#1
I'd be careful with something like parent.parent; I use it myself but dislike it cause someone might want to reorder the divs, or add a div in, and then bam, broken
The reason this worries me is that I am making a custom node reference that does wrap the link at least in a separate div ATM.
#2
Still dislike the need for parent, parent but after looking at it see no other good way to do it.
thanks for the patch though, fixed an issue I was having also
However, should probably combine it with this http://drupal.org/node/407592 and call the change event since for whatever reason it's not being called.
#3
This is an interesting idea. Can I get a patch, or at least a diff?
#4
Tested a patch version but haven't tested this patch (made it quickly since I want this change).
Doesn't include any of the other patches like the trigger change patch