[21341] | 1 | function sliderInit(){ //{{{
|
---|
| 2 | /*
|
---|
| 3 | Name:
|
---|
| 4 | sliderInit
|
---|
[19840] | 5 |
|
---|
[21341] | 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 | */
|
---|
[19840] | 31 |
|
---|
[21341] | 32 | // Convert arguments to options
|
---|
| 33 | var args = Array.prototype.slice.call(arguments);
|
---|
| 34 | var options = new pairoptions(args.slice());
|
---|
[19840] | 35 |
|
---|
[21341] | 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()));
|
---|
[19840] | 64 | });
|
---|
[21729] | 65 | $(selector).slider('refresh'); //Slider must be "refreshed" after any JavaScript change to it, as it is an AJAX object.
|
---|
[21341] | 66 | } //}}}
|
---|
[19840] | 67 |
|
---|
[21341] | 68 | function 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');
|
---|
[21729] | 86 | $(selector).slider('refresh'); //Slider must be "refreshed" after any JavaScript change to it, as it is an AJAX object.
|
---|
[21341] | 87 | } //}}}
|
---|
[20401] | 88 |
|
---|
[21341] | 89 | function progressInit(){ //{{{
|
---|
[20401] | 90 |
|
---|
[21341] | 91 | // Convert arguments to options.
|
---|
| 92 | var args = Array.prototype.slice.call(arguments);
|
---|
| 93 | var options = new pairoptions(args.slice());
|
---|
[20401] | 94 |
|
---|
[21341] | 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);
|
---|
[21729] | 122 | $(progressBar).on('slidestart', function(event, ui){
|
---|
| 123 | onSlideStart(canvas, progressBar);
|
---|
[21341] | 124 | });
|
---|
| 125 | $(progressBar).on('change', function(event, ui){
|
---|
[21729] | 126 | onSlideChange(canvas, progressBar);
|
---|
[21341] | 127 | });
|
---|
[21729] | 128 | $(progressBar).on('slidestop', function(event, ui){
|
---|
| 129 | onSlideStop(canvas, progressBar);
|
---|
[21341] | 130 | });
|
---|
[21729] | 131 | $(progressBar).slider('refresh'); //Slider must be "refreshed" after any JavaScript change to it, as it is an AJAX object.
|
---|
[20401] | 132 |
|
---|
[21341] | 133 | playButton.click(function(){
|
---|
[21729] | 134 | toggleMoviePlay(canvas);
|
---|
[20401] | 135 | });
|
---|
| 136 |
|
---|
[21729] | 137 | canvas.progressBar = progressBar;
|
---|
| 138 | canvas.playButton = playButton;
|
---|
[21341] | 139 | canvas.timeLabel = timeText;
|
---|
| 140 | } //}}}
|
---|