Reputation: 11336
I have a list of textarea
fields on the page. I need to be able to click on any of them and copy just the content of the clicked on into the clipboard. Since there are many, I prefer to refer to them as their textarea
element instead of giving an ID.
I did come to the following code which works but I notice that is not very responsive. The official zClip page suggests to load the zclip when the page loads but I do not how to do so and still work for any given textarea
element.
$(document).ready(function() {
return $("textarea").click(function() {
return $("textarea").zclip({
path: "/assets/ZeroClipboard.swf",
copy: $(this).text(),
afterCopy: function() {
return $(this).select();
}
});
});
});
Any idea how to do so?
Upvotes: 1
Views: 1051
Reputation: 92274
I think your code should just read
$(document).ready(function() {
$("textarea").zclip({
path: "/assets/ZeroClipboard.swf",
copy: function () {
return $(this).val();
},
afterCopy: function() {
$(this).select();
}
});
});
copy
config option should use a function so it can return the current value of the textarea, not the initial valueThe examples on the page show applying zclip
to another element, it will copy when you click that element, not the textarea, you'll have to dig into that.
Upvotes: 1