Bug Tracker

Changeset 5665

Show
Ignore:
Timestamp:
05/22/08 12:08:52 (3 months ago)
Author:
rdworth
Message:

ui experimental mouse - draggable, whitespace

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/ui-experimental/mouse/ui.draggable.js

    r5652 r5665  
    2121            //Initialize needed constants 
    2222            var o = this.options; 
    23  
     23             
    2424            this.mouseInit(); 
    25  
     25             
    2626            //Position the node 
    2727            if(o.helper == 'original' && !(/(relative|absolute|fixed)/).test(this.element.css('position'))) 
     
    3030        }, 
    3131        mouseStart: function(e) { 
    32  
     32             
    3333            var o = this.options; 
    3434            if($.ui.ddmanager) $.ui.ddmanager.current = this; 
     
    3838            if(!this.helper.parents('body').length) this.helper.appendTo((o.appendTo == 'parent' ? this.element[0].parentNode : o.appendTo)); 
    3939            if(this.helper[0] != this.element[0] && !(/(fixed|absolute)/).test(this.helper.css("position"))) this.helper.css("position", "absolute"); 
    40  
     40             
    4141            /* 
    4242             * - Position generation - 
     
    4848                top: (parseInt(this.element.css("marginTop"),10) || 0) 
    4949            };       
    50  
     50             
    5151            this.cssPosition = this.helper.css("position");                                                 //Store the helper's css position 
    5252            this.offset = this.element.offset();                                                            //The element's absolute position on the page 
     
    5555                left: this.offset.left - this.margins.left 
    5656            }; 
    57  
     57             
    5858            this.offset.click = {                                                                           //Where the click happened, relative to the element 
    5959                left: e.pageX - this.offset.left, 
    6060                top: e.pageY - this.offset.top 
    6161            }; 
    62      
     62             
    6363            this.offsetParent = this.helper.offsetParent(); var po = this.offsetParent.offset();            //Get the offsetParent and cache its position 
    6464            this.offset.parent = {                                                                          //Store its position plus border 
     
    6666                left: po.left + (parseInt(this.offsetParent.css("borderLeftWidth"),10) || 0) 
    6767            }; 
    68      
     68             
    6969            var p = this.element.position();                                                                //This is a relative to absolute position minus the actual position calculation - only used for relative positioned helpers 
    7070            this.offset.relative = this.cssPosition == "relative" ? { 
     
    7272                left: p.left - (parseInt(this.helper.css("left"),10) || 0) + this.offsetParent[0].scrollLeft 
    7373            } : { top: 0, left: 0 }; 
    74          
     74             
    7575            this.originalPosition = this.generatePosition(e);                                               //Generate the original position 
    7676            this.helperProportions = { width: this.helper.outerWidth(), height: this.helper.outerHeight() };//Cache the helper size 
    77  
     77             
    7878            if(o.cursorAt) { 
    7979                if(o.cursorAt.left != undefined) this.offset.click.left = o.cursorAt.left; 
     
    8282                if(o.cursorAt.bottom != undefined) this.offset.click.top = this.helperProportions.height - o.cursorAt.bottom; 
    8383            } 
    84  
    85  
     84             
     85             
    8686            /* 
    8787             * - Position constraining - 
     
    9595                    var ce = $(o.containment)[0]; 
    9696                    var co = $(o.containment).offset(); 
    97  
     97                     
    9898                    this.containment = [ 
    9999                        co.left + (parseInt($(ce).css("borderLeftWidth"),10) || 0) - this.offset.relative.left - this.offset.parent.left, 
     
    104104                } 
    105105            } 
    106  
    107  
     106             
    108107            //Call plugins and callbacks 
    109108            this.propagate("start", e); 
    110  
     109             
    111110            this.helperProportions = { width: this.helper.outerWidth(), height: this.helper.outerHeight() };//Recache the helper size 
    112111            if ($.ui.ddmanager && !o.dropBehaviour) $.ui.ddmanager.prepareOffsets(this, e); 
    113  
     112             
    114113            return !o.disabled; 
    115  
    116114        }, 
    117115        convertPositionTo: function(d, pos) { 
     
    154152                ) 
    155153            }; 
    156  
     154             
    157155            if(!this.originalPosition) return position;                                     //If we are not dragging yet, we won't check for options 
    158              
    159156             
    160157            /* 
     
    172169                var top = this.originalPosition.top + Math.round((position.top - this.originalPosition.top) / o.grid[1]) * o.grid[1]; 
    173170                position.top = this.containment ? (!(top < this.containment[1] || top > this.containment[3]) ? top : (!(top < this.containment[1]) ? top - o.grid[1] : top + o.grid[1])) : top; 
    174  
     171                 
    175172                var left = this.originalPosition.left + Math.round((position.left - this.originalPosition.left) / o.grid[0]) * o.grid[0]; 
    176173                position.left = this.containment ? (!(left < this.containment[0] || left > this.containment[2]) ? left : (!(left < this.containment[0]) ? left - o.grid[0] : left + o.grid[0])) : left; 
     
    180177        }, 
    181178        mouseDrag: function(e) { 
    182  
     179             
    183180            //Compute the helpers position 
    184181            this.position = this.generatePosition(e); 
    185182            this.positionAbs = this.convertPositionTo("absolute"); 
    186  
     183             
    187184            //Call plugins and callbacks and use the resulting position if something is returned         
    188185            this.position = this.propagate("drag", e) || this.position; 
     
    191188            if(!this.options.axis || this.options.axis == "y") this.helper[0].style.top = this.position.top+'px'; 
    192189            if($.ui.ddmanager) $.ui.ddmanager.drag(this, e); 
     190             
    193191            return false; 
    194  
    195192        }, 
    196193        mouseStop: function(e) { 
     
    210207                this.clear(); 
    211208            } 
    212  
     209             
    213210            return false; 
    214              
    215211        }, 
    216212        clear: function() { 
     
    261257        } 
    262258    }); 
    263  
     259     
    264260    $.ui.plugin.add("draggable", "zIndex", { 
    265261        start: function(e, ui) { 
     
    272268        } 
    273269    }); 
    274  
     270     
    275271    $.ui.plugin.add("draggable", "opacity", { 
    276272        start: function(e, ui) { 
     
    307303            o.scrollSensitivity = o.scrollSensitivity || 20; 
    308304            o.scrollSpeed       = o.scrollSpeed || 20; 
    309  
     305             
    310306            i.overflowY = function(el) { 
    311307                do { if(/auto|scroll/.test(el.css('overflow')) || (/auto|scroll/).test(el.css('overflow-y'))) return el; el = el.parent(); } while (el[0].parentNode); 
     
    325321            var o = ui.options; 
    326322            var i = $(this).data("draggable"); 
    327  
     323             
    328324            if(i.overflowY[0] != document && i.overflowY[0].tagName != 'HTML') { 
    329325                if((i.overflowYOffset.top + i.overflowY[0].offsetHeight) - e.pageY < o.scrollSensitivity) 
     
    350346                    $(document).scrollLeft($(document).scrollLeft() + o.scrollSpeed); 
    351347            } 
    352  
     348             
    353349        } 
    354350    }); 
     
    370366        }, 
    371367        drag: function(e, ui) { 
    372  
     368             
    373369            var inst = $(this).data("draggable"); 
    374370            var d = ui.options.snapTolerance || 20; 
    375371            var x1 = ui.absolutePosition.left, x2 = x1 + inst.helperProportions.width, 
    376372                y1 = ui.absolutePosition.top, y2 = y1 + inst.helperProportions.height; 
    377  
     373             
    378374            for (var i = inst.snapElements.length - 1; i >= 0; i--){ 
    379  
     375                 
    380376                var l = inst.snapElements[i].left, r = l + inst.snapElements[i].width,  
    381377                    t = inst.snapElements[i].top, b = t + inst.snapElements[i].height; 
    382  
     378                 
    383379                //Yes, I know, this is insane ;) 
    384380                if(!((l-d < x1 && x1 < r+d && t-d < y1 && y1 < b+d) || (l-d < x1 && x1 < r+d && t-d < y2 && y2 < b+d) || (l-d < x2 && x2 < r+d && t-d < y1 && y1 < b+d) || (l-d < x2 && x2 < r+d && t-d < y2 && y2 < b+d))) continue; 
    385  
     381                 
    386382                if(ui.options.snapMode != 'inner') { 
    387383                    var ts = Math.abs(t - y2) <= 20; 
     
    405401                    if(rs) ui.position.left = inst.convertPositionTo("relative", { top: 0, left: r - inst.helperProportions.width }).left; 
    406402                } 
    407  
     403                 
    408404            }; 
    409405        } 
     
    451447                    var height = inst.options.placeholderElement ? $(inst.options.placeholderElement, $(inst.options.items, inst.element)).innerHeight() : $(inst.options.items, inst.element).innerHeight(); 
    452448                    var width = inst.options.placeholderElement ? $(inst.options.placeholderElement, $(inst.options.items, inst.element)).innerWidth() : $(inst.options.items, inst.element).innerWidth(); 
    453  
     449                     
    454450                    //Now we fake the start of dragging for the sortable instance, 
    455451                    //by cloning the list group item, appending it to the sortable and using it as inst.currentItem 
     
    471467                 
    472468                } 
    473  
     469                 
    474470                //Provided we did all the previous steps, we can fire the drag event of the sortable on every draggable drag, when it intersects with the sortable 
    475471                if(inst.currentItem) inst.drag(e);