I have created a DNA construct database on my lab web site that contains relatively long sequences of text. I would like to display the nodes in a table, but have a button that copies the full construct sequence to the user's clipboard. I guess this is done with the following javascript:

function copy(text) {
if (window.clipboardData) {
window.clipboardData.setData("Text",text);
}
}

and a button

How would I go about putting this into a table-styled view next to the trimmed DNA sequence? Any ideas?

Comments

dawehner’s picture

Category: feature » support

you could add a custom field, for example Global: custom text.

For example

<div class="copy-link">Copy</div>

Then you can use jquery very easy

$(".copy-link").clicked(function() {
  copy($("selector for your field in the current row"));
});
waltonjones’s picture

I am not really sure I follow you dereine. I created the Global:custom text field, but where do I call the jquery function?

Thanks for your help.

dawehner’s picture

you can call it, for example in your js file of your template etc. the js file has just to be included into the page.

waltonjones’s picture

I tried that, but I keep getting this error:

Parse error: parse error, expecting `T_VARIABLE' or `'$''

on the line with the function ()

dawehner’s picture

I gave you a javascript not a php code.

waltonjones’s picture

OK. Thanks. I guess I don't know how to do this. Maybe someone else can think of an easier way to make a copy text link?
It seems like I will need pretty specific instructions, since I know almost nothing about javascript.

waltonjones’s picture

I am learning a little. I created the global text field.

I added exactly what you told me to add to the bottom of my theme's js file, but I am getting the following javascript error in firebug.

$(".copy-link").clicked is not a function
script.js?V()script.js?V (line 13)
[Break on this error] $(".copy-link").clicked(function() {\n

Any ideas? I think I need to wrap it in a function, but which one?

merlinofchaos’s picture

Status: Active » Fixed

You want click() not clicked()

This isn't really a good conversation to be having in the Views issue queue, I'm afraid. Perhaps the Drupal forum, though getting good javascript people to help can be tough, there aren't enough of them.

waltonjones’s picture

Sorry. You are right. Thanks. It was placed here out of my ignorance for where to put it. Thankfully I am learning slowly.

WJ

Status: Fixed » Closed (fixed)
Issue tags: -JavaScript, -views, -table

Automatically closed -- issue fixed for 2 weeks with no activity.