项目中写的一些比较常用的javascript通用函数

美化下拉框
var childCreate = false;
function Offset(e) {
	//取标签的绝对位置
	var t = e.offsetTop;
	var l = e.offsetLeft;
	var w = e.offsetWidth;
	var h = e.offsetHeight - 2;
	while ( e = e.offsetParent) {
		t += e.offsetTop;
		l += e.offsetLeft;
	}
	return {
		top : t,
		left : l,
		width : w,
		height : h
	}
}

function loadselect(obj) {
	//第一步:取得select所在的位置
	var offset = Offset(obj);
	//第二步:将真的select隐藏
	obj.style.display = "none";
	//第三步:虚拟一个div出来代替select
	var iDiv = document.createElement("div");
	iDiv.id = "selectof" + obj.name;
	iDiv.style.position = "absolute";
	iDiv.style.width = offset.width + "px";
	iDiv.style.height = offset.height + "px";
	iDiv.style.top = offset.top + 4 + "px";
	iDiv.style.left = offset.left + 4 + "px";
	iDiv.style.background = "url('test.png') no-repeat right -6px";
	iDiv.style.border = "1px solid #ccc";
	iDiv.style.fontSize = "12px";
	iDiv.style.lineHeight = offset.height + "px";
	iDiv.style.textIndent = "4px";
	document.body.appendChild(iDiv);
	//第四步:将select中默认的选项显示出来
	var tValue = obj.options[obj.selectedIndex].innerHTML;
	iDiv.innerHTML = tValue;
	//第五步:模拟鼠标点击
	iDiv.style.background = "url('images/select.jpg') no-repeat right -2px";
	iDiv.onclick = function() {//鼠标点击
		if (document.getElementById("selectchild" + obj.name)) {
			//判断是否创建过div
			if (childCreate) {
				//判断当前的下拉是不是打开状态,如果是打开的就关闭掉。是关闭的就打开。
				document.getElementById("selectchild" + obj.name).style.display = "none";
				childCreate = false;
			} else {
				document.getElementById("selectchild" + obj.name).style.display = "";
				childCreate = true;
			}
		} else {
			//初始一个div放在上一个div下边,当options的替身。
			var cDiv = document.createElement("div");
			cDiv.id = "selectchild" + obj.name;
			cDiv.style.position = "absolute";
			cDiv.style.width = offset.width + "px";
			cDiv.style.height = obj.options.length * 20 + "px";
			cDiv.style.top = (offset.top + offset.height + 2) + 4+"px";
			cDiv.style.left = offset.left + 4+ "px";
			cDiv.style.background = "#f7f7f7";
			cDiv.style.border = "1px solid silver";
			var uUl = document.createElement("ul");
			uUl.id = "uUlchild" + obj.name;
			uUl.style.listStyle = "none";
			uUl.style.margin = "0";
			uUl.style.padding = "0";
			uUl.style.fontSize = "12px";
			cDiv.appendChild(uUl);
			document.body.appendChild(cDiv);
			childCreate = true;
			for (var i = 0; i < obj.options.length; i++) {
				//将原始的select标签中的options添加到li中
				var lLi = document.createElement("li");
				lLi.id = obj.options[i].value;
				lLi.style.textIndent = "4px";
				lLi.style.height = "20px";
				lLi.style.lineHeight = "20px";
				lLi.innerHTML = obj.options[i].innerHTML;
				uUl.appendChild(lLi);
			}
			var liObj = document.getElementById("uUlchild" + obj.name).getElementsByTagName("li");
			for (var j = 0; j < obj.options.length; j++) {
				//为li标签添加鼠标事件
				liObj[j].onmouseover = function() {
					this.style.background = "gray";
					this.style.color = "white";
				}
				liObj[j].onmouseout = function() {
					this.style.background = "white";
					this.style.color = "black";
				}
				liObj[j].onclick = function() {
					//做两件事情,一是将用户选择的保存到原始select标签中,要不做的再好看表单递交后也获取不到select的值了。
					obj.options.length = 0;
					obj.options[0] = new Option(this.innerHTML, this.id);
					//同时我们把下拉的关闭掉。
					document.getElementById("selectchild" + obj.name).style.display = "none";
					childCreate = false;
					iDiv.innerHTML = this.innerHTML;
				}
			}
		}
	}
}
document.body.onload = function (){
	var selects = document.getElementsByTagName("select");
	for(var i = 0 ; i < selects.length;i++){
		loadselect(selects[i]);
	}
}

仿java类实现(持续更新中)
/**
 * Map实现
 */
