I managed to get clipboard.js functionality working for a private page, but even though I’ve used dozens of preventDefaults before, I can’t find where to put it on this occasion…
When I click a link (Blog Title), the page jumps to top…
I’ve tried to e.preventDefault(); in countless spots.
The few times it worked, it disabled the copying functionality at the same time…
I guess I’m not seeing the bigger picture…
Many thanks for a hint/handout
example code:
www.defeestkoffer.be/temporary/preventDefault.php
In my actual code I’m taking the text from the blog and the url that’s in the date, so I don’t think that lends itself well to the one you are mentioning. In theory I can of course put both inside that attribute (manually or with jQuery), but it feels silly doubling up 2 parts of data…
var copyCode = new Clipboard('.copy-BTN', {
text: function(trigger) {
var txt = trigger.textContent, // txt of clicked link
url = trigger.previousElementSibling.getAttribute('href'); // Get url out of previous <a>
return txt + '\r' + url; // make it 2 lines
}
});
the page in one of my list setups does not jump afterwards; so I would hope there does exist something I should be able to put there that keeps it from jumping…?
Anyway, bedtime for me. Thanks again for your help!
Yes, you’re right. I think it’s a bug with the library itself and only surfaces for the case where you don’t have inputs that you’re copying from Firefox, you should file an issue.
When you don’t have an input / textarea to copy from it creates one and appends it to the DOM positioned off-left at the top of the screen, when this gets focus in Firefox that’s what seems to cause the jump to the top. Not sure if it’s preventable but it’s a great test case for them.