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

Last change on this file since 20500 was 20500, checked in by Mathieu Morlighem, 9 years ago

merged trunk-jpl and trunk for revision 20497

File size: 4.6 KB
Line 
1function slider(){
2
3 //Convert arguments to options
4 var args = Array.prototype.slice.call(arguments);
5 var options = new pairoptions(args.slice());
6
7 //Recover option values:
8 var value = options.getfieldvalue('value',0);
9 var callback = options.getfieldvalue('callback',function(){});
10 var name = options.getfieldvalue('name','');
11 var min = options.getfieldvalue('min',0.6*value);
12 var max = options.getfieldvalue('max',1.4*value);
13 var width = options.getfieldvalue('width','auto');
14 var height = options.getfieldvalue('height',32);
15 var message = options.getfieldvalue('message','');
16 var startmessage = options.getfieldvalue('startmessage',message);
17 var middlemessage = options.getfieldvalue('middlemessage',message);
18 var endmessage = options.getfieldvalue('endmessage',message);
19 var color = options.getfieldvalue('color','#bbbbbb');
20 var precision = options.getfieldvalue('precision',3);
21 var step = options.getfieldvalue('step',1);
22 var slidersdiv = options.getfieldvalue('slidersdiv','slidersdiv');
23
24 $('#'+slidersdiv).css({width:width});
25 $('<div class="'+name+'-slider"></div>').appendTo('#'+slidersdiv);
26 $('<div class="info'+name+'">'+startmessage[0]+value.toString()+startmessage[1]+'</div>').appendTo('#'+slidersdiv);
27 var info=$('.info'+name);
28 $('.'+name+'-slider').slider({
29 range:'min',
30 value:value,
31 min:min,
32 max:max,
33 step:step,
34 slide:function(event,ui){
35 moveSlide(event,ui,info,middlemessage,precision);
36 },
37 stop:function(event,ui){
38 stopSlide(event,ui,info,callback,middlemessage,endmessage,precision);
39 }
40 });
41 $('.'+name+'-slider.ui-slider').css({
42 width:'auto',
43 height:height,
44 background:color,
45 margin:'8px'
46 });
47 $('.'+name+'-slider .ui-slider-handle').css({
48 background:color,
49 height:parseInt(height)+8
50 });
51 $('.'+name+'-slider .ui-slider-range').css({
52 background:color
53 });
54}
55
56function moveSlide(event,ui,info,middlemessage,precision){
57 var val=ui.value;
58 info.text(middlemessage[0]+val.toPrecision(precision).toString()+middlemessage[1]);
59}
60
61function stopSlide(event,ui,info,functionvalue,middlemessage,endmessage,precision){
62 var val=ui.value;
63 info.text(middlemessage[0]+val.toPrecision(precision).toString()+middlemessage[1]);
64 functionvalue(val);
65 info.text(endmessage[0]+val.toPrecision(precision).toString()+endmessage[1]);
66}
67
68function progress(){
69 //Convert arguments to options
70 var args = Array.prototype.slice.call(arguments);
71 var options = new pairoptions(args.slice());
72
73 var value = options.getfieldvalue('value',0);
74 var name = options.getfieldvalue('name','hma');
75 var min = options.getfieldvalue('min',0.6*value);
76 var max = options.getfieldvalue('max',1.4*value);
77 var width = options.getfieldvalue('width','auto');
78 var height = options.getfieldvalue('height',32);
79 var color = options.getfieldvalue('color','#bbbbbb');
80 var progressdiv = options.getfieldvalue('progressdiv','progressdiv');
81
82 var canvas = $('#'+name)[0];
83 var progressbar = $('#'+name+'-progressbar');
84 var playbutton = $('#'+name+'-playbutton');
85 var reversebutton = $('#'+name+'-reversebutton');
86 var timelabel = $('#'+name+'-timelabel');
87
88
89 playbutton.click(function() {
90 canvas.moviePlay = !canvas.moviePlay;
91 if (canvas.moviePlay) {
92 $("#playButton").html("&#10074&#10074");
93 }
94 else {
95 $("#playButton").html("&#9654");
96 }
97 });
98 reversebutton.click(function() {
99 canvas.movieReverse = !canvas.movieReverse;
100 if (canvas.movieReverse) {
101 reversebutton.html("&#9664&#9664");
102 }
103 else {
104 reversebutton.html("&#9654&#9654");
105 }
106 });
107 canvas.timeLabel = timelabel;
108
109 $('#'+progressdiv).css({width:width});
110 $('<div class="'+name+'-progressbar"></div>').prependTo('#'+progressdiv);
111 $('.'+name+'-progressbar').slider({
112 range:'min',
113 value:0,
114 min:0,
115 max:1,
116 step:1,
117 start:function(event,ui){
118 startProgress(event,ui,canvas);
119 },
120 slide:function(event,ui){
121 moveProgress(event,ui,canvas);
122 },
123 stop:function(event,ui){
124 stopProgress(event,ui,canvas);
125 }
126 });
127 $('.'+name+'-progressbar.ui-slider').css({
128 width:'auto',
129 height:height,
130 background:color,
131 margin:'8px'
132 });
133 $('.'+name+'-progressbar .ui-slider-handle').css({
134 background:color,
135 height:parseInt(height)+8
136 });
137 $('.'+name+'-progressbar .ui-slider-range').css({
138 background:'red'
139 });
140
141 canvas.progressBar = $('.'+name+'-progressbar');
142}
143
144function startProgress(event,ui,canvas){
145 canvas.movieFrame = ui.value;
146 canvas.movieIncrement = false;
147}
148
149function moveProgress(event,ui,canvas){
150 canvas.movieFrame = ui.value;
151}
152
153function stopProgress(event,ui,canvas){
154 canvas.movieFrame = ui.value;
155 canvas.movieIncrement = true;
156}
Note: See TracBrowser for help on using the repository browser.