SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    May 2005
    Posts
    172
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Different mouse left / right click options jQuery

    Hi

    I'm setting up a photo gallery (powered by Galleria).

    I would like to link an image to a URL and also have the option to 'Save As' that same image using the right click on a mouse.

    When I right click with the standard set up for Galleria I get the standard right click menu options pop up but I'm also taken to my URL (before I have time to save the image).

    Is there a way to differentiate between a right click and a left click in jQuery so I can, for example, specify that the right click shouldn't action the hyperlink?

    Hope thats clear.
    Many Thanks

  2. #2
    SitePoint Addict sdleihssirhc's Avatar
    Join Date
    Feb 2009
    Posts
    387
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Can you link to a live example?
    I'm the web overlord for Graphic Business Systems

  3. #3
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,716
    Mentioned
    103 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by rooftop View Post
    Is there a way to differentiate between a right click and a left click in jQuery so I can, for example, specify that the right click shouldn't action the hyperlink?
    The event.which property will give you 1, 2 or 3 for the left, middle or right mouse button that was clicked.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  4. #4
    SitePoint Zealot
    Join Date
    May 2005
    Posts
    172
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks both.

    The demo is at lesco[dot]uk[dot]com/home/landing.php

    I've had a quick look at the .js files and can't find the event.which.

    www[dot]lesco[dot]uk[dot]com/common/tradehome/galleria/galleria-1.2.6.js

    www[dot]lesco[dot]uk[dot]com/common/tradehome/galleria/themes/lesco/galleria.lesco.js

    This mod is likely to be above my jquery expertise - so I may need to source another gallery which is a pity as this almost ticks all the boxes!

    Thanks

  5. #5
    SitePoint Addict sdleihssirhc's Avatar
    Join Date
    Feb 2009
    Posts
    387
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    There isn't really an easy way (as far as I can tell).

    You designated a "longdesc" attribute for each image. That's how Galleria knows where to link the bigger versions of the images.

    Unfortunately, Galleria doesn't simply insert each <img> in an <a> element ([sarcasm]that would be silly[/sarcasm]). Nor does it wait for a normal "click" event (which, if I remember right, is only fired by left-click). It sends you to the "longdesc" location on mouseup.

    Even worse, the function that actually decides whether or not to do this isn't in a normal event listener, so it doesn't have access to the "e" object, so you can't just do something as simple as check e.which!

    There are workarounds, but they get exponentially more complicated and infuriating the deeper into it you go...

    Edit

    In retrospect, this post probably isn't that much help. To OP, or anyone else interested in pursuing this: The madness begins at about line 3,750 of galleria-1.2.6.js; that's where it decides whether or not to open the link.
    I'm the web overlord for Graphic Business Systems

  6. #6
    SitePoint Zealot
    Join Date
    May 2005
    Posts
    172
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thanks sdleihssirhc

    I really appreciate your taking the time to try and help (and for writing a witty reply).

    I found myself trying to take in the lines around #3750 - but experience was telling I would not make a breakthrough.
    I'm reassured that, at least sometimes, I know my limits.

    I'm going to try another gallery....

    Cheers


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •