Skip to content

Instantly share code, notes, and snippets.

@jungleBadger
Last active September 25, 2018 01:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jungleBadger/f41508ce7991f968852aefabdde2bff4 to your computer and use it in GitHub Desktop.
Save jungleBadger/f41508ce7991f968852aefabdde2bff4 to your computer and use it in GitHub Desktop.

How to Run NC Cloud widget

  1. Import widget script:
<script defer data-nc-token="{YOUR_TOKEN}" src="/widget" type="text/javascript"></script>
  1. Construct the html
<body>
  <div id="chat-parent">
     <div id="chat-element"></div>
  <div>
</body>
  1. Style up the parent element
#chat-parent {
  width: 200px;
  height: 400px;
}
// chat-element will assume 100% of width and height of it's parent, meaning that the only relevant style to control size is applied directly on the parent element
  1. Init widget on your code (On page load):
(function (window) {
window.onload = function () {
    window.initNCWidget({
        "targetEl": "#chat-element", 
       	"defaultLanguage": "pt-BR"
    });
};
}(window));

4 (ALTERNATIVE). Init widget on your code (e.g upon a button click):

(function (window) {
document.querySelector("#button-element").onclick = function () {
    window.initNCWidget({
        "targetEl": "#chat-element", 
       	"defaultLanguage": "pt-BR"
    });
};
}(window));
<body>
  <div id="chat-parent">
     <div id="chat-element"></div>
  <div>
  <button id="button-element"> Open chat </button>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment