Merge pull request #2315 from tschaub/full-screen
Use goog.dom.fullscreen.
This commit is contained in:
@@ -9,9 +9,6 @@
|
|||||||
"source": {
|
"source": {
|
||||||
"includePattern": ".+\\.js(doc)?$",
|
"includePattern": ".+\\.js(doc)?$",
|
||||||
"excludePattern": "(^|\\/|\\\\)_",
|
"excludePattern": "(^|\\/|\\\\)_",
|
||||||
"exclude": [
|
|
||||||
"src/googx/dom/fullscreen.js"
|
|
||||||
],
|
|
||||||
"include": [
|
"include": [
|
||||||
"src",
|
"src",
|
||||||
"externs/oli.js",
|
"externs/oli.js",
|
||||||
|
|||||||
@@ -1,144 +0,0 @@
|
|||||||
// Copyright 2012 The Closure Library Authors. All Rights Reserved.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS-IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @fileoverview Functions for managing full screen status of the DOM.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
goog.provide('googx.dom.fullscreen');
|
|
||||||
goog.provide('googx.dom.fullscreen.EventType');
|
|
||||||
|
|
||||||
goog.require('goog.dom');
|
|
||||||
goog.require('goog.userAgent');
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Event types for full screen.
|
|
||||||
* @enum {string}
|
|
||||||
*/
|
|
||||||
googx.dom.fullscreen.EventType = {
|
|
||||||
/** Dispatched by the Document when the fullscreen status changes. */
|
|
||||||
CHANGE: (function() {
|
|
||||||
if (goog.userAgent.WEBKIT) {
|
|
||||||
return 'webkitfullscreenchange';
|
|
||||||
}
|
|
||||||
if (goog.userAgent.GECKO) {
|
|
||||||
return 'mozfullscreenchange';
|
|
||||||
}
|
|
||||||
if (goog.userAgent.IE) {
|
|
||||||
return 'MSFullscreenChange';
|
|
||||||
}
|
|
||||||
// Opera 12-14, and W3C standard (Draft):
|
|
||||||
// https://dvcs.w3.org/hg/fullscreen/raw-file/tip/Overview.html
|
|
||||||
return 'fullscreenchange';
|
|
||||||
})()
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines if full screen is supported.
|
|
||||||
* @param {!goog.dom.DomHelper=} opt_domHelper The DomHelper for the DOM being
|
|
||||||
* queried. If not provided, use the current DOM.
|
|
||||||
* @return {boolean} True iff full screen is supported.
|
|
||||||
*/
|
|
||||||
googx.dom.fullscreen.isSupported = function(opt_domHelper) {
|
|
||||||
var doc = googx.dom.fullscreen.getDocument_(opt_domHelper);
|
|
||||||
var body = doc.body;
|
|
||||||
return !!(body.webkitRequestFullscreen ||
|
|
||||||
(body.mozRequestFullScreen && doc.mozFullScreenEnabled) ||
|
|
||||||
(body.msRequestFullscreen && doc.msFullscreenEnabled) ||
|
|
||||||
(body.requestFullscreen && doc.fullscreenEnabled));
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Requests putting the element in full screen.
|
|
||||||
* @param {!Element} element The element to put full screen.
|
|
||||||
*/
|
|
||||||
googx.dom.fullscreen.requestFullScreen = function(element) {
|
|
||||||
if (element.webkitRequestFullscreen) {
|
|
||||||
element.webkitRequestFullscreen();
|
|
||||||
} else if (element.mozRequestFullScreen) {
|
|
||||||
element.mozRequestFullScreen();
|
|
||||||
} else if (element.msRequestFullscreen) {
|
|
||||||
element.msRequestFullscreen();
|
|
||||||
} else if (element.requestFullscreen) {
|
|
||||||
element.requestFullscreen();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Requests putting the element in full screen with full keyboard access.
|
|
||||||
* @param {!Element} element The element to put full screen.
|
|
||||||
*/
|
|
||||||
googx.dom.fullscreen.requestFullScreenWithKeys = function(
|
|
||||||
element) {
|
|
||||||
if (element.mozRequestFullScreenWithKeys) {
|
|
||||||
element.mozRequestFullScreenWithKeys();
|
|
||||||
} else if (element.webkitRequestFullscreen) {
|
|
||||||
element.webkitRequestFullscreen();
|
|
||||||
} else {
|
|
||||||
googx.dom.fullscreen.requestFullScreen(element);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Exits full screen.
|
|
||||||
* @param {!goog.dom.DomHelper=} opt_domHelper The DomHelper for the DOM being
|
|
||||||
* queried. If not provided, use the current DOM.
|
|
||||||
*/
|
|
||||||
googx.dom.fullscreen.exitFullScreen = function(opt_domHelper) {
|
|
||||||
var doc = googx.dom.fullscreen.getDocument_(opt_domHelper);
|
|
||||||
if (doc.webkitCancelFullScreen) {
|
|
||||||
doc.webkitCancelFullScreen();
|
|
||||||
} else if (doc.mozCancelFullScreen) {
|
|
||||||
doc.mozCancelFullScreen();
|
|
||||||
} else if (doc.msExitFullscreen) {
|
|
||||||
doc.msExitFullscreen();
|
|
||||||
} else if (doc.exitFullscreen) {
|
|
||||||
doc.exitFullscreen();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines if the document is full screen.
|
|
||||||
* @param {!goog.dom.DomHelper=} opt_domHelper The DomHelper for the DOM being
|
|
||||||
* queried. If not provided, use the current DOM.
|
|
||||||
* @return {boolean} Whether the document is full screen.
|
|
||||||
*/
|
|
||||||
googx.dom.fullscreen.isFullScreen = function(opt_domHelper) {
|
|
||||||
var doc = googx.dom.fullscreen.getDocument_(opt_domHelper);
|
|
||||||
// IE 11 doesn't have similar boolean property, so check whether
|
|
||||||
// document.msFullscreenElement is null instead.
|
|
||||||
return !!(doc.webkitIsFullScreen || doc.mozFullScreen ||
|
|
||||||
doc.msFullscreenElement || doc.fullscreenElement);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the document object of the dom.
|
|
||||||
* @param {!goog.dom.DomHelper=} opt_domHelper The DomHelper for the DOM being
|
|
||||||
* queried. If not provided, use the current DOM.
|
|
||||||
* @return {!Document} The dom document.
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
googx.dom.fullscreen.getDocument_ = function(opt_domHelper) {
|
|
||||||
return opt_domHelper ?
|
|
||||||
opt_domHelper.getDocument() :
|
|
||||||
goog.dom.getDomHelper().getDocument();
|
|
||||||
};
|
|
||||||
@@ -4,10 +4,10 @@ goog.require('goog.asserts');
|
|||||||
goog.require('goog.dom');
|
goog.require('goog.dom');
|
||||||
goog.require('goog.dom.TagName');
|
goog.require('goog.dom.TagName');
|
||||||
goog.require('goog.dom.classlist');
|
goog.require('goog.dom.classlist');
|
||||||
|
goog.require('goog.dom.fullscreen');
|
||||||
|
goog.require('goog.dom.fullscreen.EventType');
|
||||||
goog.require('goog.events');
|
goog.require('goog.events');
|
||||||
goog.require('goog.events.EventType');
|
goog.require('goog.events.EventType');
|
||||||
goog.require('googx.dom.fullscreen');
|
|
||||||
goog.require('googx.dom.fullscreen.EventType');
|
|
||||||
goog.require('ol.control.Control');
|
goog.require('ol.control.Control');
|
||||||
goog.require('ol.css');
|
goog.require('ol.css');
|
||||||
goog.require('ol.pointer.PointerEventHandler');
|
goog.require('ol.pointer.PointerEventHandler');
|
||||||
@@ -45,7 +45,7 @@ ol.control.FullScreen = function(opt_options) {
|
|||||||
}, tipLabel);
|
}, tipLabel);
|
||||||
|
|
||||||
var button = goog.dom.createDom(goog.dom.TagName.BUTTON, {
|
var button = goog.dom.createDom(goog.dom.TagName.BUTTON, {
|
||||||
'class': this.cssClassName_ + '-' + googx.dom.fullscreen.isFullScreen() +
|
'class': this.cssClassName_ + '-' + goog.dom.fullscreen.isFullScreen() +
|
||||||
' ol-has-tooltip'
|
' ol-has-tooltip'
|
||||||
});
|
});
|
||||||
goog.dom.appendChild(button, tip);
|
goog.dom.appendChild(button, tip);
|
||||||
@@ -64,12 +64,12 @@ ol.control.FullScreen = function(opt_options) {
|
|||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
goog.events.listen(goog.global.document,
|
goog.events.listen(goog.global.document,
|
||||||
googx.dom.fullscreen.EventType.CHANGE,
|
goog.dom.fullscreen.EventType.CHANGE,
|
||||||
this.handleFullScreenChange_, false, this);
|
this.handleFullScreenChange_, false, this);
|
||||||
|
|
||||||
var cssClasses = this.cssClassName_ + ' ' + ol.css.CLASS_UNSELECTABLE +
|
var cssClasses = this.cssClassName_ + ' ' + ol.css.CLASS_UNSELECTABLE +
|
||||||
' ' + ol.css.CLASS_CONTROL +
|
' ' + ol.css.CLASS_CONTROL +
|
||||||
(!googx.dom.fullscreen.isSupported() ? ol.css.CLASS_UNSUPPORTED : '');
|
(!goog.dom.fullscreen.isSupported() ? ol.css.CLASS_UNSUPPORTED : '');
|
||||||
var element = goog.dom.createDom(goog.dom.TagName.DIV, cssClasses, button);
|
var element = goog.dom.createDom(goog.dom.TagName.DIV, cssClasses, button);
|
||||||
|
|
||||||
goog.base(this, {
|
goog.base(this, {
|
||||||
@@ -113,24 +113,24 @@ ol.control.FullScreen.prototype.handlePointerUp_ = function(pointerEvent) {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
ol.control.FullScreen.prototype.handleFullScreen_ = function() {
|
ol.control.FullScreen.prototype.handleFullScreen_ = function() {
|
||||||
if (!googx.dom.fullscreen.isSupported()) {
|
if (!goog.dom.fullscreen.isSupported()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var map = this.getMap();
|
var map = this.getMap();
|
||||||
if (goog.isNull(map)) {
|
if (goog.isNull(map)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (googx.dom.fullscreen.isFullScreen()) {
|
if (goog.dom.fullscreen.isFullScreen()) {
|
||||||
googx.dom.fullscreen.exitFullScreen();
|
goog.dom.fullscreen.exitFullScreen();
|
||||||
} else {
|
} else {
|
||||||
var target = map.getTarget();
|
var target = map.getTarget();
|
||||||
goog.asserts.assert(goog.isDefAndNotNull(target));
|
goog.asserts.assert(goog.isDefAndNotNull(target));
|
||||||
var element = goog.dom.getElement(target);
|
var element = goog.dom.getElement(target);
|
||||||
goog.asserts.assert(goog.isDefAndNotNull(element));
|
goog.asserts.assert(goog.isDefAndNotNull(element));
|
||||||
if (this.keys_) {
|
if (this.keys_) {
|
||||||
googx.dom.fullscreen.requestFullScreenWithKeys(element);
|
goog.dom.fullscreen.requestFullScreenWithKeys(element);
|
||||||
} else {
|
} else {
|
||||||
googx.dom.fullscreen.requestFullScreen(element);
|
goog.dom.fullscreen.requestFullScreen(element);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -144,7 +144,7 @@ ol.control.FullScreen.prototype.handleFullScreenChange_ = function() {
|
|||||||
var closed = this.cssClassName_ + '-false';
|
var closed = this.cssClassName_ + '-false';
|
||||||
var anchor = goog.dom.getFirstElementChild(this.element);
|
var anchor = goog.dom.getFirstElementChild(this.element);
|
||||||
var map = this.getMap();
|
var map = this.getMap();
|
||||||
if (googx.dom.fullscreen.isFullScreen()) {
|
if (goog.dom.fullscreen.isFullScreen()) {
|
||||||
goog.dom.classlist.swap(anchor, closed, opened);
|
goog.dom.classlist.swap(anchor, closed, opened);
|
||||||
} else {
|
} else {
|
||||||
goog.dom.classlist.swap(anchor, opened, closed);
|
goog.dom.classlist.swap(anchor, opened, closed);
|
||||||
|
|||||||
Reference in New Issue
Block a user