xpSpin.htc
9.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
<PUBLIC:COMPONENT
lightWeight=true
>
<PUBLIC:DEFAULTS
contentEditable=false
tabStop=true
/>
<PUBLIC:attach event="ondocumentready" onevent="initElement()" />
<PUBLIC:attach event="ondetach" onevent="cleanupElement()" />
<PUBLIC:attach event="onfocus" onevent="elementOnFocus()" />
<PUBLIC:attach event="onpropertychange" onevent="elementOnPropertyChange()" />
<PUBLIC:property name="min" value=-32768 />
<PUBLIC:property name="max" value=32768 />
<PUBLIC:property name="value" value=0 />
<script language="VBScript">
' ----------------------------------------------------
' ieWidgets: xpSpin
' ----------------------------------------------------
option explicit
dim inProc
dim absoluteX
dim absoluteY
dim prevAbsoluteX
dim prevAbsoluteY
dim offsetParentArray
dim elementCaption
dim elementButton
dim elementButtonChildUp
dim elementButtonChildDown
dim buttonTimer
dim timerCounter
' ----------------------------------------------------
' initialize/terminate functions
' ----------------------------------------------------
function initElement()
set elementCaption = document.createElement("<input class='xpSpinInput' name='finish' type='text' tabindex='" & element.tabindex & "'>")
set elementButton = document.createElement("<span class='xpSpinButton'>")
set elementButtonChildUp = document.createElement("<span class='xpSpinButtonText'>")
set elementButtonChildDown = document.createElement("<span class='xpSpinButtonText'>")
element.insertAdjacentElement "afterBegin", elementCaption
element.insertAdjacentElement "afterBegin", elementButton
with elementCaption
.attachEvent "onfocus", GetRef("captionOnFocus")
.attachEvent "onselectstart", GetRef("elementActDisabled")
.attachEvent "oncontextmenu", GetRef("elementActDisabled")
.attachEvent "onchange", GetRef("captionOnChange")
with .style
.fontFamily = cstr(element.style.fontFamily)
.fontSize = cstr(element.style.fontSize)
.fontWeight = cstr(element.style.fontWeight)
end with
end with
with elementButton
.tabIndex = -1
.insertAdjacentElement "afterBegin", elementButtonChildDown
.insertAdjacentElement "afterBegin", elementButtonChildUp
with elementButtonChildUp
.innerText = "5"
.tabIndex = -1
.style.lineHeight = ((.offsetHeight / 2) - 2) & "pt"
.attachEvent "onmouseover", GetRef("buttonOnMouseOver")
.attachEvent "onmouseout", GetRef("buttonOnMouseOut")
.attachEvent "onmousedown", GetRef("buttonOnMouseDown")
.attachEvent "onmouseup", GetRef("buttonOnMouseUp")
end with
with elementButtonChildDown
.innerText = "6"
.tabIndex = -1
.style.lineHeight = ((.offsetHeight / 2) - 2) & "pt"
.attachEvent "onmouseover", GetRef("buttonOnMouseOver")
.attachEvent "onmouseout", GetRef("buttonOnMouseOut")
.attachEvent "onmousedown", GetRef("buttonOnMouseDown")
.attachEvent "onmouseup", GetRef("buttonOnMouseUp")
end with
end with
window.attachEvent "onload", GetRef("actionOnLoad")
end function
function cleanupElement()
dim i
for i = lbound(offsetParentArray) to ubound(offsetParentArray)
offsetParentArray(i).detachEvent "onmove", GetRef("elementOnResize")
set offsetParentArray(i) = nothing
next
window.detachEvent "onload", GetRef("actionOnLoad")
with elementButtonChildUp
.detachEvent "onmouseover", GetRef("buttonOnMouseOver")
.detachEvent "onmouseout", GetRef("buttonOnMouseOut")
.detachEvent "onmousedown", GetRef("buttonOnMouseDown")
.detachEvent "onmouseup", GetRef("buttonOnMouseUp")
.removenode true
end with
with elementButtonChildDown
.detachEvent "onmouseover", GetRef("buttonOnMouseOver")
.detachEvent "onmouseout", GetRef("buttonOnMouseOut")
.detachEvent "onmousedown", GetRef("buttonOnMouseDown")
.detachEvent "onmouseup", GetRef("buttonOnMouseUp")
.removenode true
end with
with elementButton
.removenode true
end with
with elementCaption
.detachEvent "onfocus", GetRef("captionOnFocus")
.detachEvent "onselectstart", GetRef("elementActDisabled")
.detachEvent "oncontextmenu", GetRef("elementActDisabled")
.detachEvent "onchange", GetRef("captionOnChange")
.removenode true
end with
set elementCaption = nothing
set elementButton = nothing
set elementButtonChildUp = nothing
set elementButtonChildDown = nothing
end function
function actionOnLoad()
dim i
dim elHeight
dim elWidth
initOffsets element, true
prevAbsoluteX = absoluteX
prevAbsoluteY = absoluteY
with element
.tabIndex = -1
.hideFocus = true
elHeight = .offsetHeight
elWidth = .offsetWidth
end with
with elementButton.style
.top = cstr(absoluteY) & "px"
.left = cstr(absoluteX + elWidth - 16) & "px"
.height = cstr(elHeight) & "px"
.width = "16px"
end with
with elementButtonChildUp
.style.lineHeight = cstr((elHeight / 4) - .5) & "pt"
end with
with elementButtonChildDown
.style.lineHeight = cstr((elHeight / 4) - 1) & "pt"
end with
with elementCaption
.value = element.value & "%"
with .style
.top = cstr(absoluteY) & "px"
.left = cstr(absoluteX) & "px"
.height = cstr(elHeight) & "px"
.width = cstr(elWidth - 15) & "px"
end with
end with
for i = lbound(offsetParentArray) to ubound(offsetParentArray)
offsetParentArray(i).attachEvent "onmove", GetRef("elementOnResize")
next
end function
' ----------------------------------------------------
' internal functions
' ----------------------------------------------------
sub initOffsets(el, blnCreateArray)
dim i
dim tArray()
dim tElement
i = -1
absoluteX = 0
absoluteY = 0
set tElement = el
do while (not tElement is nothing)
if lcase(tElement.id) = "bodydiv" then exit do
absoluteY = absoluteY + tElement.offsetTop
absoluteX = absoluteX + tElement.offsetLeft
set tElement = tElement.offsetParent
if blnCreateArray then
if not tElement is nothing then
i = i + 1
redim preserve tArray(i)
set tArray(i) = tElement
end if
end if
loop
if el.style.position = "relative" then
absoluteX = -1
absoluteY = -1
end if
if blnCreateArray then offsetParentArray = tArray
set tElement = nothing
end sub
function incrementValue()
dim timerIncrement
window.clearTimeout(buttonTimer)
if element.value = "" then element.value = 0
element.value = clng(element.value + 1)
if clng(element.value) > clng(element.max) then element.value = element.max
elementCaption.value = element.value & "%"
timerCounter = timerCounter + 1
if timerCounter < 5 then timerIncrement = 300 else timerIncrement = 100
buttonTimer = window.setTimeout(getRef("incrementValue"), timerIncrement)
end function
function decrementValue()
dim timerIncrement
window.clearTimeout(buttonTimer)
if element.value = "" then element.value = 0
element.value = clng(element.value - 1)
if clng(element.value) < clng(element.min) then element.value = element.min
elementCaption.value = element.value & "%"
timerCounter = timerCounter + 1
if timerCounter < 5 then timerIncrement = 300 else timerIncrement = 100
buttonTimer = window.setTimeout(getRef("decrementValue"), timerIncrement)
end function
' ----------------------------------------------------
' element functions
' ----------------------------------------------------
function elementOnFocus()
elementCaption.select()
end function
function elementOnResize()
if inProc then exit function
inProc = true
initOffsets element, false
if prevAbsoluteX = absoluteX and prevAbsoluteY = absoluteY then
inProc = false
exit function
end if
prevAbsoluteX = absoluteX
prevAbsoluteY = absoluteY
with elementButton.style
.top = cstr(prevAbsoluteY) & "px"
.left = cstr(prevAbsoluteX + element.offsetWidth - 16) & "px"
end with
with elementCaption.style
.top = cstr(absoluteY) & "px"
.left = cstr(absoluteX) & "px"
end with
inProc = false
end function
function elementActDisabled()
with window.event
if element.disabled then
.cancelBubble = true
.returnValue = false
elementActDisabled = false
end if
end with
end function
sub elementOnPropertyChange()
if window.event.propertyName = "disabled" then
elementCaption.disabled = element.disabled
elementCaption.value = element.value
elseif window.event.propertyName = "value" then
elementCaption.value = element.value
end if
end sub
' ----------------------------------------------------
' element caption functions
' ----------------------------------------------------
function captionOnFocus()
elementCaption.focus()
end function
'added by hubo 050830
function captionOnChange()
On Error Resume Next
if InStr(elementCaption.value,"%")=0 then
element.value = elementCaption.value
else
element.value = Left(elementCaption.value, Len(elementCaption.value)-1)
end if
if (not IsNumeric(element.value)) then element.value = 0
if clng(element.value) > clng(element.max) then element.value = element.max
if clng(element.value) < clng(element.min) then element.value = element.min
end function
' ----------------------------------------------------
' element button functions
' ----------------------------------------------------
function buttonOnMouseOver()
if element.disabled then exit function
window.event.srcElement.className = "xpSpinButtonTextOver"
end function
function buttonOnMouseOut()
if element.disabled then exit function
window.event.srcElement.className = "xpSpinButtonText"
end function
function buttonOnMouseDown()
if element.disabled then exit function
window.event.srcElement.className = "xpSpinButtonTextDown"
timerCounter = 0
select case true
case window.event.srcElement is elementButtonChildUp
buttonTimer = window.setTimeout(getRef("incrementValue"), 1)
case window.event.srcElement is elementButtonChildDown
buttonTimer = window.setTimeout(getRef("decrementValue"), 1)
end select
end function
function buttonOnMouseUp()
if element.disabled then exit function
window.event.srcElement.className = "xpSpinButtonTextOver"
window.clearTimeout(buttonTimer)
elementCaption.focus()
end function
</script>
</PUBLIC:COMPONENT>