Server/Code/modifications to main.js

From kJams Wiki
Revision as of 02:56, 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.