@mescius/dspdfviewer
Version:
Document Solutions PDF Viewer
85 lines (70 loc) • 2.32 kB
JavaScript
const links = [{
href: '/examples',
title: 'More Examples'
}, {
href: '/docs',
title: 'Documentation'
}];
const navId = 'ds-examples-navigation';
function renderLinks() {
const navElement = document.createElement('div');
navElement.id = navId;
for (const { href, title } of links) {
const linkElement = document.createElement('a');
linkElement.href = href;
linkElement.innerText = title;
navElement.appendChild(linkElement);
}
document.body.appendChild(navElement);
}
function renderServerStartWarning() {
const navElement = document.createElement('div');
navElement.id = navId;
navElement.innerHTML = `<span>For advanced usage examples and documentation run local web server with <code>npx serve</code><span>`
document.body.appendChild(navElement);
}
function addExamplesStylesheet() {
const styleElement = document.createElement('style');
styleElement.innerHTML = `
position: absolute;
display: flex;
bottom: 16px;
right: 16px;
border-radius: 8px;
overflow: hidden;
font: 12px system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", "Liberation Sans", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
background:
}
color:
display: block;
padding: 8px;
max-width: 300px;
}
background: black;
padding: 4px;
white-space: nowrap;
}
background:
}
text-decoration: none;
}
border-right: 1px solid
}
`
document.head.appendChild(styleElement);
}
document.addEventListener('DOMContentLoaded', () => {
if (document.querySelector(`
addExamplesStylesheet();
if (location.protocol.startsWith('file')) {
renderServerStartWarning();
} else if (location.protocol.startsWith('http')) {
renderLinks();
}
});