Drupal6 VBO Open all Edit Links Bookmarklet

I needed to edit some custom content in a large number of nodes and while Views Bulk Operations (VBO) allowed me to filter down to those nodes there isn’t a custom operation to edit text in custom fields. Not that I would expect there to be one.
So I wanted to open all the edit links in one fell swoop. I have a bookmarklet: ‘Open Selected Links’ which would work OK if the edit link was the only link for each node but it’s not. So I thought Why don’t I update the script to use just the edit links.
And so I did.
The working script is all JS with one line of jQuery.
The line in question previously set the available links using

dl = document.links;

and now uses:

dl = $('#views-bulk-operations-form--1 .views-field-edit-node a');

Which is a collection of all the edit links on the page.

I could probably keep in the old default and prompt the user to use just the edit links but quick and dirty is the name of the game right now.

Here’s the link:
<a href="javascript:(function(){var%20n_to_open,dl,dll,i;%20function%20linkIsSafe(u)%20{%20if%20(u.substr(0,7)=='mailto:')%20return%20false;%20if%20(u.substr(0,11)=='javascript:')%20return%20false;%20return%20true;%20}%20n_to_open%20=%200;%20dl%20=%20$('#views-bulk-operations-form–1%20.views-field-edit-node%20a');%20dll%20=%20dl.length;%20if%20(window.getSelection%20&&%20window.getSelection().containsNode)%20{%20/*%20mozilla%20*/%20for(i=0;%20i<dll;%20++i)%20{%20if%20(window.getSelection().containsNode(dl[i],%20true)%20&&%20linkIsSafe(dl[i].href))%20++n_to_open;%20}%20if%20(n_to_open%20&&%20confirm('Open%20'%20+%20n_to_open%20+%20'%20selected%20links%20in%20new%20windows?'))%20{%20for(i=0;%20i<dll;%20++i)%20if%20(window.getSelection().containsNode(dl[i],%20true)%20&&%20linkIsSafe(dl[i].href))%20window.open(dl[i].href);%20}%20}%20/*%20/mozilla%20*/%20if%20(!n_to_open)%20{%20/*ie,%20or%20mozilla%20with%20no%20links%20selected:%20this%20section%20matches%20open_all_links,%20except%20for%20the%20alert%20text%20*/%20for(i%20=%200;%20i%20<%20dll;%20++i)%20{%20if%20(linkIsSafe(dl[i].href))%20++n_to_open;%20}%20if%20(!n_to_open)%20alert%20('no%20links');%20else%20{%20if%20(confirm('No%20links%20selected.%20%20Open%20'%20+%20n_to_open%20+%20'%20links%20in%20new%20windows?'))%20for%20(i%20=%200;%20i%20Drupal VBO Open all Edit Links

Here are some screen shots;

  1. I filtered on URL does not start with http

    I filtered on URL does not start with http

  2. Here's a sample of the results

    Here's a sample of the results

  3. The bookmarklet link

    The bookmarklet link

  4. Option to open all edit links

    Option to open all edit links

Here’s the code:

  var n_to_open,dl,dll,i;
   function linkIsSafe(u) {
     if (u.substr(0,7)=='mailto:') return false;
     if (u.substr(0,11)=='javascript:') return false;
     return true;
   n_to_open = 0;
   dl = $('#views-bulk-operations-form--1 .views-field-edit-node a');
   dll = dl.length;
   if (window.getSelection && window.getSelection().containsNode) {
     /* mozilla */
 for(i=0; i<dll; ++i) {
       if (window.getSelection().containsNode(dl[i], true) && linkIsSafe(dl[i].href)) ++n_to_open;
     if (n_to_open && confirm('Open ' + n_to_open + ' selected links in new windows?')) {
       for(i=0; i<dll; ++i) if (window.getSelection().containsNode(dl[i], true) && linkIsSafe(dl[i].href)) window.open(dl[i].href);
   /* /mozilla */
 if (!n_to_open) {
     /*ie, or mozilla with no links selected: this section matches open_all_links, except for the alert text */
 for(i = 0; i < dll; ++i) {
       if (linkIsSafe(dl[i].href)) ++n_to_open;
     if (!n_to_open) alert ('no links');
     else {
       if (confirm('No links selected.  Open ' + n_to_open + ' links in new windows?')) for (i = 0; i < dll; ++i) if (linkIsSafe(dl[i].href)) window.open(dl[i].href);

Even better would be to create a custom module the over rides the VBO page including this as an option…
Hmm, maybe I'll add this to the view header?

Leave a Comment