From db6049d3b4eec4f02619919ea1172fd7e5b583b0 Mon Sep 17 00:00:00 2001 From: crschmidt Date: Fri, 26 May 2006 12:16:02 +0000 Subject: [PATCH] * Refactor PanZooMBar so that we don't have three functions that do the exact same thing: These are simply passing information on to the slider, which then actually does the moving, so we'll create passToSlider. * Alter the dragging code so that you can't drag above or below the top/bottom of the bar. git-svn-id: http://svn.openlayers.org/trunk/openlayers@397 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Control/PanZoomBar.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/OpenLayers/Control/PanZoomBar.js b/lib/OpenLayers/Control/PanZoomBar.js index 7efb1d8eb1..ab3c8848fa 100644 --- a/lib/OpenLayers/Control/PanZoomBar.js +++ b/lib/OpenLayers/Control/PanZoomBar.js @@ -86,9 +86,11 @@ OpenLayers.Control.PanZoomBar.prototype = imgLocation+"zoombar.png"); } + this.zoombarDiv = div; + this.divEvents = new OpenLayers.Events(this, div); this.divEvents.register("mousedown", this, this.divClick); - this.divEvents.register("mousemove", this, this.zoomBarDivDrag); + this.divEvents.register("mousemove", this, this.passEventToSlider); this.divEvents.register("dblclick", this, this.doubleClick); this.div.appendChild(div); @@ -109,26 +111,25 @@ OpenLayers.Control.PanZoomBar.prototype = Event.stop(evt); }, zoomBarDown:function(evt) { - this.map.events.register("mousemove", this, this.mapMouseDrag); - this.map.events.register("mouseup", this, this.mapMouseUp); + this.map.events.register("mousemove", this, this.passEventToSlider); + this.map.events.register("mouseup", this, this.passEventToSlider); this.mouseDragStart = evt.xy.copyOf(); this.zoomStart = evt.xy.copyOf(); this.div.style.cursor = "move"; Event.stop(evt); }, - mapMouseDrag:function(evt) { - this.sliderEvents.handleBrowserEvent(evt); - }, - mapMouseUp:function(evt) { - this.sliderEvents.handleBrowserEvent(evt); - }, - zoomBarDivDrag: function(evt) { + passEventToSlider:function(evt) { this.sliderEvents.handleBrowserEvent(evt); }, zoomBarDrag:function(evt) { if (this.mouseDragStart != null) { var deltaY = this.mouseDragStart.y - evt.xy.y - this.slider.style.top = (parseInt(this.slider.style.top)-deltaY)+"px"; + var offsets = Position.page(this.zoombarDiv); + if ((evt.clientY - offsets[1]) > 0 && + (evt.clientY - offsets[1]) < parseInt(this.zoombarDiv.style.height) - 2) { + var newTop = parseInt(this.slider.style.top) - deltaY; + this.slider.style.top = newTop+"px"; + } this.mouseDragStart = evt.xy.copyOf(); } Event.stop(evt);