# Panel
Display HTML content on a sidebar on the left of the viewer.
# Example
This example adds a custom button to toggle a panel.
title: PSV Panel Demo
const baseUrl = 'https://photo-sphere-viewer-data.netlify.app/assets/';
const buttonId = 'panel-button';
const panelId = 'custom-panel';
const viewer = new PhotoSphereViewer.Viewer({
container: 'viewer',
panorama: baseUrl + 'sphere.jpg',
caption: 'Parc national du Mercantour <b>© Damien Sorel</b>',
loadingImg: baseUrl + 'loader.gif',
touchmoveTwoFingers: true,
mousewheelCtrlKey: true,
navbar: [
'zoom',
{
id: buttonId,
title: 'Toggle panel',
content: '🆘',
onClick: function() {
if (viewer.panel.isVisible(panelId)) {
viewer.panel.hide();
} else {
viewer.panel.show({
id: panelId,
width: '60%',
content: document.querySelector('#panel-content').innerHTML,
});
}
},
},
'caption',
'fullscreen',
],
});
viewer.on('open-panel', function(e, id) {
if (id === panelId) {
viewer.navbar.getButton(buttonId).toggleActive(true);
}
});
viewer.on('close-panel', function(e, id) {
if (id === panelId) {
viewer.navbar.getButton(buttonId).toggleActive(false);
}
});
<script type="html/template" id="panel-content">
<h1>HTML Ipsum Presents</h1>
<p><strong>Pellentesque habitant morbi tristique</strong> senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. <em>Aenean ultricies mi vitae est.</em> Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, <code>commodo vitae</code>, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. <a href="#">Donec non enim</a> in turpis pulvinar facilisis. Ut felis.</p>
<h2>Header Level 2</h2>
<ol>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
<li>Aliquam tincidunt mauris eu risus.</li>
</ol>
<blockquote><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus magna. Cras in mi at felis aliquet congue. Ut a est eget ligula molestie gravida. Curabitur massa. Donec eleifend, libero at sagittis mollis, tellus est malesuada tellus, at luctus turpis elit sit amet quam. Vivamus pretium ornare est.</p></blockquote>
<h3>Header Level 3</h3>
<ul>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
<li>Aliquam tincidunt mauris eu risus.</li>
</ul>
</script>
# Methods
# show(config)
Open the side panel.
option | type | |
---|---|---|
id | string | Unique identifier of the panel, this will be used to hide the panel only if the content has not been replaced by something else. It will be used to store the width defined by the user when using the resize handle. |
content (required) | string | HTML content of the panel. |
noMargin (default false ) | boolean | Remove the default margins inside the panel. |
width (default 400px ) | string | Initial width if the panel (example: 100% , 600px ). |
clickHandler | function | Function called when the user clicks inside the panel or presses the Enter key while an element focused. |
Content focus
After openning, the first focusable element (a
, button
or anything with tabindex
) will be focused, allowing the user to navigate with the Tab key and activate the clickHandler
with the Enter
key.
# hide([id])
Hide the panel, without condition if id
is not provided, or only if the last show
was called with the same id
.
# isVisible([id]): boolean
Check if the panel is opened.
# Events
# open-panel(id)
Triggered when the panel is opened.
# close-panel(id)
Triggered when the panel is closed.