1// Bas van der Graaf ([email protected]): 2// Declare getInputElementsByClassName to collect all input fields with a certain classname 3var getInputElementsByClassName = function (c) { 4 var r = new Array(); 5 var j = 0; 6 var o = document.getElementsByTagName('input'); 7 for(i=0;i<o.length;i++) 8 { 9 if(o[i].className == c) { 10 r[j]=o[i];j++; 11 } 12 } 13 return r; 14} 15 16/* This code will grab two mouse coordinate sets from the user's mouse. 17 * The first set is shortly after the user starts moving thier mouse across the web page. 18 * The second set is grabbed a specified time later. The distance between the two sets 19 * is calculated and stored in a form field 20 */ 21 22//tell the browser to start executing the timedMousePos function every x milliseconds 23var myInterval = window.setInterval(timedMousePos,250) 24 25// Variables for mouse positions 26var xPos = -1; 27var yPos = -1; 28var firstX = -1; 29var firstY = -1; 30// variable to track how many times I polled the mouse position 31var intervals = 0; 32 33// retrieve mouse x,y coordinates 34function getMousePos(p) { 35 if (!p) var p = window.event; 36 if (p.pageX || p.pageY) { 37 xPos = p.pageX; 38 yPos = p.pageY; 39 } else if (p.clientX || p.clientY) { 40 xPos = p.clientX + document.body.scrollLeft + document.documentElement.scrollLeft; 41 yPos = p.clientY + document.body.scrollTop + document.documentElement.scrollTop; 42 } 43} 44 45// capture mouse movement 46function timedMousePos() { 47 //when the user moves the mouse, start working 48 document.onmousemove = getMousePos; 49 if (xPos >= 0 && yPos >= 0) { 50 //0,0 is a valid mouse position, so I want to accept that. for this reason 51 //my vars are initialized to -1 52 var newX = xPos; 53 var newY = yPos; 54 intervals++; 55 } 56 if (intervals == 1) { 57 //store the first coordinates when we've got a pair (not when 'intervals' is 0) 58 firstX = xPos; 59 firstY = yPos; 60 } else if (intervals == 2) { 61 //I've got two coordinate sets 62 //tell the browser to stop executing the timedMousePos function 63 clearInterval(myInterval); 64 //send the 4 mouse coordinates to the calcDistance function 65 calcDistance(firstX,firstY,newX,newY); 66 } 67} 68 69function calcDistance(aX,aY,bX,bY) { 70 //use the Euclidean 2 dimensional distance formula to calculate the distance 71 //in pizels between the coordinate sets 72 var mouseTraveled = Math.round(Math.sqrt(Math.pow(aX-bX,2)+Math.pow(aY-bY,2))); 73 //ajax stuff to set a session variable 74 try { 75 // Dave Shuck - 26 Mar 2007 - added try/catch for giant pages that take a while to 76 // load, in case the user moves their mouse before the page is completely rendered. 77 // Bas van der Graaf ([email protected]) 78 // Get all usedKeyboard inputs and set value 79 var elMouseMovement = getInputElementsByClassName('cffp_mm'); 80 for (var i=0;i<elMouseMovement.length;i++) 81 { 82 elMouseMovement[i].value = mouseTraveled 83 } 84 } 85 catch(excpt) { /* no action to take */ } 86} 87 88var keysPressed = 0; 89//capture when a user uses types on their keyboard 90document.onkeypress = logKeys; 91 92function logKeys() { 93 //user hit a key, increment the counter 94 keysPressed++; 95 // Bas van der Graaf ([email protected]) 96 // Get all usedKeyboard inputs and set value 97 var elKeyPressed = getInputElementsByClassName('cffp_kp'); 98 for (var i=0;i<elKeyPressed.length;i++) 99 { 100 elKeyPressed[i].value = keysPressed 101 } 102} 103 104function dummy() {}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.