Changeset 468

Show
Ignore:
Timestamp:
07/17/08 09:13:10 (19 months ago)
Author:
paul.bakaus
Message:

draggable: implemented more advanced features for the snap option - you can now pass in a object instead of a bolean into "snap", possible keys are the callbacks snap/release (which both receive ui.snapItem) and items (jQuery selector, defaults to :data(draggable))

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/ui/ui.draggable.js

    r467 r468  
    380380                var inst = $(this).data("draggable"); 
    381381                inst.snapElements = []; 
    382                 $(ui.options.snap === true ? ':data(draggable)' : ui.options.snap).each(function() { 
     382 
     383                $(ui.options.snap.constructor != String ? ( ui.options.snap.items || ':data(draggable)' ) : ui.options.snap).each(function() { 
    383384                        var $t = $(this); var $o = $t.offset(); 
    384385                        if(this != inst.element[0]) inst.snapElements.push({ 
     
    391392        }, 
    392393        drag: function(e, ui) { 
    393                  
     394         
    394395                var inst = $(this).data("draggable"); 
    395396                var d = ui.options.snapTolerance || 20; 
     
    403404                         
    404405                        //Yes, I know, this is insane ;) 
    405                         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; 
     406                        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))) { 
     407                                if(inst.snapElements[i].snapping) (inst.options.snap.release && inst.options.snap.release.call(inst.element, null, $.extend(inst.uiHash(), { snapItem: inst.snapElements[i].item }))); 
     408                                inst.snapElements[i].snapping = false; 
     409                                continue; 
     410                        } 
    406411                         
    407412                        if(ui.options.snapMode != 'inner') { 
     
    416421                        } 
    417422                         
     423                        var first = (ts || bs || ls || rs); 
     424                         
    418425                        if(ui.options.snapMode != 'outer') { 
    419426                                var ts = Math.abs(t - y1) <= 20; 
     
    427434                        } 
    428435                         
    429                 }; 
     436                        if(!inst.snapElements[i].snapping && (ts || bs || ls || rs || first)) 
     437                                (inst.options.snap.snap && inst.options.snap.snap.call(inst.element, null, $.extend(inst.uiHash(), { snapItem: inst.snapElements[i].item }))); 
     438                        inst.snapElements[i].snapping = (ts || bs || ls || rs || first); 
     439                         
     440                }; 
     441 
    430442        } 
    431443});