|
525
|
1 |
<!DOCTYPE html> |
|
|
2 |
<html lang="en"> |
|
|
3 |
<head> |
|
|
4 |
<meta charset="utf-8"> |
|
|
5 |
<title>Slider</title> |
|
|
6 |
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic,700italic"> |
|
|
7 |
<link rel="stylesheet" href="../../build/cssgrids/cssgrids-min.css"> |
|
|
8 |
<link rel="stylesheet" href="../assets/css/main.css"> |
|
|
9 |
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css"> |
|
|
10 |
<link rel="shortcut icon" type="image/png" href="../assets/favicon.png"> |
|
|
11 |
<script src="../../build/yui/yui-min.js"></script> |
|
|
12 |
|
|
|
13 |
</head> |
|
|
14 |
<body> |
|
|
15 |
<!-- |
|
|
16 |
<a href="https://github.com/yui/yui3"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a> |
|
|
17 |
--> |
|
|
18 |
<div id="doc"> |
|
|
19 |
<div id="hd"> |
|
|
20 |
<h1><img src="http://yuilibrary.com/img/yui-logo.png"></h1> |
|
|
21 |
</div> |
|
|
22 |
|
|
|
23 |
<a href="#toc" class="jump">Jump to Table of Contents</a> |
|
|
24 |
|
|
|
25 |
|
|
|
26 |
<h1>Slider</h1> |
|
|
27 |
<div class="yui3-g"> |
|
|
28 |
<div class="yui3-u-3-4"> |
|
|
29 |
<div id="main"> |
|
|
30 |
<div class="content"><div class="intro"> |
|
|
31 |
<p> |
|
|
32 |
The Slider widget is a UI control that enables the user to adjust |
|
|
33 |
values in a finite range along a horizontal or vertical axis. |
|
|
34 |
Typically, the Slider widget is used in a web application as a visual |
|
|
35 |
replacement for an input box that takes a number as input. |
|
|
36 |
</p> |
|
|
37 |
</div> |
|
|
38 |
|
|
|
39 |
<h2 id="getting-started">Getting Started</h2> |
|
|
40 |
|
|
|
41 |
<p> |
|
|
42 |
To include the source files for Slider and its dependencies, first load |
|
|
43 |
the YUI seed file if you haven't already loaded it. |
|
|
44 |
</p> |
|
|
45 |
|
|
|
46 |
<pre class="code prettyprint"><script src="http://yui.yahooapis.com/3.10.3/build/yui/yui-min.js"></script></pre> |
|
|
47 |
|
|
|
48 |
|
|
|
49 |
<p> |
|
|
50 |
Next, create a new YUI instance for your application and populate it with the |
|
|
51 |
modules you need by specifying them as arguments to the <code>YUI().use()</code> method. |
|
|
52 |
YUI will automatically load any dependencies required by the modules you |
|
|
53 |
specify. |
|
|
54 |
</p> |
|
|
55 |
|
|
|
56 |
<pre class="code prettyprint"><script> |
|
|
57 |
// Create a new YUI instance and populate it with the required modules. |
|
|
58 |
YUI().use('slider', function (Y) { |
|
|
59 |
// Slider is available and ready for use. Add implementation |
|
|
60 |
// code here. |
|
|
61 |
}); |
|
|
62 |
</script></pre> |
|
|
63 |
|
|
|
64 |
|
|
|
65 |
<p> |
|
|
66 |
For more information on creating YUI instances and on the |
|
|
67 |
<a href="http://yuilibrary.com/yui/docs/api/classes/YUI.html#method_use"><code>use()</code> method</a>, see the |
|
|
68 |
documentation for the <a href="../yui/index.html">YUI Global Object</a>. |
|
|
69 |
</p> |
|
|
70 |
|
|
|
71 |
|
|
|
72 |
<h2 id="using">Using Sliders</h2> |
|
|
73 |
|
|
|
74 |
<h3 id="anatomy">Anatomy of a Slider</h3> |
|
|
75 |
|
|
|
76 |
<h4 id="dom-structure">DOM structure</h4> |
|
|
77 |
|
|
|
78 |
<p> |
|
|
79 |
A Slider is comprised of a thumb that slides along a rail. In the DOM, the |
|
|
80 |
thumb is a child of the rail element. The visualization of the rail is |
|
|
81 |
created by applying a CSS background image to the rail element and two |
|
|
82 |
child elements used to display the rail's end caps. The thumb contains two |
|
|
83 |
<code><img></code> elements, one for the thumb graphic and one for |
|
|
84 |
its shadow. Using an <code><img></code> in the DOM rather than a |
|
|
85 |
background image for the thumb circumvents a performance issue in older |
|
|
86 |
versions of Internet Explorer. |
|
|
87 |
</p> |
|
|
88 |
|
|
|
89 |
<p> |
|
|
90 |
The rail element is contained within the standard <code>contentBox</code> |
|
|
91 |
and <code>boundingBox</code> common to all YUI 3 Widgets. |
|
|
92 |
</p> |
|
|
93 |
|
|
|
94 |
<p> |
|
|
95 |
Like other form controls, Sliders are inline elements. |
|
|
96 |
</p> |
|
|
97 |
|
|
|
98 |
<p> |
|
|
99 |
The complete markup of a Slider is as follows: |
|
|
100 |
</p> |
|
|
101 |
|
|
|
102 |
<p> |
|
|
103 |
<strong>Note:</strong> be sure to add the <code>yui3-skin-sam</code> classname to the |
|
|
104 |
page's <code><body></code> element or to a parent element of the widget in order to apply |
|
|
105 |
the default CSS skin. See <a href="http://yuilibrary.com/yui/docs/tutorials/skins/">Understanding Skinning</a>. |
|
|
106 |
</p> |
|
|
107 |
<pre class="code prettyprint"><body class="yui3-skin-sam"> <!-- You need this skin class --></pre> |
|
|
108 |
|
|
|
109 |
|
|
|
110 |
<pre class="code prettyprint"><!-- boundingBox --> |
|
|
111 |
<span class="yui3-widget yui3-sliderbase yui-slider"> |
|
|
112 |
<!-- contentBox --> |
|
|
113 |
<span class="yui3-slider-content yui3-slider-x"><!-- or slider-y --> |
|
|
114 |
|
|
|
115 |
<!-- rail --> |
|
|
116 |
<span class="yui3-slider-rail"> |
|
|
117 |
<span class="yui3-slider-rail-cap-left"></span><!-- or cap-top --> |
|
|
118 |
<span class="yui3-slider-rail-cap-right"></span><!-- or cap-bottom --> |
|
|
119 |
|
|
|
120 |
<!-- thumb --> |
|
|
121 |
<span class="yui3-slider-thumb"> |
|
|
122 |
<img class="yui3-slider-thumb-shadow"> |
|
|
123 |
<img class="yui3-slider-thumb-image"> |
|
|
124 |
</span> |
|
|
125 |
</span> |
|
|
126 |
|
|
|
127 |
</span> |
|
|
128 |
</span></pre> |
|
|
129 |
|
|
|
130 |
|
|
|
131 |
<h4 id="appearance">Appearance</h4> |
|
|
132 |
|
|
|
133 |
<p> |
|
|
134 |
This is the appearance of a Slider with default Sam skin applied: |
|
|
135 |
</p> |
|
|
136 |
|
|
|
137 |
<img src="../assets/slider/images/horiz_slider.png" alt="Horizontal Sliderwith default Sam skin"> |
|
|
138 |
|
|
|
139 |
<img src="../assets/slider/images/vert_slider.png" alt="Vertical Slider with default Sam skin"> |
|
|
140 |
|
|
|
141 |
<p> |
|
|
142 |
See the <a href="#skinning">skinning</a> section below for tips on creating |
|
|
143 |
your own skin or using one of the prepackaged skins available for Slider as |
|
|
144 |
of version 3.1. |
|
|
145 |
</p> |
|
|
146 |
|
|
|
147 |
<h4 id="thumb_placement">Thumb and end cap placement</h4> |
|
|
148 |
|
|
|
149 |
<p> |
|
|
150 |
The Slider thumb is positioned within the dimensional boundaries of the |
|
|
151 |
rail element. The skin CSS positions the rail's end caps just outside the |
|
|
152 |
rail. The rail element's height or width, for vertical or horizontal |
|
|
153 |
Sliders respectively, is configured by the <code>length</code> attribute. |
|
|
154 |
The default <code>length</code> is 150px. Due to the end caps, the actual |
|
|
155 |
footprint of the Slider is a few pixels longer than the |
|
|
156 |
<code>length</code>. |
|
|
157 |
</p> |
|
|
158 |
|
|
|
159 |
<img src="../assets/slider/images/anatomy.png" alt="illustration of the parts and config properties of a Slider"> |
|
|
160 |
|
|
|
161 |
<h3 id="instantiating">Instantiating and configuring a Slider</h3> |
|
|
162 |
|
|
|
163 |
<p> |
|
|
164 |
There is no required configuration to instantiate a Slider. By default, |
|
|
165 |
Sliders are horizontal, 150px wide, and report values from 0 to 100. Below |
|
|
166 |
are the configuration attributes available for Slider (excluding those |
|
|
167 |
inherited from Widget): |
|
|
168 |
</p> |
|
|
169 |
|
|
|
170 |
<table> |
|
|
171 |
<thead> |
|
|
172 |
<tr> |
|
|
173 |
<th>Attribute</th> |
|
|
174 |
<th>Description</th> |
|
|
175 |
<th>Default</th> |
|
|
176 |
</tr> |
|
|
177 |
</thead> |
|
|
178 |
<tbody> |
|
|
179 |
<tr> |
|
|
180 |
<td><code>axis</code></td> |
|
|
181 |
<td>Specifies horizontal or vertical Slider ("y" for vertical)</td> |
|
|
182 |
<td>"x"</td> |
|
|
183 |
</tr> |
|
|
184 |
<tr> |
|
|
185 |
<td><code>min</code></td> |
|
|
186 |
<td>Value at the far left or top of the rail</td> |
|
|
187 |
<td>0</td> |
|
|
188 |
</tr> |
|
|
189 |
<tr> |
|
|
190 |
<td><code>max</code></td> |
|
|
191 |
<td>Value at the far right or bottom of the rail</td> |
|
|
192 |
<td>100</td> |
|
|
193 |
</tr> |
|
|
194 |
<tr> |
|
|
195 |
<td><code>value</code></td> |
|
|
196 |
<td>The initial value, which will be translated into initial thumb placement</td> |
|
|
197 |
<td>0</td> |
|
|
198 |
</tr> |
|
|
199 |
<tr> |
|
|
200 |
<td><code>length</code></td> |
|
|
201 |
<td>Height of vertical Slider rail; width of horizontal Slider rail</td> |
|
|
202 |
<td>150px</td> |
|
|
203 |
</tr> |
|
|
204 |
<tr> |
|
|
205 |
<td><code>thumbUrl</code></td> |
|
|
206 |
<td>The path to an image to use as the <code><img></code> for the thumb</td> |
|
|
207 |
<td>Appropriate thumb image for the configured axis in the current skin</td> |
|
|
208 |
</tr> |
|
|
209 |
<tr> |
|
|
210 |
<td><code>clickableRail</code></td> |
|
|
211 |
<td>Clicking on the rail moves the thumb to that point</td> |
|
|
212 |
<td>true</td> |
|
|
213 |
</tr> |
|
|
214 |
</tbody> |
|
|
215 |
</table> |
|
|
216 |
|
|
|
217 |
<p> |
|
|
218 |
Here are a few ways to instantiate a Slider: |
|
|
219 |
</p> |
|
|
220 |
|
|
|
221 |
<pre class="code prettyprint">YUI({...}).use('slider',function (Y) { |
|
|
222 |
|
|
|
223 |
// Default everything |
|
|
224 |
var slider = new Y.Slider(); |
|
|
225 |
slider.render("#slider-parent"); |
|
|
226 |
|
|
|
227 |
// Use a custom thumb and width |
|
|
228 |
var slider = new Y.Slider({ |
|
|
229 |
length : '200px', |
|
|
230 |
thumbUrl : '/path/to/local/thumb-image.png' |
|
|
231 |
}); |
|
|
232 |
slider.render('#slider-parent'); |
|
|
233 |
|
|
|
234 |
// Vertical slider with values that increase from bottom to top and |
|
|
235 |
// initialize the thumb in the middle. |
|
|
236 |
var slider = new Y.Slider({ |
|
|
237 |
axis : 'y', |
|
|
238 |
min : 100, |
|
|
239 |
max : 0, |
|
|
240 |
value : 50 |
|
|
241 |
}); |
|
|
242 |
slider.render('#slider-parent'); |
|
|
243 |
});</pre> |
|
|
244 |
|
|
|
245 |
|
|
|
246 |
<h3 id="value">Setting and constraining the Slider value</h3> |
|
|
247 |
|
|
|
248 |
<h4 id="setting-and-getting-slider-values">Setting and getting Slider values</h4> |
|
|
249 |
|
|
|
250 |
<p> |
|
|
251 |
Like any input element, the most important thing about a Slider is its |
|
|
252 |
<code>value</code>. Though <code>value</code> is managed as an attribute, |
|
|
253 |
Slider provides two convenience methods for accessing it: |
|
|
254 |
</p> |
|
|
255 |
|
|
|
256 |
<ul> |
|
|
257 |
<li><code>getValue()</code></li> |
|
|
258 |
<li><code>setValue(newVal)</code></li> |
|
|
259 |
</ul> |
|
|
260 |
|
|
|
261 |
<pre class="code prettyprint">// Specify value at construction |
|
|
262 |
var slider = new Y.Slider({ |
|
|
263 |
value : 50 |
|
|
264 |
}); |
|
|
265 |
|
|
|
266 |
// Get and set the value as an attribute |
|
|
267 |
var val = slider.get('value'); |
|
|
268 |
|
|
|
269 |
slider.set('value',val + 10); |
|
|
270 |
|
|
|
271 |
// Use the Slider API convenience methods |
|
|
272 |
val = slider.getValue(); |
|
|
273 |
|
|
|
274 |
slider.setValue(val - 20);</pre> |
|
|
275 |
|
|
|
276 |
|
|
|
277 |
|
|
|
278 |
<h4 id="min_max">Constraining Slider values</h4> |
|
|
279 |
|
|
|
280 |
<p> |
|
|
281 |
A Slider's <code>value</code> is constrained between the configured |
|
|
282 |
<code>min</code> and <code>max</code> attribute values. Values outside |
|
|
283 |
this range are treated as the closer of <code>min</code> or |
|
|
284 |
<code>max</code>. |
|
|
285 |
</p> |
|
|
286 |
|
|
|
287 |
<pre class="code prettyprint">// Create a horizontal Slider 300px wide with values from -100 to 100 |
|
|
288 |
var slider = new Y.Slider({ |
|
|
289 |
length : 300, |
|
|
290 |
min : -100, |
|
|
291 |
max : 100 |
|
|
292 |
}); |
|
|
293 |
|
|
|
294 |
slider.setValue(-200); // same as setValue(-100)</pre> |
|
|
295 |
|
|
|
296 |
|
|
|
297 |
<p> |
|
|
298 |
By default, <code>min</code> is <code>0</code>, <code>max</code> is |
|
|
299 |
<code>100</code> and <code>value</code> is <code>0</code>. |
|
|
300 |
</p> |
|
|
301 |
|
|
|
302 |
<h4 id="vert_min_max"><code>min</code> and <code>max</code> for vertical Sliders</h4> |
|
|
303 |
|
|
|
304 |
<p> |
|
|
305 |
Vertical Sliders associate the top edge of the rail with the |
|
|
306 |
<code>min</code> value and the bottom edge of the rail with the |
|
|
307 |
<code>max</code>. If you prefer values to increase from bottom to top, |
|
|
308 |
just flip the specified <code>min</code> and <code>max</code> values. |
|
|
309 |
</p> |
|
|
310 |
|
|
|
311 |
<pre class="code prettyprint">// Create a vertical Slider with value 0 at the bottom, 100 at the top |
|
|
312 |
var v_slider = new Y.Slider({ |
|
|
313 |
axis : 'y', |
|
|
314 |
min : 100, // vertical Sliders have min at the top |
|
|
315 |
max : 0, |
|
|
316 |
value : 33 // initial value |
|
|
317 |
});</pre> |
|
|
318 |
|
|
|
319 |
|
|
|
320 |
<h4 id="hidden">Sync the UI if the Slider was rendered off the DOM</h4> |
|
|
321 |
|
|
|
322 |
<p> |
|
|
323 |
If a Slider is rendered off the DOM, you must call the Slider's |
|
|
324 |
<code>syncUI()</code> method after attaching it to the DOM in order for the |
|
|
325 |
thumb to be placed correctly. When off DOM, the dimensional information |
|
|
326 |
necessary to place the thumb is unavailable. |
|
|
327 |
</p> |
|
|
328 |
|
|
|
329 |
<pre class="code prettyprint">// Create a Slider and render it to an element not on the DOM |
|
|
330 |
var container = Y.Node.create("<div></div>"); |
|
|
331 |
|
|
|
332 |
var slider = new Y.Slider({ value: 30 }); |
|
|
333 |
|
|
|
334 |
slider.render( container ); |
|
|
335 |
|
|
|
336 |
... |
|
|
337 |
|
|
|
338 |
// Insert the Slider's container into the DOM |
|
|
339 |
Y.one( "body" ).insert( container ); |
|
|
340 |
|
|
|
341 |
// Call syncUI() to sync the thumb to the current value |
|
|
342 |
slider.syncUI();</pre> |
|
|
343 |
|
|
|
344 |
|
|
|
345 |
<h3 id="events">Slider events</h3> |
|
|
346 |
|
|
|
347 |
<p> |
|
|
348 |
Sliders fire the following events during operation: |
|
|
349 |
</p> |
|
|
350 |
|
|
|
351 |
<table> |
|
|
352 |
<thead> |
|
|
353 |
<tr> |
|
|
354 |
<th>Event</th> |
|
|
355 |
<th>When</th> |
|
|
356 |
<th>Payload</th> |
|
|
357 |
</tr> |
|
|
358 |
</thead> |
|
|
359 |
<tbody> |
|
|
360 |
<tr> |
|
|
361 |
<td><code>slideStart</code></td> |
|
|
362 |
<td>Beginning a thumb drag</td> |
|
|
363 |
<td><code>{ ddEvent: (drag:start event) }</code></td> |
|
|
364 |
</tr> |
|
|
365 |
<tr> |
|
|
366 |
<td><code>thumbMove</code></td> |
|
|
367 |
<td>The thumb position is being changed</td> |
|
|
368 |
<td><code>{ ddEvent : (drag:drag event) }</code></td> |
|
|
369 |
</tr> |
|
|
370 |
<tr> |
|
|
371 |
<td><code>valueChange</code></td> |
|
|
372 |
<td>The value attribute is changed by any means</td> |
|
|
373 |
<td>Normal change event signature (<code>newVal</code>, <code>prevVal</code>, etc). When dragging, extra event property <code>ddEvent : (drag:drag event)</code> is added</td> |
|
|
374 |
</tr> |
|
|
375 |
<tr> |
|
|
376 |
<td><code>slideEnd</code></td> |
|
|
377 |
<td>Finishing a thumb drag</td> |
|
|
378 |
<td><code>{ ddEvent: (drag:end event) }</code></td> |
|
|
379 |
</tr> |
|
|
380 |
<tr> |
|
|
381 |
<td><code>railMouseDown</code></td> |
|
|
382 |
<td>The rail was clicked</td> |
|
|
383 |
<td><code>{ ev: (DOM mousedown event) }</code></td> |
|
|
384 |
</tr> |
|
|
385 |
</tbody> |
|
|
386 |
</table> |
|
|
387 |
|
|
|
388 |
<p> |
|
|
389 |
This is not an exhaustive list. See the <a href="http://yuilibrary.com/yui/docs/api/module_slider.html">API docs</a> for a complete listing. |
|
|
390 |
</p> |
|
|
391 |
|
|
|
392 |
<h3 id="skinning">Skinning</h3> |
|
|
393 |
|
|
|
394 |
<p> |
|
|
395 |
<strong>Note:</strong> be sure to add the <code>yui3-skin-sam</code> classname to the |
|
|
396 |
page's <code><body></code> element or to a parent element of the widget in order to apply |
|
|
397 |
the default CSS skin. See <a href="http://yuilibrary.com/yui/docs/tutorials/skins/">Understanding Skinning</a>. |
|
|
398 |
</p> |
|
|
399 |
<pre class="code prettyprint"><body class="yui3-skin-sam"> <!-- You need this skin class --></pre> |
|
|
400 |
|
|
|
401 |
|
|
|
402 |
<h4 id="skin_thumbUrl">Using custom thumb or rail images</h4> |
|
|
403 |
|
|
|
404 |
<p> |
|
|
405 |
You can use alternate rail images by specifying a new image path in your |
|
|
406 |
CSS, and alternate thumbs can be targeted in the Slider configuration. |
|
|
407 |
</p> |
|
|
408 |
|
|
|
409 |
<pre class="code prettyprint"><style type="text/css"> |
|
|
410 |
/* The rail and end cap images are shared in a sprite. |
|
|
411 |
* Include the id of the slider container to increase css specificity */ |
|
|
412 |
.yui3-skin-sam #slider-parent .yui3-slider-x .yui3-slider-rail, |
|
|
413 |
.yui3-skin-sam #slider-parent .yui3-slider-x .yui3-slider-rail-cap-left, |
|
|
414 |
.yui3-skin-sam #slider-parent .yui3-slider-x .yui3-slider-rail-cap-right { |
|
|
415 |
background-image: url(/path/to/new/rail.png); |
|
|
416 |
} |
|
|
417 |
</style> |
|
|
418 |
|
|
|
419 |
<script> |
|
|
420 |
YUI().use( "slider", function (Y) { |
|
|
421 |
|
|
|
422 |
var slider = new Y.Slider({ |
|
|
423 |
thumbUrl: '/path/to/new/thumb.png' |
|
|
424 |
}); |
|
|
425 |
|
|
|
426 |
slider.render("#slider-parent"); |
|
|
427 |
|
|
|
428 |
}); |
|
|
429 |
</script></pre> |
|
|
430 |
|
|
|
431 |
|
|
|
432 |
<h4 id="skins">Available skins</h4> |
|
|
433 |
|
|
|
434 |
<p> |
|
|
435 |
Slider is provided with several alternate skins that can be applied by |
|
|
436 |
configuring a skin override in your YUI instance configuration. |
|
|
437 |
</p> |
|
|
438 |
|
|
|
439 |
<pre class="code prettyprint">YUI({ |
|
|
440 |
skin: { |
|
|
441 |
overrides: { |
|
|
442 |
slider: [ 'round-dark' ] |
|
|
443 |
} |
|
|
444 |
} |
|
|
445 |
}).use( "slider", ... );</pre> |
|
|
446 |
|
|
|
447 |
|
|
|
448 |
<p> |
|
|
449 |
The available skins are each provided in a light and dark theme. A few |
|
|
450 |
include optional thumbs or rails (for both light and dark). |
|
|
451 |
</p> |
|
|
452 |
|
|
|
453 |
<table> |
|
|
454 |
<thead> |
|
|
455 |
<tr> |
|
|
456 |
<th>Skin class</th> |
|
|
457 |
<th>Visualization</th> |
|
|
458 |
<th>Optional</th> |
|
|
459 |
</tr> |
|
|
460 |
</thead> |
|
|
461 |
<tbody> |
|
|
462 |
<tr> |
|
|
463 |
<td rowspan="2"><code>yui3-skin-sam</code></td> |
|
|
464 |
<td><img src="../assets/slider/images/sam.png" alt="Slider with Sam skin"></td> |
|
|
465 |
<td></td> |
|
|
466 |
</tr> |
|
|
467 |
<tr> |
|
|
468 |
<td><img src="../assets/slider/images/sam_lines.png" alt="Slider with Sam skin and alternate rail image"></td> |
|
|
469 |
<td> |
|
|
470 |
<code>rail-x-lines.png</code> |
|
|
471 |
</td> |
|
|
472 |
</tr> |
|
|
473 |
<tr> |
|
|
474 |
<td><code>yui3-skin-sam-dark</code></td> |
|
|
475 |
<td><img src="../assets/slider/images/sam_dark.png" alt="Slider with Dark Sam skin"></td> |
|
|
476 |
<td></td> |
|
|
477 |
</tr> |
|
|
478 |
<tr> |
|
|
479 |
<td rowspan="4"><code>yui3-skin-capsule</code></td> |
|
|
480 |
<td><img src="../assets/slider/images/capsule.png" alt="Slider with Capsule skin"></td> |
|
|
481 |
<td></td> |
|
|
482 |
</tr> |
|
|
483 |
<tr> |
|
|
484 |
<td><img src="../assets/slider/images/capsule_thumb.png" alt="Slider with Capsule skin and alternate thumb image"></td> |
|
|
485 |
<td> |
|
|
486 |
<code>thumb-x-line.png</code> |
|
|
487 |
</td> |
|
|
488 |
</tr> |
|
|
489 |
<tr> |
|
|
490 |
<td><img src="../assets/slider/images/capsule_dots.png" alt="Slider with Sam skin and alternate rail image"></td> |
|
|
491 |
<td> |
|
|
492 |
<code>rail-x-dots.png</code> |
|
|
493 |
</td> |
|
|
494 |
</tr> |
|
|
495 |
<tr> |
|
|
496 |
<td><img src="../assets/slider/images/capsule_lines.png" alt="Slider with Sam skin and alternate rail image"></td> |
|
|
497 |
<td> |
|
|
498 |
<code>rail-x-lines.png</code> |
|
|
499 |
</td> |
|
|
500 |
</tr> |
|
|
501 |
<tr> |
|
|
502 |
<td><code>yui3-skin-capsule-dark</code></td> |
|
|
503 |
<td><img src="../assets/slider/images/capsule_dark.png" alt="Slider with Dark Capsule skin"></td> |
|
|
504 |
<td></td> |
|
|
505 |
</tr> |
|
|
506 |
<tr> |
|
|
507 |
<td rowspan="2"><code>yui3-skin-round</code></td> |
|
|
508 |
<td><img src="../assets/slider/images/round.png" alt="Slider with Round skin"></td> |
|
|
509 |
<td></td> |
|
|
510 |
</tr> |
|
|
511 |
<tr> |
|
|
512 |
<td><img src="../assets/slider/images/round_thumb.png" alt="Slider with Round skin and alternate thumb image"></td> |
|
|
513 |
<td> |
|
|
514 |
<code>thumb-x-grip.png</code> |
|
|
515 |
</td> |
|
|
516 |
</tr> |
|
|
517 |
<tr> |
|
|
518 |
<td><code>yui3-skin-audio-light</code></td> |
|
|
519 |
<td><img src="../assets/slider/images/audio_light.png" alt="Slider with Light Audio skin"></td> |
|
|
520 |
<td></td> |
|
|
521 |
</tr> |
|
|
522 |
<tr> |
|
|
523 |
<td><code>yui3-skin-audio</code></td> |
|
|
524 |
<td><img src="../assets/slider/images/audio.png" alt="Slider with Audio skin"></td> |
|
|
525 |
<td></td> |
|
|
526 |
</tr> |
|
|
527 |
</tbody> |
|
|
528 |
</table> |
|
|
529 |
|
|
|
530 |
<p> |
|
|
531 |
Here's an example illustrating using the capsule skin with provided |
|
|
532 |
alternate rail and thumb: |
|
|
533 |
</p> |
|
|
534 |
|
|
|
535 |
<pre class="code prettyprint"><style type="text/css"> |
|
|
536 |
// The rail and end cap images are shared in a sprite |
|
|
537 |
.yui3-skin-capsule .yui3-slider-x .yui3-slider-rail, |
|
|
538 |
.yui3-skin-capsule .yui3-slider-x .yui3-slider-rail-cap-left, |
|
|
539 |
.yui3-skin-capsule .yui3-slider-x .yui3-slider-rail-cap-right { |
|
|
540 |
background-image: url(/path/to/build/slider-base/assets/skins/capsule/rail-x-lines.png); |
|
|
541 |
} |
|
|
542 |
</style> |
|
|
543 |
|
|
|
544 |
<script> |
|
|
545 |
YUI({ skin: { overrides: { slider: [ 'capsule' ] } } }) |
|
|
546 |
.use( "slider", function (Y) { |
|
|
547 |
|
|
|
548 |
var slider = new Y.Slider({ |
|
|
549 |
axis : 'y', |
|
|
550 |
min : 1, |
|
|
551 |
max : 5, |
|
|
552 |
value : 3, |
|
|
553 |
length : '100px', |
|
|
554 |
thumbUrl: Y.config.base + '/slider-base/assets/skins/capsule/thumb-x-line.png' |
|
|
555 |
}); |
|
|
556 |
|
|
|
557 |
slider.render("#slider-parent"); |
|
|
558 |
|
|
|
559 |
}); |
|
|
560 |
</script></pre> |
|
|
561 |
|
|
|
562 |
|
|
|
563 |
<h4 id="skin_sprites">Skin image sprites</h4> |
|
|
564 |
|
|
|
565 |
<p> |
|
|
566 |
To reduce the number of resource requests for Slider's visual treatment, |
|
|
567 |
the rail and end caps are combined into one image sprite, and thumb and |
|
|
568 |
shadow into another (examples shown below with borders added for |
|
|
569 |
clarity). |
|
|
570 |
</p> |
|
|
571 |
|
|
|
572 |
<style type="text/css"> |
|
|
573 |
.sprite-example { |
|
|
574 |
border: 1px solid #d9d9d9; |
|
|
575 |
} |
|
|
576 |
</style> |
|
|
577 |
|
|
|
578 |
<img src="../assets/slider/images/thumb.png" alt="Thumb image sprite showing both thumb and shadow" class="sprite-example"> |
|
|
579 |
|
|
|
580 |
<p> |
|
|
581 |
Thumb and shadow sprite. As noted <a href="#anatomy">above</a>, the thumb |
|
|
582 |
and shadow are both represented as <code><img></code>s in the DOM. |
|
|
583 |
This sprite allows both <code><img></code>s to reference the same |
|
|
584 |
<code>src</code> URL, but masked and positioned appropriately by the skin |
|
|
585 |
CSS. Thumb image and shadow for vertical Sliders are set next to each |
|
|
586 |
other horizontally as shown. Horizontal Slider thumb sprites are stacked |
|
|
587 |
vertically. |
|
|
588 |
</p> |
|
|
589 |
<img src="../assets/slider/images/rail.png" alt="Rail sprite showing the repeatable rail and both end caps" class="sprite-example"> |
|
|
590 |
|
|
|
591 |
<p> |
|
|
592 |
Rail image (repeated across <code>length</code>), top cap, and bottom cap |
|
|
593 |
sprite. This sprite is assigned in the skin CSS as the |
|
|
594 |
<code>background-image</code> for the rail element and the two end caps. |
|
|
595 |
The CSS <code>background</code> for the rail is set to repeat vertically or |
|
|
596 |
horizontally, relative to the Slider <code>axis</code>. The image need be |
|
|
597 |
only as tall (vertical) or wide (horizontal) as the end caps unless the |
|
|
598 |
rail includes a more involved repeating section, such as the audio skin. |
|
|
599 |
End caps should be aligned against the top edge for vertical rails, or the |
|
|
600 |
left edge for horizontal rails. |
|
|
601 |
</p> |
|
|
602 |
|
|
|
603 |
<p> |
|
|
604 |
Standard heights and widths are used for the placement of the image bits |
|
|
605 |
within the sprites to allow for minimal differences between the CSS in one |
|
|
606 |
skin versus another. This allows you to start from an existing skin and |
|
|
607 |
change very little of the CSS (potentially only swapping image URLs) to |
|
|
608 |
achieve a new look and feel. |
|
|
609 |
</p> |
|
|
610 |
|
|
|
611 |
<h3 id="extending">Extending Slider</h3> |
|
|
612 |
|
|
|
613 |
<p> |
|
|
614 |
Slider is built up from a base implementation (<code>Y.SliderBase</code>) |
|
|
615 |
that has no notion of value. It is just a draggable thumb on a rail. The |
|
|
616 |
<code>slider-value-range</code> submodule provides an extension class that |
|
|
617 |
adds the attributes, API, and logic relating the thumb's position to a |
|
|
618 |
<code>value</code> within a <code>min</code>imum and <code>max</code>imum |
|
|
619 |
range. Similarly, the <code>clickableRail</code> implementation is |
|
|
620 |
relegated to an extension class. These classes are combined with |
|
|
621 |
<code>Y.Base.build</code> to generate the <code>Y.Slider</code> class. |
|
|
622 |
</p> |
|
|
623 |
|
|
|
624 |
<p> |
|
|
625 |
If you want to use a different value algorithm or decorate the basic Slider |
|
|
626 |
in other ways, you can write an extension class or <code>Y.extend</code> an |
|
|
627 |
existing extension class and create a new Slider implementation with |
|
|
628 |
<code>Y.Base.build</code>. |
|
|
629 |
</p> |
|
|
630 |
|
|
|
631 |
<pre class="code prettyprint">YUI().use( "slider-base", function (Y) { |
|
|
632 |
|
|
|
633 |
// Define a new extension class to calculate values differently |
|
|
634 |
function MyValueClass() { |
|
|
635 |
this._initValueAlgo(); |
|
|
636 |
} |
|
|
637 |
|
|
|
638 |
// Add attribute configuration and prototype to decorate the Slider |
|
|
639 |
Y.mix( MyValueClass, { |
|
|
640 |
|
|
|
641 |
ATTRS: { /* new configuration attributes */ }, |
|
|
642 |
|
|
|
643 |
prototype: { /* additional prototype members and methods */ } |
|
|
644 |
}); |
|
|
645 |
|
|
|
646 |
|
|
|
647 |
// Combine SliderBase with the new extension class any others to |
|
|
648 |
// create a new Slider |
|
|
649 |
Y.MySlider = Y.Base.build( "slider", Y.SliderBase, [ |
|
|
650 |
Y.ClickableRail, // Should also support rail clicks |
|
|
651 |
MyValueClass // Use the new value methods and attributes |
|
|
652 |
] ); |
|
|
653 |
|
|
|
654 |
|
|
|
655 |
// Instantiate and use the new Slider class as you would Y.Slider |
|
|
656 |
var slider = new Y.MySlider({ /* config */ }); |
|
|
657 |
|
|
|
658 |
slider.render( "#slider-parent" ); |
|
|
659 |
|
|
|
660 |
});</pre> |
|
|
661 |
|
|
|
662 |
</div> |
|
|
663 |
</div> |
|
|
664 |
</div> |
|
|
665 |
|
|
|
666 |
<div class="yui3-u-1-4"> |
|
|
667 |
<div class="sidebar"> |
|
|
668 |
|
|
|
669 |
<div id="toc" class="sidebox"> |
|
|
670 |
<div class="hd"> |
|
|
671 |
<h2 class="no-toc">Table of Contents</h2> |
|
|
672 |
</div> |
|
|
673 |
|
|
|
674 |
<div class="bd"> |
|
|
675 |
<ul class="toc"> |
|
|
676 |
<li> |
|
|
677 |
<a href="#getting-started">Getting Started</a> |
|
|
678 |
</li> |
|
|
679 |
<li> |
|
|
680 |
<a href="#using">Using Sliders</a> |
|
|
681 |
<ul class="toc"> |
|
|
682 |
<li> |
|
|
683 |
<a href="#anatomy">Anatomy of a Slider</a> |
|
|
684 |
<ul class="toc"> |
|
|
685 |
<li> |
|
|
686 |
<a href="#dom-structure">DOM structure</a> |
|
|
687 |
</li> |
|
|
688 |
<li> |
|
|
689 |
<a href="#appearance">Appearance</a> |
|
|
690 |
</li> |
|
|
691 |
<li> |
|
|
692 |
<a href="#thumb_placement">Thumb and end cap placement</a> |
|
|
693 |
</li> |
|
|
694 |
</ul> |
|
|
695 |
</li> |
|
|
696 |
<li> |
|
|
697 |
<a href="#instantiating">Instantiating and configuring a Slider</a> |
|
|
698 |
</li> |
|
|
699 |
<li> |
|
|
700 |
<a href="#value">Setting and constraining the Slider value</a> |
|
|
701 |
<ul class="toc"> |
|
|
702 |
<li> |
|
|
703 |
<a href="#setting-and-getting-slider-values">Setting and getting Slider values</a> |
|
|
704 |
</li> |
|
|
705 |
<li> |
|
|
706 |
<a href="#min_max">Constraining Slider values</a> |
|
|
707 |
</li> |
|
|
708 |
<li> |
|
|
709 |
<a href="#vert_min_max"><code>min</code> and <code>max</code> for vertical Sliders</a> |
|
|
710 |
</li> |
|
|
711 |
<li> |
|
|
712 |
<a href="#hidden">Sync the UI if the Slider was rendered off the DOM</a> |
|
|
713 |
</li> |
|
|
714 |
</ul> |
|
|
715 |
</li> |
|
|
716 |
<li> |
|
|
717 |
<a href="#events">Slider events</a> |
|
|
718 |
</li> |
|
|
719 |
<li> |
|
|
720 |
<a href="#skinning">Skinning</a> |
|
|
721 |
<ul class="toc"> |
|
|
722 |
<li> |
|
|
723 |
<a href="#skin_thumbUrl">Using custom thumb or rail images</a> |
|
|
724 |
</li> |
|
|
725 |
<li> |
|
|
726 |
<a href="#skins">Available skins</a> |
|
|
727 |
</li> |
|
|
728 |
<li> |
|
|
729 |
<a href="#skin_sprites">Skin image sprites</a> |
|
|
730 |
</li> |
|
|
731 |
</ul> |
|
|
732 |
</li> |
|
|
733 |
<li> |
|
|
734 |
<a href="#extending">Extending Slider</a> |
|
|
735 |
</li> |
|
|
736 |
</ul> |
|
|
737 |
</li> |
|
|
738 |
</ul> |
|
|
739 |
</div> |
|
|
740 |
</div> |
|
|
741 |
|
|
|
742 |
|
|
|
743 |
|
|
|
744 |
<div class="sidebox"> |
|
|
745 |
<div class="hd"> |
|
|
746 |
<h2 class="no-toc">Examples</h2> |
|
|
747 |
</div> |
|
|
748 |
|
|
|
749 |
<div class="bd"> |
|
|
750 |
<ul class="examples"> |
|
|
751 |
|
|
|
752 |
|
|
|
753 |
<li data-description="The basics of setting up a horizontal and vertical Slider"> |
|
|
754 |
<a href="slider-basic.html">Basic Sliders</a> |
|
|
755 |
</li> |
|
|
756 |
|
|
|
757 |
|
|
|
758 |
|
|
|
759 |
<li data-description="Creating a vertical Slider from existing markup"> |
|
|
760 |
<a href="slider-from-markup.html">Creating a Slider from Existing Markup</a> |
|
|
761 |
</li> |
|
|
762 |
|
|
|
763 |
|
|
|
764 |
|
|
|
765 |
<li data-description="Specifying an alternate skin for a Slider instance"> |
|
|
766 |
<a href="slider-skin.html">Alternate Skins</a> |
|
|
767 |
</li> |
|
|
768 |
|
|
|
769 |
|
|
|
770 |
|
|
|
771 |
|
|
|
772 |
|
|
|
773 |
|
|
|
774 |
|
|
|
775 |
|
|
|
776 |
|
|
|
777 |
|
|
|
778 |
|
|
|
779 |
|
|
|
780 |
|
|
|
781 |
|
|
|
782 |
</ul> |
|
|
783 |
</div> |
|
|
784 |
</div> |
|
|
785 |
|
|
|
786 |
|
|
|
787 |
|
|
|
788 |
<div class="sidebox"> |
|
|
789 |
<div class="hd"> |
|
|
790 |
<h2 class="no-toc">Examples That Use This Component</h2> |
|
|
791 |
</div> |
|
|
792 |
|
|
|
793 |
<div class="bd"> |
|
|
794 |
<ul class="examples"> |
|
|
795 |
|
|
|
796 |
|
|
|
797 |
|
|
|
798 |
|
|
|
799 |
|
|
|
800 |
|
|
|
801 |
|
|
|
802 |
|
|
|
803 |
<li data-description="Use three sliders to control RGB values and update Hex and HSL strings."> |
|
|
804 |
<a href="../color/rgb-slider.html">RGB Slider</a> |
|
|
805 |
</li> |
|
|
806 |
|
|
|
807 |
|
|
|
808 |
|
|
|
809 |
<li data-description="Use the HSL color picker to select a new color. Then chose the color type you like best."> |
|
|
810 |
<a href="../color/hsl-picker.html">HSL Color Picker</a> |
|
|
811 |
</li> |
|
|
812 |
|
|
|
813 |
|
|
|
814 |
|
|
|
815 |
<li data-description="Use the HSL color picker to create harmony colors."> |
|
|
816 |
<a href="../color/hsl-harmony.html">HSL Harmony</a> |
|
|
817 |
</li> |
|
|
818 |
|
|
|
819 |
|
|
|
820 |
|
|
|
821 |
<li data-description="Shows how to use Overlay's constrainment support, to limit the XY value which can be set for an Overlay."> |
|
|
822 |
<a href="../overlay/overlay-constrain.html">Constrain Support</a> |
|
|
823 |
</li> |
|
|
824 |
|
|
|
825 |
|
|
|
826 |
|
|
|
827 |
<li data-description="Use StyleSheet to adjust the CSS rules applying a page theme from user input"> |
|
|
828 |
<a href="../stylesheet/stylesheet-theme.html">Adjusting a Page Theme on the Fly</a> |
|
|
829 |
</li> |
|
|
830 |
|
|
|
831 |
|
|
|
832 |
|
|
|
833 |
<li data-description="Example Photo Browser application."> |
|
|
834 |
<a href="../dd/photo-browser.html">Photo Browser</a> |
|
|
835 |
</li> |
|
|
836 |
|
|
|
837 |
|
|
|
838 |
</ul> |
|
|
839 |
</div> |
|
|
840 |
</div> |
|
|
841 |
|
|
|
842 |
</div> |
|
|
843 |
</div> |
|
|
844 |
</div> |
|
|
845 |
</div> |
|
|
846 |
|
|
|
847 |
<script src="../assets/vendor/prettify/prettify-min.js"></script> |
|
|
848 |
<script>prettyPrint();</script> |
|
|
849 |
|
|
|
850 |
<script> |
|
|
851 |
YUI.Env.Tests = { |
|
|
852 |
examples: [], |
|
|
853 |
project: '../assets', |
|
|
854 |
assets: '../assets/slider', |
|
|
855 |
name: 'slider', |
|
|
856 |
title: 'Slider', |
|
|
857 |
newWindow: '', |
|
|
858 |
auto: false |
|
|
859 |
}; |
|
|
860 |
YUI.Env.Tests.examples.push('slider-basic'); |
|
|
861 |
YUI.Env.Tests.examples.push('slider-from-markup'); |
|
|
862 |
YUI.Env.Tests.examples.push('slider-skin'); |
|
|
863 |
YUI.Env.Tests.examples.push('rgb-slider'); |
|
|
864 |
YUI.Env.Tests.examples.push('hsl-picker'); |
|
|
865 |
YUI.Env.Tests.examples.push('hsl-harmony'); |
|
|
866 |
YUI.Env.Tests.examples.push('overlay-constrain'); |
|
|
867 |
YUI.Env.Tests.examples.push('stylesheet-theme'); |
|
|
868 |
YUI.Env.Tests.examples.push('photo-browser'); |
|
|
869 |
|
|
|
870 |
</script> |
|
|
871 |
<script src="../assets/yui/test-runner.js"></script> |
|
|
872 |
|
|
|
873 |
|
|
|
874 |
|
|
|
875 |
</body> |
|
|
876 |
</html> |