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. 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) ### `crossOrigin` (string)


This specifies the type of CORS request used and can be set to either 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, draggable: true,
disableKeyboardCtrl: false, disableKeyboardCtrl: false,
crossOrigin: 'anonymous', crossOrigin: 'anonymous',
targetBlank: false,
touchPanSpeedCoeffFactor: 1, touchPanSpeedCoeffFactor: 1,
capturedKeyNumbers: [16, 17, 27, 37, 38, 39, 40, 61, 65, 68, 83, 87, 107, 109, 173, 187, 189], capturedKeyNumbers: [16, 17, 27, 37, 38, 39, 40, 61, 65, 68, 83, 87, 107, 109, 173, 187, 189],
friction: 0.15 friction: 0.15
@@ -160,7 +161,13 @@ uiContainer.appendChild(dragFix);
// Display about information on right click // Display about information on right click
var aboutMsg = document.createElement('span'); var aboutMsg = document.createElement('span');
aboutMsg.className = 'pnlm-about-msg'; 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); uiContainer.appendChild(aboutMsg);
dragFix.addEventListener('contextmenu', aboutMessage); dragFix.addEventListener('contextmenu', aboutMessage);


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


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


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

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


// Create viewer // Create viewer
configFromURL.escapeHTML = true; configFromURL.escapeHTML = true;
configFromURL.targetBlank = true;
viewer = pannellum.viewer('container', configFromURL); 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: else:
print('No .git folder detected, setting version to testing') print('No .git folder detected, setting version to testing')
version = "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: with open('../../src/standalone/standalone.js', 'r') as f:
standalone_js = f.read() standalone_js = f.read()
standalone_js = JScompress(js + standalone_js) standalone_js = JScompress(js + standalone_js)


Loading…
Cancel
Save