var Map = function() {
	this.flag = false;
	this.store = new Array();
	if (!this.flag) {
		Map.prototype.entry = function(key, val) {
			this.key = key;
			this.val = val;
		}
		Map.prototype.put = function(key, val) {
			this.store[this.store.length] = new this.entry(key, val);
		}
		Map.prototype.get = function(key) {
			for (var i = this.store.length - 1; i >= 0; i--) {
				if (this.store[i].key === key)
					return this.store[i].val;
			}
			return null;
		}
		Map.prototype.remove = function(key) {
			for (var i = this.store.length - 1; i >= 0; i--) {
				this.store[i].key === key && this.store.splice(i, 1);
			}
		}
		Map.prototype.keySet = function() {
			var keys = new Array();
			for (var i = 0; i <= this.store.length - 1; i++) {
				keys.push(this.store[i].key);
			}
			return keys;
		}
		Map.prototype.valSet = function() {
			var vals = new Array();
			for (var i = 0; i <= this.store.length - 1; i++) {
				vals.push(this.store[i].val);
			}
			return vals;
		}
		Map.prototype.clear = function() {
			this.store.length = 0;
		}
		Map.prototype.size = function() {
			return this.store.length;
		}
		this.flag = true;
	}
}
/**
 * StringBuilder实现
 */
var StringBuilder = function() {
	this.vStrings = new Array();
	this.flag = false;
	if (!this.flag) {
		StringBuilder.prototype.append = function(str) {
			this.vStrings.push(str);
		}
		StringBuilder.prototype.toString = function() {
			return this.vStrings.join("");
		}
		StringBuilder.prototype.charAt = function(index) {
			return this.toString().charAt(index);
		}
		StringBuilder.prototype.clear = function() {
			this.vStrings.length = 0;
		}
		StringBuilder.prototype.Delete = function(start, end) {
			var tempString = this.toString();
			var prevString = tempString.substring(0, start);
			var nextString = end ? tempString.substring(end) : tempString.substring(start + 1);
			this.clear();
			this.append(prevString);
			this.append(nextString);
		}
		StringBuilder.prototype.length = function() {
			return this.toString().length;
		}
		StringBuilder.prototype.substring = function(start, end) {
			return this.toString().substring(start, end);
		}
		StringBuilder.prototype.replace = function(oldStr, newStr) {
			var newStr = newStr ? newStr : "";
			var tempString = this.toString().replace(new RegExp(oldStr, "g"), newStr);
			this.clear();
			this.append(tempString);
		}
		StringBuilder.prototype.indexOf = function(val) {
			return this.toString().indexOf(val);
		}
		StringBuilder.prototype.lastIndexOf = function(val) {
			return this.toString().lastIndexOf(val);
		}
		StringBuilder.prototype.insert = function(offset, str) {
			var prevString = this.substring(0, offset);
			var middleString = str;
			var nextString = this.substring(offset);
			this.clear();
			this.append(prevString);
			this.append(middleString);
			this.append(nextString);
		}
		StringBuilder.prototype.split = function(sep) {
			return this.toString().split(sep);
		}
		this.flag = true;
	}
}


为类库对象加入新方法
/**
 * @author wsf
 */
 /**
  * 判断是否为数字型数据
  */
 if (!Object.prototype.isNumber) {
	 String.prototype.isNumber = function() {
		 return !this || isNuN(this.val()) ? false : (typeof this.val() === "number");
	 }
 }
 /**
  * 为数组添加remove方法
  */
 if (!Array.prototype.remove) {
	 Array.prototype.remove = function(s) {
		 for (var i = this.length; i >= 0; i--) {
			 if (s === this[i])
				 this.splice(i, 1);
		 }
	 }
 }
/**
 * 为数组添加push方法
 */
if (!Array.prototype.push) {
	 Array.prototype.push = function() {
		 var B = this.length;
		 for (var A = 0; A < arguments.length; A++) {
			 this[B + A] = arguments[A]
		 }
		 return this.length
	 }
}
 /**
  * 为数组添加indexOf方法
  */
 if (!Array.prototype.indexOf) {
	 Array.prototype.indexOf = function(o) {
		 for (var i = this.length; i >= 0; i--) {
			 if (this[i] === o)
				 return i;
		 }
		 return -1;
	 }
 }
 /**
  * 为数组添加contain方法
  */
 if (!Array.prototype.contain) {
	 Array.prototype.contain = function(o) {
		 var validx = this.indexOf(o)//拿到索引
		 return validx > 0;
	 }
 }
 /**
  * 为数组添加put方法(添加的到指定下标位置)
  */
 if (!Array.prototype.put) {
	 Array.prototype.put = function(o, idx) {
		 return this.splice(idx, 0, o);
	 }
 }
