Bug Tracker

Changeset 5050

Show
Ignore:
Timestamp:
03/17/08 11:14:42 (10 months ago)
Author:
joern.zaefferer
Message:

ui.slider: autocreate sliders if none present (#2523)

Location:
trunk/ui
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/ui/tests/slider_test.html

    r5000 r5050  
    2727 
    2828    <div id="main" style="position:absolute;top:-20000px"> 
     29        <div id='slider1'></div> 
    2930        <div id='slider3' style="position: relative; margin: 40px; width: 217px; height: 28px; background: url(http://developer.yahoo.com/yui/examples/slider/assets/bg-fader.gif) no-repeat scroll 5px 0px;"> 
    3031            <div class='ui-slider-handle' style='position: absolute; height: 21px; left: 0px; bottom: 0px; width: 17px; background-image: url(http://developer.yahoo.com/yui/examples/slider/assets/thumb-n.gif);'></div>    
  • trunk/ui/tests/slider_test.js

    r4897 r5050  
    5454 
    5555test("options update min/max", function() { 
    56     //expect(1); 
     56    expect(2); 
    5757    var slider = $("#slider3").slider({ 
    5858        stepping: 1, 
    59         startValue: 1, 
    60         minValue: 0, 
    61         maxValue: 100, 
    62         change: function(e, ui) { 
    63             //equals(ui.value, result, "changed to " + ui.value); 
    64         } 
     59        startValue: 1 
    6560    }); 
    6661    slider.slider("moveTo", "-=10"); 
     
    7166}) 
    7267 
     68module("setup and teardown"); 
     69 
    7370test("destroy and recreate", function() { 
     71    expect(3) 
    7472    var slider = $("#slider3").slider(); 
    7573    slider.slider("moveTo", "+=20"); 
    7674    equals(slider.slider("value"), 20); 
    7775    slider.slider("destroy"); 
    78     try { 
    79         slider.slider("moveTo", "+=30"); 
    80         ok(false, "must throw error when destroyed"); 
    81     } catch(e) { 
    82         ok(true, "can't move a destroyed slider"); 
    83     } 
     76     
     77    slider.slider("moveTo", "+=30"); 
     78    ok(true, "nothing happens after slider is destroyed"); 
     79     
    8480    slider.slider().slider("moveTo", "30"); 
    8581     
    8682    equals(Math.round(slider.slider("value")), 30); 
    87      
    8883}) 
     84 
     85test("handle creation", function() { 
     86    var slider = $("#slider1"); 
     87    equals(slider.children().size(), 0); 
     88    slider.slider({ 
     89        handles: [ 
     90            { start: 0 }, 
     91            { start: 10 } 
     92        ] 
     93    }); 
     94    equals(slider.children().size(), 2); 
     95    var instance = $.data(slider[0], "slider") 
     96    equals(instance.handle.length, 2); 
     97    ok(instance.handle.jquery, "handle must be a jquery object") 
     98}) 
  • trunk/ui/ui.slider.js

    r4983 r5050  
    2828         
    2929        //Prepare the passed options 
    30         this.options = $.extend({}, options); 
     30        this.options = $.extend({}, $.ui.slider.defaults, options); 
    3131        var o = this.options; 
    3232        $.extend(o, { 
     
    4949 
    5050        //Initialize mouse and key events for interaction 
    51         this.handle = o.handle ? $(o.handle, element) : $('> *', element); 
     51        this.handle = $(o.handle, element); 
     52        if (!this.handle.length) { 
     53            self.handle = $(o.handles || [0]).map(function() { 
     54                var handle = $("<div/>").addClass("ui-slider-handle").appendTo(element); 
     55                if (this.id) 
     56                    handle.attr("id", this.id); 
     57                return handle[0]; 
     58            }); 
     59        } 
    5260        $(this.handle) 
    5361            .mouseInteraction({ 
     
    94102         
    95103        //Move the first handle to the startValue 
    96         if (o.startValue && o.startValue.constructor == Array) { 
    97             $.each(o.startValue, function(index, value) { 
    98                 self.moveTo(value, index, true); 
    99             }); 
    100         } else if (!isNaN(o.startValue)) 
     104        $.each(o.handles || [], function(index, handle) { 
     105            self.moveTo(handle.start, index, true); 
     106        }); 
     107        if (!isNaN(o.startValue)) 
    101108            this.moveTo(o.startValue, 0, true); 
    102109         
     
    276283        } 
    277284    }); 
     285     
     286    $.ui.slider.defaults = { 
     287        handle: ".ui-slider-handle" 
     288    }; 
    278289 
    279290})(jQuery);