3 L
.Control
.FullScreen
= L
.Control
.extend({
7 titleCancel
: 'Exit Full Screen',
8 forceSeparateButton
: false,
9 forcePseudoFullscreen
: false,
10 fullscreenElement
: false
13 onAdd: function (map
) {
14 var className
= 'leaflet-control-zoom-fullscreen', container
, content
= '';
16 if (map
.zoomControl
&& !this.options
.forceSeparateButton
) {
17 container
= map
.zoomControl
._container
;
19 container
= L
.DomUtil
.create('div', 'leaflet-bar');
22 if (this.options
.content
) {
23 content
= this.options
.content
;
25 className
+= ' fullscreen-icon';
28 this._createButton(this.options
.title
, className
, content
, container
, this.toggleFullScreen
, this);
30 this._map
.on('enterFullscreen exitFullscreen', this._toggleTitle
, this);
35 _createButton: function (title
, className
, content
, container
, fn
, context
) {
36 this.link
= L
.DomUtil
.create('a', className
, container
);
38 this.link
.title
= title
;
39 this.link
.innerHTML
= content
;
42 .addListener(this.link
, 'click', L
.DomEvent
.stopPropagation
)
43 .addListener(this.link
, 'click', L
.DomEvent
.preventDefault
)
44 .addListener(this.link
, 'click', fn
, context
);
47 .addListener(container
, fullScreenApi
.fullScreenEventName
, L
.DomEvent
.stopPropagation
)
48 .addListener(container
, fullScreenApi
.fullScreenEventName
, L
.DomEvent
.preventDefault
)
49 .addListener(container
, fullScreenApi
.fullScreenEventName
, this._handleEscKey
, context
);
52 .addListener(document
, fullScreenApi
.fullScreenEventName
, L
.DomEvent
.stopPropagation
)
53 .addListener(document
, fullScreenApi
.fullScreenEventName
, L
.DomEvent
.preventDefault
)
54 .addListener(document
, fullScreenApi
.fullScreenEventName
, this._handleEscKey
, context
);
59 toggleFullScreen: function () {
61 map
._exitFired
= false;
62 if (map
._isFullscreen
) {
63 if (fullScreenApi
.supportsFullScreen
&& !this.options
.forcePseudoFullscreen
) {
64 fullScreenApi
.cancelFullScreen(this.options
.fullscreenElement
? this.options
.fullscreenElement
: map
._container
);
66 L
.DomUtil
.removeClass(map
._container
, 'leaflet-pseudo-fullscreen');
69 map
.fire('exitFullscreen');
70 map
._exitFired
= true;
71 map
._isFullscreen
= false;
74 if (fullScreenApi
.supportsFullScreen
&& !this.options
.forcePseudoFullscreen
) {
75 fullScreenApi
.requestFullScreen(this.options
.fullscreenElement
? this.options
.fullscreenElement
: map
._container
);
77 L
.DomUtil
.addClass(map
._container
, 'leaflet-pseudo-fullscreen');
80 map
.fire('enterFullscreen');
81 map
._isFullscreen
= true;
85 _toggleTitle: function () {
86 this.link
.title
= this._map
._isFullscreen
? this.options
.title
: this.options
.titleCancel
;
89 _handleEscKey: function () {
91 if (!fullScreenApi
.isFullScreen(map
) && !map
._exitFired
) {
92 map
.fire('exitFullscreen');
93 map
._exitFired
= true;
94 map
._isFullscreen
= false;
99 L
.Map
.addInitHook(function () {
100 if (this.options
.fullscreenControl
) {
101 this.fullscreenControl
= L
.control
.fullscreen(this.options
.fullscreenControlOptions
);
102 this.addControl(this.fullscreenControl
);
106 L
.control
.fullscreen = function (options
) {
107 return new L
.Control
.FullScreen(options
);
111 Native FullScreen JavaScript API
113 Assumes Mozilla naming conventions instead of W3C for now
115 source : http://johndyer.name/native-fullscreen-javascript-api-plus-jquery-plugin/
121 supportsFullScreen
: false,
122 isFullScreen: function () { return false; },
123 requestFullScreen: function () {},
124 cancelFullScreen: function () {},
125 fullScreenEventName
: '',
128 browserPrefixes
= 'webkit moz o ms khtml'.split(' ');
130 // check for native support
131 if (typeof document
.exitFullscreen
!== 'undefined') {
132 fullScreenApi
.supportsFullScreen
= true;
134 // check for fullscreen support by vendor prefix
135 for (var i
= 0, il
= browserPrefixes
.length
; i
< il
; i
++) {
136 fullScreenApi
.prefix
= browserPrefixes
[i
];
137 if (typeof document
[fullScreenApi
.prefix
+ 'CancelFullScreen'] !== 'undefined') {
138 fullScreenApi
.supportsFullScreen
= true;
142 if (typeof document
['msExitFullscreen'] !== 'undefined') {
143 fullScreenApi
.prefix
= 'ms';
144 fullScreenApi
.supportsFullScreen
= true;
148 // update methods to do something useful
149 if (fullScreenApi
.supportsFullScreen
) {
150 if (fullScreenApi
.prefix
=== 'ms') {
151 fullScreenApi
.fullScreenEventName
= 'MSFullscreenChange';
153 fullScreenApi
.fullScreenEventName
= fullScreenApi
.prefix
+ 'fullscreenchange';
155 fullScreenApi
.isFullScreen = function () {
156 switch (this.prefix
) {
158 return document
.fullScreen
;
160 return document
.webkitIsFullScreen
;
162 return document
.msFullscreenElement
;
164 return document
[this.prefix
+ 'FullScreen'];
167 fullScreenApi
.requestFullScreen = function (el
) {
168 switch (this.prefix
) {
170 return el
.requestFullscreen();
172 return el
.msRequestFullscreen();
174 return el
[this.prefix
+ 'RequestFullScreen']();
177 fullScreenApi
.cancelFullScreen = function () {
178 switch (this.prefix
) {
180 return document
.exitFullscreen();
182 return document
.msExitFullscreen();
184 return document
[this.prefix
+ 'CancelFullScreen']();
190 if (typeof jQuery
!== 'undefined') {
191 jQuery
.fn
.requestFullScreen = function () {
192 return this.each(function () {
193 var el
= jQuery(this);
194 if (fullScreenApi
.supportsFullScreen
) {
195 fullScreenApi
.requestFullScreen(el
);
202 window
.fullScreenApi
= fullScreenApi
;