Przeglądaj źródła

Add option to turn device orientation control on by default.

pull/234/head
Matthew Petroff 8 lat temu
rodzic
commit
13cd182f82
2 zmienionych plików z 26 dodań i 6 usunięć
  1. +7
    -0
      doc/json-config-parameters.md
  2. +19
    -6
      src/js/pannellum.js

+ 7
- 0
doc/json-config-parameters.md Wyświetl plik

@@ -63,6 +63,13 @@ not supported by the user's device. The user will be given the option to click
a link and visit this URL if Pannellum fails to work.


### `orientationOnByDefault` (boolean)

If set to `true`, device orientation control will be used when the panorama is
loaded, if the device supports it. If false, device orientation control needs
to be activated by pressing a button. Defaults to `false`.


### `showZoomCtrl` (boolean)

If set to `false`, the zoom controls will not be displayed. Defaults to `true`.


+ 19
- 6
src/js/pannellum.js Wyświetl plik

@@ -192,13 +192,10 @@ if (document.fullscreenEnabled || document.mozFullScreenEnabled || document.webk
// Device orientation toggle
controls.orientation = document.createElement('div');
controls.orientation.addEventListener('click', function(e) {
if (orientation) {
if (orientation)
stopOrientation();
} else {
orientation = true;
window.addEventListener('deviceorientation', orientationListener);
controls.orientation.classList.add('pnlm-orientation-button-active');
}
else
startOrientation();
});
controls.orientation.addEventListener('mousedown', function(e) {e.stopPropagation();});
controls.orientation.addEventListener('touchstart', function(e) {e.stopPropagation();});
@@ -1820,6 +1817,12 @@ function processOptions() {
controls.zoom.style.display = 'none';
controls.fullscreen.style.display = 'none';
}
break;

case 'orientationOnByDefault':
if (config[key])
startOrientation();
break;
}
}
}
@@ -2043,6 +2046,16 @@ function stopOrientation() {
}

/**
* Start using device orientation.
* @private
*/
function startOrientation() {
orientation = true;
window.addEventListener('deviceorientation', orientationListener);
controls.orientation.classList.add('pnlm-orientation-button-active');
}

/**
* Escapes HTML string (to mitigate possible DOM XSS attacks).
* @private
* @param {string} s - String to escape


Ładowanie…
Anuluj
Zapisz