Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I have a view displaying multiple nodes with their associated vote widgets.
I have a JS file including the following code:
Drupal.behaviors.response = {
attach: function (context, settings) {
$(document).bind('eventAfterRate', function(event, rate_data)
{
alert('called');
}
}
}
The first time a vote is cast by clicking on a widget, the above script runs once. The second time a vote is cast, by clicking on another node's widget (Only a single vote allowed per node), the script runs twice. On the third vote, the script runs 3X. etc.
Comments
Comment #1
msypes CreditAttribution: msypes commentedUpdate:
I now see this isn't an issue with this module, but system-wide "fact of life." Every time the AJAX call to update the votes is called, my Javascript file is loaded anew and appended to what I already have, so it's attached multiple times.
If there's a way to prevent this behavior, I'd love a response. In the meantime, I've added logic to prevent multiple executions within the script itself.
Comment #2
msypes CreditAttribution: msypes commented