-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
do not display fullscreen control on unsupported devices #4786 #4838
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
bd3891d
do not display fullscreen control on unsupported devices #4786
stepankuzmin c306596
move className into class property #4838
stepankuzmin c662998
check for fullscreen support with fullscreenEnabled #4838
stepankuzmin 5529de4
remove extra mozFullScreenEnabled check #4838
stepankuzmin 4adf6bc
check that Fullscreen control gets added then fullscreen is enabled #…
stepankuzmin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ const DOM = require('../../util/dom'); | |
const util = require('../../util/util'); | ||
const window = require('../../util/window'); | ||
|
||
const className = 'mapboxgl-ctrl'; | ||
|
||
/** | ||
* A `FullscreenControl` control contains a button for toggling the map in and out of fullscreen mode. | ||
* | ||
|
@@ -33,15 +35,15 @@ class FullscreenControl { | |
} | ||
|
||
onAdd(map) { | ||
const className = 'mapboxgl-ctrl'; | ||
const container = this._container = DOM.create('div', `${className} mapboxgl-ctrl-group`); | ||
const button = this._fullscreenButton = DOM.create('button', (`${className}-icon ${className}-fullscreen`), this._container); | ||
button.setAttribute("aria-label", "Toggle fullscreen"); | ||
button.type = 'button'; | ||
this._fullscreenButton.addEventListener('click', this._onClickFullscreen); | ||
this._mapContainer = map.getContainer(); | ||
window.document.addEventListener(this._fullscreenchange, this._changeIcon); | ||
return container; | ||
this._map = map; | ||
this._mapContainer = this._map.getContainer(); | ||
this._container = DOM.create('div', `${className} mapboxgl-ctrl-group`); | ||
if (this._checkFullscreenSupport()) { | ||
this._setupUI(); | ||
} else { | ||
util.warnOnce('This device does not support fullscreen mode.'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should also set |
||
} | ||
return this._container; | ||
} | ||
|
||
onRemove() { | ||
|
@@ -50,6 +52,23 @@ class FullscreenControl { | |
window.document.removeEventListener(this._fullscreenchange, this._changeIcon); | ||
} | ||
|
||
_checkFullscreenSupport() { | ||
return !!( | ||
this._mapContainer.requestFullscreen || | ||
this._mapContainer.mozRequestFullScreen || | ||
this._mapContainer.msRequestFullscreen || | ||
this._mapContainer.webkitRequestFullscreen | ||
); | ||
} | ||
|
||
_setupUI() { | ||
const button = this._fullscreenButton = DOM.create('button', (`${className}-icon ${className}-fullscreen`), this._container); | ||
button.setAttribute("aria-label", "Toggle fullscreen"); | ||
button.type = 'button'; | ||
this._fullscreenButton.addEventListener('click', this._onClickFullscreen); | ||
window.document.addEventListener(this._fullscreenchange, this._changeIcon); | ||
} | ||
|
||
_isFullscreen() { | ||
return this._fullscreen; | ||
} | ||
|
@@ -63,7 +82,6 @@ class FullscreenControl { | |
|
||
if ((fullscreenElement === this._mapContainer) !== this._fullscreen) { | ||
this._fullscreen = !this._fullscreen; | ||
const className = 'mapboxgl-ctrl'; | ||
this._fullscreenButton.classList.toggle(`${className}-shrink`); | ||
this._fullscreenButton.classList.toggle(`${className}-fullscreen`); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict'; | ||
|
||
const test = require('mapbox-gl-js-test').test; | ||
const window = require('../../../../src/util/window'); | ||
const Map = require('../../../../src/ui/map'); | ||
const FullscreenControl = require('../../../../src/ui/control/fullscreen_control'); | ||
|
||
function createMap() { | ||
const container = window.document.createElement('div'); | ||
return new Map({ | ||
container: container, | ||
style: { | ||
version: 8, | ||
sources: {}, | ||
layers: [] | ||
} | ||
}); | ||
} | ||
|
||
test('FullscreenControl with no options', (t) => { | ||
t.plan(0); | ||
|
||
const map = createMap(); | ||
const fullscreen = new FullscreenControl(); | ||
map.addControl(fullscreen); | ||
t.end(); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of another global variable could you store this as
this._className
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure!