Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making a Google-Calendar-like dragging interface

When you use Google Calendar and want to make a new event, you can drag from the start time to the end time, and this creates the event in the desired range.

I want to implement the same functionality for my site using jQuery.

Does anyone have an idea how I can accomplish this?

like image 914
Ram Rachum Avatar asked May 14 '12 22:05

Ram Rachum


People also ask

Can you drag and drop in Google Calendar?

Drag and Drop Events on Google CalendarYou can manually edit it, or just drag and drop to the desired day. Similarly, if you click to add a new event, and the date is incorrect, drag and drop it to the right day.


1 Answers

The basic idea is to have time "slot" elements that each refer to a specific time (usually 15-minute intervals). Each slot element has an onmouseup and onmousedown handler. The mousedown handler, when triggered, stores the time referred to by that slot and updates a boolean variable that indicates whether dragging is occurring. When mouseup is triggered, the handler checks if dragging has started, and if so, decides that this is the ending slot. You now have a beginning and ending time, and you can take it from there to show some dialog that completes the rest of the booking.

Demo: http://www.dstrout.net/pub/appointment.htm
The demo also includes code to prevent text selection, since that is a "side-effect" of dragging. Check out the code to see how that works.

like image 73
Ashley Strout Avatar answered Nov 02 '22 11:11

Ashley Strout