/**
 * 为字符对象添加intVal方法
 */
if (!String.prototype.intVal) {
	String.prototype.intVal = function() {
		return parseInt(this);
	}
}
/**
 * 为字符对象添加doubleVal方法
 */
if (!String.prototype.floatVal) {
	String.prototype.floatVal = function() {
		return parseFloat(this);
	}
}
/**
 * 为String添加trim方法
 */
if(!String.prototype.trim){
	String.prototype.trim = function (){
		this.replace(/\s*|\s$/g,"");
	}
}

分页

/**
* 创建实例的的方法
* @param {Object} Class
* @param {Object} params
*/
var newObj = function (Class,params){
	function _new (){
		if(Class._new){
			Class._new.call(this,params);//改变this指向
		}
	}
	_new.prototype = Class;
	return new _new();
}

/**
* page对象
*/
var page = {
	/**
	 * 构造函数
	 * @param {Object} pageSize :一页显示多少条
	 * @param {Object} dataTotalCount :总共数据条数
	 * @param {Object} mode : 分页模式 (1:不显示页数,只显示上一页下一页;2:待续);
	 * @param {Object} pageItem :一页显示多少条目页
	 * @param {Object} pageContainer :容器
	 * @param {Function} selfReqFun : 自定义请求函数
	 */
	_new : function(options){
		var pageItem = options.pageItem;
		var pageContainer = options.pageContainer;
		var selfReqFun = options.selfReqFun;
		/**
		 * 初始化page属性
		 */
		this.pageNo = options.pageNo;
		this.pageSize = options.pageSize;
		this.dataTotalCount = options.dataTotalCount;
		this.mode = options.mode;
		this.pageItem = pageItem == ""||pageItem == null ? this.mode = 1 : pageItem;
		this.pageContainer = pageContainer == "" || pageContainer == null ? (function (){
			var container = document.createElement("div");
				container.id = "pages";
				container.style.textAlign = "center";
				container.align = "center";
			document.getElementsByTagName("body")[0].appendChild(container);
			return container;
		})() : pageContainer;
		this.pageCount = Math.ceil(this.dataTotalCount/this.pageSize);
		this.selfReqFun = selfReqFun == null ? function(){} : selfReqFun;
		this.itemStyle = options.itemStyle;
		this.selfArgs = options.selfArgs;
	},
	/**
	 * 注册事件
	 * @param {Object} target
	 * @param {Object} eventName
	 * @param {Object} handler
	 * @param {Object} args
	 */
	attachEvent : function  (target,eventName,handler,args){
		var eventHandler = handler;
		if(args){
			eventHandler = function(e){
				handler.call(args,e);
			}
		}
	    if(window.attachEvent){
	        target.attachEvent("on" + eventName, eventHandler );   
		} else{
	        target.addEventListener(eventName, eventHandler, true); 
		}   
	},
	/**
	 * 检查pageNo是否合法
	 * @param {Object} pageNo
	 */
	checkPageNo : function(pageNo){
		 if(pageNo == ""  || pageNo == null || pageNo < 1) pageNo = 1;
		 if(pageNo > this.pageCount)pageNo = this.pageCount;
		 return pageNo;
	},
	/**
	 * 创建分页条目
	 * @param {Object} pageNo
	 */
	createPageTab : function(){
		var flag = false;
		//动态添加属性
		this.pageNo = this.checkPageNo(arguments[0]||1);
		var html = '';
		if(this.mode == 1){
				html += '<span title="首页" class="firstPage pageSpan reqSpan" id="first"><<</span>';
				html += '<span title="上一页" class="prevPage pageSpan reqSpan" id="prev">&nbsp;&nbsp;<&nbsp;</span>';
				html += '<span class="pageNo" id = '+this.pageNo+'>'+this.pageNo+'/'+this.pageCount+'</span>';
				html += '<span title="下一页" class="nextPage pageSpan reqSpan" id="next">&nbsp;>&nbsp;&nbsp;</span>';
				html += '<span title="末页" class="lastPage pageSpan reqSpan" id="last">>></span>';
		}
		this.pageContainer.innerHTML = html;
		if(this.itemStyle){
			var itemStyle = this.itemStyle;
			for(var i in itemStyle){
				//判断对象是否为空
				flag = true;
			}
			if (flag) {
				var first = document.getElementById("first");
				var prev  = document.getElementById("prev");
				var next = document.getElementById("next");
				var last = document.getElementById("last");
				first.innerHTML = "<img src="+ itemStyle.firstImg +" style='width:14px;height:14px;cursor:pointer;vertical-align:middle;'/>";
				prev.innerHTML = "<img src="+ itemStyle.prevImg +" style='width:14px;height:14px;cursor:pointer;vertical-align:middle;'/>"
				next.innerHTML = "<img src="+ itemStyle.nextImg +" style='width:14px;height:14px;cursor:pointer;vertical-align:middle;'/>"
				last.innerHTML = "<img src="+ itemStyle.lastImg +" style='width:14px;height:14px;cursor:pointer;vertical-align:middle;'/>"
			}
				
		}
		/**
		 * 注册点击事件
		 */
	   var reqSpans = this.pageContainer.getElementsByTagName("span");
	   for(var j = 0 ; j < reqSpans.length ; j++){
	   		var _this = reqSpans[j];
			_this.style.cursor="pointer";
	   		if((_this.className || _this.getAttribute("class")).indexOf("reqSpan") > 0){
				this.attachEvent(_this,"click",this.requestEvent,this);
			}
	   }
	   //this.selfReqFun(this.pageNo);
	},
	/**
	 * 请求函数
	 * @param {Object} pageNo
	 * @param {Object} id
	 */
	requestEvent : function(e){
		var target = e.srcElement || e.target;
		if(target.nodeName.toLowerCase() === "img"){
			target = target.parentNode;
		}
		var id = target.id;
		var pageNo = this.pageNo
		pageNo = (id === "first")? 1 :
		(id === "prev" && pageNo >= 1) ? this.checkPageNo(pageNo-1):
		(id === "next" && pageNo <= this.pageCount) ? this.checkPageNo(pageNo+1):
		(id === "last")? this.pageCount : 1;
		this.selfReqFun(pageNo);
	}				
}		



