schnack
schnack copied to clipboard
I can't get Schnack to work programmatically
With this:
<div class="comments-go-here"></div>
<script src="https://schnack.exam.tld/client.js"></script>
<script>
new Schnack({
target: ".comments-go-here",
slug: "post-slug",
host: "https://schnack.exam.tld"
});
</script>
I receive:
Uncaught (in promise) TypeError: Cannot read property 'SignInVia' of undefined
in the client. Embedding it directly in the HTML works though. Do you have any guesses what am I doing wrong?
shouldn't it be embed.js ?
If I replace https://schnack.exam.tld/client.js with https://schnack.exam.tld/embed.js I receive the following error:
schnack script tag needs some data attributes
ah I see. with the last version we added the localization feature. this breaks your use case bc the default values are pre-filled in index.js, not in client.js.
you can copy them into your constructor for now: https://github.com/schn4ck/schnack/blob/master/src/embed/index.js#L11-L25
Thanks!
Maybe obvious to everyone else but you need a partials property like this:
new Schnack({
target: '#comments-container',
slug: $(this).data('slug'),
host: 'https://comments.example.com',
partials: {
Preview: `Preview`,
Edit: `Edit`,
SendComment: `Send comment`,
Cancel: `Cancel`,
Or: ``,
Mute: `mute notifications`,
UnMute: `unmute`,
PostComment: `Post a comment. Markdown is supported!`,
AdminApproval: `This comment is still waiting for your approval`,
WaitingForApproval: `Your comment is still waiting for approval by the site owner`,
SignInVia: `To post a comment you need to sign in with one of these providers:`,
Reply: `<i class='icon schnack-icon-reply'></i> reply`,
LoginStatus: "(signed in as <span class='schnack-user'>@%USER%</span> :: <a class='schnack-signout' href='#'>sign out</a>)"
}
})
Took me a while to figure out why mine wasn't working :)