Server/Code/modifications to main.js

From kJams Wiki
Revision as of 03:48, 4 September 2012 by Deusexmachina (talk | contribs)
Jump to navigation Jump to search

Often times when using kJams Server, the user will miss the "Song Added" alert at the bottom of the window. (Heck, even I just recently noticed it!) As a result, they will mistakenly hit the "Tonight" button over and over, thus adding the song multiple times. To combat this (but not be quite as intrusive as a pop up alert) I made this little code snippet that will make the text bright red and flash it several times to catch the users attention.

To use it, open the file "main.js" (it should be in "~/Libraries/Preferences/kJams/server") and find the "function m_setStatus(status, revert)" code block. Replace it with the text below and save.

function m_setStatus(status, revert) {
	statusObj = document.getElementById("status");
	statusObj.innerHTML = "<span style='color:#FF0000'>" + status + "</span>";
	var newInnerHTML='statusObj.innerHTML = "<span style="color:#FF0000">" + status + "</span>"';
	blink();
	setTimeout("statusObj.innerHTML = newInnerHTML",1250);
}

function blink(){ 
blinkFlag = 1 
blinkCount = 1 
blinkTimer(); 
}

function blinkTimer(){ 
if(blinkFlag==1){
blinkSpeed=250
blinkNumber=10 //If this value is even, the text flashes then remains visible. If it is odd, it flashes, then disappears
blinkFlag=0; 
blinkCount++; 
document.getElementById("status").style.visibility='visible'; 
}else { 
blinkFlag=1; 
blinkCount++; 
document.getElementById("status").style.visibility='hidden'; 
} 
if (blinkCount < blinkNumber) {setTimeout('blinkTimer()', blinkSpeed);} 
} 

In addition, it is very useful to trap the delete key, so that users do not inadvertently go back to the previous page by hitting this key (which, for instance, might take them back to the previous singers page from the login screen after a log out). This would be bad! To do this, you need to make a few mods to the pages. In particular, you need to call the function in your pages. To make it work, paste this into the variable declaration section of your main.js (at the top).

//checks to see if the search field it in focus. If it is, allow the user to use the Delete/Backspace key. Otherwise, set flag to trap it.
var inSearch = {
   on: function() {allowBackspace = true;},
   off: function() {allowBackspace = false;}
}

And then add this somewhere in the function declarations:

function trapDelete() {
	//Checks to see if the key pressed is the Delete/Backspace key, and if so, stop it from getting to the browser.
   var keyID = (window.event) ? event.keyCode : e.keyCode;
   if (keyID==8 && !allowBackspace){
	  return false;
   }
   return true;
}

Then you can just add the following code into the javascript section of your other pages:

	//Bind key press function
	document.onkeyup = m_keyPressed;
	//Prevent browser from seeing the Delete key press
	document.onkeydown=trapDelete;

Alternately, you can just use the entire main.js file from the previous page.

Lastly, it is probably undesirable in a kiosk-type session to allow the person to close the window on your laptops, thus making the machine useless for the next user. To block this, I added the following code:

Add this to the script section of your mainscreen.html file (and any other page you want to stop the user from closing:

    //function triggered by any closing of the current document
    function confirmUnload(){ 
        if(!allowUnload){
            //message displayed (as well as inbuilt IE junk) when page is unloaded.
            return 'Why on earth would you think it is a good idea to close this window?!? Well, it ISN\'T!!! Do NOT close this window. If you do, all hell will rain down upon you, you will cause a micro-singularity to destroy the known universe, and I will get very upset. (At you closing the window, not the destruction of the universe, that can fend for itself.)\n :\'(';
        }
    }

Then add the following lines to the function m_sessionLogout function of your main.js

	// Sets the flag to tell confirmUnload subroutine that it is OK to let the user leave this page (close the Window, etc.)
	allowUnload = true;