Drupal6 VBO – ‘Open Links’ header link option updated

Last month I posted the code I used to add a link to header that opens all the edit links in a view. Developments » Drupal6 VBO – ‘Open Edit Links’ link added to header.
This month I had a view with a workflow link and I wanted to add a link to open those links as well.

So I updated the function to take two variables: the descriptive name of the link type (descName) and the jQuery css selector (cssSelector).
So the original ‘Edit’ link had to be updated from

openEditLinks()

to:

openEditLinks('Edit','.views-field-edit-node a');

But now it can be called side by side with the workflow link option:

openEditLinks('Workflow','a.workflow-link');

. Like so:

<a href="#" title="Click to open ALL edit links or highlight a group of edit links to limit the number of links that open.">Open Edit Links</a> |
<a href="#" title="Click to open ALL Workflow links or highlight a group of workflow links to limit the number of links that open.">Open Workflow Links</a>


Here’s the code:

&lt;?php
/* ########## Add JS ############ */
$openEditLinkScript = &lt;&lt;&lt;javascript
/* ########## Add open edit link JS ########## */
function openEditLinks(descName,cssSelector){
	var n_to_open,dl,dll,i,openThese;
	function linkIsSafe(u) {
		if (u.substr(0,7)==&#039;mailto:&#039;) { return false; }
		if (u.substr(0,11)==&#039;javascript:&#039;) { return false; }
		return true;
	}
	n_to_open = 0;
	dl = $(cssSelector); /*&#039;.views-field-edit-node a&#039;); */
	dll = dl.length;
	openThese=[];
	if (window.getSelection &amp;&amp; window.getSelection().containsNode) {
		/* mozilla - increment n_to_open */
		for(i=0; i&lt;dll; ++i) {
			if (window.getSelection().containsNode(dl[i], true) &amp;&amp; linkIsSafe(dl[i].href)) {
				++n_to_open;
				openThese.push(i);
			}
		}
		if (n_to_open &amp;&amp; confirm(&#039;Open &#039; + n_to_open + &#039; selected &#039;+descName+&#039; links in new windows?&#039;)) {
			for(i=0; i&lt;openThese.length; ++i) {
				window.open(dl[openThese[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 &lt; dll; ++i) {
			if (linkIsSafe(dl[i].href)) ++n_to_open;
		}
		if (!n_to_open) alert (&#039;no links&#039;);
		else {
			if (confirm(&#039;No links selected.  Open &#039; + n_to_open + &#039; &#039; + descName + &#039; links in new windows?&#039;)) for (i = 0; i 

<a href="#" title="Click to open ALL edit links or highlight a group of edit links to limit the number of links that open.">Open Edit Links</a> |
<a href="#" title="Click to open ALL Workflow links or highlight a group of workflow links to limit the number of links that open.">Open Workflow Links</a>

There is one thing holding this back from full portability and that is the lack of a fall back option if no descName, or cssSelector values are passed. But maybe I’ll need that next month…

Leave a Comment