Committing patch for #614 to add panel_div element to control panel
subcontrols. This will allow users to modify properties of the div -- for example, adding a title element to the div. Access this property via panel_div on the added control after addControls is called on the panel. git-svn-id: http://svn.openlayers.org/trunk/openlayers@2973 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -33,6 +33,14 @@ OpenLayers.Control.Panel.prototype =
|
|||||||
this.controls = [];
|
this.controls = [];
|
||||||
},
|
},
|
||||||
|
|
||||||
|
destroy: function() {
|
||||||
|
OpenLayers.Control.prototype.destroy.apply(this, arguments);
|
||||||
|
for(var i = this.controls.length - 1 ; i >= 0; i--) {
|
||||||
|
OpenLayers.Event.stopObservingElement(this.controls[i].panel_div);
|
||||||
|
this.controls[i].panel_div = null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
activate: function() {
|
activate: function() {
|
||||||
if (OpenLayers.Control.prototype.activate.apply(this, arguments)) {
|
if (OpenLayers.Control.prototype.activate.apply(this, arguments)) {
|
||||||
for(var i = 0; i < this.controls.length; i++) {
|
for(var i = 0; i < this.controls.length; i++) {
|
||||||
@@ -46,6 +54,7 @@ OpenLayers.Control.Panel.prototype =
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
deactivate: function() {
|
deactivate: function() {
|
||||||
if (OpenLayers.Control.prototype.deactivate.apply(this, arguments)) {
|
if (OpenLayers.Control.prototype.deactivate.apply(this, arguments)) {
|
||||||
for(var i = 0; i < this.controls.length; i++) {
|
for(var i = 0; i < this.controls.length; i++) {
|
||||||
@@ -78,24 +87,12 @@ OpenLayers.Control.Panel.prototype =
|
|||||||
this.div.innerHTML = "";
|
this.div.innerHTML = "";
|
||||||
if (this.active) {
|
if (this.active) {
|
||||||
for (var i = 0; i < this.controls.length; i++) {
|
for (var i = 0; i < this.controls.length; i++) {
|
||||||
var element = document.createElement("div");
|
var element = this.controls[i].panel_div;
|
||||||
var textNode = document.createTextNode(" ");
|
|
||||||
if (this.controls[i].active) {
|
if (this.controls[i].active) {
|
||||||
element.className = this.controls[i].displayClass + "ItemActive";
|
element.className = this.controls[i].displayClass + "ItemActive";
|
||||||
} else {
|
} else {
|
||||||
element.className = this.controls[i].displayClass + "ItemInactive";
|
element.className = this.controls[i].displayClass + "ItemInactive";
|
||||||
}
|
}
|
||||||
var onClick = function (ctrl, evt) {
|
|
||||||
OpenLayers.Event.stop(evt ? evt : window.event);
|
|
||||||
this.activateControl(ctrl);
|
|
||||||
};
|
|
||||||
var control = this.controls[i];
|
|
||||||
OpenLayers.Event.observe(element, "click",
|
|
||||||
onClick.bind(this, control));
|
|
||||||
OpenLayers.Event.observe(element, "mousedown",
|
|
||||||
OpenLayers.Event.stop.bindAsEventListener());
|
|
||||||
OpenLayers.Event.observe(element, "mouseup",
|
|
||||||
OpenLayers.Event.stop.bindAsEventListener());
|
|
||||||
this.div.appendChild(element);
|
this.div.appendChild(element);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -128,6 +125,22 @@ OpenLayers.Control.Panel.prototype =
|
|||||||
controls = [controls];
|
controls = [controls];
|
||||||
}
|
}
|
||||||
this.controls = this.controls.concat(controls);
|
this.controls = this.controls.concat(controls);
|
||||||
|
|
||||||
|
// Give each control a panel_div which will be used later.
|
||||||
|
// Access to this div is via the panel_div attribute of the
|
||||||
|
// control added to the panel.
|
||||||
|
for (var i = 0; i < controls.length; i++) {
|
||||||
|
var element = document.createElement("div");
|
||||||
|
var textNode = document.createTextNode(" ");
|
||||||
|
controls[i].panel_div = element;
|
||||||
|
OpenLayers.Event.observe(controls[i].panel_div, "click",
|
||||||
|
this.onClick.bind(this, controls[i]));
|
||||||
|
OpenLayers.Event.observe(controls[i].panel_div, "mousedown",
|
||||||
|
OpenLayers.Event.stop.bindAsEventListener());
|
||||||
|
OpenLayers.Event.observe(controls[i].panel_div, "mouseup",
|
||||||
|
OpenLayers.Event.stop.bindAsEventListener());
|
||||||
|
}
|
||||||
|
|
||||||
if (this.map) { // map.addControl() has already been called on the panel
|
if (this.map) { // map.addControl() has already been called on the panel
|
||||||
for (var i = 0; i < controls.length; i++) {
|
for (var i = 0; i < controls.length; i++) {
|
||||||
this.map.addControl(controls[i]);
|
this.map.addControl(controls[i]);
|
||||||
@@ -137,6 +150,11 @@ OpenLayers.Control.Panel.prototype =
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
onClick: function (ctrl, evt) {
|
||||||
|
OpenLayers.Event.stop(evt ? evt : window.event);
|
||||||
|
this.activateControl(ctrl);
|
||||||
|
},
|
||||||
|
|
||||||
/** @final @type String */
|
/** @final @type String */
|
||||||
CLASS_NAME: "OpenLayers.Control.Panel"
|
CLASS_NAME: "OpenLayers.Control.Panel"
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user