Please type the name of the public, existing room that you want to load into your sidecar. E.g. gitterHQ/sidecar
Just copy and paste it into your site.
<script>
((window.gitter = {}).chat = {}).options = {
room: ''
};
</script>
<script src="https://sidecar.gitter.im/dist/sidecar.v1.js" async defer></script>
Primarily sidecar has an activation element that will show sidecar and a target element where sidecar gets loaded. These elements are specified by default but can be customised (see below).
If you need a custom button or want to insert the chat in your own element, use the following setup:
<script>
((window.gitter = {}).chat = {}).options = {
room: 'gitterHQ/sidecar',
activationElement: '.my-special-button',
targetElement: '.my-special-target-element'
};
</script>
You can define toggle/open/close buttons in your page using the .js-gitter-toggle-chat-button
class and an optional data-gitter-toggle-chat-state
attribute. If you do not provide a data-gitter-toggle-chat-state
, it will default to 'toggle'
. See the examples/toggle-chat-class-buttons
example.
<button class="js-gitter-toggle-chat-button">Toggle Chat</button>
<button class="js-gitter-toggle-chat-button" data-gitter-toggle-chat-state="true">Open Chat</button>
<button class="js-gitter-toggle-chat-button" data-gitter-toggle-chat-state="false">Close Chat</button>
Set options with the global window option:
<script>
((window.gitter = {}).chat = {}).options = {
room: 'gitterHQ/sidecar'
};
</script>
You can also override these options individually on the target element:
<div
class="gitter-chat-embed"
data-room="gitterHQ/sidecar"
></div>
options.room
: string - This is the Gitter room that sidecar will load (gitterHQ/sidecar
)undefined
options.targetElement
: Where you want to embed the chat.'.gitter-chat-embed'
options.activationElement
: When options.showChatByDefault
is false
, this is the element you have to click/interact with to get the chat to actually embed, "Open Chat" button.undefined
undefined
, or true
)false
or null
will disable the activation elementoptions.showChatByDefault
: Whether to embed the chat on page load(true) or wait until the options.activation
is resolved/clicked/interacted with(false).false
options.useStyles
: This will embed CSS into your document to style the activation and target element. If you want to customise these, set this option to false
and specify your own CSS.true
preload
: Whether the Gitter chat iframe should be loaded in when the chat embed instance is created(this is the page load for default embed)false
You can set any of the chat options above in this object as well
window.gitter.chat.options.disableDefaultChat
: Stop the default chat from loading on the page when including the Sidecar script. So you can handle the Gitter chat creation yourself.window.gitter.chat.defaultChat
.gitter.Chat
var chat = new window.gitter.Chat(/* options */);`
options
(getter): Get a readable copy of the options used for this chat instancetoggleChat(isChatOpen)
: Function/method - Takes a boolean which toggles the visibility of the chat paneldestroy()
: Function/method - Clean-up and remove any elements created by the embedEmitted on Document:
gitter-sidecar-ready
: Emitted when the sidecar script has loaded and is available via window.gitter
gitter-sidecar-instance-started
: Emitted after any Sidecar chat instance has initializedchat
: The sidecar chat instance that was initializedEmitted on Target Element:
gitter-chat-toggle
: Emitted whenever the chat is opened or closedstate
: Whether it was opened(true) or closed(false)gitter-chat-started
: Emitted after the Sidecar chat instance has initializedchat
: The sidecar chat instance that was initializedexample:
document.querySelector('.gitter-chat-embed').addEventListener('gitter-chat-toggle', function(e) {
console.log(e.detail.state ? 'Chat Opened' : 'Chat Closed');
});
Sidecar is a (mostly) code-free way of embedding Gitter into your website with a simple JavaScript snippet.
It works out of the box with no customization, or you can control its behaviour with some basic configuration.