OpenLayers OpenLayers

Ticket #1359: RightMouse.patch

File RightMouse.patch, 5.6 kB (added by openlayers, 5 months ago)
  • lib/OpenLayers/Control/Navigation.js

    old new  
    105105     */ 
    106106    draw: function() { 
    107107        this.handlers.click = new OpenLayers.Handler.Click(this,  
    108                                         { 'dblclick': this.defaultDblClick }, 
    109                                        
     108                                        { 'dblclick': this.defaultDblClick, 'dblrightclick': this.defaultDblRightClick }, 
     109                                       
    110110                                          'double': true,  
    111111                                          'stopDouble': true 
    112112                                        }); 
     
    133133    }, 
    134134 
    135135    /** 
     136     * Method: defaultRightDblClick  
     137     *  
     138     * Parameters: 
     139     * evt - {Event}  
     140     */ 
     141    defaultDblRightClick: function (evt) { 
     142        var newCenter = this.map.getLonLatFromViewPortPx( evt.xy );  
     143        this.map.setCenter(newCenter, this.map.zoom - 1); 
     144    }, 
     145     
     146    /** 
    136147     * Method: wheelChange   
    137148     * 
    138149     * Parameters: 
  • lib/OpenLayers/Events.js

    old new  
    105105    }, 
    106106 
    107107    /** 
     108     * Method: isRightClick 
     109     * Determine whether event was caused by a right mouse click.  
     110     * 
     111     * Parameters: 
     112     * event - {Event}  
     113     *  
     114     * Returns: 
     115     * {Boolean} 
     116     */ 
     117     isRightClick: function(event) { 
     118        return (((event.which) && (event.which == 3)) || 
     119                ((event.button) && (event.button == 2))); 
     120    }, 
     121      
     122    /** 
    108123     * Method: stop 
    109124     * Stops an event from propagating.  
    110125     * 
     
    352367    BROWSER_EVENTS: [ 
    353368        "mouseover", "mouseout", 
    354369        "mousedown", "mouseup", "mousemove",  
    355         "click", "dblclick", 
     370        "click", "dblclick", "rightclick", "dblrightclick", 
    356371        "resize", "focus", "blur" 
    357372    ], 
    358373 
  • lib/OpenLayers/Handler/Click.js

    old new  
    9090    down: null, 
    9191     
    9292    /** 
     93     * Property: rightclickTimerId 
     94     * {Number} The id of the right mouse timeout waiting to clear the <delayedEvent>. 
     95     */ 
     96    rightclickTimerId: null, 
     97     
     98    /** 
    9399     * Constructor: OpenLayers.Handler.Click 
    94100     * Create a new click handler. 
    95101     *  
     
    125131     * {Boolean} Continue propagating this event. 
    126132     */ 
    127133    mousedown: null, 
     134    /** 
     135     * Method: mouseup 
     136     * Handle mouseup.  Installed to support collection of right mouse events 
     137     *  
     138     * Returns: 
     139     * {Boolean} Continue propagating this event. 
     140     */ 
     141    mouseup:  function (evt) { 
     142        var propagate = true; 
     143        // Collect right mouse clicks from the mouseup 
     144        // IE - ignores the second right click in mousedown so using mouseup instead 
     145        if (this.checkModifiers(evt) && OpenLayers.Event.isRightClick(evt)) { 
     146          this.rightclick(evt);             
     147        } 
     148        return propagate; 
     149    }, 
    128150     
    129151    /** 
     152     * Method: rightclick 
     153     * Handle rightclick.  For a dblrightclick, we get two clicks 
     154     * so we need to always register for dblrightclick to properly handle single clicks. 
     155     *      
     156     * Returns: 
     157     * {Boolean} Continue propagating this event. 
     158     */ 
     159    rightclick: function(evt) { 
     160        if(this.passesTolerance(evt)) { 
     161           if(this.rightclickTimerId != null) { 
     162                // Second click received before timeout this must be a double click 
     163                this.clearTimer();       
     164                this.callback('dblrightclick', [evt]); 
     165                return !this.stopDouble; 
     166            } else {  
     167            // set the rightclickTimerId, send evt only if double is true else trigger single 
     168            var clickEvent = this.double ? 
     169                OpenLayers.Util.extend({}, evt) : this.callback('rightclick', [evt]); 
     170            this.rightclickTimerId = window.setTimeout( 
     171                OpenLayers.Function.bind(this.delayedRightCall, this, clickEvent), 
     172                    this.delay ); 
     173            }  
     174        } 
     175        return !this.stopSingle; 
     176    }, 
     177     
     178    /** 
     179     * Method: delayedRightCall 
     180     * Sets <rightclickTimerId> to null.  And optionally triggers the rightclick callback if 
     181     *     evt is set. 
     182     */ 
     183    delayedRightCall: function(evt) { 
     184        this.rightclickTimerId = null; 
     185        if(evt) { 
     186           this.callback('rightclick', [evt]); 
     187        } 
     188        return !this.stopSingle; 
     189    }, 
     190     
     191    /** 
    130192     * Method: dblclick 
    131193     * Handle dblclick.  For a dblclick, we get two clicks in some browsers 
    132194     *     (FF) and one in others (IE).  So we need to always register for 
  • lib/OpenLayers/Map.js

    old new  
    420420        this.layerContainerDiv.style.zIndex=this.Z_INDEX_BASE['Popup']-1; 
    421421         
    422422        this.viewPortDiv.appendChild(this.layerContainerDiv); 
    423  
     423         
     424        // disable right mouse context menu for support of right click events 
     425        this.div.oncontextmenu = function () { return false;}; 
     426         
    424427        this.events = new OpenLayers.Events(this,  
    425428                                            this.div,  
    426429                                            this.EVENT_TYPES,