Mercurial > hg > vamp-website
comparison forum/Themes/default/scripts/captcha.js @ 76:e3e11437ecea website
Add forum code
author | Chris Cannam |
---|---|
date | Sun, 07 Jul 2013 11:25:48 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
75:72f59aa7e503 | 76:e3e11437ecea |
---|---|
1 // This file contains javascript associated with the captcha visual verification stuffs. | |
2 | |
3 function smfCaptcha(imageURL, uniqueID, useLibrary, letterCount) | |
4 { | |
5 // By default the letter count is five. | |
6 if (!letterCount) | |
7 letterCount = 5; | |
8 | |
9 uniqueID = uniqueID ? '_' + uniqueID : ''; | |
10 autoCreate(); | |
11 | |
12 // Automatically get the captcha event handlers in place and the like. | |
13 function autoCreate() | |
14 { | |
15 // Is there anything to cycle images with - if so attach the refresh image function? | |
16 var cycleHandle = document.getElementById('visual_verification' + uniqueID + '_refresh'); | |
17 if (cycleHandle) | |
18 { | |
19 createEventListener(cycleHandle); | |
20 cycleHandle.addEventListener('click', refreshImages, false); | |
21 } | |
22 | |
23 // Maybe a voice is here to spread light? | |
24 var soundHandle = document.getElementById('visual_verification' + uniqueID + '_sound'); | |
25 if (soundHandle) | |
26 { | |
27 createEventListener(soundHandle); | |
28 soundHandle.addEventListener('click', playSound, false); | |
29 } | |
30 } | |
31 | |
32 // Change the images. | |
33 function refreshImages() | |
34 { | |
35 // Make sure we are using a new rand code. | |
36 var new_url = new String(imageURL); | |
37 new_url = new_url.substr(0, new_url.indexOf("rand=") + 5); | |
38 | |
39 // Quick and dirty way of converting decimal to hex | |
40 var hexstr = "0123456789abcdef"; | |
41 for(var i=0; i < 32; i++) | |
42 new_url = new_url + hexstr.substr(Math.floor(Math.random() * 16), 1); | |
43 | |
44 if (useLibrary && document.getElementById("verification_image" + uniqueID)) | |
45 { | |
46 document.getElementById("verification_image" + uniqueID).src = new_url; | |
47 } | |
48 else if (document.getElementById("verification_image" + uniqueID)) | |
49 { | |
50 for (i = 1; i <= letterCount; i++) | |
51 if (document.getElementById("verification_image" + uniqueID + "_" + i)) | |
52 document.getElementById("verification_image" + uniqueID + "_" + i).src = new_url + ";letter=" + i; | |
53 } | |
54 | |
55 return false; | |
56 } | |
57 | |
58 // Request a sound... play it Mr Soundman... | |
59 function playSound(ev) | |
60 { | |
61 if (!ev) | |
62 ev = window.event; | |
63 | |
64 popupFailed = reqWin(imageURL + ";sound", 400, 120); | |
65 // Don't follow the link if the popup worked, which it would have done! | |
66 if (!popupFailed) | |
67 { | |
68 if (is_ie && ev.cancelBubble) | |
69 ev.cancelBubble = true; | |
70 else if (ev.stopPropagation) | |
71 { | |
72 ev.stopPropagation(); | |
73 ev.preventDefault(); | |
74 } | |
75 } | |
76 | |
77 return popupFailed; | |
78 } | |
79 } |