File: /home/investoo.co.uk/public_html/js/Interface.js
/*
Static Class: Interface
----------------------------------------
Interface is the primary port of call for most scripts.
*/
var Interface = new(function(){
this._listeners = new Array();
this.depth = 1;
this.interval = null;
this._iePngFixPath = 'js/iePngFix.htc';
this.addListener = function(obj){
this._listeners[this._listeners.length] = obj;
}
this.onLoad = function(){
Interface.init();
}
this.init = function(){
// to do this is temporary till moved into its own object
this.fixPng();
for(var i=0; i < this._listeners.length; i++){
if(this._listeners[i].init) this._listeners[i].init();
}
}
this.fixPng = function(){
// we only need this for IE so only worry about addRule
// Make sure we only work on IE 5.5 or 6
if(/MSIE (5\.5|6\.)/.test(navigator.userAgent)){
var css = document.styleSheets[document.styleSheets.length-1];
if(css && css.addRule){
var b = 'behavior: url("' + this._iePngFixPath + '")';
css.addRule('div', b);
css.addRule('img', b);
css.addRule('span', b);
css.addRule('td', b);
}
}
}
this.resize = function(){
// resize the interface cover
for(var i=0; i < this._listeners.length; i++){
if(this._listeners[i].onResize) this._listeners[i].onResize();
}
}
this.onResize = function(){
clearTimeout(this.interval);
this.interval = setTimeout(function(){Interface.resize();}, 500);
}
this.preload = function(){
var args = this.preload.arguments;
document.imageArray = new Array(args.length);
for(var i=0; i<args.length; i++){
document.imageArray[i] = new Image;
document.imageArray[i].src = args[i];
}
}
this.getObjectsByType = function(htmlType, type){
var objects = document.getElementsByTagName(htmlType);
var returnObjects = new Array();
if(objects.length > 0){
for(var i=0; i < objects.length; i++){
if(objects[i].getAttribute('evance-uiobject')){
returnObjects[returnObjects.length] = objects[i];
}
}
}
return returnObjects;
}
this.getNextZIndex = function(){
++this.depth;
return this.depth;
}
this.disableSelect = function(target){
if(typeof target == 'string'){
target = document.getElementById(target);
}
target.onselectstart = function() {
return false;
};
target.unselectable = "on";
target.style.MozUserSelect = "none";
}
this.getElementDimensions = function(Elem){
if(typeof Elem == 'string'){
if(document.getElementById) {
var elem = document.getElementById(Elem);
} else if (document.all){
var elem = document.all[Elem];
}
} else if (typeof Elem == 'object') {
var elem = Elem;
} else {
return false;
}
if ((navigator.userAgent.indexOf("Opera 5")!=-1)
||(navigator.userAgent.indexOf("Opera/5")!=-1)) {
h = elem.style.pixelHeight;
w = elem.style.pixelWidth;
} else {
w = elem.offsetWidth;
h = elem.offsetHeight;
}
elem = null;
return {_width:w, _height:h};
}
this.getElementPosition = function (obj){
if(typeof obj == 'string') obj = document.getElementById(obj);
var left = 0;
var top = 0;
var e = obj;
while (e.offsetParent){
left += e.offsetLeft;
top += e.offsetTop;
e = e.offsetParent;
}
left += e.offsetLeft;
top += e.offsetTop;
return {_x:left, _y:top};
}
});
/*
Mouse Information
----------------------------------------
*/
var Mouse = new ( function () {
this._listeners = new Array();
this._x = 0;
this._y = 0;
this.isDragging = false;
this.move = function(event){
Mouse.onMouseMove(event);
}
this.onMouseMove = function(event){
event = Event.fix(event);
this.getCoords(event);
for(var i=0; i < this._listeners.length; i++){
if(this._listeners[i].onMouseMove) this._listeners[i].onMouseMove(event);
}
}
this.up = function(event){
Mouse.onMouseUp(event);
}
this.onMouseUp = function (event){
event = Event.fix(event);
this.getCoords(event);
for(var i=0; i < this._listeners.length; i++){
if(this._listeners[i].onMouseUp) this._listeners[i].onMouseUp(event);
}
}
this.down = function (event){
Mouse.onMouseDown(event);
}
this.onMouseDown = function (event){
event = Event.fix(event);
this.getCoords(event);
for(var i=0; i < this._listeners.length; i++){
if(this._listeners[i].onMouseDown) this._listeners[i].onMouseDown(event);
}
}
this.addListener = function(obj){
this._listeners[this._listeners.length] = obj;
}
this.getCoords = function(event){
if(event.pageX || event.pageY){
this._x = event.pageX;
this._y = event.pageY;
} else {
this._x = event.clientX + document.body.scrollLeft - document.body.clientLeft,
this._y = event.clientY + document.body.scrollTop - document.body.clientTop
}
}
});
/*
Event Information
----------------------------------------
*/
Event = {
fix : function(event){
if (!event) event = window.event;
if (event.target) {
if (event.target.nodeType == 3) event.target = event.target.parentNode;
} else if (event.srcElement) {
event.target = event.srcElement;
}
return event;
}
}
/*
Setup Browser Event Monitoring
*/
document.onmousemove = Mouse.move;
document.onmouseup = Mouse.up;
document.onmousedown = Mouse.down;
window.onresize = Interface.onResize;
window.onload = Interface.onLoad;