Changeset 4203
- Timestamp:
- 12/17/07 13:13:51 (1 year ago)
- Location:
- trunk/ui/experimental/mouse
- Files:
-
- 4 modified
-
drag.html (modified) (1 diff)
-
ui.draggable.ext.js (modified) (6 diffs)
-
ui.draggable.js (modified) (4 diffs)
-
ui.mouse.js (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ui/experimental/mouse/drag.html
r4201 r4203 63 63 stop: function(e,ui) { 64 64 //console.log("Draggable: stop , ", e, " , ", ui); 65 } 65 }, 66 cursor: 'move', 67 containment: 'parent', 68 //axis: 'x', 69 //grid: [20,20], 70 //cursorAt: { top: 0, right: 0 } 66 71 }); 67 72 }); -
trunk/ui/experimental/mouse/ui.draggable.ext.js
r4201 r4203 43 43 $.ui.plugin.add("draggable", "revert", { 44 44 stop: function(e,ui) { 45 46 var o = ui.options; 47 var rpos = { left: 0, top: 0 }; 48 o.beQuietAtEnd = true; 49 50 if(ui.helper != this) { 51 rpos = $(ui.draggable.sorthelper || this).offset(); 52 var nl = rpos.left-o.po.left-o.margins.left; 53 var nt = rpos.top-o.po.top-o.margins.top; 54 } else { 55 var nl = o.co.left - (o.po ? o.po.left : 0); 56 var nt = o.co.top - (o.po ? o.po.top : 0); 57 } 58 59 var self = ui.draggable; 60 61 $(ui.helper).animate({ left: nl, top: nt }, 500, function() { 62 if(o.wasPositioned) $(self.element).css('position', o.wasPositioned); 63 if(o.stop) o.stop.apply(self.element, [self.helper, self.pos, [o.co.left - o.po.left,o.co.top - o.po.top],self]); 64 65 if(self.helper != self.element) 66 window.setTimeout(function() { $(self.helper).remove(); }, 0); //Using setTimeout because of strange flickering in Firefox 45 var self = ui.instance; 46 self.cancelHelperRemoval = true; 47 $(ui.helper).animate({ left: self.originalPosition.left, top: self.originalPosition.top }, parseInt(ui.options.revert) || 500, function() { 48 if(ui.options.helper != 'original') self.helper.remove(); 49 self.clear(); 67 50 }); 68 69 51 } 70 52 }); … … 74 56 75 57 var o = ui.options; 76 if(ui. draggable.slowMode) return; // Make clones on top of iframes (only if we are not in slowMode)58 if(ui.instance.slowMode) return; // Make clones on top of iframes (only if we are not in slowMode) 77 59 78 60 if(o.iframeFix.constructor == Array) { … … 98 80 99 81 var o = ui.options; 100 if(( !o.cursorAtIgnore ||o.containment.left != undefined || o.containment.constructor == Array) && !o._containment) return;82 if((o.containment.left != undefined || o.containment.constructor == Array) && !o._containment) return; 101 83 if(!o._containment) o._containment = o.containment; 102 84 103 if(o._containment == 'parent') o._containment = this .parentNode;85 if(o._containment == 'parent') o._containment = this[0].parentNode; 104 86 if(o._containment == 'document') { 105 87 o.containment = [ 106 0 -o.margins.left,107 0 -o.margins.top,108 $(document).width() -o.margins.right,109 ($(document).height() || document.body.parentNode.scrollHeight) -o.margins.bottom88 0, 89 0, 90 $(document).width(), 91 ($(document).height() || document.body.parentNode.scrollHeight) 110 92 ]; 111 93 } else { //I'm a node, so compute top/left/right/bottom 112 94 113 95 var ce = $(o._containment)[0]; 114 var co = $(o._containment).offset( { border: false });96 var co = $(o._containment).offset(); 115 97 116 98 o.containment = [ 117 co.left -o.margins.left,118 co.top -o.margins.top,119 co.left+(ce.offsetWidth || ce.scrollWidth) -o.margins.right,120 co.top+(ce.offsetHeight || ce.scrollHeight) -o.margins.bottom99 co.left, 100 co.top, 101 co.left+(ce.offsetWidth || ce.scrollWidth), 102 co.top+(ce.offsetHeight || ce.scrollHeight) 121 103 ]; 122 104 } … … 126 108 127 109 var o = ui.options; 128 if(!o.cursorAtIgnore) return; 129 130 var h = $(ui.helper); 110 var h = ui.helper; 131 111 var c = o.containment; 112 var self = ui.instance; 113 132 114 if(c.constructor == Array) { 133 115 134 if((ui.draggable.pos[0] < c[0]-o.po.left)) ui.draggable.pos[0] = c[0]-o.po.left; 135 if((ui.draggable.pos[1] < c[1]-o.po.top)) ui.draggable.pos[1] = c[1]-o.po.top; 136 if(ui.draggable.pos[0]+h[0].offsetWidth > c[2]-o.po.left) ui.draggable.pos[0] = c[2]-o.po.left-h[0].offsetWidth; 137 if(ui.draggable.pos[1]+h[0].offsetHeight > c[3]-o.po.top) ui.draggable.pos[1] = c[3]-o.po.top-h[0].offsetHeight; 116 117 if((ui.absolutePosition.left < c[0])) self.position.left = c[0] - (self.offset.left - self.clickOffset.left); 118 if((ui.absolutePosition.top < c[1])) self.position.top = c[1] - (self.offset.top - self.clickOffset.top); 119 //if(ui.draggable.pos[0]+h[0].offsetWidth > c[2]-o.po.left) ui.draggable.pos[0] = c[2]-o.po.left-h[0].offsetWidth; 120 //if(ui.draggable.pos[1]+h[0].offsetHeight > c[3]-o.po.top) ui.draggable.pos[1] = c[3]-o.po.top-h[0].offsetHeight; 138 121 139 122 } else { … … 155 138 drag: function(e,ui) { 156 139 var o = ui.options; 157 if(!o.cursorAtIgnore) return; 158 ui.draggable.pos[0] = o.co.left + o.margins.left - o.po.left + Math.round((ui.draggable.pos[0] - o.co.left - o.margins.left + o.po.left) / o.grid[0]) * o.grid[0]; 159 ui.draggable.pos[1] = o.co.top + o.margins.top - o.po.top + Math.round((ui.draggable.pos[1] - o.co.top - o.margins.top + o.po.top) / o.grid[1]) * o.grid[1]; 140 ui.instance.position.left = ui.instance.originalPosition.left + Math.round((e.pageX - ui.instance._pageX) / o.grid[0]) * o.grid[0]; 141 ui.instance.position.top = ui.instance.originalPosition.top + Math.round((e.pageY - ui.instance._pageY) / o.grid[1]) * o.grid[1]; 160 142 } 161 143 }); … … 164 146 drag: function(e,ui) { 165 147 var o = ui.options; 166 if(!o.cursorAtIgnore) return;167 148 if(o.constraint) o.axis = o.constraint; //Legacy check 168 o.axis ? ( o.axis == 'x' ? ui.draggable.pos[1] = o.co.top - o.margins.top - o.po.top : ui.draggable.pos[0] = o.co.left - o.margins.left - o.po.left ) : null;149 o.axis == 'x' ? ui.instance.position.top = ui.instance.originalPosition.top : ui.instance.position.left = ui.instance.originalPosition.left; 169 150 } 170 151 }); -
trunk/ui/experimental/mouse/ui.draggable.js
r4201 r4203 8 8 if(!$(this).is(".ui-draggable")) new $.ui.draggable(this, o); 9 9 }); 10 } 10 }; 11 11 12 12 $.ui.draggable = function(element, options) { … … 43 43 this.element.css('position', 'relative'); 44 44 45 } 45 }; 46 46 47 47 $.extend($.ui.draggable.prototype, { … … 91 91 //Prepare variables for position generation 92 92 this.elementOffset = this.element.offset(); 93 this._pageX = e.pageX; this._pageY = e.pageY; 93 94 this.clickOffset = { left: e.pageX - this.elementOffset.left, top: e.pageY - this.elementOffset.top }; 94 95 var elementPosition = this.element.position(); 95 96 var r = this.helper.css('position') == 'relative'; 97 98 //Generate the original position 99 this.originalPosition = { 100 left: (r ? parseInt(this.helper.css('left')) || 0 : elementPosition.left + (offsetParent[0] == document.body ? 0 : offsetParent[0].scrollLeft)), 101 top: (r ? parseInt(this.helper.css('top')) || 0 : elementPosition.top + (offsetParent[0] == document.body ? 0 : offsetParent[0].scrollTop)) 102 }; 96 103 97 104 //Generate a flexible offset that will later be subtracted from e.pageX/Y 98 this.offset = { 99 left: e.pageX - (r ? parseInt(this.helper.css('left')) || 0 : elementPosition.left + offsetParent[0].scrollLeft), 100 top: e.pageY - (r ? parseInt(this.helper.css('top')) || 0 : elementPosition.top + offsetParent[0].scrollTop) 101 }; 102 105 this.offset = {left: e.pageX - this.originalPosition.left, top: e.pageY - this.originalPosition.top }; 106 103 107 //Call plugins and callbacks 104 108 this.propagate("start", e); 105 109 106 110 this.helperProportions = { width: this.helper.outerWidth(), height: this.helper.outerHeight() }; 107 if (this.slowMode && $.ui.ddmanager && !o.dropBehaviour) $.ui.ddmanager.prepareOffsets(this, e); 111 if ($.ui.ddmanager && !o.dropBehaviour) $.ui.ddmanager.prepareOffsets(this, e); 112 113 //If we have something in cursorAt, we'll use it 114 if(o.cursorAt) { 115 if(o.cursorAt.top != undefined || o.cursorAt.bottom != undefined) { 116 this.offset.top -= this.clickOffset.top - (o.cursorAt.top != undefined ? o.cursorAt.top : (this.helperProportions.height - o.cursorAt.bottom)); 117 this.clickOffset.top = (o.cursorAt.top != undefined ? o.cursorAt.top : (this.helperProportions.height - o.cursorAt.bottom)); 118 } 119 if(o.cursorAt.left != undefined || o.cursorAt.right != undefined) { 120 this.offset.left -= this.clickOffset.left - (o.cursorAt.left != undefined ? o.cursorAt.left : (this.helperProportions.width - o.cursorAt.right)); 121 this.clickOffset.left = (o.cursorAt.left != undefined ? o.cursorAt.left : (this.helperProportions.width - o.cursorAt.right)); 122 } 123 } 124 108 125 return false; 109 126 110 127 }, 111 stop: function(e) { 112 113 //Call plugins and callbacks 114 this.propagate("stop", e); 115 116 if (this.slowMode && $.ui.ddmanager && !this.options.dropBehaviour) $.ui.ddmanager.drop(this, e); 117 if(this.options.helper != 'original' && !this.cancelHelperRemoval) this.helper.remove(); 118 128 clear: function() { 119 129 if($.ui.ddmanager) { 120 130 $.ui.ddmanager.current = null; 121 131 $.ui.ddmanager.last = this; 122 132 } 123 this.helper = null; this.offset = null; this.positionCurrent = null; 133 this.helper = null; 134 }, 135 stop: function(e) { 136 137 if ($.ui.ddmanager && !this.options.dropBehaviour) $.ui.ddmanager.drop(this, e); 138 this.propagate("stop", e); 139 140 if(this.cancelHelperRemoval) return false; 141 if(this.options.helper != 'original') this.helper.remove(); 142 this.clear(); 143 124 144 return false; 125 126 145 }, 127 146 drag: function(e) { … … 129 148 //Compute the helpers position 130 149 this.position = { top: e.pageY - this.offset.top, left: e.pageX - this.offset.left }; 131 this.positionAbs = { left: e.pageX + this.clickOffset.left, top: e.pageY +this.clickOffset.top };150 this.positionAbs = { left: e.pageX - this.clickOffset.left, top: e.pageY - this.clickOffset.top }; 132 151 133 152 //Call plugins and callbacks -
trunk/ui/experimental/mouse/ui.mouse.js
r4189 r4203 58 58 if($.browser.msie) $(element).attr('unselectable', 'on'); //Prevent text selection in IE 59 59 60 } 60 }; 61 61 62 62 $.extend($.ui.mouseInteraction.prototype, { … … 93 93 94 94 var o = this.options; 95 if( this.initialized == false) return true;95 if(!this.initialized) return $(document).unbind('mouseup.draggable').unbind('mousemove.draggable'); 96 96 97 97 if(this.options.stop) this.options.stop.call(this.options.executor || this, e);
