3 $.dragstart = function(e)
5 this.dragElement.deltaX = e.clientX - this.dragElement.offsetLeft;
6 this.dragElement.deltaY = e.clientY - this.dragElement.offsetTop;
9 this.dragElement.oldPos = $.css(this.dragElement, 'position');
10 this.dragElement.oldCursor = $.css(this.dragElement, 'cursor');
11 this.dragElement.oldUserSelect = $.css(this.dragElement, 'user-select');
13 $(this.dragElement).css('position', 'absolute')
14 .css('cursor', 'move')
15 .css('user-select', 'none');
16 $.drug = this.dragElement;
19 $.dragstop = function(e)
24 $(this).css('cursor', this.oldCursor)
25 .css('user-select', this.oldUserSelect);
35 var nx = (e.clientX - $.drug.deltaX);
36 var ny = (e.clientY - $.drug.deltaY);
40 nx = (nx < 0) ? 0 : nx;
42 nx = (nx + $.drug.offsetWidth) > document.width ? document.width - $.drug.offsetWidth : nx;
45 ny = (ny < window.scrollY) ? window.scrollY : ny;
48 ny = (ny + $.drug.offsetHeight) > window.innerHeight + window.scrollY ? window.innerHeight + window.scrollY - $.drug.offsetHeight: ny;
50 $($.drug).css('left', nx + 'px')
51 .css('top', ny + 'px');
56 $.fn.Draggable = function(handle)
58 // Don't add > 1 of these handlers
60 $(document).bind('mousemove', $.drag);
63 return this.each(function()
65 var dhe = handle ? $(this).find(handle) : $(this);
66 dhe.get(0).dragElement = this;
68 dhe.bind('mousedown', $.dragstart)
69 .bind('mouseup', $.dragstop);