[2] | 1 | /*********************************************************************** |
---|
| 2 | ** Title.........: Simple Lite Slider for Image Editor |
---|
| 3 | ** Version.......: 1.0 |
---|
| 4 | ** Author........: Xiang Wei ZHUO <wei@zhuo.org> |
---|
| 5 | ** Filename......: slider.php |
---|
| 6 | ** Last changed..: 31 Aug 2003 |
---|
| 7 | ** Notes.........: Works in IE and Mozilla |
---|
| 8 | **/ |
---|
| 9 | |
---|
| 10 | var ie=document.all |
---|
| 11 | var ns6=document.getElementById&&!document.all |
---|
| 12 | |
---|
| 13 | document.onmouseup = captureStop; |
---|
| 14 | |
---|
| 15 | var currentSlider = null,sliderField = null; |
---|
| 16 | var rangeMin = null, rangeMax= null, sx = -1, sy = -1, initX=0; |
---|
| 17 | |
---|
| 18 | function getMouseXY(e) { |
---|
| 19 | |
---|
| 20 | //alert('hello'); |
---|
| 21 | x = ns6? e.clientX: event.clientX |
---|
| 22 | y = ns6? e.clientY: event.clientY |
---|
| 23 | |
---|
| 24 | if (sx < 0) sx = x; if (sy < 0) sy = y; |
---|
| 25 | |
---|
| 26 | var dx = initX +(x-sx); |
---|
| 27 | |
---|
| 28 | if (dx <= rangeMin) |
---|
| 29 | dx = rangeMin; |
---|
| 30 | else if (dx >= rangeMax) |
---|
| 31 | dx = rangeMax; |
---|
| 32 | |
---|
| 33 | var range = (dx-rangeMin)/(rangeMax - rangeMin)*100; |
---|
| 34 | |
---|
| 35 | if (currentSlider != null) |
---|
| 36 | currentSlider.style.left = dx; |
---|
| 37 | |
---|
| 38 | if (sliderField != null) |
---|
| 39 | { |
---|
| 40 | sliderField.value = parseInt(range); |
---|
| 41 | } |
---|
| 42 | return false; |
---|
| 43 | |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | function init() |
---|
| 47 | { |
---|
| 48 | if (currentSlider == null) |
---|
| 49 | currentSlider = MM_findObj('sliderbar'); |
---|
| 50 | |
---|
| 51 | if (sliderField == null) |
---|
| 52 | sliderField = MM_findObj('quality'); |
---|
| 53 | |
---|
| 54 | if (rangeMin == null) |
---|
| 55 | rangeMin = 3 |
---|
| 56 | if (rangeMax == null) |
---|
| 57 | { |
---|
| 58 | var track = MM_findObj('slidertrack'); |
---|
| 59 | rangeMax = parseInt(track.style.width); |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | function updateSlider(value) |
---|
| 65 | { |
---|
| 66 | init(); |
---|
| 67 | |
---|
| 68 | var newValue = parseInt(value)/100*(rangeMax-rangeMin); |
---|
| 69 | |
---|
| 70 | if (newValue <= rangeMin) |
---|
| 71 | newValue = rangeMin; |
---|
| 72 | else if (newValue >= rangeMax) |
---|
| 73 | newValue = rangeMax; |
---|
| 74 | |
---|
| 75 | if (currentSlider != null) |
---|
| 76 | currentSlider.style.left = newValue; |
---|
| 77 | |
---|
| 78 | var range = newValue/(rangeMax - rangeMin)*100; |
---|
| 79 | |
---|
| 80 | if (sliderField != null) |
---|
| 81 | sliderField.value = parseInt(range); |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | function captureStart(){ |
---|
| 85 | |
---|
| 86 | init(); |
---|
| 87 | |
---|
| 88 | initX = parseInt(currentSlider.style.left); |
---|
| 89 | if (initX > rangeMax) |
---|
| 90 | initX = rangeMax; |
---|
| 91 | else if (initX < rangeMin) |
---|
| 92 | initX = rangeMin; |
---|
| 93 | |
---|
| 94 | document.onmousemove = getMouseXY; |
---|
| 95 | |
---|
| 96 | return false; |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | function captureStop() |
---|
| 100 | { |
---|
| 101 | sx = -1; sy = -1; |
---|
| 102 | document.onmousemove = null; |
---|
| 103 | return false; |
---|
| 104 | } |
---|