Browse Source

Make opening of links in new tabs configurable.

Default to not doing so except for in standalone viewer.
pull/940/head
Matthew Petroff 4 years ago
parent
commit
4382de1604
4 changed files with 35 additions and 9 deletions
  1. +8
    -0
      doc/json-config-parameters.md
  2. +25
    -8
      src/js/pannellum.js
  3. +1
    -0
      src/standalone/standalone.js
  4. +1
    -1
      utils/build/build.py

+ 8
- 0
doc/json-config-parameters.md View File

@@ -234,6 +234,14 @@ the configuration is provided via the URL; it defaults to `false` but can be
set to `true` when using the API.


### `targetBlank` (boolean)

When `true`, `target="_blank"` is set on most hyperlinks to open them in new
tabs. This is always `true` when using the standalone viewer since said viewer
is often used in an `<iframe>`, where it doesn't make sense to open the link in
the same place. Defaults to `false`.


### `crossOrigin` (string)

This specifies the type of CORS request used and can be set to either


+ 25
- 8
src/js/pannellum.js View File

@@ -110,6 +110,7 @@ var defaultConfig = {
draggable: true,
disableKeyboardCtrl: false,
crossOrigin: 'anonymous',
targetBlank: false,
touchPanSpeedCoeffFactor: 1,
capturedKeyNumbers: [16, 17, 27, 37, 38, 39, 40, 61, 65, 68, 83, 87, 107, 109, 173, 187, 189],
friction: 0.15
@@ -160,7 +161,13 @@ uiContainer.appendChild(dragFix);
// Display about information on right click
var aboutMsg = document.createElement('span');
aboutMsg.className = 'pnlm-about-msg';
aboutMsg.innerHTML = '<a href="https://pannellum.org/" target="_blank" rel="noopener">Pannellum</a>';
var aboutMsgLink = document.createElement('a');
aboutMsgLink.href = 'https://pannellum.org/';
aboutMsgLink.textContent = 'Pannellum';
aboutMsg.appendChild(aboutMsgLink);
var aboutMsgVersion = document.createElement('span');
// VERSION PLACEHOLDER FOR BUILD
aboutMsg.appendChild(aboutMsgVersion);
uiContainer.appendChild(aboutMsg);
dragFix.addEventListener('contextmenu', aboutMessage);

@@ -1789,8 +1796,10 @@ function createHotSpot(hs) {
imgp = config.basePath + imgp;
a = document.createElement('a');
a.href = sanitizeURL(hs.URL ? hs.URL : imgp, true);
a.target = '_blank';
a.rel = 'noopener';
if (config.targetBlank) {
a.target = '_blank';
a.rel = 'noopener';
}
span.appendChild(a);
var image = document.createElement('img');
image.src = sanitizeURL(imgp);
@@ -1806,7 +1815,7 @@ function createHotSpot(hs) {
for (var key in hs.attributes) {
a.setAttribute(key, hs.attributes[key]);
}
} else {
} else if (config.targetBlank) {
a.target = '_blank';
a.rel = 'noopener';
}
@@ -2109,6 +2118,10 @@ function processOptions(isPreview) {
infoDisplay.author.innerHTML = '';
if (!config.hasOwnProperty('title') && !config.hasOwnProperty('author'))
infoDisplay.container.style.display = 'none';
if (config.targetBlank) {
aboutMsgLink.rel = 'noopener';
aboutMsgLink.target = '_blank';
}

// Fill in load button label and loading box text
controls.load.innerHTML = '<div><p>' + config.strings.loadButtonLabel + '</p></div>';
@@ -2128,8 +2141,10 @@ function processOptions(isPreview) {
if (config.authorURL) {
var authorLink = document.createElement('a');
authorLink.href = sanitizeURL(config['authorURL'], true);
authorLink.target = '_blank';
authorLink.rel = 'noopener';
if (config.targetBlank) {
authorLink.target = '_blank';
authorLink.rel = 'noopener';
}
authorLink.innerHTML = escapeHTML(config[key]);
authorText = authorLink.outerHTML;
}
@@ -2140,8 +2155,10 @@ function processOptions(isPreview) {
case 'fallback':
var link = document.createElement('a');
link.href = sanitizeURL(config[key], true);
link.target = '_blank';
link.rel = 'noopener';
if (config.targetBlank) {
link.target = '_blank';
link.rel = 'noopener';
}
link.textContent = 'Click here to view this panorama in an alternative viewer.';
var message = document.createElement('p');
message.textContent = 'Your browser does not support WebGL.';


+ 1
- 0
src/standalone/standalone.js View File

@@ -96,6 +96,7 @@ function parseURLParameters() {

// Create viewer
configFromURL.escapeHTML = true;
configFromURL.targetBlank = true;
viewer = pannellum.viewer('container', configFromURL);
}



+ 1
- 1
utils/build/build.py View File

@@ -104,7 +104,7 @@ def build(files, css, html, filename, release=False):
else:
print('No .git folder detected, setting version to testing')
version = "testing"
js = js.replace('"_blank">Pannellum</a>','"_blank">Pannellum</a> ' + version)
js = js.replace('// VERSION PLACEHOLDER FOR BUILD', 'aboutMsgVersion.textContent = " ' + version + '";')
with open('../../src/standalone/standalone.js', 'r') as f:
standalone_js = f.read()
standalone_js = JScompress(js + standalone_js)


Loading…
Cancel
Save