Bug Tracker

Changeset 4203

Show
Ignore:
Timestamp:
12/17/07 13:13:51 (1 year ago)
Author:
paul.bakaus
Message:
 
Location:
trunk/ui/experimental/mouse
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/ui/experimental/mouse/drag.html

    r4201 r4203  
    6363                stop: function(e,ui) { 
    6464                    //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 } 
    6671            }); 
    6772        }); 
  • trunk/ui/experimental/mouse/ui.draggable.ext.js

    r4201 r4203  
    4343    $.ui.plugin.add("draggable", "revert", { 
    4444        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(); 
    6750            }); 
    68          
    6951        } 
    7052    }); 
     
    7456 
    7557            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) 
    7759             
    7860            if(o.iframeFix.constructor == Array) { 
     
    9880 
    9981            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; 
    10183            if(!o._containment) o._containment = o.containment; 
    10284 
    103             if(o._containment == 'parent') o._containment = this.parentNode; 
     85            if(o._containment == 'parent') o._containment = this[0].parentNode; 
    10486            if(o._containment == 'document') { 
    10587                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.bottom 
     88                    0, 
     89                    0, 
     90                    $(document).width(), 
     91                    ($(document).height() || document.body.parentNode.scrollHeight) 
    11092                ]; 
    11193            } else { //I'm a node, so compute top/left/right/bottom 
    11294 
    11395                var ce = $(o._containment)[0]; 
    114                 var co = $(o._containment).offset({ border: false }); 
     96                var co = $(o._containment).offset(); 
    11597 
    11698                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.bottom 
     99                    co.left, 
     100                    co.top, 
     101                    co.left+(ce.offsetWidth || ce.scrollWidth), 
     102                    co.top+(ce.offsetHeight || ce.scrollHeight) 
    121103                ]; 
    122104            } 
     
    126108 
    127109            var o = ui.options; 
    128             if(!o.cursorAtIgnore) return; 
    129  
    130             var h = $(ui.helper); 
     110            var h = ui.helper; 
    131111            var c = o.containment; 
     112            var self = ui.instance; 
     113             
    132114            if(c.constructor == Array) { 
    133115 
    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; 
    138121 
    139122            } else { 
     
    155138        drag: function(e,ui) { 
    156139            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]; 
    160142        } 
    161143    }); 
     
    164146        drag: function(e,ui) { 
    165147            var o = ui.options; 
    166             if(!o.cursorAtIgnore) return; 
    167148            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; 
    169150        } 
    170151    }); 
  • trunk/ui/experimental/mouse/ui.draggable.js

    r4201 r4203  
    88            if(!$(this).is(".ui-draggable")) new $.ui.draggable(this, o); 
    99        }); 
    10     } 
     10    }; 
    1111     
    1212    $.ui.draggable = function(element, options) { 
     
    4343            this.element.css('position', 'relative'); 
    4444         
    45     } 
     45    }; 
    4646     
    4747    $.extend($.ui.draggable.prototype, { 
     
    9191            //Prepare variables for position generation 
    9292            this.elementOffset = this.element.offset(); 
     93            this._pageX = e.pageX; this._pageY = e.pageY; 
    9394            this.clickOffset = { left: e.pageX - this.elementOffset.left, top: e.pageY - this.elementOffset.top }; 
    9495            var elementPosition = this.element.position(); 
    9596            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            }; 
    96103             
    97104            //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             
    103107            //Call plugins and callbacks 
    104108            this.propagate("start", e); 
    105109 
    106110            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 
    108125            return false; 
    109                          
     126 
    110127        }, 
    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() { 
    119129            if($.ui.ddmanager) { 
    120130                $.ui.ddmanager.current = null; 
    121131                $.ui.ddmanager.last = this;              
    122132            } 
    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 
    124144            return false; 
    125              
    126145        }, 
    127146        drag: function(e) { 
     
    129148            //Compute the helpers position 
    130149            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 }; 
    132151 
    133152            //Call plugins and callbacks 
  • trunk/ui/experimental/mouse/ui.mouse.js

    r4189 r4203  
    5858        if($.browser.msie) $(element).attr('unselectable', 'on'); //Prevent text selection in IE 
    5959         
    60     } 
     60    }; 
    6161     
    6262    $.extend($.ui.mouseInteraction.prototype, { 
     
    9393             
    9494            var o = this.options; 
    95             if(this.initialized == false) return true; 
     95            if(!this.initialized) return $(document).unbind('mouseup.draggable').unbind('mousemove.draggable'); 
    9696 
    9797            if(this.options.stop) this.options.stop.call(this.options.executor || this, e);