Changeset 5050
- Timestamp:
- 03/17/08 11:14:42 (10 months ago)
- Location:
- trunk/ui
- Files:
-
- 3 modified
-
tests/slider_test.html (modified) (1 diff)
-
tests/slider_test.js (modified) (2 diffs)
-
ui.slider.js (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ui/tests/slider_test.html
r5000 r5050 27 27 28 28 <div id="main" style="position:absolute;top:-20000px"> 29 <div id='slider1'></div> 29 30 <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;"> 30 31 <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 54 54 55 55 test("options update min/max", function() { 56 //expect(1);56 expect(2); 57 57 var slider = $("#slider3").slider({ 58 58 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 65 60 }); 66 61 slider.slider("moveTo", "-=10"); … … 71 66 }) 72 67 68 module("setup and teardown"); 69 73 70 test("destroy and recreate", function() { 71 expect(3) 74 72 var slider = $("#slider3").slider(); 75 73 slider.slider("moveTo", "+=20"); 76 74 equals(slider.slider("value"), 20); 77 75 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 84 80 slider.slider().slider("moveTo", "30"); 85 81 86 82 equals(Math.round(slider.slider("value")), 30); 87 88 83 }) 84 85 test("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 28 28 29 29 //Prepare the passed options 30 this.options = $.extend({}, options);30 this.options = $.extend({}, $.ui.slider.defaults, options); 31 31 var o = this.options; 32 32 $.extend(o, { … … 49 49 50 50 //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 } 52 60 $(this.handle) 53 61 .mouseInteraction({ … … 94 102 95 103 //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)) 101 108 this.moveTo(o.startValue, 0, true); 102 109 … … 276 283 } 277 284 }); 285 286 $.ui.slider.defaults = { 287 handle: ".ui-slider-handle" 288 }; 278 289 279 290 })(jQuery);