自定义弹出框
/**
 * 选择器
 * @return {}
 */
function G() {
	var C = new Array();
	for (var B = 0; B < arguments.length; B++) {
		var A = arguments[B];
		if ( typeof A == "string") {
			A = document.getElementById(A)
		}
		if (arguments.length == 1) {
			return A
		}
		C.push(A)
	}
	return C
}
/**
 * 为函数对象添加bind方法
 * @param {} B
 * @return {}
 */
Function.prototype.bind = function(B) {
	var A = this;
	return function() {
		A.apply(B, arguments)
	}
};
/**
 * @param {} B
 * @return {}
 */
Function.prototype.bindAsEventListener = function(B) {
	var A = this;
	return function(C) {
		A.call(B, C || window.event)
	}
};
/**
 * javascript继承机制
 * @param {} A
 * @param {} B
 * @return {}
 */
Object.extend = function(A, B) {
	for (property in B) {
		A[property] = B[property]
	}
	return A
};
/**
 *自定义event对象 
 */
if (!window.Event) {
	var Event = new Object()
}
Object.extend(Event, {
	observers : false,
	element : function(A) {
		return A.target || A.srcElement
	},
	isLeftClick : function(A) {
		return (((A.which) && (A.which == 1)) || ((A.button) && (A.button == 1)))
	},
	pointerX : function(A) {
		return A.pageX || (A.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft))
	},
	pointerY : function(A) {
		return A.pageY || (A.clientY + (document.documentElement.scrollTop || document.body.scrollTop))
	},
	stop : function(A) {
		if (A.preventDefault) {
			A.preventDefault();
			A.stopPropagation()
		} else {
			A.returnValue = false;
			A.cancelBubble = true
		}
	},
	findElement : function(C, B) {
		var A = Event.element(C);
		while (A.parentNode && (!A.tagName || (A.tagName.toUpperCase() != B.toUpperCase()))) {
			A = A.parentNode
		}
		return A
	},
	_observeAndCache : function(D, C, B, A) {
		if (!this.observers) {
			this.observers = []
		}
		if (D.addEventListener) {
			this.observers.push([D, C, B, A]);
			D.addEventListener(C, B, A)
		} else {
			if (D.attachEvent) {
				this.observers.push([D, C, B, A]);
				D.attachEvent("on" + C, B)
			}
		}
	},
	unloadCache : function() {
		if (!Event.observers) {
			return
		}
		for (var A = 0; A < Event.observers.length; A++) {
			Event.stopObserving.apply(this, Event.observers[A]);
			Event.observers[A][0] = null
		}
		Event.observers = false
	},
	observe : function(D, C, B, A) {
		var D = G(D);
		A = A || false;
		if (C == "keypress" && (navigator.appVersion.match(/Konqueror|Safari|KHTML/) || D.attachEvent)) {
			C = "keydown"
		}
		this._observeAndCache(D, C, B, A)
	},
	stopObserving : function(D, C, B, A) {
		var D = G(D);
		A = A || false;
		if (C == "keypress" && (navigator.appVersion.match(/Konqueror|Safari|KHTML/) || D.detachEvent)) {
			C = "keydown"
		}
		if (D.removeEventListener) {
			D.removeEventListener(C, B, A)
		} else {
			if (D.detachEvent) {
				D.detachEvent("on" + C, B)
			}
		}
	}
});
Event.observe(window, "unload", Event.unloadCache, false);
var Class = function() {
	var A = function() {
		this.initialize.apply(this, arguments)
	};
	for ( i = 0; i < arguments.length; i++) {
		superClass = arguments[i];
		for (member in superClass.prototype) {
			A.prototype[member] = superClass.prototype[member]
		}
	}
	A.child = function() {
		return new Class(this)
	};
	A.extend = function(B) {
		for (property in B) {
			A.prototype[property] = B[property]
		}
	};
	return A
};
var Popup = new Class();
Popup.prototype = {
	iframeIdName : "ifr_popup",
	initialize : function(A) {
		this.config = Object.extend({
			contentType : 1,
			isHaveTitle : true,
			scrollType : "no",
			isBackgroundCanClick : false,
			isSupportDraging : true,
			isShowShadow : true,
			isReloadOnClose : true,
			width : 400,
			isPop : false,
			height : 300
		}, A || {});
		this.info = {
			shadowWidth : 4,
			title : "",
			contentUrl : "",
			contentHtml : "",
			callBack : null,
			parameter : null,
			confirmCon : "",
			alertCon : "",
			someHiddenTag : "select,object,embed",
			someDisabledBtn : "",
			someHiddenEle : "",
			overlay : 0,
			coverOpacity : 40
		};
		this.color = {
			cColor : "#EEEEEE",
			bColor : "#FFFFFF",
			tColor : "#709CD2",
			wColor : "#FFFFFF"
		};
		this.dropClass = null;
		this.someToHidden = [];
		this.someToDisabled = [];
		if (!this.config.isHaveTitle) {
			this.config.isSupportDraging = false
		}
		this.iniBuild()
	},
	setContent : function(A, B) {
		if (B != "") {
			switch(A) {
				case"width":
					this.config.width = B;
					break;
				case"height":
					this.config.height = B;
					break;
				case"title":
					this.info.title = B;
					break;
				case"contentUrl":
					this.info.contentUrl = B;
					break;
				case"contentHtml":
					this.info.contentHtml = B;
					break;
				case"callBack":
					this.info.callBack = B;
					break;
				case"parameter":
					this.info.parameter = B;
					break;
				case"confirmCon":
					this.info.confirmCon = B;
					break;
				case"alertCon":
					this.info.alertCon = B;
					break;
				case"someHiddenTag":
					this.info.someHiddenTag = B;
					break;
				case"someHiddenEle":
					this.info.someHiddenEle = B;
					break;
				case"someDisabledBtn":
					this.info.someDisabledBtn = B;
					break;
				case"overlay":
					this.info.overlay = B
			}
		}
	},
	iniBuild : function() {
		G("dialogCase") ? G("dialogCase").parentNode.removeChild(G("dialogCase")) : function() {
		};
		var A = document.createElement("span");
		A.id = "dialogCase";
		document.body.insertBefore(A, document.body.firstChild)
	},
	build : function() {
		var A = 10001 + this.info.overlay * 10;
		var B = A + 2;
		this.iframeIdName = "ifr_popup" + this.info.overlay;
		var D = "images/close.gif";
		var F = '<input type="image" id="dialogBoxClose" src="' + D + '" border="0" width="10" height="16" align="absmiddle" title="关闭"/>';
		var H = "filter: alpha(opacity=" + this.info.coverOpacity + ");opacity:" + this.info.coverOpacity / 100 + ";";
		var C = '<div id="dialogBoxBG" style="position:absolute;top:0px;left:0px;width:100%;height:' + document.body.scrollHeight + "px;z-index:" + A + ";" + H + "background-color:" + this.color.cColor + ';display:none;"></div>';
		var E = '<div id="dialogBox" style="border:1px solid ' + this.color.tColor + ";display:none;z-index:" + B + ";position:relative;width:" + this.config.width + 'px;"><table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="' + this.color.bColor + '">';
		if (this.config.isHaveTitle) {
			E += '<tr height="24" bgcolor="' + this.color.tColor + '"><td><table style="-moz-user-select:none;height:24px;" width="100%" border="0" cellpadding="0" cellspacing="0" ><tr><td width="6" height="24"></td><td id="dialogBoxTitle" style="color:' + this.color.wColor + ';font-size:14px;font-weight:bold;">' + this.info.title + '&nbsp;</td><td id="dialogClose" width="20" align="right" valign="middle">' + F + '</td><td width="6"></td></tr></table></td></tr>'
		} else {
			E += '<tr height="10"><td align="right">' + F + "</td></tr>"
		}
		E += '<tr style="height:' + this.config.height + 'px" valign="top"><td id="dialogBody" style="position:relative;"></td></tr></table></div><div id="dialogBoxShadow" style="display:none;z-index:' + A + ';"></div>';
		if (!this.config.isBackgroundCanClick) {
			G("dialogCase").innerHTML = C + E;
			G("dialogBoxBG").style.height = document.body.scrollHeight
		} else {
			G("dialogCase").innerHTML = E
		}
		Event.observe(G("dialogBoxClose"), "click", this.reset.bindAsEventListener(this), false);
		if (this.config.isSupportDraging) {
			dropClass = new Dragdrop(this.config.width, this.config.height, this.info.shadowWidth, this.config.isSupportDraging, this.config.contentType);
			G("dialogBoxTitle").style.cursor = "move"
		}
		this.lastBuild()
	},
	lastBuild : function() {
		var B = '<div style="width:100%;height:100%;text-align:center;"><div style="margin:20px 20px 0 20px;font-size:14px;line-height:16px;color:#000000;">' + this.info.confirmCon + '</div><div style="margin:20px;"><input id="dialogOk" type="button" value="  确定  "/>&nbsp;<input id="dialogCancel" type="button" value="  取消  "/></div></div>';
		var E = '<div style="width:100%;height:100%;text-align:center;"><div style="margin:20px 20px 0 20px;font-size:14px;line-height:16px;color:#000000;">' + this.info.alertCon + '</div><div style="margin:20px;"><input id="dialogYES" type="button" value="  确定  "/></div></div>';
		var A = 10001 + this.info.overlay * 10;
		var D = A + 4;
		if (this.config.contentType == 1) {
			var C = "<iframe width='100%' style='height:" + this.config.height + "px' name='" + this.iframeIdName + "' id='" + this.iframeIdName + "' src='" + this.info.contentUrl + "' frameborder='0' scrolling='" + this.config.scrollType + "'></iframe>";
			var F = "<div id='iframeBG' style='position:absolute;top:0px;left:0px;width:1px;height:1px;z-index:" + D + ";filter: alpha(opacity=00);opacity:0.00;background-color:#ffffff;'><div>";
			G("dialogBody").innerHTML = C + F
		} else {
			if (this.config.contentType == 2) {
				G("dialogBody").innerHTML = this.info.contentHtml
			} else {
				if (this.config.contentType == 3) {
					G("dialogBody").innerHTML = B;
					Event.observe(G("dialogOk"), "click", this.forCallback.bindAsEventListener(this), false);
					Event.observe(G("dialogCancel"), "click", this.close.bindAsEventListener(this), false)
				} else {
					if (this.config.contentType == 4) {
						G("dialogBody").innerHTML = E;
						Event.observe(G("dialogYES"), "click", this.close.bindAsEventListener(this), false)
					}
				}
			}
		}
	},
	reBuild : function() {
		G("dialogBody").height = G("dialogBody").clientHeight;
		this.lastBuild()
	},
	show : function() {
		this.hiddenSome();
		this.middle();
		if (this.config.isShowShadow) {
			this.shadow()
		}
	},
	forCallback : function() {
		return this.info.callBack(this.info.parameter)
	},
	shadow : function() {
		var A = G("dialogBoxShadow");
		var B = G("dialogBox");
		A.style["position"] = "absolute";
		A.style["background"] = "#000";
		A.style["display"] = "";
		A.style["opacity"] = "0.2";
		A.style["filter"] = "alpha(opacity=20)";
		A.style["top"] = B.offsetTop + this.info.shadowWidth;
		A.style["left"] = B.offsetLeft + this.info.shadowWidth;
		A.style["width"] = B.offsetWidth;
		A.style["height"] = B.offsetHeight
	},
	middle : function() {
		if (!this.config.isBackgroundCanClick) {
			G("dialogBoxBG").style.display = ""
		}
		var F = G("dialogBox");
		F.style["position"] = "absolute";
		F.style["display"] = "";
		var C = (document.documentElement.clientWidth || document.body.clientWidth);
		var E = (document.documentElement.clientHeight || document.body.clientHeight);
		var B = (document.documentElement.scrollTop || document.body.scrollTop);
		var D = (C / 2) - (F.offsetWidth / 2);
		var H = -80 + (E / 2 + B) - (F.offsetHeight / 2);
		var A = H > 0 ? H : (E / 2 + B) - (F.offsetHeight / 2);
		if (A < 1) {
			A = "20"
		}
		if (D < 1) {
			D = "20"
		}
		F.style["left"] = D + "px";
		F.style["top"] = A + "px"
	},
	reset : function() {
		this.close();
		if (this.config.isReloadOnClose) {
			top.location.reload()
		}
	},
	close : function() {
		G("dialogBox").style.display = "none";
		if (!this.config.isBackgroundCanClick) {
			G("dialogBoxBG").style.display = "none"
		}
		if (this.config.isShowShadow) {
			G("dialogBoxShadow").style.display = "none"
		}
		G("dialogBody").innerHTML = "";
		this.showSome()
	},
	hiddenSome : function() {
		var A = this.info.someHiddenTag.split(",");
		if (A.length == 1 && A[0] == "") {
			A.length = 0
		}
		for (var B = 0; B < A.length; B++) {
			this.hiddenTag(A[B])
		}
		var C = this.info.someHiddenEle.split(",");
		if (C.length == 1 && C[0] == "") {
			C.length = 0
		}
		for (var B = 0; B < C.length; B++) {
			this.hiddenEle(C[B])
		}
		var C = this.info.someDisabledBtn.split(",");
		if (C.length == 1 && C[0] == "") {
			C.length = 0
		}
		for (var B = 0; B < C.length; B++) {
			this.disabledBtn(C[B])
		}
	},
	disabledBtn : function(B) {
		var A = document.getElementById(B);
		if ( typeof (A) != "undefined" && A != null && A.disabled == false) {
			A.disabled = true;
			this.someToDisabled.push(A)
		}
	},
	hiddenTag : function(B) {
		var C = document.getElementsByTagName(B);
		if (C != null) {
			for (var A = 0; A < C.length; A++) {
				if (C[A].style.display != "none" && C[A].style.visibility != "hidden") {
					C[A].style.visibility = "hidden";
					this.someToHidden.push(C[A])
				}
			}
		}
	},
	hiddenEle : function(B) {
		var A = document.getElementById(B);
		if ( typeof (A) != "undefined" && A != null) {
			A.style.visibility = "hidden";
			this.someToHidden.push(A)
		}
	},
	showSome : function() {
		for (var A = 0; A < this.someToHidden.length; A++) {
			this.someToHidden[A].style.visibility = "visible"
		}
		for (var A = 0; A < this.someToDisabled.length; A++) {
			this.someToDisabled[A].disabled = false
		}
	}
};
var Dragdrop = new Class();
Dragdrop.prototype = {
	initialize : function(C, B, A, D, E) {
		this.dragData = null;
		this.dragDataIn = null;
		this.backData = null;
		this.width = C;
		this.height = B;
		this.shadowWidth = A;
		this.showShadow = D;
		this.contentType = E;
		this.IsDraging = false;
		this.oObj = G("dialogBox");
		Event.observe(G("dialogBoxTitle"), "mousedown", this.moveStart.bindAsEventListener(this), false)
	},
	moveStart : function(A) {
		this.IsDraging = true;
		if (this.contentType == 1) {
			G("iframeBG").style.display = "";
			G("iframeBG").style.width = this.width + "px";
			G("iframeBG").style.height = this.height + "px"
		}
		Event.observe(document, "mousemove", this.mousemove.bindAsEventListener(this), false);
		Event.observe(document, "mouseup", this.mouseup.bindAsEventListener(this), false);
		Event.observe(document, "selectstart", this.returnFalse, false);
		this.dragData = {
			x : Event.pointerX(A),
			y : Event.pointerY(A)
		};
		this.backData = {
			x : parseInt(this.oObj.style.left),
			y : parseInt(this.oObj.style.top)
		}
	},
	mousemove : function(A) {
		if (!this.IsDraging) {
			return
		}
		var C = Event.pointerX(A) - this.dragData.x + parseInt(this.oObj.style.left);
		var B = Event.pointerY(A) - this.dragData.y + parseInt(this.oObj.style.top);
		if (this.dragData.y < parseInt(this.oObj.style.top)) {
			B = B - 12
		} else {
			if (this.dragData.y > parseInt(this.oObj.style.top) + 25) {
				B = B + 12
			}
		}
		this.oObj.style.left = C + "px";
		this.oObj.style.top = B + "px";
		if (this.showShadow) {
			G("dialogBoxShadow").style.left = C + this.shadowWidth + "px";
			G("dialogBoxShadow").style.top = B + this.shadowWidth + "px"
		}
		this.dragData = {
			x : Event.pointerX(A),
			y : Event.pointerY(A)
		};
		document.body.style.cursor = "move"
	},
	mouseup : function(C) {
		if (!this.IsDraging) {
			return
		}
		if (this.contentType == 1) {
			G("iframeBG").style.display = "none"
		}
		document.onmousemove = null;
		document.onmouseup = null;
		var B = Event.pointerX(C) - (document.documentElement.scrollLeft || document.body.scrollLeft);
		var A = Event.pointerY(C) - (document.documentElement.scrollTop || document.body.scrollTop);
		if (B < 1 || A < 1 || B > document.body.clientWidth || A > document.body.clientHeight) {
			this.oObj.style.left = this.backData.x + "px";
			this.oObj.style.top = this.backData.y + "px";
			if (this.showShadow) {
				G("dialogBoxShadow").style.left = this.backData.x + this.shadowWidth + "px";
				G("dialogBoxShadow").style.top = this.backData.y + this.shadowWidth + "px"
			}
		}
		this.IsDraging = false;
		document.body.style.cursor = "";
		Event.stopObserving(window, "selectstart", this.returnFalse, false)
	},
	returnFalse : function() {
		return false
	}
};
/**
 *弹出iframe 
 * @param {Object} iframesrc
 * @param {Object} title
 */
