Add Node to control label type

This commit is contained in:
tsauerwein
2015-01-16 09:44:50 +01:00
parent 7679069520
commit fbb2883f6e
4 changed files with 90 additions and 61 deletions
+38 -28
View File
@@ -806,8 +806,8 @@ olx.control;
* collapsible: (boolean|undefined), * collapsible: (boolean|undefined),
* collapsed: (boolean|undefined), * collapsed: (boolean|undefined),
* tipLabel: (string|undefined), * tipLabel: (string|undefined),
* label: (string|undefined), * label: (string|Node|undefined),
* collapseLabel: (string|undefined), * collapseLabel: (string|Node|undefined),
* render: (function(ol.MapEvent)|undefined), * render: (function(ol.MapEvent)|undefined),
* target: (Element|undefined)}} * target: (Element|undefined)}}
* @api * @api
@@ -859,15 +859,17 @@ olx.control.AttributionOptions.prototype.tipLabel;
/** /**
* Text label to use for the collapsed attributions button. Default is `i` * Text label to use for the collapsed attributions button. Default is `i`.
* @type {string|undefined} * Instead of text, also a Node (e.g. a `span` element) can be used.
* @type {string|Node|undefined}
* @api * @api
*/ */
olx.control.AttributionOptions.prototype.label; olx.control.AttributionOptions.prototype.label;
/** /**
* Text label to use for the expanded attributions button. Default is `»` * Text label to use for the expanded attributions button. Default is `»`.
* @type {string|undefined} * Instead of text, also a Node (e.g. a `span` element) can be used.
* @type {string|Node|undefined}
* @api * @api
*/ */
olx.control.AttributionOptions.prototype.collapseLabel; olx.control.AttributionOptions.prototype.collapseLabel;
@@ -980,8 +982,8 @@ olx.control.DefaultsOptions.prototype.zoomOptions;
/** /**
* @typedef {{className: (string|undefined), * @typedef {{className: (string|undefined),
* label: (string|undefined), * label: (string|Node|undefined),
* labelActive: (string|undefined), * labelActive: (string|Node|undefined),
* tipLabel: (string|undefined), * tipLabel: (string|undefined),
* keys: (boolean|undefined), * keys: (boolean|undefined),
* target: (Element|undefined)}} * target: (Element|undefined)}}
@@ -1000,7 +1002,8 @@ olx.control.FullScreenOptions.prototype.className;
/** /**
* Text label to use for the button. Default is `\u2194` (an arrow). * Text label to use for the button. Default is `\u2194` (an arrow).
* @type {string|undefined} * Instead of text, also a Node (e.g. a `span` element) can be used.
* @type {string|Node|undefined}
* @api * @api
*/ */
olx.control.FullScreenOptions.prototype.label; olx.control.FullScreenOptions.prototype.label;
@@ -1009,7 +1012,8 @@ olx.control.FullScreenOptions.prototype.label;
/** /**
* Text label to use for the button when full-screen is active. * Text label to use for the button when full-screen is active.
* Default is `\u00d7` (a cross). * Default is `\u00d7` (a cross).
* @type {string|undefined} * Instead of text, also a Node (e.g. a `span` element) can be used.
* @type {string|Node|undefined}
* @api * @api
*/ */
olx.control.FullScreenOptions.prototype.labelActive; olx.control.FullScreenOptions.prototype.labelActive;
@@ -1102,9 +1106,9 @@ olx.control.MousePositionOptions.prototype.undefinedHTML;
/** /**
* @typedef {{collapsed: (boolean|undefined), * @typedef {{collapsed: (boolean|undefined),
* collapseLabel: (string|undefined), * collapseLabel: (string|Node|undefined),
* collapsible: (boolean|undefined), * collapsible: (boolean|undefined),
* label: (string|undefined), * label: (string|Node|undefined),
* layers: (Array.<ol.layer.Layer>|ol.Collection|undefined), * layers: (Array.<ol.layer.Layer>|ol.Collection|undefined),
* render: (function(ol.MapEvent)|undefined), * render: (function(ol.MapEvent)|undefined),
* target: (Element|undefined), * target: (Element|undefined),
@@ -1124,8 +1128,9 @@ olx.control.OverviewMapOptions.prototype.collapsed;
/** /**
* Text label to use for the expanded overviewmap button. Default is `«` * Text label to use for the expanded overviewmap button. Default is `«`.
* @type {string|undefined} * Instead of text, also a Node (e.g. a `span` element) can be used.
* @type {string|Node|undefined}
* @api * @api
*/ */
olx.control.OverviewMapOptions.prototype.collapseLabel; olx.control.OverviewMapOptions.prototype.collapseLabel;
@@ -1140,8 +1145,9 @@ olx.control.OverviewMapOptions.prototype.collapsible;
/** /**
* Text label to use for the collapsed overviewmap button. Default is `»` * Text label to use for the collapsed overviewmap button. Default is `»`.
* @type {string|undefined} * Instead of text, also a Node (e.g. a `span` element) can be used.
* @type {string|Node|undefined}
* @api * @api
*/ */
olx.control.OverviewMapOptions.prototype.label; olx.control.OverviewMapOptions.prototype.label;
@@ -1237,7 +1243,7 @@ olx.control.ScaleLineOptions.prototype.units;
/** /**
* @typedef {{duration: (number|undefined), * @typedef {{duration: (number|undefined),
* className: (string|undefined), * className: (string|undefined),
* label: (string|undefined), * label: (string|Node|undefined),
* tipLabel: (string|undefined), * tipLabel: (string|undefined),
* target: (Element|undefined), * target: (Element|undefined),
* render: (function(ol.MapEvent)|undefined), * render: (function(ol.MapEvent)|undefined),
@@ -1256,8 +1262,9 @@ olx.control.RotateOptions.prototype.className;
/** /**
* Text label to use for the rotate button. Default is `⇧` * Text label to use for the rotate button. Default is `⇧`.
* @type {string|undefined} * Instead of text, also a Node (e.g. a `span` element) can be used.
* @type {string|Node|undefined}
* @api stable * @api stable
*/ */
olx.control.RotateOptions.prototype.label; olx.control.RotateOptions.prototype.label;
@@ -1307,8 +1314,8 @@ olx.control.RotateOptions.prototype.target;
/** /**
* @typedef {{duration: (number|undefined), * @typedef {{duration: (number|undefined),
* className: (string|undefined), * className: (string|undefined),
* zoomInLabel: (string|undefined), * zoomInLabel: (string|Node|undefined),
* zoomOutLabel: (string|undefined), * zoomOutLabel: (string|Node|undefined),
* zoomInTipLabel: (string|undefined), * zoomInTipLabel: (string|undefined),
* zoomOutTipLabel: (string|undefined), * zoomOutTipLabel: (string|undefined),
* delta: (number|undefined), * delta: (number|undefined),
@@ -1335,16 +1342,18 @@ olx.control.ZoomOptions.prototype.className;
/** /**
* Text label to use for the zoom-in button. Default is `+` * Text label to use for the zoom-in button. Default is `+`.
* @type {string|undefined} * Instead of text, also a Node (e.g. a `span` element) can be used.
* @type {string|Node|undefined}
* @api stable * @api stable
*/ */
olx.control.ZoomOptions.prototype.zoomInLabel; olx.control.ZoomOptions.prototype.zoomInLabel;
/** /**
* Text label to use for the zoom-out button. Default is `-` * Text label to use for the zoom-out button. Default is `-`.
* @type {string|undefined} * Instead of text, also a Node (e.g. a `span` element) can be used.
* @type {string|Node|undefined}
* @api stable * @api stable
*/ */
olx.control.ZoomOptions.prototype.zoomOutLabel; olx.control.ZoomOptions.prototype.zoomOutLabel;
@@ -1428,7 +1437,7 @@ olx.control.ZoomSliderOptions.prototype.render;
/** /**
* @typedef {{className: (string|undefined), * @typedef {{className: (string|undefined),
* target: (Element|undefined), * target: (Element|undefined),
* label: (string|undefined), * label: (string|Node|undefined),
* tipLabel: (string|undefined), * tipLabel: (string|undefined),
* extent: (ol.Extent|undefined)}} * extent: (ol.Extent|undefined)}}
* @api stable * @api stable
@@ -1453,8 +1462,9 @@ olx.control.ZoomToExtentOptions.prototype.target;
/** /**
* Text label to use for the button. Default is `E` * Text label to use for the button. Default is `E`.
* @type {string|undefined} * Instead of text, also a Node (e.g. a `span` element) can be used.
* @type {string|Node|undefined}
* @api stable * @api stable
*/ */
olx.control.ZoomToExtentOptions.prototype.label; olx.control.ZoomToExtentOptions.prototype.label;
+19 -15
View File
@@ -69,32 +69,33 @@ ol.control.Attribution = function(opt_options) {
var tipLabel = goog.isDef(options.tipLabel) ? var tipLabel = goog.isDef(options.tipLabel) ?
options.tipLabel : 'Attributions'; options.tipLabel : 'Attributions';
/** var collapseLabel = goog.isDef(options.collapseLabel) ?
* @private
* @type {string}
*/
this.collapseLabel_ = goog.isDef(options.collapseLabel) ?
options.collapseLabel : '\u00BB'; options.collapseLabel : '\u00BB';
/** /**
* @private * @private
* @type {string} * @type {Node}
*/ */
this.label_ = goog.isDef(options.label) ? options.label : 'i'; this.collapseLabel_ = /** @type {Node} */ (goog.isString(collapseLabel) ?
var label = goog.dom.createDom(goog.dom.TagName.SPAN, {}, goog.dom.createDom(goog.dom.TagName.SPAN, {}, collapseLabel) :
(this.collapsible_ && !this.collapsed_) ? collapseLabel);
this.collapseLabel_ : this.label_);
var label = goog.isDef(options.label) ? options.label : 'i';
/** /**
* @private * @private
* @type {Element} * @type {Node}
*/ */
this.labelSpan_ = label; this.label_ = /** @type {Node} */ (goog.isString(label) ?
goog.dom.createDom(goog.dom.TagName.SPAN, {}, label) :
label);
var activeLabel = (this.collapsible_ && !this.collapsed_) ?
this.collapseLabel_ : this.label_;
var button = goog.dom.createDom(goog.dom.TagName.BUTTON, { var button = goog.dom.createDom(goog.dom.TagName.BUTTON, {
'type': 'button', 'type': 'button',
'title': tipLabel 'title': tipLabel
}, this.labelSpan_); }, activeLabel);
goog.events.listen(button, goog.events.EventType.CLICK, goog.events.listen(button, goog.events.EventType.CLICK,
this.handleClick_, false, this); this.handleClick_, false, this);
@@ -341,8 +342,11 @@ ol.control.Attribution.prototype.handleClick_ = function(event) {
*/ */
ol.control.Attribution.prototype.handleToggle_ = function() { ol.control.Attribution.prototype.handleToggle_ = function() {
goog.dom.classlist.toggle(this.element, 'ol-collapsed'); goog.dom.classlist.toggle(this.element, 'ol-collapsed');
goog.dom.setTextContent(this.labelSpan_, if (this.collapsed_) {
(this.collapsed_) ? this.collapseLabel_ : this.label_); goog.dom.replaceNode(this.collapseLabel_, this.label_);
} else {
goog.dom.replaceNode(this.label_, this.collapseLabel_);
}
this.collapsed_ = !this.collapsed_; this.collapsed_ = !this.collapsed_;
}; };
+20 -15
View File
@@ -57,31 +57,33 @@ ol.control.OverviewMap = function(opt_options) {
var tipLabel = goog.isDef(options.tipLabel) ? var tipLabel = goog.isDef(options.tipLabel) ?
options.tipLabel : 'Overview map'; options.tipLabel : 'Overview map';
/** var collapseLabel = goog.isDef(options.collapseLabel) ?
* @private
* @type {string}
*/
this.collapseLabel_ = goog.isDef(options.collapseLabel) ?
options.collapseLabel : '\u00AB'; options.collapseLabel : '\u00AB';
/** /**
* @private * @private
* @type {string} * @type {Node}
*/ */
this.label_ = goog.isDef(options.label) ? options.label : '\u00BB'; this.collapseLabel_ = /** @type {Node} */ (goog.isString(collapseLabel) ?
var label = goog.dom.createDom(goog.dom.TagName.SPAN, {}, goog.dom.createDom(goog.dom.TagName.SPAN, {}, collapseLabel) :
(this.collapsible_ && !this.collapsed_) ? collapseLabel);
this.collapseLabel_ : this.label_);
var label = goog.isDef(options.label) ? options.label : '\u00BB';
/** /**
* @private * @private
* @type {Element} * @type {Node}
*/ */
this.labelSpan_ = label; this.label_ = /** @type {Node} */ (goog.isString(label) ?
goog.dom.createDom(goog.dom.TagName.SPAN, {}, label) :
label);
var activeLabel = (this.collapsible_ && !this.collapsed_) ?
this.collapseLabel_ : this.label_;
var button = goog.dom.createDom(goog.dom.TagName.BUTTON, { var button = goog.dom.createDom(goog.dom.TagName.BUTTON, {
'type': 'button', 'type': 'button',
'title': tipLabel 'title': tipLabel
}, this.labelSpan_); }, activeLabel);
goog.events.listen(button, goog.events.EventType.CLICK, goog.events.listen(button, goog.events.EventType.CLICK,
this.handleClick_, false, this); this.handleClick_, false, this);
@@ -427,8 +429,11 @@ ol.control.OverviewMap.prototype.handleClick_ = function(event) {
*/ */
ol.control.OverviewMap.prototype.handleToggle_ = function() { ol.control.OverviewMap.prototype.handleToggle_ = function() {
goog.dom.classlist.toggle(this.element, 'ol-collapsed'); goog.dom.classlist.toggle(this.element, 'ol-collapsed');
goog.dom.setTextContent(this.labelSpan_, if (this.collapsed_) {
(this.collapsed_) ? this.collapseLabel_ : this.label_); goog.dom.replaceNode(this.collapseLabel_, this.label_);
} else {
goog.dom.replaceNode(this.label_, this.collapseLabel_);
}
this.collapsed_ = !this.collapsed_; this.collapsed_ = !this.collapsed_;
// manage overview map if it had not been rendered before and control // manage overview map if it had not been rendered before and control
+13 -3
View File
@@ -32,12 +32,22 @@ ol.control.Rotate = function(opt_options) {
var className = goog.isDef(options.className) ? var className = goog.isDef(options.className) ?
options.className : 'ol-rotate'; options.className : 'ol-rotate';
var label = goog.isDef(options.label) ?
options.label : '\u21E7';
/** /**
* @type {Element} * @type {Node}
* @private * @private
*/ */
this.label_ = goog.dom.createDom(goog.dom.TagName.SPAN, this.label_ = null;
'ol-compass', goog.isDef(options.label) ? options.label : '\u21E7');
if (goog.isString(label)) {
this.label_ = goog.dom.createDom(goog.dom.TagName.SPAN,
'ol-compass', label);
} else {
this.label_ = label;
goog.dom.classlist.add(this.label_, 'ol-compass');
}
var tipLabel = goog.isDef(options.tipLabel) ? var tipLabel = goog.isDef(options.tipLabel) ?
options.tipLabel : 'Reset rotation'; options.tipLabel : 'Reset rotation';