source: issm/trunk/src/m/plot/slider.js

Last change on this file was 21729, checked in by Mathieu Morlighem, 8 years ago

merged trunk-jpl and trunk for revision 21727

File size: 4.6 KB
Line 
1function sliderInit(){ //{{{
2 /*
3 Name:
4 sliderInit
5
6 Description:
7 Initialize slider corresponding to passed selector with passed value,
8 minimum and maximum values, step (which is the increment for the
9 slider), and callback function (which is called when slider is changed).
10
11 Options are passed as pairs to the function according to the usage
12 example below.
13
14 Usage:
15 sliderInit(
16 'selector', #some-element,
17 'value', 0,
18 'min', -1,
19 'max', 1,
20 'step', 0.1,
21 'callback', function(value){someEngineFunction(value)}
22 );
23
24 NOTE: jQuery Mobile will reflect changes to slider in its input "label"
25 based on the width of the slider. For example, step might be set to
26 0.1, but if the width of the slider is too narrow, changes to the
27 slider will only be reflected in whole numeral increments in the
28 slider' label. That said, *all* sliders can be adjusted via the
29 "up" and "down" keys by whatever increment step is set to.
30 */
31
32 // Convert arguments to options
33 var args = Array.prototype.slice.call(arguments);
34 var options = new pairoptions(args.slice());
35
36 // Recover option values
37 var selector = options.getfieldvalue('selector', '');
38 var value = options.getfieldvalue('value', 0);
39 var callback = options.getfieldvalue('callback', function(event, ui){});
40 var min = options.getfieldvalue('min', 0.6 * value);
41 var max = options.getfieldvalue('max', 1.4 * value);
42 var step = options.getfieldvalue('step', 1);
43
44 /*
45 Update slider attributes.
46
47 NOTE: Although slider has already been created, need to call slider()
48 in order to avoid:
49
50 Error: cannot call methods on slider prior to
51 initialization; attempted to call method 'refresh'
52
53 Attempted all other methods for intialization of slider widget
54 from jQuery Mobile, and this is the only one that seemed to work
55 (see index.php for related markup).
56 */
57 $(selector).slider();
58 $(selector).val(value);
59 $(selector).attr('min', min);
60 $(selector).attr('max', max);
61 $(selector).attr('step', step);
62 $(selector).on('slidestop', function(event, ui){
63 callback(parseFloat($(selector).val()));
64 });
65 $(selector).slider('refresh'); //Slider must be "refreshed" after any JavaScript change to it, as it is an AJAX object.
66} //}}}
67
68function sliderMoveInput(selector){ //{{{
69 /*
70 Name:
71 sliderMoveInput
72
73 Description:
74 Appends a jQuery Mobile slider input to an element whose selector
75 adheres to the following protocol,
76
77 destination = sliderSelector + '-value'
78
79 Usage:
80 sliderMoveInput('#someSliderSelector');
81
82 NOTE: Destination element must, obviously, be hardcoded into markup for a
83 call to this function to work as expected.
84 */
85 $(selector).appendTo(selector + '-value');
86 $(selector).slider('refresh'); //Slider must be "refreshed" after any JavaScript change to it, as it is an AJAX object.
87} //}}}
88
89function progressInit(){ //{{{
90
91 // Convert arguments to options.
92 var args = Array.prototype.slice.call(arguments);
93 var options = new pairoptions(args.slice());
94
95 // Recover option values
96 var sim = options.getfieldvalue('sim', '');
97
98 var canvas = $(sim + '-canvas')[0];
99 var progressBar = $(sim + '-controls-slider-progress');
100 var playButton = $(sim + '-controls-button-play');
101 var reverseButton = $(sim + '-controls-button-reverse');
102 var timeText = $(sim + '-controls-progress-time');
103
104 /*
105 Update slider attributes.
106
107 NOTE: Although slider has already been created, need to call slider()
108 in order to avoid:
109
110 Error: cannot call methods on slider prior to
111 initialization; attempted to call method 'refresh'
112
113 Attempted all other methods for intialization of slider widget
114 from jQuery Mobile, and this is the only one that seemed to work
115 (see index.php for related markup).
116 */
117 $(progressBar).slider();
118 $(progressBar).val(value);
119 $(progressBar).attr('min', 0);
120 $(progressBar).attr('max', 1);
121 $(progressBar).attr('step', 1);
122 $(progressBar).on('slidestart', function(event, ui){
123 onSlideStart(canvas, progressBar);
124 });
125 $(progressBar).on('change', function(event, ui){
126 onSlideChange(canvas, progressBar);
127 });
128 $(progressBar).on('slidestop', function(event, ui){
129 onSlideStop(canvas, progressBar);
130 });
131 $(progressBar).slider('refresh'); //Slider must be "refreshed" after any JavaScript change to it, as it is an AJAX object.
132
133 playButton.click(function(){
134 toggleMoviePlay(canvas);
135 });
136
137 canvas.progressBar = progressBar;
138 canvas.playButton = playButton;
139 canvas.timeLabel = timeText;
140} //}}}
Note: See TracBrowser for help on using the repository browser.