Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling drag if Shift key is held down

I have an image that I've set up with jQuery UI to be draggable. This works fine but now I'd like to be able to Shift-drag on the image to draw a box on the image and not have it move. So if the Shift key is held down I don't want to do the drag.

I've tried putting

if(e.shiftKey)return; 

at the top of the drag_start, dragging, and drag_stop functions but this doesn't do anything because the drag operation seems to be done internally in jQuery UI and the calls to drag_start, dragging and drag_stop are just courtesy calls to let you know what jQueryUI is currently doing.

Is there a way to disable the drag if the Shift key is held down?

Thanks

(For more information on this see my "answer" farther below with a jsfiddle.)

like image 474
Steve Avatar asked Mar 03 '14 04:03

Steve


1 Answers

How about on start_drag if shift key then return false; (don't initiate drag)

function box_start_drag(e, ui) {
    if(e.shiftKey)
        return false;
}

Fiddle

Or to stop dragging any time shift is held down. Put the return false in the drag method as Dom suggests in the comments below.

like image 187
Trevor Avatar answered Oct 06 '22 18:10

Trevor