Web SDK
Reference for Jahuty's web SDK.
Installation
This library requires a modern web browser.
It’s built from the same code as our Node SDK, and it’s available from the unpkg.com CDN. To use this SDK, add the following script
tag to your document (where x.y.z
is the latest version):
<script src="https://unpkg.com/@jahuty/jahuty@x.y.z/dist/jahuty.js"></script>
Usage
Once configured and initialized, this script will query the DOM for snippet containers to be filled with content.
Add a container for your snippets to the DOM using the HTML5 data-* attribute data-snippet-id
:
<div data-snippet-id="1">
<p>
Hello, world!
</p>
</div>
Set your API key and call initialize()
, after the resource and the DOM have finished loading, to render your snippets:
<script>
window.addEventListener('load', function () {
jahuty.Jahuty.setKey('kn2Kj5ijmT2pH6ZKqAQyNexUqKeRM4VG6DDgWN1lIcc');
jahuty.Jahuty.initialize();
});
</script>
This will cause the innerHTML
of any element with the data-* attribute data-snippet-id
to be replaced with its content:
<div data-snippet-id="1">
<p>
This is my first snippet!
</p>
</div>
Parameters
At this time, this package doesn’t support parameters.
Errors
Any errors will be logged to the browser’s console.
Example
If you’d like to see the SDK in action, see jahuty/jahuty-web-example.
Contributing
Bug reports and pull requests are welcome on GitHub.
Find a typo? Something is wrong in this documentation? Fork and edit it!