日期:2014-05-16 浏览次数:20520 次
/**
* 当id是字符串的时候,根据ID获取指定的元素。否则直接返回id
*/
function $(id){
return typeof id === "string" ? document.getElementById(id) : id;
}
/**
*根据父元素以及指定的节点名称获取节点集合(这里是元素标签的名称)
*oParent:指定父元素,如果未指定,默认为document,oParent || document "或(||)":意思是前面如果不存在或者省略了,则取后面的document,
*elem:节点的名称,比如div,span,p等
* 返回元素集合
* 比如:$$($('aaa'),'span');获取id为aaa下面的span元素集合
*/
function $$(oParent, elem){
return (oParent || document).getElementsByTagName(elem);
}
/**
* 根据父元素以及指定的类名获取节点集合(注意这里是class的名称)
* oParent 父元素,这里调用了上面的方法,其余解释同上
*/
function $$$(oParent, sClass){
var aElem = $$(oParent, '*');
var aClass = [];
var i = 0;
for(i=0;i<aElem.length;i++)if(aElem[i].className == sClass)aClass.push(aElem[i]);
return aClass;
}
/**
* 这里其实就是调用这个Alert类的initialize方法,Alert是一个对象,javascript里面,函数也是对象
* 在prototype里面有的,apply是借用某个方法的意思,
* 也就是说直接执行某个方法,前面是指定当前上下文对象,这里就是本对象,arguments是参数
*/
function Alert(){
this.initialize.apply(this, arguments);
}
/**
* 这里是对象的拷贝而已,将一个对象复制给另一个对象而已,跟jquery版本的extend类似,jquery复杂的多
* 简单点说就是吧source对象里面的属性直接复制给destination对象
* destination:是目标对象
* source:源对象
*
*/
Object.extend = function(destination, source){
for (var property in source) {
destination[property] = source[property];
}
return destination;
};
/**
* 这个就是Alert对象了,里面有initialize方法,自己看吧。其余的应该不要解释了。
*/
Alert.prototype = {
//初始化
initialize : function(obj, frame, onEnd){
if($(obj)){
var _this = this;
this.obj = $(obj);
this.frame = frame;
this.oEve(onEnd);
this.oTitle = this.onEnd.title;
this.oContent = this.onEnd.content;
this.iWidth = this.onEnd.width;
this.iHeight = this.onEnd.height;
this.iTop = this.onEnd.top;
this.iLeft = this.onEnd.left;
this.iFixed = this.onEnd.fixed;
this.iClose = this.onEnd.close;
this.obj.onclick = function(){_this.create(),_this.backg();};
window.onresize = function(){_this.backg();};
}
},
//创建对话框的一些基本元素
create : function(){
//csdn内容限制长度,内容我删除了,你自己对着看...
},
oEve: function(onEnd){
this.onEnd = {};
Object.extend(this.onEnd, onEnd || {});
},
//赋值内容,就是对话框里面的内容
content : function(){
this.conent = $$$(this.tit, 'alert_con')[0];
this.conent == undefined ? this.con.innerHTML = this.oContent : this.conent.innerHTML = this.oContent;
this.oButton = $$(this.tit, 'button');
var i = 0;
var _this = this;
for(i=0;i<this.oButton.length;i++)this.oButton[i].onclick = function(){_this.em.onclick()};
},
//计算宽度
width : function(){
},
//计算对话框高度
height : function(){
if(this.iHeight != ""){
this.oFrame.style.height = parseInt(this.iHeight) +'px';
this.oFrame.style.marginTop = -parseInt(this.iHeight) / 2 +'px';
this.oCon.style.height = parseInt(this.iHeight) - 10 +'px';
this.oAlert_con.style.height = parseInt(this.iHeight) - 40 +'px';
}
},
//计算对话框距离顶部的距离,居中
top : function(){
if(this.iTop != "")this.oFrame.style.top = parseInt(this.iTop) +'px',this.oFrame.style.marginTop = 0;
},
//计算对话框距离左边的距离,居中
left : function(){
if(this.iLeft != "")this.oFrame.style.left = parseInt(this.iLeft) +'px',this.oFrame.style.marginLeft = 0;
},
backg : function(){
this.oScrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight;
this.oScrollWidth = document.documentElement.scrollWidth || document.body.scrollWidth;
this.oBackg.