function showIframe(iframesrc,title) {
	var pop = new Popup({
		contentType : 1,
		isReloadOnClose : false,
		width : 800,
		height : 400
	});
	pop.setContent("contentUrl", iframesrc);
	pop.setContent("title", title);
	pop.build();
	pop.show();
}
/**
 *弹出iframe 
 * @param {Object} iframesrc
 * @param {Object} title
 */
function showIframe2(iframesrc,title) {
	var pop = new Popup({
		contentType : 1,
		isReloadOnClose : false,
		width : 800,
		height : 510
	});
	pop.setContent("contentUrl", iframesrc);
	pop.setContent("title", title);
	pop.build();
	pop.show();
}
/**
 *关闭当前弹出窗口 
 */
function closeCurrentPop(type){
	var closeBtn;
	if(type){
		closeBtn = window.parent.document.getElementById("dialogBoxClose");
	}else{
		closeBtn = document.getElementById("dialogBoxClose")
	}
	closeBtn.click();
}
/**
 * 弹出alert框
 * @param {} msg
 */
function showAlert(msg){
	var pop = new Popup({
		contentType : 2,
		isReloadOnClose : false,
		width : 200,
		height : 60
	});
	pop.setContent("contentHtml", "<p style='text-align:center;font-size:12px;padding-top:15px;'>"+msg+"</p>");
	pop.setContent("title", "");
	pop.build();
	pop.show();
	setTimeout("closeCurrentPop(0)",1000); 
}
/**
 * 弹出confirm框
 */
function showConfirm(msg){
	var builder = new StringBuilder();
	builder.append('<div style="text-align:center;font-size:12px;padding-top:15px;">');
	builder.append(msg);
	builder.append('<p id="buttons" style="margin-top:40px;">');
	builder.append('<input type="button" hidefocus onclick="con()" id="confirm" value="确认"  style="float:left;margin-left:10px;border:1px solid grey;cursor:pointer;background-color:#709CD2;"/>');
	builder.append('<input type="button" hidefocus onclick="can()" id="cancel" value="取消"  style="margin-left:90px;border:1px solid grey;cursor:pointer;background-color:#709CD2;"/>');
	builder.append('</p>');
	builder.append('</div>');
	var pop = new Popup({
		contentType : 2,
		isReloadOnClose : false,
		width : 200,
		height : 100
	});
	pop.setContent("contentHtml", builder.toString());
	pop.setContent("title", "");
	pop.build();
	pop.show();
}
/**
 * 确认
 */
function confirm(){
	closeCurrentPop(0);
	return true;
}
/**
 * 取消
 */
function cancel(){
	closeCurrentPop(0);
	return false;
}

 

你可能感兴趣的:(JavaScript)