Toggle css class and use css content for anchor

This commit is contained in:
Tim Schaub
2013-04-09 15:47:33 -06:00
committed by Tom Payne
parent 0bd11d0a70
commit 93041becbe
2 changed files with 23 additions and 3 deletions

View File

@@ -52,6 +52,13 @@
text-decoration: none;
width: 22px;
}
a.ol-full-screen-false:after {
content: "\2194";
}
a.ol-full-screen-true:after {
content: "\00d7";
}
.ol-full-screen div {
border-radius: 2px;
}

View File

@@ -3,6 +3,7 @@ goog.provide('ol.control.FullScreen');
goog.require('goog.asserts');
goog.require('goog.dom');
goog.require('goog.dom.TagName');
goog.require('goog.dom.classes');
goog.require('goog.dom.fullscreen');
goog.require('goog.events');
goog.require('goog.events.EventType');
@@ -20,16 +21,23 @@ ol.control.FullScreen = function(opt_options) {
var options = goog.isDef(opt_options) ? opt_options : {};
/**
* @private
* @type {string}
*/
this.cssClassName_ = 'ol-full-screen';
var aElement = goog.dom.createDom(goog.dom.TagName.A, {
'href': '#fullScreen'
}, '\u00d7');
'href': '#fullScreen',
'class': this.cssClassName_ + '-' + goog.dom.fullscreen.isFullScreen()
});
goog.events.listen(aElement, [
goog.events.EventType.CLICK,
goog.events.EventType.TOUCHEND
], this.handleClick_, false, this);
var element = goog.dom.createDom(goog.dom.TagName.DIV, {
'class': 'ol-full-screen ' + ol.css.CLASS_UNSELECTABLE
'class': this.cssClassName_ + ' ' + ol.css.CLASS_UNSELECTABLE
}, aElement);
goog.base(this, {
@@ -61,11 +69,16 @@ ol.control.FullScreen.prototype.handleClick_ = function(browserEvent) {
if (!goog.dom.fullscreen.isSupported()) {
return;
}
var opened = this.cssClassName_ + '-true';
var closed = this.cssClassName_ + '-false';
var anchor = goog.dom.getFirstElementChild(this.element);
if (goog.dom.fullscreen.isFullScreen()) {
goog.dom.classes.swap(anchor, opened, closed);
goog.dom.fullscreen.exitFullScreen();
} else {
var element = map.getTarget();
goog.asserts.assert(!goog.isNull(element));
goog.dom.classes.swap(anchor, closed, opened);
if (this.keys_) {
goog.dom.fullscreen.requestFullScreenWithKeys(element);
} else {