schnack icon indicating copy to clipboard operation
schnack copied to clipboard

I can't get Schnack to work programmatically

Open jfilter opened this issue 6 years ago • 5 comments
trafficstars

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?

jfilter avatar Nov 30 '18 13:11 jfilter

shouldn't it be embed.js ?

gka avatar Nov 30 '18 14:11 gka

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

jfilter avatar Nov 30 '18 15:11 jfilter

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

gka avatar Nov 30 '18 17:11 gka

Thanks!

jfilter avatar Dec 01 '18 00:12 jfilter

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 :)

leviwheatcroft avatar Jan 14 '19 08:01 leviwheatcroft