juristr
4/21/2013 - 2:52 PM

cursorblink.js

function CursorBlink(blinkregion, rate, cursorCh, window){
	this.blinkRegionId = blinkregion;
	this.blinkrate = rate;
	this.cursorChar = cursorCh;
	this.window = window;
}

CursorBlink.prototype.getBlinkRegionId = function(){
	return this.blinkRegionId;
}

CursorBlink.prototype.setBlinkRegionId = function(value){
	this.blinkRegionId = value;
}

CursorBlink.prototype.getBlinkrate = function(){
	return this.blinkrate;
}

CursorBlink.prototype.setBlinkrate = function(value){
	this.blinkrate = value;
}

CursorBlink.prototype.getCursorChar = function(){
	return this.cursorChar;
}

CursorBlink.prototype.setCursorChar = function(value){
	this.cursorChar = value;
}

CursorBlink.prototype.doBlink = function(){
	var cursorEl = document.getElementById(this.blinkRegionId);
	if(cursorEl != null){
		try{
		if(cursorEl.innerHTML == this.cursorChar)
			cursorEl.innerHTML = "";
		else
			cursorEl.innerHTML = this.cursorChar;
		}catch(e){
			//do nothing, this is just for IE not working on 'innerHTML' prop
		}
	}
}

CursorBlink.prototype.write = function(containerId, msg){
	var container = document.getElementById(this.blinkRegionId);
	var chars = msg.split(" ");
	var i=0;
	if(container != null){
		this.window.setInterval(function(){
			container.innerHTML = container.innerHTML + " " + chars[i];
			i = i+1;
		}, 200);
	}
}

CursorBlink.prototype.stopBlinking = function(){
	this.timer = null;
}