Can anyone help me with getting Zeroclipboard running with Meteor? I’ve not used it before, but it looks like it’s the best solution for what I need to do (put something on the clipboard).
I’ve tried using Propercursive’s package (https://atmospherejs.com/propercursive/zeroclipboard) but because I’m not that good a JS coder I keep running into errors I can’t really seem to understand. Even trying to do it ‘statically’ - like getting a bit of test-text into the clipboard - seems to end with no result.
Does anyone have a working example out there for me to have a look at?
I think the .swf file is in the correct location when I trawl through the package code, but as I said, I’ve not got much JS/Meteor experience so I’m wondering if I’m making a rookie error here.
I haven’t used this package, so I may be completely off-base here
The github docs suggest that you need to supply a DOM element to ZeroClipboard (which may explain the Cannot read property 'appendChild' of null message.
// main.js
var client = new ZeroClipboard( document.getElementById(“copy-button”) );
If that’s the case, then your best bet for instantiating this may be in the onRendered function of a template.
<template name="copyToClipboard">
<button id="copy-button" data-clipboard-text="Copy Me!" title="Click to copy me.">Copy to Clipboard</button>
</template>
Template.copyToClipboard.onRendered(function() {
this.client = new ZeroClipboard(document.getElementById("copy-button"));
});
That’s a rather naive example, but it re-uses the github documented code.
Naive enough to actually work! Thank you very much!!
I was looking in the right direction (adding a DOM element) but obviously not putting everything in the right locations. The missing link for me was the onRendered() function.
I dont know, I scope everything in template as @something in coffeescript.
Not sure what is correct JS equivalent.
And I want it to be template scoped, so if you render more instances of copy buttons, it would not touch each others “client” reference in global scope.