Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 24
- Log:
Initial import of Collaboa 0.5.6 from downloaded Tarball. Collaboa is
a Ruby On Rails based bug tracker and SVN repository browsing tool.
- Author:
- adh
- Date:
- Mon Jul 24 21:54:39 +0100 2006
- Size:
- 8869 Bytes
1 | // Copyright (c) 2005 Marty Haught |
2 | // |
3 | // See scriptaculous.js for full license. |
4 | |
5 | if(!Control) var Control = {}; |
6 | Control.Slider = Class.create(); |
7 | |
8 | // options: |
9 | // axis: 'vertical', or 'horizontal' (default) |
10 | // increment: (default: 1) |
11 | // step: (default: 1) |
12 | // |
13 | // callbacks: |
14 | // onChange(value) |
15 | // onSlide(value) |
16 | Control.Slider.prototype = { |
17 | initialize: function(handle, track, options) { |
18 | this.handle = $(handle); |
19 | this.track = $(track); |
20 | |
21 | this.options = options || {}; |
22 | |
23 | this.axis = this.options.axis || 'horizontal'; |
24 | this.increment = this.options.increment || 1; |
25 | this.step = parseInt(this.options.step) || 1; |
26 | this.value = 0; |
27 | |
28 | var defaultMaximum = Math.round(this.track.offsetWidth / this.increment); |
29 | if(this.isVertical()) defaultMaximum = Math.round(this.track.offsetHeight / this.increment); |
30 | |
31 | this.maximum = this.options.maximum || defaultMaximum; |
32 | this.minimum = this.options.minimum || 0; |
33 | |
34 | // Will be used to align the handle onto the track, if necessary |
35 | this.alignX = parseInt (this.options.alignX) || 0; |
36 | this.alignY = parseInt (this.options.alignY) || 0; |
37 | |
38 | // Zero out the slider position |
39 | this.setCurrentLeft(Position.cumulativeOffset(this.track)[0] - Position.cumulativeOffset(this.handle)[0] + this.alignX); |
40 | this.setCurrentTop(this.trackTop() - Position.cumulativeOffset(this.handle)[1] + this.alignY); |
41 | |
42 | this.offsetX = 0; |
43 | this.offsetY = 0; |
44 | |
45 | this.originalLeft = this.currentLeft(); |
46 | this.originalTop = this.currentTop(); |
47 | this.originalZ = parseInt(this.handle.style.zIndex || "0"); |
48 | |
49 | // Prepopulate Slider value |
50 | this.setSliderValue(parseInt(this.options.sliderValue) || 0); |
51 | |
52 | this.active = false; |
53 | this.dragging = false; |
54 | this.disabled = false; |
55 | |
56 | // FIXME: use css |
57 | this.handleImage = $(this.options.handleImage) || false; |
58 | this.handleDisabled = this.options.handleDisabled || false; |
59 | this.handleEnabled = false; |
60 | if(this.handleImage) |
61 | this.handleEnabled = this.handleImage.src || false; |
62 | |
63 | if(this.options.disabled) |
64 | this.setDisabled(); |
65 | |
66 | // Value Array |
67 | this.values = this.options.values || false; // Add method to validate and sort?? |
68 | |
69 | Element.makePositioned(this.handle); // fix IE |
70 | |
71 | this.eventMouseDown = this.startDrag.bindAsEventListener(this); |
72 | this.eventMouseUp = this.endDrag.bindAsEventListener(this); |
73 | this.eventMouseMove = this.update.bindAsEventListener(this); |
74 | this.eventKeypress = this.keyPress.bindAsEventListener(this); |
75 | |
76 | Event.observe(this.handle, "mousedown", this.eventMouseDown); |
77 | Event.observe(document, "mouseup", this.eventMouseUp); |
78 | Event.observe(document, "mousemove", this.eventMouseMove); |
79 | Event.observe(document, "keypress", this.eventKeypress); |
80 | }, |
81 | dispose: function() { |
82 | Event.stopObserving(this.handle, "mousedown", this.eventMouseDown); |
83 | Event.stopObserving(document, "mouseup", this.eventMouseUp); |
84 | Event.stopObserving(document, "mousemove", this.eventMouseMove); |
85 | Event.stopObserving(document, "keypress", this.eventKeypress); |
86 | }, |
87 | setDisabled: function(){ |
88 | this.disabled = true; |
89 | if(this.handleDisabled) |
90 | this.handleImage.src = this.handleDisabled; |
91 | }, |
92 | setEnabled: function(){ |
93 | this.disabled = false; |
94 | if(this.handleEnabled) |
95 | this.handleImage.src = this.handleEnabled; |
96 | }, |
97 | currentLeft: function() { |
98 | return parseInt(this.handle.style.left || '0'); |
99 | }, |
100 | currentTop: function() { |
101 | return parseInt(this.handle.style.top || '0'); |
102 | }, |
103 | setCurrentLeft: function(left) { |
104 | this.handle.style.left = left +"px"; |
105 | }, |
106 | setCurrentTop: function(top) { |
107 | this.handle.style.top = top +"px"; |
108 | }, |
109 | trackLeft: function(){ |
110 | return Position.cumulativeOffset(this.track)[0]; |
111 | }, |
112 | trackTop: function(){ |
113 | return Position.cumulativeOffset(this.track)[1]; |
114 | }, |
115 | getNearestValue: function(value){ |
116 | if(this.values){ |
117 | var i = 0; |
118 | var offset = Math.abs(this.values[0] - value); |
119 | var newValue = this.values[0]; |
120 | |
121 | for(i=0; i < this.values.length; i++){ |
122 | var currentOffset = Math.abs(this.values[i] - value); |
123 | if(currentOffset < offset){ |
124 | newValue = this.values[i]; |
125 | offset = currentOffset; |
126 | } |
127 | } |
128 | return newValue; |
129 | } |
130 | return value; |
131 | }, |
132 | setSliderValue: function(sliderValue){ |
133 | // First check our max and minimum and nearest values |
134 | sliderValue = this.getNearestValue(sliderValue); |
135 | if(sliderValue > this.maximum) sliderValue = this.maximum; |
136 | if(sliderValue < this.minimum) sliderValue = this.minimum; |
137 | var offsetDiff = (sliderValue - (this.value||this.minimum)) * this.increment; |
138 | |
139 | if(this.isVertical()){ |
140 | this.setCurrentTop(offsetDiff + this.currentTop()); |
141 | } else { |
142 | this.setCurrentLeft(offsetDiff + this.currentLeft()); |
143 | } |
144 | this.value = sliderValue; |
145 | this.updateFinished(); |
146 | }, |
147 | minimumOffset: function(){ |
148 | return(this.isVertical() ? |
149 | this.trackTop() + this.alignY : |
150 | this.trackLeft() + this.alignX); |
151 | }, |
152 | maximumOffset: function(){ |
153 | return(this.isVertical() ? |
154 | this.trackTop() + this.alignY + (this.maximum - this.minimum) * this.increment : |
155 | this.trackLeft() + this.alignX + (this.maximum - this.minimum) * this.increment); |
156 | }, |
157 | isVertical: function(){ |
158 | return (this.axis == 'vertical'); |
159 | }, |
160 | startDrag: function(event) { |
161 | if(Event.isLeftClick(event)) { |
162 | if(!this.disabled){ |
163 | this.active = true; |
164 | var pointer = [Event.pointerX(event), Event.pointerY(event)]; |
165 | var offsets = Position.cumulativeOffset(this.handle); |
166 | this.offsetX = (pointer[0] - offsets[0]); |
167 | this.offsetY = (pointer[1] - offsets[1]); |
168 | this.originalLeft = this.currentLeft(); |
169 | this.originalTop = this.currentTop(); |
170 | } |
171 | Event.stop(event); |
172 | } |
173 | }, |
174 | update: function(event) { |
175 | if(this.active) { |
176 | if(!this.dragging) { |
177 | var style = this.handle.style; |
178 | this.dragging = true; |
179 | if(style.position=="") style.position = "relative"; |
180 | style.zIndex = this.options.zindex; |
181 | } |
182 | this.draw(event); |
183 | // fix AppleWebKit rendering |
184 | if(navigator.appVersion.indexOf('AppleWebKit')>0) window.scrollBy(0,0); |
185 | Event.stop(event); |
186 | } |
187 | }, |
188 | draw: function(event) { |
189 | var pointer = [Event.pointerX(event), Event.pointerY(event)]; |
190 | var offsets = Position.cumulativeOffset(this.handle); |
191 | |
192 | offsets[0] -= this.currentLeft(); |
193 | offsets[1] -= this.currentTop(); |
194 | |
195 | // Adjust for the pointer's position on the handle |
196 | pointer[0] -= this.offsetX; |
197 | pointer[1] -= this.offsetY; |
198 | var style = this.handle.style; |
199 | |
200 | if(this.isVertical()){ |
201 | if(pointer[1] > this.maximumOffset()) |
202 | pointer[1] = this.maximumOffset(); |
203 | if(pointer[1] < this.minimumOffset()) |
204 | pointer[1] = this.minimumOffset(); |
205 | |
206 | // Increment by values |
207 | if(this.values){ |
208 | this.value = this.getNearestValue(Math.round((pointer[1] - this.minimumOffset()) / this.increment) + this.minimum); |
209 | pointer[1] = this.trackTop() + this.alignY + (this.value - this.minimum) * this.increment; |
210 | } else { |
211 | this.value = Math.round((pointer[1] - this.minimumOffset()) / this.increment) + this.minimum; |
212 | } |
213 | style.top = pointer[1] - offsets[1] + "px"; |
214 | } else { |
215 | if(pointer[0] > this.maximumOffset()) pointer[0] = this.maximumOffset(); |
216 | if(pointer[0] < this.minimumOffset()) pointer[0] = this.minimumOffset(); |
217 | // Increment by values |
218 | if(this.values){ |
219 | this.value = this.getNearestValue(Math.round((pointer[0] - this.minimumOffset()) / this.increment) + this.minimum); |
220 | pointer[0] = this.trackLeft() + this.alignX + (this.value - this.minimum) * this.increment; |
221 | } else { |
222 | this.value = Math.round((pointer[0] - this.minimumOffset()) / this.increment) + this.minimum; |
223 | } |
224 | style.left = (pointer[0] - offsets[0]) + "px"; |
225 | } |
226 | if(this.options.onSlide) this.options.onSlide(this.value); |
227 | }, |
228 | endDrag: function(event) { |
229 | if(this.active && this.dragging) { |
230 | this.finishDrag(event, true); |
231 | Event.stop(event); |
232 | } |
233 | this.active = false; |
234 | this.dragging = false; |
235 | }, |
236 | finishDrag: function(event, success) { |
237 | this.active = false; |
238 | this.dragging = false; |
239 | this.handle.style.zIndex = this.originalZ; |
240 | this.originalLeft = this.currentLeft(); |
241 | this.originalTop = this.currentTop(); |
242 | this.updateFinished(); |
243 | }, |
244 | updateFinished: function() { |
245 | if(this.options.onChange) this.options.onChange(this.value); |
246 | }, |
247 | keyPress: function(event) { |
248 | if(this.active && !this.disabled) { |
249 | switch(event.keyCode) { |
250 | case Event.KEY_ESC: |
251 | this.finishDrag(event, false); |
252 | Event.stop(event); |
253 | break; |
254 | } |
255 | if(navigator.appVersion.indexOf('AppleWebKit')>0) Event.stop(event); |
256 | } |
257 | } |
258 | } |