Skip to content

Commit 6661f17

Browse files
committed
clean branch for jquery-archive#2381
2 parents c716ab7 + ad6d040 commit 6661f17

File tree

5 files changed

+38
-0
lines changed

5 files changed

+38
-0
lines changed

css/structure/jquery.mobile.forms.slider.css

100644100755
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ input.ui-slider-input,
44
select.ui-slider-switch { display: none; }
55
div.ui-slider { position: relative; display: inline-block; overflow: visible; height: 15px; padding: 0; margin: 0 2% 0 20px; top: 4px; width: 60%; }
66
div.ui-slider-switch { width: 99.8%; }
7+
div.ui-slider-range-background {height:15px; padding:0; margin: 0; border: none}
78
a.ui-slider-handle { position: absolute; z-index: 10; top: 50%; width: 28px; height: 28px; margin-top: -15px; margin-left: -15px; }
89
a.ui-slider-handle .ui-btn-inner { padding-left: 0; padding-right: 0; }
910
@media all and (min-width: 480px){

docs/forms/slider/index.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,21 @@ <h2>Theming the slider</h2>
9191
<label for="slider-2">Input slider:</label>
9292
<input type="range" name="slider-2" id="slider-2" value="25" min="0" max="100" data-theme="a" data-track-theme="b" />
9393
</div>
94+
95+
<p>By adding a <code>data-range-theme</code> attribute to the <code>input</code>, a separate swatch is set for the track between the start- and the handles position.</p>
96+
97+
<pre><code>
98+
&lt;div data-role=&quot;fieldcontain&quot;&gt;
99+
&lt;label for=&quot;slider-3&quot;&gt;Input slider:&lt;/label&gt;
100+
&lt;input type=&quot;range&quot; name=&quot;slider-3&quot; id=&quot;slider-3&quot; value=&quot;25&quot; min=&quot;0&quot; max=&quot;100&quot; <strong>data-theme=&quot;a&quot; data-range-theme=&quot;b&quot;</strong> /&gt;
101+
&lt;/div&gt;
102+
</code></pre>
103+
104+
<p>This will produce a themed slider:</p>
105+
<div data-role="fieldcontain">
106+
<label for="slider-3">Input slider:</label>
107+
<input type="range" name="slider-3" id="slider-3" value="25" min="0" max="100" data-theme="a" data-range-theme="b" />
108+
</div>
94109
</form>
95110
</div><!--/content-primary -->
96111

js/jquery.mobile.forms.slider.js

100644100755
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ $.widget( "mobile.slider", $.mobile.widget, {
88
options: {
99
theme: null,
1010
trackTheme: null,
11+
rangeTheme: null,
1112
disabled: false,
1213
initSelector: "input[type='range'], :jqmData(type='range'), :jqmData(role='slider')"
1314
},
@@ -23,8 +24,12 @@ $.widget( "mobile.slider", $.mobile.widget, {
2324

2425
theme = this.options.theme || parentTheme,
2526

27+
// theme of the outer track-bar
2628
trackTheme = this.options.trackTheme || parentTheme,
2729

30+
// theme for the part between start & current slider position
31+
rangeTheme = this.options.rangeTheme || trackTheme,
32+
2833
cType = control[ 0 ].nodeName.toLowerCase(),
2934

3035
selectClass = ( cType == "select" ) ? "ui-slider-switch" : "",
@@ -94,6 +99,9 @@ $.widget( "mobile.slider", $.mobile.widget, {
9499
});
95100

96101
}
102+
else if (trackTheme != rangeTheme) {
103+
slider.wrapInner( "<div class='ui-slider-range-background ui-btn-down-" + rangeTheme + " ui-btn-corner-all' role='application'></div>" );
104+
}
97105

98106
label.addClass( "ui-slider" );
99107

@@ -307,6 +315,7 @@ $.widget( "mobile.slider", $.mobile.widget, {
307315
newval = max;
308316
}
309317

318+
this.slider.find('div.ui-slider-range-background').css('width', percent + "%");
310319
this.handle.css( "left", percent + "%" );
311320
this.handle.attr( {
312321
"aria-valuenow": cType === "input" ? newval : control.find( "option" ).eq( newval ).attr( "value" ),

tests/unit/slider/index.html

100644100755
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ <h2 id="qunit-userAgent"></h2>
5050
<input type="range" name="stepped" id="stepped" value="15" min="0" max="100" step="10" data-nstest-theme="b" data-nstest-track-theme="a" />
5151
</div>
5252

53+
<div data-nstest-role="fieldcontain">
54+
<input type="range" name="range-background" id="range-background" value="15" min="0" max="100" data-nstest-theme="b" data-nstest-track-theme="a" data-nstest-range-theme="c" />
55+
</div>
56+
5357
<div data-nstest-role="fieldcontain">
5458
<select name="slider" id="slider-switch" data-nstest-role="slider">
5559
<option value="off">Off</option>

tests/unit/slider/slider_events.js

100644100755
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,15 @@
110110
same($("#range-slider-up").attr( "type" ), "number");
111111
});
112112

113+
test( "slider with range-background theme should have a inner range-div with corresponding theme and width", function(){
114+
var slider = $("#range-background");
115+
slider.focus();
116+
same(slider.val(), "15");
117+
var backgroundDiv = slider.next().find('.ui-slider-range-background');
118+
same((Math.round(100 * parseFloat(backgroundDiv.css('width')) / parseFloat(backgroundDiv.parent().css('width')) ) + '%'), '15%');
119+
ok(backgroundDiv.hasClass('ui-btn-down-c'));
120+
});
121+
113122
// generic switch test function
114123
var sliderSwitchTest = function(opts){
115124
var slider = $("#slider-switch"),

0 commit comments

Comments
 (0)