Sidebar component ​
Example code ​
Basic example ​
html
<html>
<template id="layout-template">
<webpdf>
<div class="btn-container">
<xbutton @controller="custom:SidebarActionController" action="collapse">collapse</xbutton>
<xbutton @controller="custom:SidebarActionController" action="collpase.totally">collapse totally</xbutton>
<xbutton @controller="custom:SidebarActionController" action="expand">expand</xbutton>
<xbutton @controller="custom:SidebarActionController" action="active.layers">active layers panel</xbutton>
<xbutton @controller="custom:SidebarActionController" action="active.bookmark">active bookmark panel
</xbutton>
</div>
<div class="fv__ui-body">
<sidebar name="my-sidebar">
<sidebar-panel name="sidebar-layers" icon-class="fv__icon-sidebar-page-manager"
title="Layers"></sidebar-panel>
<sidebar-panel name="sidebar-bookmark" active icon-class="fv__icon-sidebar-bookmark"
title="Bookmark"></sidebar-panel>
</sidebar>
<viewer></viewer>
</div>
</webpdf>
</template>
</html>
<style>
.btn-container {
display: flex;
padding: 10px 0;
}
.btn-container > .fv__ui-button + .fv__ui-button {
margin-left: 20px;
}
</style>
<script>
UIExtension.PDFUI.module('custom', [])
.controller('SidebarActionController', {
handle: function () {
var action = this.component.getAttribute('action');
var sidebar = this.getComponentByName('my-sidebar');
switch (action) {
case 'collapse':
sidebar.collapse();
break;
case 'collpase.totally':
sidebar.collapseTotally();
break;
case 'expand':
sidebar.expand();
break;
case 'active.layers':
sidebar.getComponentByName('sidebar-layers').active();
break;
case 'active.bookmark':
sidebar.getComponentByName('sidebar-bookmark').active();
break;
}
}
})
var CustomAppearance = UIExtension.appearances.Appearance.extend({
getLayoutTemplate: function () {
return document.getElementById('layout-template').innerHTML;
},
disableAll: function () {
}
});
var libPath = window.top.location.origin + '/lib';
var pdfui = new UIExtension.PDFUI({
viewerOptions: {
libPath: libPath,
jr: {
licenseSN: licenseSN,
licenseKey: licenseKey
}
},
renderTo: document.body,
appearance: CustomAppearance,
addons: []
});
</script>json
{
"iframeOptions": {
"style": "height: 500px"
}
}Sidebar width ​
html
<html>
<template id="layout-template">
<webpdf>
<p> Use a fixed pixel value as the initial width
<p>
<div>
<sidebar width="500" open>
<sidebar-panel icon-class="fv__icon-sidebar-page-manager" title="Layers"></sidebar-panel>
<sidebar-panel active icon-class="fv__icon-sidebar-bookmark" title="Bookmark"></sidebar-panel>
</sidebar>
</div>
<p> Use the scale value of window.innerWidth as the initial width </p>
<div>
<sidebar width="0.5" open>
<sidebar-panel icon-class="fv__icon-sidebar-page-manager" title="Layers"></sidebar-panel>
<sidebar-panel active icon-class="fv__icon-sidebar-bookmark" title="Bookmark"></sidebar-panel>
</sidebar>
</div>
<div class="hide">
<viewer></viewer>
</div>
</webpdf>
</template>
</html>
<script>
var CustomAppearance = UIExtension.appearances.Appearance.extend({
getLayoutTemplate: function () {
return document.getElementById('layout-template').innerHTML;
},
disableAll: function () {
}
});
var libPath = window.top.location.origin + '/lib';
var pdfui = new UIExtension.PDFUI({
viewerOptions: {
libPath: libPath,
jr: {
licenseSN: licenseSN,
licenseKey: licenseKey
}
},
renderTo: document.body,
appearance: CustomAppearance,
addons: []
});
</script>json
{
"iframeOptions": {
"style": "height: 500px"
}
}Expand and collapse the sidebar ​
html
<html>
<template id="layout-template">
<webpdf>
<p>Expand sidebar by default</p>
<div>
<sidebar open>
<sidebar-panel icon-class="fv__icon-sidebar-page-manager" title="Layers"></sidebar-panel>
<sidebar-panel active icon-class="fv__icon-sidebar-bookmark" title="Bookmark"></sidebar-panel>
</sidebar>
</div>
<p>Collapse sidebar by default/p>
<div>
<sidebar>
<sidebar-panel icon-class="fv__icon-sidebar-page-manager" title="Layers"></sidebar-panel>
<sidebar-panel active icon-class="fv__icon-sidebar-bookmark" title="Bookmark"></sidebar-panel>
</sidebar>
</div>
<div class="hide">
<viewer></viewer>
</div>
</webpdf>
</template>
</html>
<script>
var CustomAppearance = UIExtension.appearances.Appearance.extend({
getLayoutTemplate: function () {
return document.getElementById('layout-template').innerHTML;
},
disableAll: function () {
}
});
var libPath = window.top.location.origin + '/lib';
var pdfui = new UIExtension.PDFUI({
viewerOptions: {
libPath: libPath,
jr: {
licenseSN: licenseSN,
licenseKey: licenseKey
}
},
renderTo: document.body,
appearance: CustomAppearance,
addons: []
});
</script>json
{
"iframeOptions": {
"style": "height: 500px"
}
}Sidebar button tooltips ​
Hover over a button to show tooltip text.
html
<html>
<template id="layout-template">
<webpdf>
<div>
<sidebar open>
<sidebar-panel @tooltip tooltip-title="Layers sidebar panel" tooltip-placement="right"
icon-class="fv__icon-sidebar-page-manager" title="Layers"></sidebar-panel>
<sidebar-panel @tooltip tooltip-title="Bookmark sidebar panel" tooltip-placement="right" active
icon-class="fv__icon-sidebar-bookmark" title="Bookmark"></sidebar-panel>
</sidebar>
</div>
<div class="hide">
<viewer></viewer>
</div>
</webpdf>
</template>
</html>
<script>
var CustomAppearance = UIExtension.appearances.Appearance.extend({
getLayoutTemplate: function () {
return document.getElementById('layout-template').innerHTML;
},
disableAll: function () {
}
});
var libPath = window.top.location.origin + '/lib';
var pdfui = new UIExtension.PDFUI({
viewerOptions: {
libPath: libPath,
jr: {
licenseSN: licenseSN,
licenseKey: licenseKey
}
},
renderTo: document.body,
appearance: CustomAppearance,
addons: []
});
</script>json
{
"iframeOptions": {
"style": "height: 500px"
}
}Insert a sidebar panel dynamically with JavaScript ​
html
<html>
<template id="layout-template">
<webpdf>
<div>
<xbutton @controller="custom:InsertSidebarController">Add sidebar panel</xbutton>
</div>
<div>
<sidebar open name="sidebar-component-name">
<sidebar-panel @tooltip tooltip-title="Layers sidebar panel" tooltip-placement="right"
icon-class="fv__icon-sidebar-page-manager" title="Layers"></sidebar-panel>
<sidebar-panel @tooltip tooltip-title="Bookmark sidebar panel" tooltip-placement="right" active
icon-class="fv__icon-sidebar-bookmark" title="Bookmark"></sidebar-panel>
</sidebar>
</div>
<div class="hide">
<viewer></viewer>
</div>
</webpdf>
</template>
</html>
<script>
UIExtension.PDFUI.module('custom', [])
.controller('InsertSidebarController', {
mounted: function () {
this.count = 0;
},
handle: function () {
if (this.count >= 3) {
return;
}
this.count++;
this.getPDFUI().getComponentByName('sidebar-component-name')
.then(sidebar => {
sidebar.append(
'<sidebar-panel icon-class="fv__icon-sidebar-bookmark" title="Dynamic sidebar panel"></sidebar-panel>'
);
})
}
});
var CustomAppearance = UIExtension.appearances.Appearance.extend({
getLayoutTemplate: function () {
return document.getElementById('layout-template').innerHTML;
},
disableAll: function () {
}
});
var libPath = window.top.location.origin + '/lib';
var pdfui = new UIExtension.PDFUI({
viewerOptions: {
libPath: libPath,
jr: {
licenseSN: licenseSN,
licenseKey: licenseKey
}
},
renderTo: document.body,
appearance: CustomAppearance,
addons: []
});
</script>json
{
"iframeOptions": {
"style": "height: 300px"
}
}API ​
Sidebar component template ​
Template example:
html
<!-- The width value smaller than 1 means that is a scale value of window.innerWidth -->
<sidebar open width="500">
<sidebar-panel icon-class="fv__icon-sidebar-page-manager" title="Layers"></sidebar-panel>
<sidebar-panel active icon-class="fv__icon-sidebar-bookmark" title="Bookmark"></sidebar-panel>
</sidebar>sidebar template attributes:
| Attribute | Description | Type | Default | Version |
|---|---|---|---|---|
| open | Expanded state | boolean | false | 7.0.0 |
| width | If the expanded sidebar width is greater than or equal to 1, it is treated as pixels; if less than 1, it is multiplied by window.innerWidth for responsive width | number | 310px | 7.0.0 |
sidebar-panel attributes:
| Attribute | Description | Type | Default | Version |
|---|---|---|---|---|
| title | String shown at the top of the expanded sidebar panel | string | '' | 7.0.0 |
| active | Whether the sidebar panel is active | boolean | false | 7.0.0 |
Sidebar object properties ​
sidebar object properties:
| Property | Description | Type |
|---|---|---|
| disabled | Whether the sidebar is disabled | boolean |
| isVisible | Whether the sidebar is visible | boolean |
| status | One of three states: 'SidebarComponent.STATUS_COLLAPSED' 'SidebarComponent.STATUS_COLLAPSED_TOTALLY' 'SidebarComponent.STATUS_EXPANDED' | string |
sidebar-panel object properties:
| Property | Description | Type |
|---|---|---|
| disabled | Whether the sidebar panel is disabled | boolean |
| isVisible | Whether the sidebar panel is visible | boolean |
| isActive | Whether the sidebar panel is active | boolean |
Methods ​
sidebar methods:
| Method | Description | Version |
|---|---|---|
| isCollapsed(): boolean | Returns true if status is not SidebarComponent.STATUS_EXPANDED | 7.0.0 |
| expand(width: number): void | Expand the sidebar | 7.0.0 |
| collapse(): void | Hide sidebar panels while keeping sidebar buttons visible | 7.0.0 |
| collapseTotally(): void | Hide sidebar panels and sidebar buttons | 7.0.0 |
sidebar-panel methods:
| Method | Description | Version |
|---|---|---|
| disable(): void | Disable the sidebar panel; once disabled, it cannot be activated | 7.0 |
| enable(): void | Enable the sidebar panel | 7.0 |
| show(): void | Show a hidden sidebar panel | 7.0 |
| hide(): void | Hide the sidebar panel | 7.0 |
| destroy(): void | Destroy the sidebar panel | 7.0 |
Events ​
Sidebar events:
| Event name | Description | Example | Version |
|---|---|---|---|
COMPONENT_EVENTS.EXPAND | Fired when the sidebar expands | sidebar.on(COMPONENT_EVENTS.EXPAND, () => void) | 7.0.0 |
COMPONENT_EVENTS.COLLAPSE | Fired when the sidebar collapses | sidebar.on(COMPONENT_EVENTS.COLLAPSE, () => void) | 7.0.0 |
Sidebar-panel events:
| Event name | Description | Example | Version |
|---|---|---|---|
| active | Fired when the sidebar panel is activated | sidebarPanel.on('active', () => {}) | 7.0.0 |
| deactive | Fired when the sidebar panel is deactivated | sidebarPanel.on('deactive', () => {}) | 7.0.0 |
| shown | Fired when the sidebar panel is shown | sidebarPanel.on('shown', () => {}) | 7.0.0 |
| hidden | Fired when the sidebar panel is hidden | sidebarPanel.on('hidden', () => {}) | 7.0.0 |