Update leaflet fullscreen.

This commit is contained in:
David Molineus
2016-10-04 13:50:43 +02:00
parent 8a15b79623
commit 6e7cd514c1
11 changed files with 65 additions and 31 deletions

View File

@@ -1,4 +1,4 @@
(function() {
(function () {
L.Control.FullScreen = L.Control.extend({
options: {
@@ -6,7 +6,8 @@ L.Control.FullScreen = L.Control.extend({
title: 'Full Screen',
titleCancel: 'Exit Full Screen',
forceSeparateButton: false,
forcePseudoFullscreen: false
forcePseudoFullscreen: false,
fullscreenElement: false
},
onAdd: function (map) {
@@ -60,7 +61,7 @@ L.Control.FullScreen = L.Control.extend({
map._exitFired = false;
if (map._isFullscreen) {
if (fullScreenApi.supportsFullScreen && !this.options.forcePseudoFullscreen) {
fullScreenApi.cancelFullScreen(map._container);
fullScreenApi.cancelFullScreen(this.options.fullscreenElement ? this.options.fullscreenElement : map._container);
} else {
L.DomUtil.removeClass(map._container, 'leaflet-pseudo-fullscreen');
}
@@ -71,7 +72,7 @@ L.Control.FullScreen = L.Control.extend({
}
else {
if (fullScreenApi.supportsFullScreen && !this.options.forcePseudoFullscreen) {
fullScreenApi.requestFullScreen(map._container);
fullScreenApi.requestFullScreen(this.options.fullscreenElement ? this.options.fullscreenElement : map._container);
} else {
L.DomUtil.addClass(map._container, 'leaflet-pseudo-fullscreen');
}
@@ -81,7 +82,7 @@ L.Control.FullScreen = L.Control.extend({
}
},
_toggleTitle: function() {
_toggleTitle: function () {
this.link.title = this._map._isFullscreen ? this.options.title : this.options.titleCancel;
},
@@ -118,9 +119,9 @@ source : http://johndyer.name/native-fullscreen-javascript-api-plus-jquery-plugi
var
fullScreenApi = {
supportsFullScreen: false,
isFullScreen: function() { return false; },
requestFullScreen: function() {},
cancelFullScreen: function() {},
isFullScreen: function () { return false; },
requestFullScreen: function () {},
cancelFullScreen: function () {},
fullScreenEventName: '',
prefix: ''
},
@@ -131,40 +132,64 @@ source : http://johndyer.name/native-fullscreen-javascript-api-plus-jquery-plugi
fullScreenApi.supportsFullScreen = true;
} else {
// check for fullscreen support by vendor prefix
for (var i = 0, il = browserPrefixes.length; i < il; i++ ) {
for (var i = 0, il = browserPrefixes.length; i < il; i++) {
fullScreenApi.prefix = browserPrefixes[i];
if (typeof document[fullScreenApi.prefix + 'CancelFullScreen' ] !== 'undefined' ) {
if (typeof document[fullScreenApi.prefix + 'CancelFullScreen'] !== 'undefined') {
fullScreenApi.supportsFullScreen = true;
break;
}
}
if (typeof document['msExitFullscreen'] !== 'undefined') {
fullScreenApi.prefix = 'ms';
fullScreenApi.supportsFullScreen = true;
}
}
// update methods to do something useful
if (fullScreenApi.supportsFullScreen) {
fullScreenApi.fullScreenEventName = fullScreenApi.prefix + 'fullscreenchange';
fullScreenApi.isFullScreen = function() {
switch (this.prefix) {
if (fullScreenApi.prefix === 'ms') {
fullScreenApi.fullScreenEventName = 'MSFullscreenChange';
} else {
fullScreenApi.fullScreenEventName = fullScreenApi.prefix + 'fullscreenchange';
}
fullScreenApi.isFullScreen = function () {
switch (this.prefix) {
case '':
return document.fullScreen;
case 'webkit':
return document.webkitIsFullScreen;
case 'ms':
return document.msFullscreenElement;
default:
return document[this.prefix + 'FullScreen'];
}
};
fullScreenApi.requestFullScreen = function(el) {
return (this.prefix === '') ? el.requestFullscreen() : el[this.prefix + 'RequestFullScreen']();
fullScreenApi.requestFullScreen = function (el) {
switch (this.prefix) {
case '':
return el.requestFullscreen();
case 'ms':
return el.msRequestFullscreen();
default:
return el[this.prefix + 'RequestFullScreen']();
}
};
fullScreenApi.cancelFullScreen = function(el) {
return (this.prefix === '') ? document.exitFullscreen() : document[this.prefix + 'CancelFullScreen']();
fullScreenApi.cancelFullScreen = function () {
switch (this.prefix) {
case '':
return document.exitFullscreen();
case 'ms':
return document.msExitFullscreen();
default:
return document[this.prefix + 'CancelFullScreen']();
}
};
}
// jQuery plugin
if (typeof jQuery !== 'undefined') {
jQuery.fn.requestFullScreen = function() {
return this.each(function() {
jQuery.fn.requestFullScreen = function () {
return this.each(function () {
var el = jQuery(this);
if (fullScreenApi.supportsFullScreen) {
fullScreenApi.requestFullScreen(el);