Answered on Twitter, but for the benefit of others who were faced with the same situation (and for clarification), I thought I would rearrange here.
As a rule, I would not recommend views_php - there are many shortcomings for enabling / using PHP filters, which have already been discussed in detail , and this adds a twist to another module when you really do not need it. You can still use drupal_add_js() in the preprocess function in this case and keep things overall dynamic.
In short, you have a list of items for which you want to associate the same event. The event delegation immediately comes to mind as a possible solution. Instead of n event handlers, you now have one for your parent container, which will make your page more responsive. You do not need jQuery for this, but if you prefer to use .delegate()
How to get the identifier from this external JS file is simple: make sure it is in the original markup that you capture. Assuming you're looking for the row identifier, you can usually find it in the "views-row-N" class for each row. Otherwise, you will want to add the class identifier to the template in other ways. Inside the event handler for the target element (your row, the element corresponding to the .views-row row in your parent element), parse the identifier from the class you are going to use and execute the rest of your script based on the value you find from there.
This approach has several advantages: it is one less module, it is another source of security headaches, your JS is in one place, you are binding fewer event handlers, your markup is easier and easier to read, and the event means this method will work. even if elements for some reason will be added to the DOM dynamically later. In terms of features, this will help you know exactly what you are going to do with the popup. Is this an AJAX call for another node? Does it do something based on the position in the list? I would be happy to clarify my answer from there.
source share