Mercurial > hg > STI-GWT
comparison war/scripts/sliderCombined.js @ 3:cf06b77a8bbd
Committed branch of the e4D repos sti-gwt branch 16384.
git-svn-id: http://dev.dariah.eu/svn/repos/eu.dariah.de/ap1/sti-gwt-dariah-geobrowser@36 f2b5be40-def6-11e0-8a09-b3c1cc336c6b
author | StefanFunk <StefanFunk@f2b5be40-def6-11e0-8a09-b3c1cc336c6b> |
---|---|
date | Tue, 17 Jul 2012 13:34:40 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
2:2897af43ccc6 | 3:cf06b77a8bbd |
---|---|
1 function Range(){ | |
2 this._value=0; | |
3 this._minimum=0; | |
4 this._maximum=100; | |
5 this._extent=0; | |
6 this._isChanging=false; | |
7 }; | |
8 Range.prototype.setValue=function(_1){ | |
9 _1=Math.round(parseFloat(_1)); | |
10 if(isNaN(_1)){ | |
11 return; | |
12 } | |
13 if(this._value!=_1){ | |
14 if(_1+this._extent>this._maximum){ | |
15 this._value=this._maximum-this._extent; | |
16 }else{ | |
17 if(_1<this._minimum){ | |
18 this._value=this._minimum; | |
19 }else{ | |
20 this._value=_1; | |
21 } | |
22 } | |
23 if(!this._isChanging&&typeof this.onchange=="function"){ | |
24 this.onchange(); | |
25 } | |
26 } | |
27 }; | |
28 Range.prototype.getValue=function(){ | |
29 return this._value; | |
30 }; | |
31 Range.prototype.setExtent=function(_2){ | |
32 if(this._extent!=_2){ | |
33 if(_2<0){ | |
34 this._extent=0; | |
35 }else{ | |
36 if(this._value+_2>this._maximum){ | |
37 this._extent=this._maximum-this._value; | |
38 }else{ | |
39 this._extent=_2; | |
40 } | |
41 } | |
42 if(!this._isChanging&&typeof this.onchange=="function"){ | |
43 this.onchange(); | |
44 } | |
45 } | |
46 }; | |
47 Range.prototype.getExtent=function(){ | |
48 return this._extent; | |
49 }; | |
50 Range.prototype.setMinimum=function(_3){ | |
51 if(this._minimum!=_3){ | |
52 var _4=this._isChanging; | |
53 this._isChanging=true; | |
54 this._minimum=_3; | |
55 if(_3>this._value){ | |
56 this.setValue(_3); | |
57 } | |
58 if(_3>this._maximum){ | |
59 this._extent=0; | |
60 this.setMaximum(_3); | |
61 this.setValue(_3); | |
62 } | |
63 if(_3+this._extent>this._maximum){ | |
64 this._extent=this._maximum-this._minimum; | |
65 } | |
66 this._isChanging=_4; | |
67 if(!this._isChanging&&typeof this.onchange=="function"){ | |
68 this.onchange(); | |
69 } | |
70 } | |
71 }; | |
72 Range.prototype.getMinimum=function(){ | |
73 return this._minimum; | |
74 }; | |
75 Range.prototype.setMaximum=function(_5){ | |
76 if(this._maximum!=_5){ | |
77 var _6=this._isChanging; | |
78 this._isChanging=true; | |
79 this._maximum=_5; | |
80 if(_5<this._value){ | |
81 this.setValue(_5-this._extent); | |
82 } | |
83 if(_5<this._minimum){ | |
84 this._extent=0; | |
85 this.setMinimum(_5); | |
86 this.setValue(this._maximum); | |
87 } | |
88 if(_5<this._minimum+this._extent){ | |
89 this._extent=this._maximum-this._minimum; | |
90 } | |
91 if(_5<this._value+this._extent){ | |
92 this._extent=this._maximum-this._value; | |
93 } | |
94 this._isChanging=_6; | |
95 if(!this._isChanging&&typeof this.onchange=="function"){ | |
96 this.onchange(); | |
97 } | |
98 } | |
99 }; | |
100 Range.prototype.getMaximum=function(){ | |
101 return this._maximum; | |
102 }; | |
103 Slider.isSupported=typeof document.createElement!="undefined"&&typeof document.documentElement!="undefined"&&typeof document.documentElement.offsetWidth=="number"; | |
104 function Slider(_7,_8,_9){ | |
105 if(!_7){ | |
106 return; | |
107 } | |
108 this._orientation=_9||"horizontal"; | |
109 this._range=new Range(); | |
110 this._range.setExtent(0); | |
111 this._blockIncrement=10; | |
112 this._unitIncrement=1; | |
113 this._timer=new Timer(100); | |
114 if(Slider.isSupported&&_7){ | |
115 this.document=_7.ownerDocument||_7.document; | |
116 this.element=_7; | |
117 this.element.slider=this; | |
118 this.element.unselectable="on"; | |
119 this.element.className=this._orientation+" "+this.classNameTag+" "+this.element.className; | |
120 this.line=this.document.createElement("DIV"); | |
121 this.line.className="line"; | |
122 this.line.unselectable="on"; | |
123 this.line.appendChild(this.document.createElement("DIV")); | |
124 this.element.appendChild(this.line); | |
125 this.handle=this.document.createElement("DIV"); | |
126 this.handle.className="handle"; | |
127 this.handle.unselectable="on"; | |
128 this.handle.appendChild(this.document.createElement("DIV")); | |
129 this.handle.firstChild.appendChild(this.document.createTextNode(String.fromCharCode(160))); | |
130 this.element.appendChild(this.handle); | |
131 } | |
132 this.input=_8; | |
133 var _a=this; | |
134 this._range.onchange=function(){ | |
135 _a.recalculate(); | |
136 if(typeof _a.onchange=="function"){ | |
137 _a.onchange(); | |
138 } | |
139 }; | |
140 if(Slider.isSupported&&_7){ | |
141 this.element.onfocus=Slider.eventHandlers.onfocus; | |
142 this.element.onblur=Slider.eventHandlers.onblur; | |
143 this.element.onmousedown=Slider.eventHandlers.onmousedown; | |
144 this.element.onmouseover=Slider.eventHandlers.onmouseover; | |
145 this.element.onmouseout=Slider.eventHandlers.onmouseout; | |
146 this.element.onkeydown=Slider.eventHandlers.onkeydown; | |
147 this.element.onkeypress=Slider.eventHandlers.onkeypress; | |
148 this.element.onmousewheel=Slider.eventHandlers.onmousewheel; | |
149 this.handle.onselectstart=this.element.onselectstart=function(){ | |
150 return false; | |
151 }; | |
152 this._timer.ontimer=function(){ | |
153 _a.ontimer(); | |
154 }; | |
155 window.setTimeout(function(){ | |
156 _a.recalculate(); | |
157 },1); | |
158 }else{ | |
159 this.input.onchange=function(e){ | |
160 _a.setValue(_a.input.value); | |
161 }; | |
162 } | |
163 }; | |
164 Slider.eventHandlers={getEvent:function(e,el){ | |
165 if(!e){ | |
166 if(el){ | |
167 e=el.document.parentWindow.event; | |
168 }else{ | |
169 e=window.event; | |
170 } | |
171 } | |
172 if(!e.srcElement){ | |
173 var el=e.target; | |
174 while(el!=null&&el.nodeType!=1){ | |
175 el=el.parentNode; | |
176 } | |
177 e.srcElement=el; | |
178 } | |
179 if(typeof e.offsetX=="undefined"){ | |
180 e.offsetX=e.layerX; | |
181 e.offsetY=e.layerY; | |
182 } | |
183 return e; | |
184 },getDocument:function(e){ | |
185 if(e.target){ | |
186 return e.target.ownerDocument; | |
187 } | |
188 return e.srcElement.document; | |
189 },getSlider:function(e){ | |
190 var el=e.target||e.srcElement; | |
191 while(el!=null&&el.slider==null){ | |
192 el=el.parentNode; | |
193 } | |
194 if(el){ | |
195 return el.slider; | |
196 } | |
197 return null; | |
198 },getLine:function(e){ | |
199 var el=e.target||e.srcElement; | |
200 while(el!=null&&el.className!="line"){ | |
201 el=el.parentNode; | |
202 } | |
203 return el; | |
204 },getHandle:function(e){ | |
205 var el=e.target||e.srcElement; | |
206 var re=/handle/; | |
207 while(el!=null&&!re.test(el.className)){ | |
208 el=el.parentNode; | |
209 } | |
210 return el; | |
211 },onfocus:function(e){ | |
212 var s=this.slider; | |
213 s._focused=true; | |
214 s.handle.className="handle hover"; | |
215 },onblur:function(e){ | |
216 var s=this.slider; | |
217 s._focused=false; | |
218 s.handle.className="handle"; | |
219 },onmouseover:function(e){ | |
220 e=Slider.eventHandlers.getEvent(e,this); | |
221 var s=this.slider; | |
222 if(e.srcElement==s.handle){ | |
223 s.handle.className="handle hover"; | |
224 } | |
225 },onmouseout:function(e){ | |
226 e=Slider.eventHandlers.getEvent(e,this); | |
227 var s=this.slider; | |
228 if(e.srcElement==s.handle&&!s._focused){ | |
229 s.handle.className="handle"; | |
230 } | |
231 },onmousedown:function(e){ | |
232 e=Slider.eventHandlers.getEvent(e,this); | |
233 var s=this.slider; | |
234 if(s.element.focus){ | |
235 s.element.focus(); | |
236 } | |
237 Slider._currentInstance=s; | |
238 var doc=s.document; | |
239 if(doc.addEventListener){ | |
240 doc.addEventListener("mousemove",Slider.eventHandlers.onmousemove,true); | |
241 doc.addEventListener("mouseup",Slider.eventHandlers.onmouseup,true); | |
242 }else{ | |
243 if(doc.attachEvent){ | |
244 doc.attachEvent("onmousemove",Slider.eventHandlers.onmousemove); | |
245 doc.attachEvent("onmouseup",Slider.eventHandlers.onmouseup); | |
246 doc.attachEvent("onlosecapture",Slider.eventHandlers.onmouseup); | |
247 s.element.setCapture(); | |
248 } | |
249 } | |
250 if(Slider.eventHandlers.getHandle(e)){ | |
251 Slider._sliderDragData={screenX:e.screenX,screenY:e.screenY,dx:e.screenX-s.handle.offsetLeft,dy:e.screenY-s.handle.offsetTop,startValue:s.getValue(),slider:s}; | |
252 }else{ | |
253 var _21=Slider.eventHandlers.getLine(e); | |
254 s._mouseX=e.offsetX+(_21?s.line.offsetLeft:0); | |
255 s._mouseY=e.offsetY+(_21?s.line.offsetTop:0); | |
256 s._increasing=null; | |
257 s.ontimer(); | |
258 } | |
259 },onmousemove:function(e){ | |
260 e=Slider.eventHandlers.getEvent(e,this); | |
261 if(Slider._sliderDragData){ | |
262 var s=Slider._sliderDragData.slider; | |
263 var _24=s.getMaximum()-s.getMinimum(); | |
264 var _25,pos,_27; | |
265 if(s._orientation=="horizontal"){ | |
266 _25=s.element.offsetWidth-s.handle.offsetWidth; | |
267 pos=e.screenX-Slider._sliderDragData.dx; | |
268 _27=Math.abs(e.screenY-Slider._sliderDragData.screenY)>100; | |
269 }else{ | |
270 _25=s.element.offsetHeight-s.handle.offsetHeight; | |
271 pos=s.element.offsetHeight-s.handle.offsetHeight-(e.screenY-Slider._sliderDragData.dy); | |
272 _27=Math.abs(e.screenX-Slider._sliderDragData.screenX)>100; | |
273 } | |
274 s.setValue(_27?Slider._sliderDragData.startValue:s.getMinimum()+_24*pos/_25); | |
275 return false; | |
276 }else{ | |
277 var s=Slider._currentInstance; | |
278 if(s!=null){ | |
279 var _28=Slider.eventHandlers.getLine(e); | |
280 s._mouseX=e.offsetX+(_28?s.line.offsetLeft:0); | |
281 s._mouseY=e.offsetY+(_28?s.line.offsetTop:0); | |
282 } | |
283 } | |
284 },onmouseup:function(e){ | |
285 e=Slider.eventHandlers.getEvent(e,this); | |
286 var s=Slider._currentInstance; | |
287 var doc=s.document; | |
288 if(doc.removeEventListener){ | |
289 doc.removeEventListener("mousemove",Slider.eventHandlers.onmousemove,true); | |
290 doc.removeEventListener("mouseup",Slider.eventHandlers.onmouseup,true); | |
291 }else{ | |
292 if(doc.detachEvent){ | |
293 doc.detachEvent("onmousemove",Slider.eventHandlers.onmousemove); | |
294 doc.detachEvent("onmouseup",Slider.eventHandlers.onmouseup); | |
295 doc.detachEvent("onlosecapture",Slider.eventHandlers.onmouseup); | |
296 s.element.releaseCapture(); | |
297 } | |
298 } | |
299 if(Slider._sliderDragData){ | |
300 Slider._sliderDragData=null; | |
301 }else{ | |
302 s._timer.stop(); | |
303 s._increasing=null; | |
304 } | |
305 Slider._currentInstance=null; | |
306 },onkeydown:function(e){ | |
307 e=Slider.eventHandlers.getEvent(e,this); | |
308 var s=this.slider; | |
309 var kc=e.keyCode; | |
310 switch(kc){ | |
311 case 33: | |
312 s.setValue(s.getValue()+s.getBlockIncrement()); | |
313 break; | |
314 case 34: | |
315 s.setValue(s.getValue()-s.getBlockIncrement()); | |
316 break; | |
317 case 35: | |
318 s.setValue(s.getOrientation()=="horizontal"?s.getMaximum():s.getMinimum()); | |
319 break; | |
320 case 36: | |
321 s.setValue(s.getOrientation()=="horizontal"?s.getMinimum():s.getMaximum()); | |
322 break; | |
323 case 38: | |
324 case 39: | |
325 s.setValue(s.getValue()+s.getUnitIncrement()); | |
326 break; | |
327 case 37: | |
328 case 40: | |
329 s.setValue(s.getValue()-s.getUnitIncrement()); | |
330 break; | |
331 } | |
332 if(kc>=33&&kc<=40){ | |
333 return false; | |
334 } | |
335 },onkeypress:function(e){ | |
336 e=Slider.eventHandlers.getEvent(e,this); | |
337 var kc=e.keyCode; | |
338 if(kc>=33&&kc<=40){ | |
339 return false; | |
340 } | |
341 },onmousewheel:function(e){ | |
342 e=Slider.eventHandlers.getEvent(e,this); | |
343 var s=this.slider; | |
344 if(s._focused){ | |
345 s.setValue(s.getValue()+e.wheelDelta/120*s.getUnitIncrement()); | |
346 return false; | |
347 } | |
348 }}; | |
349 Slider.prototype.classNameTag="dynamic-slider-control",Slider.prototype.setValue=function(v){ | |
350 this._range.setValue(v); | |
351 this.input.value=this.getValue(); | |
352 }; | |
353 Slider.prototype.getValue=function(){ | |
354 return this._range.getValue(); | |
355 }; | |
356 Slider.prototype.setMinimum=function(v){ | |
357 this._range.setMinimum(v); | |
358 this.input.value=this.getValue(); | |
359 }; | |
360 Slider.prototype.getMinimum=function(){ | |
361 return this._range.getMinimum(); | |
362 }; | |
363 Slider.prototype.setMaximum=function(v){ | |
364 this._range.setMaximum(v); | |
365 this.input.value=this.getValue(); | |
366 }; | |
367 Slider.prototype.getMaximum=function(){ | |
368 return this._range.getMaximum(); | |
369 }; | |
370 Slider.prototype.setUnitIncrement=function(v){ | |
371 this._unitIncrement=v; | |
372 }; | |
373 Slider.prototype.getUnitIncrement=function(){ | |
374 return this._unitIncrement; | |
375 }; | |
376 Slider.prototype.setBlockIncrement=function(v){ | |
377 this._blockIncrement=v; | |
378 }; | |
379 Slider.prototype.getBlockIncrement=function(){ | |
380 return this._blockIncrement; | |
381 }; | |
382 Slider.prototype.getOrientation=function(){ | |
383 return this._orientation; | |
384 }; | |
385 Slider.prototype.setOrientation=function(_38){ | |
386 if(_38!=this._orientation){ | |
387 if(Slider.isSupported&&this.element){ | |
388 this.element.className=this.element.className.replace(this._orientation,_38); | |
389 } | |
390 this._orientation=_38; | |
391 this.recalculate(); | |
392 } | |
393 }; | |
394 Slider.prototype.recalculate=function(){ | |
395 if(!Slider.isSupported||!this.element){ | |
396 return; | |
397 } | |
398 var w=this.element.offsetWidth; | |
399 var h=this.element.offsetHeight; | |
400 var hw=this.handle.offsetWidth; | |
401 var hh=this.handle.offsetHeight; | |
402 var lw=this.line.offsetWidth; | |
403 var lh=this.line.offsetHeight; | |
404 if(this._orientation=="horizontal"){ | |
405 this.handle.style.left=(w-hw)*(this.getValue()-this.getMinimum())/(this.getMaximum()-this.getMinimum())+"px"; | |
406 this.handle.style.top=(h-hh)/2+"px"; | |
407 this.line.style.top=(h-lh)/2+"px"; | |
408 this.line.style.left=hw/2+"px"; | |
409 this.line.style.width=Math.max(0,w-hw-2)+"px"; | |
410 this.line.firstChild.style.width=Math.max(0,w-hw-4)+"px"; | |
411 }else{ | |
412 this.handle.style.left=(w-hw)/2+"px"; | |
413 this.handle.style.top=h-hh-(h-hh)*(this.getValue()-this.getMinimum())/(this.getMaximum()-this.getMinimum())+"px"; | |
414 this.line.style.left=(w-lw)/2+"px"; | |
415 this.line.style.top=hh/2+"px"; | |
416 this.line.style.height=Math.max(0,h-hh-2)+"px"; | |
417 this.line.firstChild.style.height=Math.max(0,h-hh-4)+"px"; | |
418 } | |
419 }; | |
420 Slider.prototype.ontimer=function(){ | |
421 var hw=this.handle.offsetWidth; | |
422 var hh=this.handle.offsetHeight; | |
423 var hl=this.handle.offsetLeft; | |
424 var ht=this.handle.offsetTop; | |
425 if(this._orientation=="horizontal"){ | |
426 if(this._mouseX>hl+hw&&(this._increasing==null||this._increasing)){ | |
427 this.setValue(this.getValue()+this.getBlockIncrement()); | |
428 this._increasing=true; | |
429 }else{ | |
430 if(this._mouseX<hl&&(this._increasing==null||!this._increasing)){ | |
431 this.setValue(this.getValue()-this.getBlockIncrement()); | |
432 this._increasing=false; | |
433 } | |
434 } | |
435 }else{ | |
436 if(this._mouseY>ht+hh&&(this._increasing==null||!this._increasing)){ | |
437 this.setValue(this.getValue()-this.getBlockIncrement()); | |
438 this._increasing=false; | |
439 }else{ | |
440 if(this._mouseY<ht&&(this._increasing==null||this._increasing)){ | |
441 this.setValue(this.getValue()+this.getBlockIncrement()); | |
442 this._increasing=true; | |
443 } | |
444 } | |
445 } | |
446 this._timer.start(); | |
447 }; | |
448 function Timer(_43){ | |
449 this._pauseTime=typeof _43=="undefined"?1000:_43; | |
450 this._timer=null; | |
451 this._isStarted=false; | |
452 }; | |
453 Timer.prototype.start=function(){ | |
454 if(this.isStarted()){ | |
455 this.stop(); | |
456 } | |
457 var _44=this; | |
458 this._timer=window.setTimeout(function(){ | |
459 if(typeof _44.ontimer=="function"){ | |
460 _44.ontimer(); | |
461 } | |
462 },this._pauseTime); | |
463 this._isStarted=false; | |
464 }; | |
465 Timer.prototype.stop=function(){ | |
466 if(this._timer!=null){ | |
467 window.clearTimeout(this._timer); | |
468 } | |
469 this._isStarted=false; | |
470 }; | |
471 Timer.prototype.isStarted=function(){ | |
472 return this._isStarted; | |
473 }; | |
474 Timer.prototype.getPauseTime=function(){ | |
475 return this._pauseTime; | |
476 }; | |
477 Timer.prototype.setPauseTime=function(_45){ | |
478 this._pauseTime=_45; | |
479 }; |