Bug Tracker

Ticket #2729: itemQuery.patch

File itemQuery.patch, 1.9 kB (added by rfb, 9 months ago)

patch to svn current

  • ui/ui.sortable.js

     
    220220            this.items = []; 
    221221            this.containers = [this]; 
    222222            var items = this.items; 
    223             var queries = [$(this.options.items, this.element)]; 
     223 
     224      // itemQuery allows us to refine the selection of items used in the sortable. 
     225      var queries = typeof this.options.itemQuery == 'function' ?  
     226        this.options.itemQuery.apply(this) : [$(this.options.items, this.element)]; 
    224227             
    225228            if(this.options.connectWith) { 
    226229                for (var i = this.options.connectWith.length - 1; i >= 0; i--){ 
  • ui/demos/ui.sortable.html

     
    9191    </ul> 
    9292</div> 
    9393 
     94<h2>5. Nested lists limited to 1 level deep</h2> 
     95<div class="playground"> 
     96    <ul id="example5" style="cursor: hand; cursor: pointer;"> 
     97        <li>Drag us</li> 
     98        <li>around</li> 
     99        <li>and change 
     100            <ul> 
     101                <li>Lorem</li> 
     102                <li>Ipsum</li> 
     103            </ul> 
     104        </li> 
     105        <li>our</li> 
     106        <li>positions 
     107            <ul> 
     108                <li>Something else</li> 
     109                <li>Foo bar</li> 
     110            </ul> 
     111        </li> 
     112    </ul> 
     113</div> 
     114 
    94115<script type="text/javascript"> 
    95116if(!window.console) { 
    96117 window.console = { 
     
    110131    $("#example3").sortable({ items: "li", revert: true, tree: true }); 
    111132    $("#example4").sortable({ placeholder: "hover", revert: true }); 
    112133 
     134    $("#example5").sortable({  
     135    items: "li", revert: true, tree: true, 
     136    itemQuery: function() { 
     137      if (this.currentItem) { 
     138 
     139        // if list item has a list 
     140        if ($('ul', this.currentItem).size()) { 
     141 
     142          // return only list items from the root list 
     143          return [$('> li', this.element)]; 
     144        } 
     145      } 
     146      return [$(this.options.items, this.element)]; 
     147    } 
     148  }); 
     149 
     150 
    113151}); 
    114152</script> 
    115153</body>