author | Dan |
Fri, 22 Jun 2007 18:42:26 -0400 | |
changeset 14 | ce6053bb48d8 |
parent 9 | 1e61232606d6 |
child 40 | 723bb7acf914 |
permissions | -rw-r--r-- |
1 | 1 |
// Some additional DHTML functions |
2 |
||
3 |
function fetch_offset(obj) { |
|
4 |
var left_offset = obj.offsetLeft; |
|
5 |
var top_offset = obj.offsetTop; |
|
6 |
while ((obj = obj.offsetParent) != null) { |
|
7 |
left_offset += obj.offsetLeft; |
|
8 |
top_offset += obj.offsetTop; |
|
9 |
} |
|
10 |
return { 'left' : left_offset, 'top' : top_offset }; |
|
11 |
} |
|
12 |
||
13 |
function fetch_dimensions(o) { |
|
14 |
var w = o.offsetWidth; |
|
15 |
var h = o.offsetHeight; |
|
16 |
return { 'w' : w, 'h' : h }; |
|
17 |
} |
|
18 |
||
19 |
function findParentForm(o) |
|
20 |
{ |
|
21 |
// Not implemented - someone please let me know how to do this, what I need to do is |
|
22 |
// find the first parent <form> tag above param 'o', not sure how to do it with DOM |
|
23 |
} |
|
24 |
||
25 |
function ajaxReverseDNS(o, text) |
|
26 |
{ |
|
27 |
if(text) var ipaddr = text; |
|
28 |
else var ipaddr = o.innerHTML; |
|
29 |
rDnsObj = o; |
|
30 |
rDnsBannerObj = bannerOn('Retrieving reverse DNS info...'); |
|
31 |
ajaxGet(stdAjaxPrefix+'&_mode=rdns&ip='+ipaddr, function() { |
|
32 |
if(ajax.readyState == 4) |
|
33 |
{ |
|
34 |
off = fetch_offset(rDnsObj); |
|
35 |
dim = fetch_dimensions(rDnsObj); |
|
36 |
right = off['left'] + dim['w']; |
|
37 |
top = off['top'] + dim['h']; |
|
38 |
var thediv = document.createElement('div'); |
|
39 |
thediv.className = 'info-box'; |
|
40 |
thediv.style.margin = '0'; |
|
41 |
thediv.style.position = 'absolute'; |
|
42 |
thediv.style.top = top + 'px'; |
|
43 |
thediv.style.display = 'none'; |
|
44 |
thediv.style.zIndex = getHighestZ() + 2; |
|
45 |
thediv.id = 'mdgDynamic_rDnsInfoDiv_'+Math.floor(Math.random() * 1000000); |
|
46 |
thediv.innerHTML = '<b>Reverse DNS:</b><br />'+ajax.responseText+' <a href="#" onclick="elem = document.getElementById(\''+thediv.id+'\'); elem.innerHTML = \'\'; elem.style.display = \'none\';return false;">Close</a>'; |
|
47 |
var body = document.getElementsByTagName('body'); |
|
48 |
body = body[0]; |
|
49 |
bannerOff(rDnsBannerObj); |
|
50 |
body.appendChild(thediv); |
|
51 |
thediv.style.display = 'block'; |
|
52 |
left = fetch_dimensions(thediv); |
|
53 |
thediv.style.display = 'none'; |
|
54 |
left = right - left['w']; |
|
55 |
thediv.style.left = left + 'px'; |
|
56 |
thediv.style.display = 'block'; |
|
57 |
fadeInfoBoxes(); |
|
58 |
} |
|
59 |
}); |
|
60 |
} |
|
61 |
||
62 |
function bannerOn(text) |
|
63 |
{ |
|
64 |
darken(true); |
|
65 |
var thediv = document.createElement('div'); |
|
66 |
thediv.className = 'mdg-comment'; |
|
67 |
thediv.style.padding = '0'; |
|
68 |
thediv.style.marginLeft = '0'; |
|
69 |
thediv.style.position = 'absolute'; |
|
70 |
thediv.style.display = 'none'; |
|
71 |
thediv.style.padding = '4px'; |
|
72 |
thediv.style.fontSize = '14pt'; |
|
73 |
thediv.id = 'mdgDynamic_bannerDiv_'+Math.floor(Math.random() * 1000000); |
|
74 |
thediv.innerHTML = text; |
|
75 |
||
76 |
var body = document.getElementsByTagName('body'); |
|
77 |
body = body[0]; |
|
78 |
body.appendChild(thediv); |
|
79 |
body.style.cursor = 'wait'; |
|
80 |
||
81 |
thediv.style.display = 'block'; |
|
82 |
dim = fetch_dimensions(thediv); |
|
83 |
thediv.style.display = 'none'; |
|
84 |
bdim = { 'w' : getWidth(), 'h' : getHeight() }; |
|
85 |
so = getScrollOffset(); |
|
86 |
||
87 |
left = (bdim['w'] / 2) - ( dim['w'] / 2 ); |
|
88 |
top = (bdim['h'] / 2) - ( dim['h'] / 2 ) + so; |
|
89 |
||
90 |
thediv.style.top = top + 'px'; |
|
91 |
thediv.style.left = left + 'px'; |
|
92 |
||
93 |
thediv.style.display = 'block'; |
|
94 |
||
95 |
return thediv.id; |
|
96 |
} |
|
97 |
||
98 |
function bannerOff(id) |
|
99 |
{ |
|
100 |
e = document.getElementById(id); |
|
101 |
if(!e) return; |
|
102 |
e.innerHTML = ''; |
|
103 |
e.style.display = 'none'; |
|
104 |
var body = document.getElementsByTagName('body'); |
|
105 |
body = body[0]; |
|
106 |
body.style.cursor = 'default'; |
|
107 |
enlighten(true); |
|
108 |
} |
|
109 |
||
110 |
function disableUnload(message) |
|
111 |
{ |
|
112 |
if(typeof message != 'string') message = 'You may want to save your changes first.'; |
|
113 |
var body = document.getElementsByTagName('body'); |
|
114 |
body = body[0]; |
|
115 |
body.onbeforeunload='return unescape(\''+escape(message)+'\')'; |
|
116 |
} |
|
117 |
||
118 |
function enableUnload() |
|
119 |
{ |
|
120 |
var body = document.getElementsByTagName('body'); |
|
121 |
body = body[0]; |
|
122 |
body.onbeforeunload = null; |
|
123 |
} |
|
124 |
||
125 |
/** |
|
126 |
* Gets the highest z-index of all divs in the document |
|
127 |
* @return integer |
|
128 |
*/ |
|
129 |
function getHighestZ() |
|
130 |
{ |
|
131 |
z = 0; |
|
132 |
var divs = document.getElementsByTagName('div'); |
|
133 |
for(var i = 0; i < divs.length; i++) |
|
134 |
{ |
|
135 |
if(divs[i].style.zIndex > z) z = divs[i].style.zIndex; |
|
136 |
} |
|
137 |
return z; |
|
138 |
} |
|
139 |
||
140 |
function isKeyPressed(event) |
|
141 |
{ |
|
142 |
if (event.shiftKey==1) |
|
143 |
{ |
|
144 |
shift = true; |
|
145 |
} |
|
146 |
else |
|
147 |
{ |
|
148 |
shift = false; |
|
149 |
} |
|
150 |
} |
|
151 |
||
152 |
function moveDiv(div, newparent) |
|
153 |
{ |
|
154 |
var backup = div; |
|
155 |
var oldparent = div.parentNode; |
|
156 |
oldparent.removeChild(div); |
|
157 |
newparent.appendChild(backup); |
|
158 |
} |
|
159 |
||
160 |
function readCookie(name) {var nameEQ = name + "=";var ca = document.cookie.split(';');for(var i=0;i < ca.length;i++){var c = ca[i];while (c.charAt(0)==' ') c = c.substring(1,c.length);if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);}return null;} |
|
161 |
function createCookie(name,value,days){if (days){var date = new Date();date.setTime(date.getTime()+(days*24*60*60*1000));var expires = "; expires="+date.toGMTString();}else var expires = "";document.cookie = name+"="+value+expires+"; path=/";} |
|
162 |
function eraseCookie(name) {createCookie(name,"",-1);} |
|
163 |
||
164 |
var busyBannerID; |
|
165 |
function goBusy(msg) |
|
166 |
{ |
|
167 |
if(!msg) msg = 'Please wait...'; |
|
168 |
body = document.getElementsByTagName('body'); |
|
169 |
body = body[0]; |
|
170 |
body.style.cursor = 'wait'; |
|
171 |
busyBannerID = bannerOn(msg); |
|
172 |
} |
|
173 |
||
174 |
function unBusy() |
|
175 |
{ |
|
176 |
body = document.getElementsByTagName('body'); |
|
177 |
body = body[0]; |
|
178 |
body.style.cursor = 'default'; |
|
179 |
bannerOff(busyBannerID); |
|
180 |
} |
|
181 |
||
182 |
function setAjaxLoading() |
|
183 |
{ |
|
184 |
if ( document.getElementById('ajaxloadicon') ) |
|
185 |
{ |
|
186 |
document.getElementById('ajaxloadicon').src=scriptPath + '/images/loading.gif'; |
|
187 |
} |
|
188 |
} |
|
189 |
||
190 |
function unsetAjaxLoading() |
|
191 |
{ |
|
192 |
if ( document.getElementById('ajaxloadicon') ) |
|
193 |
{ |
|
194 |
document.getElementById('ajaxloadicon').src=scriptPath + '/images/spacer.gif'; |
|
195 |
} |
|
196 |
} |
|
197 |
||
198 |
/* |
|
199 |
* Search boxes |
|
200 |
*/ |
|
201 |
||
202 |
function buildSearchBoxes() |
|
203 |
{ |
|
204 |
var divs = document.getElementsByTagName('*'); |
|
205 |
var boxes = new Array(); |
|
206 |
for ( var i = 0; i < divs.length; i++ ) |
|
207 |
{ |
|
208 |
if ( divs[i].className) |
|
209 |
{ |
|
210 |
if ( divs[i].className.substr(0, 9) == 'searchbox' ) |
|
211 |
{ |
|
212 |
boxes.push(divs[i]); |
|
213 |
} |
|
214 |
} |
|
215 |
} |
|
216 |
for ( var i = 0; i < boxes.length; i++ ) |
|
217 |
{ |
|
218 |
if ( boxes[i].className.match(/^searchbox\[([0-9]+)px\]$/) ) |
|
219 |
{ |
|
220 |
var width = boxes[i].className.match(/^searchbox\[([0-9]+)px\]$/); |
|
221 |
width = parseInt(width[1]); |
|
222 |
} |
|
223 |
else |
|
224 |
{ |
|
225 |
var width = 120; |
|
226 |
} |
|
227 |
createSearchBox(boxes[i], width); |
|
228 |
} |
|
229 |
} |
|
230 |
||
231 |
function createSearchBox(parent, width) |
|
232 |
{ |
|
233 |
if ( typeof(parent) != 'object') |
|
234 |
{ |
|
235 |
alert('BUG: createSearchBox(): parent is not an object'); |
|
236 |
return false; |
|
237 |
} |
|
238 |
//parent.style.padding = '0px'; |
|
239 |
//parent.style.textAlign = 'center'; |
|
240 |
parent.style.width = width + 'px'; |
|
241 |
var submit = document.createElement('div'); |
|
242 |
submit.onclick = function() { searchFormSubmit(this); }; |
|
243 |
submit.className = 'js-search-submit'; |
|
244 |
var input = document.createElement('input'); |
|
245 |
input.className = 'js-search-box'; |
|
246 |
input.value = 'Search'; |
|
247 |
input.name = 'q'; |
|
248 |
input.style.width = ( width - 28 ) + 'px'; |
|
249 |
input.onfocus = function() { if ( this.value == 'Search' ) this.value = ''; }; |
|
250 |
input.onblur = function() { if ( this.value == '' ) this.value = 'Search'; }; |
|
251 |
parent.appendChild(input); |
|
252 |
var off = fetch_offset(input); |
|
253 |
var top = off['top'] + 'px'; |
|
254 |
var left = ( parseInt(off['left']) + ( width - 24 ) ) + 'px'; |
|
255 |
submit.style.top = top; |
|
256 |
submit.style.left = left; |
|
257 |
parent.appendChild(submit); |
|
258 |
} |
|
259 |
||
260 |
function searchFormSubmit(obj) |
|
261 |
{ |
|
262 |
var input = obj.previousSibling; |
|
263 |
if ( input.value == 'Search' || input.value == '' ) |
|
264 |
return false; |
|
265 |
var p = obj; |
|
266 |
while(true) |
|
267 |
{ |
|
268 |
p = p.parentNode; |
|
269 |
if ( !p ) |
|
270 |
break; |
|
271 |
if ( typeof(p.tagName) != 'string' ) |
|
272 |
break; |
|
273 |
else if ( p.tagName.toLowerCase() == 'form' ) |
|
274 |
{ |
|
275 |
p.submit(); |
|
276 |
} |
|
277 |
else if ( p.tagName.toLowerCase() == 'body' ) |
|
278 |
{ |
|
279 |
break; |
|
280 |
} |
|
281 |
} |
|
282 |
} |
|
283 |
||
284 |
/* |
|
285 |
* AJAX login box (experimental) |
|
286 |
*/ |
|
287 |
||
288 |
var ajax_auth_prompt_cache = false; |
|
289 |
var ajax_auth_mb_cache = false; |
|
290 |
var ajax_auth_level_cache = false; |
|
291 |
||
292 |
function ajaxPromptAdminAuth(call_on_ok, level) |
|
293 |
{ |
|
294 |
if ( typeof(call_on_ok) == 'function' ) |
|
295 |
{ |
|
296 |
ajax_auth_prompt_cache = call_on_ok; |
|
297 |
} |
|
298 |
if ( !level ) |
|
299 |
level = 2; |
|
300 |
ajax_auth_level_cache = level; |
|
301 |
var loading_win = '<div align="center" style="text-align: center;"> \ |
|
302 |
<p>Fetching an encryption key...</p> \ |
|
303 |
<p><small>Not working? Use the <a href="'+makeUrlNS('Special', 'Login/' + title)+'">alternate login form</a>.</p> \ |
|
304 |
<p><img alt="Please wait..." src="'+scriptPath+'/images/loading-big.gif" /></p> \ |
|
305 |
</div>'; |
|
306 |
ajax_auth_mb_cache = new messagebox(MB_OKCANCEL|MB_ICONLOCK, 'Please enter your username and password to continue.', loading_win); |
|
307 |
ajax_auth_mb_cache.onbeforeclick['OK'] = ajaxValidateLogin; |
|
308 |
ajaxAuthLoginInnerSetup(); |
|
309 |
} |
|
310 |
||
311 |
function ajaxAuthLoginInnerSetup() |
|
312 |
{ |
|
313 |
ajaxGet(makeUrlNS('Special', 'Login', 'act=getkey'), function() { |
|
314 |
if ( ajax.readyState == 4 ) |
|
315 |
{ |
|
316 |
var response = ajax.responseText; |
|
317 |
if ( response.substr(0,1) != '{' ) |
|
318 |
{ |
|
319 |
alert('Invalid JSON response from server: ' + response); |
|
320 |
return false; |
|
321 |
} |
|
322 |
response = parseJSON(response); |
|
323 |
var form_html = ' \ |
|
324 |
<table border="0" align="center"> \ |
|
325 |
<tr> \ |
|
326 |
<td>Username:</td><td><input tabindex="1" id="ajaxlogin_user" type="text" size="25" /> \ |
|
327 |
</tr> \ |
|
328 |
<tr> \ |
|
329 |
<td>Password:</td><td><input tabindex="2" id="ajaxlogin_pass" type="password" size="25" /> \ |
|
330 |
</tr> \ |
|
331 |
<tr> \ |
|
332 |
<td colspan="2" style="text-align: center;"> \ |
|
333 |
<br /><small>Trouble logging in? Try the <a href="'+makeUrlNS('Special', 'Login/' + title)+'">full login form</a>.<br /> \ |
|
334 |
Did you <a href="'+makeUrlNS('Special', 'PasswordReset')+'">forget your password</a>?<br /> \ |
|
335 |
Maybe you need to <a href="'+makeUrlNS('Special', 'Register')+'">create an account</a>.</small> \ |
|
336 |
</td> \ |
|
337 |
</tr> \ |
|
338 |
</table> \ |
|
339 |
<input type="hidden" id="ajaxlogin_crypt_key" value="' + response.key + '" /> \ |
|
340 |
<input type="hidden" id="ajaxlogin_crypt_challenge" value="' + response.challenge + '" /> \ |
|
341 |
</form>'; |
|
342 |
ajax_auth_mb_cache.updateContent(form_html); |
|
343 |
$('messageBox').object.nextSibling.firstChild.tabindex = '3'; |
|
344 |
$('ajaxlogin_user').object.focus(); |
|
9
1e61232606d6
Following fixes: admin theme supports <button> tag now, PageProcessor can eval now, and SpecialAdmin.php plugin can no longer be disabled
dan@fuhry
parents:
1
diff
changeset
|
345 |
$('ajaxlogin_pass').object.onblur = function(e) { if ( !shift ) $('messageBox').object.nextSibling.firstChild.focus(); }; |
1e61232606d6
Following fixes: admin theme supports <button> tag now, PageProcessor can eval now, and SpecialAdmin.php plugin can no longer be disabled
dan@fuhry
parents:
1
diff
changeset
|
346 |
$('ajaxlogin_pass').object.onkeypress = function(e) { if ( e.keyCode == 13 ) $('messageBox').object.nextSibling.firstChild.click(); }; |
1 | 347 |
} |
348 |
}); |
|
349 |
} |
|
350 |
||
351 |
function ajaxValidateLogin() |
|
352 |
{ |
|
353 |
var username,password,auth_enabled,crypt_key,crypt_data,challenge_salt,challenge_data; |
|
354 |
username = document.getElementById('ajaxlogin_user'); |
|
355 |
if ( !username ) |
|
356 |
return false; |
|
357 |
username = document.getElementById('ajaxlogin_user').value; |
|
358 |
password = document.getElementById('ajaxlogin_pass').value; |
|
359 |
auth_enabled = false; |
|
360 |
||
361 |
disableJSONExts(); |
|
362 |
||
363 |
// |
|
364 |
// Encryption test |
|
365 |
// |
|
366 |
||
367 |
var str = ''; |
|
368 |
for(i=0;i<keySizeInBits/4;i++) |
|
369 |
{ |
|
370 |
str+='0'; |
|
371 |
} |
|
372 |
str = hexToByteArray(str); |
|
373 |
var ct = rijndaelEncrypt(str, str, 'ECB'); |
|
374 |
ct = byteArrayToHex(ct); |
|
375 |
var v; |
|
376 |
switch(keySizeInBits) |
|
377 |
{ |
|
378 |
case 128: |
|
379 |
v = '66e94bd4ef8a2c3b884cfa59ca342b2e'; |
|
380 |
break; |
|
381 |
case 192: |
|
382 |
v = 'aae06992acbf52a3e8f4a96ec9300bd7aae06992acbf52a3e8f4a96ec9300bd7'; |
|
383 |
break; |
|
384 |
case 256: |
|
385 |
v = 'dc95c078a2408989ad48a21492842087dc95c078a2408989ad48a21492842087'; |
|
386 |
break; |
|
387 |
} |
|
388 |
auth_enabled = ( ct == v && md5_vm_test() ); |
|
389 |
if ( !auth_enabled ) |
|
390 |
{ |
|
391 |
alert('Login error: encryption sanity check failed\n'); |
|
392 |
return true; |
|
393 |
} |
|
394 |
||
395 |
crypt_key = document.getElementById('ajaxlogin_crypt_key').value; |
|
396 |
challenge_salt = document.getElementById('ajaxlogin_crypt_challenge').value; |
|
397 |
||
398 |
var crypt_key_md5 = hex_md5(crypt_key); |
|
399 |
||
400 |
challenge_data = hex_md5(password + challenge_salt) + challenge_salt; |
|
401 |
||
402 |
password = stringToByteArray(password); |
|
403 |
crypt_key = hexToByteArray(crypt_key); |
|
404 |
||
405 |
crypt_data = rijndaelEncrypt(password, crypt_key, 'ECB'); |
|
406 |
crypt_data = byteArrayToHex(crypt_data); |
|
407 |
||
408 |
var json_data = { |
|
409 |
'username' : username, |
|
410 |
'crypt_key' : crypt_key_md5, |
|
411 |
'challenge' : challenge_data, |
|
412 |
'crypt_data' : crypt_data, |
|
413 |
'level' : ajax_auth_level_cache |
|
414 |
}; |
|
415 |
||
416 |
json_data = toJSONString(json_data); |
|
417 |
json_data = ajaxEscape(json_data); |
|
418 |
||
419 |
var loading_win = '<div align="center" style="text-align: center;"> \ |
|
420 |
<p>Logging in...</p> \ |
|
421 |
<p><img alt="Please wait..." src="'+scriptPath+'/images/loading-big.gif" /></p> \ |
|
422 |
</div>'; |
|
423 |
||
424 |
ajax_auth_mb_cache.updateContent(loading_win); |
|
425 |
||
426 |
ajaxPost(makeUrlNS('Special', 'Login', 'act=ajaxlogin'), 'params=' + json_data, function() { |
|
427 |
if ( ajax.readyState == 4 ) |
|
428 |
{ |
|
429 |
var response = ajax.responseText; |
|
430 |
if ( response.substr(0,1) != '{' ) |
|
431 |
{ |
|
432 |
alert('Invalid JSON response from server: ' + response); |
|
433 |
ajaxAuthLoginInnerSetup(); |
|
434 |
return false; |
|
435 |
} |
|
436 |
response = parseJSON(response); |
|
437 |
switch(response.result) |
|
438 |
{ |
|
439 |
case 'success': |
|
440 |
if ( typeof(ajax_auth_prompt_cache) == 'function' ) |
|
441 |
{ |
|
442 |
ajax_auth_prompt_cache(response.key); |
|
443 |
} |
|
444 |
break; |
|
445 |
case 'success_reset': |
|
446 |
var conf = confirm('You have logged in using a temporary password. Before you can log in, you must finish resetting your password. Do you want to reset your real password now?'); |
|
447 |
if ( conf ) |
|
448 |
{ |
|
449 |
var url = makeUrlNS('Special', 'PasswordReset/stage2/' + response.user_id + '/' + response.temppass); |
|
450 |
window.location = url; |
|
451 |
} |
|
452 |
else |
|
453 |
{ |
|
454 |
ajaxAuthLoginInnerSetup(); |
|
455 |
} |
|
456 |
break; |
|
457 |
case 'error': |
|
458 |
alert(response.error); |
|
459 |
ajaxAuthLoginInnerSetup(); |
|
460 |
break; |
|
461 |
default: |
|
462 |
alert(ajax.responseText); |
|
463 |
break; |
|
464 |
} |
|
465 |
} |
|
466 |
}); |
|
467 |
||
468 |
return true; |
|
469 |
||
470 |
} |
|
471 |
||
472 |
// This code is in the public domain. Feel free to link back to http://jan.moesen.nu/ |
|
473 |
function sprintf() |
|
474 |
{ |
|
475 |
if (!arguments || arguments.length < 1 || !RegExp) |
|
476 |
{ |
|
477 |
return; |
|
478 |
} |
|
479 |
var str = arguments[0]; |
|
480 |
var re = /([^%]*)%('.|0|\x20)?(-)?(\d+)?(\.\d+)?(%|b|c|d|u|f|o|s|x|X)(.*)/; |
|
481 |
var a = b = [], numSubstitutions = 0, numMatches = 0; |
|
482 |
while (a = re.exec(str)) |
|
483 |
{ |
|
484 |
var leftpart = a[1], pPad = a[2], pJustify = a[3], pMinLength = a[4]; |
|
485 |
var pPrecision = a[5], pType = a[6], rightPart = a[7]; |
|
486 |
||
487 |
//alert(a + '\n' + [a[0], leftpart, pPad, pJustify, pMinLength, pPrecision); |
|
488 |
||
489 |
numMatches++; |
|
490 |
if (pType == '%') |
|
491 |
{ |
|
492 |
subst = '%'; |
|
493 |
} |
|
494 |
else |
|
495 |
{ |
|
496 |
numSubstitutions++; |
|
497 |
if (numSubstitutions >= arguments.length) |
|
498 |
{ |
|
499 |
alert('Error! Not enough function arguments (' + (arguments.length - 1) + ', excluding the string)\nfor the number of substitution parameters in string (' + numSubstitutions + ' so far).'); |
|
500 |
} |
|
501 |
var param = arguments[numSubstitutions]; |
|
502 |
var pad = ''; |
|
503 |
if (pPad && pPad.substr(0,1) == "'") pad = leftpart.substr(1,1); |
|
504 |
else if (pPad) pad = pPad; |
|
505 |
var justifyRight = true; |
|
506 |
if (pJustify && pJustify === "-") justifyRight = false; |
|
507 |
var minLength = -1; |
|
508 |
if (pMinLength) minLength = parseInt(pMinLength); |
|
509 |
var precision = -1; |
|
510 |
if (pPrecision && pType == 'f') precision = parseInt(pPrecision.substring(1)); |
|
511 |
var subst = param; |
|
512 |
if (pType == 'b') subst = parseInt(param).toString(2); |
|
513 |
else if (pType == 'c') subst = String.fromCharCode(parseInt(param)); |
|
514 |
else if (pType == 'd') subst = parseInt(param) ? parseInt(param) : 0; |
|
515 |
else if (pType == 'u') subst = Math.abs(param); |
|
516 |
else if (pType == 'f') subst = (precision > -1) ? Math.round(parseFloat(param) * Math.pow(10, precision)) / Math.pow(10, precision): parseFloat(param); |
|
517 |
else if (pType == 'o') subst = parseInt(param).toString(8); |
|
518 |
else if (pType == 's') subst = param; |
|
519 |
else if (pType == 'x') subst = ('' + parseInt(param).toString(16)).toLowerCase(); |
|
520 |
else if (pType == 'X') subst = ('' + parseInt(param).toString(16)).toUpperCase(); |
|
521 |
} |
|
522 |
str = leftpart + subst + rightPart; |
|
523 |
} |
|
524 |
return str; |
|
525 |
} |
|
526 |
||
527 |
function paginator_goto(parentobj, this_page, num_pages, perpage, url_string) |
|
528 |
{ |
|
529 |
var height = $(parentobj).Height(); |
|
530 |
var width = $(parentobj).Width(); |
|
531 |
var left = $(parentobj).Left(); |
|
532 |
var top = $(parentobj).Top(); |
|
533 |
var left_pos = left + width ; |
|
534 |
var top_pos = height + top; |
|
535 |
var div = document.createElement('div'); |
|
536 |
div.style.position = 'absolute'; |
|
537 |
div.style.top = top_pos + 'px'; |
|
538 |
div.className = 'question-box'; |
|
539 |
div.style.margin = '1px 0 0 2px'; |
|
540 |
var vtmp = 'input_' + Math.floor(Math.random() * 1000000); |
|
541 |
div.innerHTML = 'Go to page:<br /><input type="text" size="2" style="padding: 1px; font-size: 8pt;" value="'+(parseInt(this_page)+1)+'" id="'+vtmp+'" /> <a href="#" onclick="paginator_submit(this, '+num_pages+', '+perpage+', unescape(\'' + escape(url_string) + '\')); return false;" style="font-size: 14pt; text-decoration: none;">»</a> <a href="#" onclick="fly_out_top(this.parentNode, false, true); return false;" style="font-size: 14pt; text-decoration: none;">×</a>'; |
|
542 |
||
543 |
var body = document.getElementsByTagName('body')[0]; |
|
544 |
body.appendChild(div); |
|
545 |
||
546 |
document.getElementById(vtmp).onkeypress = function(e){if(e.keyCode==13)this.nextSibling.nextSibling.onclick();}; |
|
547 |
document.getElementById(vtmp).focus(); |
|
548 |
||
549 |
// fade the div |
|
550 |
/* |
|
551 |
if(!div.id) div.id = 'autofade_'+Math.floor(Math.random() * 100000); |
|
552 |
var from = '#33FF33'; |
|
553 |
Fat.fade_element(div.id,30,2000,from,Fat.get_bgcolor(div.id)); |
|
554 |
*/ |
|
555 |
fly_in_bottom(div, false, true); |
|
556 |
||
557 |
var divh = $(div).Width(); |
|
558 |
left_pos = left_pos - divh; |
|
559 |
div.style.left = left_pos + 'px'; |
|
560 |
} |
|
561 |
||
562 |
function paginator_submit(obj, max, perpage, formatstring) |
|
563 |
{ |
|
564 |
var userinput = obj.previousSibling.previousSibling.value; |
|
565 |
userinput = parseInt(userinput); |
|
566 |
var offset = ( userinput - 1 ) * perpage; |
|
567 |
if ( userinput > max || isNaN(userinput) || userinput < 1 ) |
|
568 |
{ |
|
569 |
new messagebox(MB_OK|MB_ICONSTOP, 'Invalid entry', 'Please enter a page number between 1 and ' + max + '.'); |
|
570 |
return false; |
|
571 |
} |
|
572 |
var url = sprintf(formatstring, String(offset)); |
|
573 |
fly_out_top(obj.parentNode, false, true); |
|
574 |
window.location = url; |
|
575 |
} |
|
576 |