d356a4ea36e644cda6760fbec67e883564da5523
3 L
.Control
.FullScreen
= L
.Control
.extend({
7 forceSeparateButton
: false,
8 forcePseudoFullscreen
: false
11 onAdd: function (map
) {
12 var className
= 'leaflet-control-zoom-fullscreen', container
, content
= '';
14 if (map
.zoomControl
&& !this.options
.forceSeparateButton
) {
15 container
= map
.zoomControl
._container
;
17 container
= L
.DomUtil
.create('div', 'leaflet-bar');
20 if (this.options
.content
) {
21 content
= this.options
.content
;
23 className
+= ' fullscreen-icon';
26 this._createButton(this.options
.title
, className
, content
, container
, this.toggleFullScreen
, this);
31 _createButton: function (title
, className
, content
,container
, fn
, context
) {
32 var link
= L
.DomUtil
.create('a', className
, container
);
35 link
.innerHTML
= content
;
38 .addListener(link
, 'click', L
.DomEvent
.stopPropagation
)
39 .addListener(link
, 'click', L
.DomEvent
.preventDefault
)
40 .addListener(link
, 'click', fn
, context
);
43 .addListener(container
, fullScreenApi
.fullScreenEventName
, L
.DomEvent
.stopPropagation
)
44 .addListener(container
, fullScreenApi
.fullScreenEventName
, L
.DomEvent
.preventDefault
)
45 .addListener(container
, fullScreenApi
.fullScreenEventName
, this._handleEscKey
, context
);
48 .addListener(document
, fullScreenApi
.fullScreenEventName
, L
.DomEvent
.stopPropagation
)
49 .addListener(document
, fullScreenApi
.fullScreenEventName
, L
.DomEvent
.preventDefault
)
50 .addListener(document
, fullScreenApi
.fullScreenEventName
, this._handleEscKey
, context
);
55 toggleFullScreen: function () {
57 map
._exitFired
= false;
58 if (map
._isFullscreen
) {
59 if (fullScreenApi
.supportsFullScreen
&& !this.options
.forcePseudoFullscreen
) {
60 fullScreenApi
.cancelFullScreen(map
._container
);
62 L
.DomUtil
.removeClass(map
._container
, 'leaflet-pseudo-fullscreen');
65 map
.fire('exitFullscreen');
66 map
._exitFired
= true;
67 map
._isFullscreen
= false;
70 if (fullScreenApi
.supportsFullScreen
&& !this.options
.forcePseudoFullscreen
) {
71 fullScreenApi
.requestFullScreen(map
._container
);
73 L
.DomUtil
.addClass(map
._container
, 'leaflet-pseudo-fullscreen');
76 map
.fire('enterFullscreen');
77 map
._isFullscreen
= true;
81 _handleEscKey: function () {
83 if (!fullScreenApi
.isFullScreen(map
) && !map
._exitFired
) {
84 map
.fire('exitFullscreen');
85 map
._exitFired
= true;
86 map
._isFullscreen
= false;
91 L
.Map
.addInitHook(function () {
92 if (this.options
.fullscreenControl
) {
93 this.fullscreenControl
= L
.control
.fullscreen(this.options
.fullscreenControlOptions
);
94 this.addControl(this.fullscreenControl
);
98 L
.control
.fullscreen = function (options
) {
99 return new L
.Control
.FullScreen(options
);
103 Native FullScreen JavaScript API
105 Assumes Mozilla naming conventions instead of W3C for now
107 source : http://johndyer.name/native-fullscreen-javascript-api-plus-jquery-plugin/
113 supportsFullScreen
: false,
114 isFullScreen: function() { return false; },
115 requestFullScreen: function() {},
116 cancelFullScreen: function() {},
117 fullScreenEventName
: '',
120 browserPrefixes
= 'webkit moz o ms khtml'.split(' ');
122 // check for native support
123 if (typeof document
.exitFullscreen
!== 'undefined') {
124 fullScreenApi
.supportsFullScreen
= true;
126 // check for fullscreen support by vendor prefix
127 for (var i
= 0, il
= browserPrefixes
.length
; i
< il
; i
++ ) {
128 fullScreenApi
.prefix
= browserPrefixes
[i
];
129 if (typeof document
[fullScreenApi
.prefix
+ 'CancelFullScreen' ] !== 'undefined' ) {
130 fullScreenApi
.supportsFullScreen
= true;
136 // update methods to do something useful
137 if (fullScreenApi
.supportsFullScreen
) {
138 fullScreenApi
.fullScreenEventName
= fullScreenApi
.prefix
+ 'fullscreenchange';
139 fullScreenApi
.isFullScreen = function() {
140 switch (this.prefix
) {
142 return document
.fullScreen
;
144 return document
.webkitIsFullScreen
;
146 return document
[this.prefix
+ 'FullScreen'];
149 fullScreenApi
.requestFullScreen = function(el
) {
150 return (this.prefix
=== '') ? el
.requestFullscreen() : el
[this.prefix
+ 'RequestFullScreen']();
152 fullScreenApi
.cancelFullScreen = function(el
) {
153 return (this.prefix
=== '') ? document
.exitFullscreen() : document
[this.prefix
+ 'CancelFullScreen']();
158 if (typeof jQuery
!== 'undefined') {
159 jQuery
.fn
.requestFullScreen = function() {
160 return this.each(function() {
161 var el
= jQuery(this);
162 if (fullScreenApi
.supportsFullScreen
) {
163 fullScreenApi
.requestFullScreen(el
);
170 window
.fullScreenApi
= fullScreenApi
;