diff --git a/docs/forms/sliders/events.html b/docs/forms/sliders/events.html new file mode 100644 index 00000000..385afe00 --- /dev/null +++ b/docs/forms/sliders/events.html @@ -0,0 +1,102 @@ + + +
Since the native input field is used as a proxy for the custom slider, you can watch for events on the original, native input field instead of needing to go through the slider plugin. Bind to the change event by type: change, blur, focus, keypress, click, etc.
+$( ".selector" ).bind( "change", function(event, ui) { + ... +}); +
The slider plugin has the following custom event:
create
This event is used to find out when a custom slider was created. It is not used to create a custom slider. The slider create event can be used like this:
+$( ".selector" ).slider({ + create: function(event, ui) { ... } +}); +
To add a slider widget to your page, start with an input with a new HTML5 type="range" attribute. Specify the value (current value), min and max attribute values to configure the slider. The framework will parse these attributes to configure the slider.
input
type="range"
value
min
max
As you drag the slider, the input will update and vice-versa so they are always in sync so you can submit the slider value with form in a simple way. Set the for attribute of the label to match the ID of the input so they are semantically associated and wrap them in a div with the data-role="fieldcontain" attribute to group them.
for
label
div
data-role="fieldcontain"
+ <div data-role="fieldcontain"> + <label for="slider">Input slider:</label> + <input type="range" name="slider" id="slider" value="0" min="0" max="100" /> + </div> +
An example of a slider and input is displayed like this:
By setting the min and maxattributes you can configure the allowable number range of the slider track. The value of the input is used to configure the starting position of the handle and the value populated in the text input.
The slider with a min of 500, max of 5,000 and initial value of 2,500
Sliders also respond to the keyboards shortcuts. To increase the current value the Right Arrow, Up Arrow, and Page Up keys can be used. To decrease the current value the Left Arrow, Down Arrow, and Page Down keys can be used. To move the slider to its minimum or maximum value use the Home and End keys respectively.
If you manipulate a slider via JavaScript, you must call the refresh method on it to update the visual styling. Here is an example:
+ $("input[type=range]").val(60).slider("refresh"); +
The slider plugin has the following methods:
enable
+$('select').slider('enable'); +
disable
+$('select').slider('disable'); +
refresh
+//refresh value +$('select').slider('refresh'); + +//refresh and force rebuild +$('select').slider('refresh', true); +
The slider plugin has the following options:
initSelector
default: "input[type='range'], :jqmData(type='range'), :jqmData(role='slider')"
This is used to define the selectors (element types, data roles, etc.) that should be used as the trigger to automatic initialization of the widget plugin. To affect all selects, this option can be set by binding to the mobileinit event:
$( document ).bind( "mobileinit", function(){ + $.mobile.slider.prototype.options.initSelector = ".myslider"; +}); +
theme
default: null, inherited from parent
Sets the theme swatch color scheme for the select element. This is a single letter from a-z that maps to the swatches included in your theme. By default, a select will inherit the same swatch color as it's parent container if not explicitly set. This option is also exposed as a data attribute: data-theme="a"
data-theme="a"
$('input').slider({ theme: "a" });