/*
* Is JavaScript Framework
*
* 18:11 2011-6-28 By Zhang Hong
*/ if(!Is) {
//定义命名空间
var Is = {}; //定义插件对象
Is.bin = {
common : {
//公共插件盒子
},
action : {
//行为插件盒子
},
control : {
//控件插件盒子
},
plugins : {
//组件插件盒子
}
}; //定义原型对象
Is.min = function() {
//工具函数
var _$ = function(n, w) {
return typeof n == "string" ? (w || window).document.getElementById(n) : n;
}; var _getElementByStyle = function(n, w) {
return _$(n, w).currentStyle || (w || window).getComputedStyle(_$(n, w), null);
}; var _getElementBySite = function(n, w) {
for(var e = _$(n, w), l = e.scrollLeft, t = e.scrollTop; e && e != (w || window).document.body; e = e.offsetParent) {
l += e.offsetLeft - e.scrollLeft;
t += e.offsetTop - e.scrollTop ;
}
return {
left : l,
top : t
};
}; var _getDocumentByScroll = function(w) {
var w = w || window;
return {
x : w.document.documentElement.scrollLeft || w.document.body.scrollLeft || 0,
y : w.document.documentElement.scrollTop || w.document.body.scrollTop || 0
};
}; var _getDocumentBySize = function(w) {
var w = w || window;
if(w.innerWidth) {
return {
width : w.innerWidth,
height : w.innerHeight
};
}
if(w.document.documentElement.clientWidth) {
return {
width : w.document.documentElement.clientWidth,
height : w.document.documentElement.clientHeight
};
}
if(w.document.body.clientWidth) {
return {
width : w.document.body.clientWidth,
height : w.document.body.clientHeight
};
}
}; var _getBrowserByType = function() {
var u = navigator.userAgent;
var t;
if(t = u.match(/msie ([\d.]+)/i)) {
return {type : 1, version : t[1], depict : "Internet Explorer " + t[1]};
}
if(t = u.match(/firefox\/([\d.]+)/i)) {
return {type : 2, version : t[1], depict : "Firefox " + t[1]};
}
if(t = u.match(/version\/([\d.]+).*safari/i)) {
return {type : 3, version : t[1], depict : "Safari " + t[1]};
}
if(t = u.match(/opera.([\d.]+)/i)) {
return {type : 4, version : t[1], depict : "Opera " + t[1]};
}
if(t = u.match(/chrome\/([\d.]+)/i)) {
return {type : 5, version : t[1], depict : "Chrome " + t[1]};
}
}; var _ergodicSibling = function(n, f, w) {
for(var e = _$(n, w).firstChild, n = e && e.nextSibling; e; e = n, n = e && e.nextSibling) {
if(e.nodeType == 1) {
f(e);
}
}
}; var _ergodicElement = function(n, f, w) {
var e = _$(n, w);
if(e.nodeType == 1) {
f(e);
}
if(e.firstChild) {
for(var n = e.firstChild; n; n = n.nextSibling) {
_ergodicElement(n, f, w);
}
}
}; var _bubbleElement = function(n, f, w) {
for(var e = _$(n, w).target || _$(n, w).srcElement; e; e = e.parentNode) {
if(f(e)) {
return e;
}
}
}; //事件函数
var _attachEvent = function(n, e, w) {
if(document.addEventListener) {
for(var i in e) {
_$(n, w).addEventListener(i, e[i], false);
}
} else if(document.attachEvent) {
for(var i in e) {
_$(n, w).attachEvent("on" + i, e[i]);
}
}
}; var _detachEvent = function(n, e, w) {
if(document.removeEventListener) {
for(var i in e) {
_$(n, w).removeEventListener(i, e[i], false);
}
} else if(document.detachEvent) {
for(var i in e) {
_$(n, w).detachEvent("on" + i, e[i]);
}
}
}; var _cancelBubble = function(e) {
if(e.stopPropagation) {
e.stopPropagation();
} else {
e.cancelBubble = true;
}
}; var _cancelDefault = function(e) {
if(e.preventDefault) {
e.preventDefault();
} else {
e.returnValue = false;
}
}; //工厂函数
var _createElement = function(t, a, c, w) {
var w = w || window;
var e = w.document.createElement(t);
if(a && a.constructor != Object) {
c = a;
a = undefined;
}
if(a) {
for(var i in a) {
switch(i) {
case "style" : {e.style.cssText = a[i]; break}
case "class" : {e.className = a[i]; break}
case "onclick" : {e.onclick = a[i]; break}
case "ondblclick" : {e.ondblclick = a[i]; break}
case "onmouseover" : {e.onmouseover = a[i]; break}
case "onmouseout" : {e.onmouseout = a[i]; break}
case "onmousedown" : {e.onmousedown = a[i]; break}
case "onmouseup" : {e.onmouseup = a[i]; break}
case "onkeypress" : {e.onkeypress = a[i]; break}
case "onkeydown" : {e.onkeydown = a[i]; break}
case "onkeyup" : {e.onkeyup = a[i]; break}
case "onfocus" : {e.onfocus = a[i]; break}
case "onblur" : {e.onblur = a[i]; break}
default : {e.setAttribute(i, a[i], 0)}
}
}
}
if(c) {
if(c.constructor == Array) {
for(var i = 0; i < c.length; i++) {
if(c[i].constructor == String) {
c[i] = w.document.createTextNode(c[i]);
}
e.appendChild(c[i]);
}
} else if(c.constructor == String) {
e.appendChild(w.document.createTextNode(c));
} else {
e.appendChild(c);
}
}
return e;
}; var _createAnimate = function(n, a, c, w) {
c.elapsed = 0;
c.timer = setInterval(function() {
c.elapsed += c.interval;
for(var i in a) {
try {
_$(n, w).style[i] = a[i](c);
} catch(error) {
continue;
}
}
if(c.duration <= c.elapsed) {
clearInterval(c.timer);
if(c.execute) {
c.execute(_$(n, w));
}
}
}, c.interval);
}; var _createRequest = function() {
try {
return new XMLHttpRequest();
} catch(error) {
try {
return new ActiveXObject("Microsoft.XMLHTTP");
} catch(error) {
return new ActiveXObject("Msxml2.XMLHTTP");
}
}
}; //数据函数
var _rewriteAccess = function(a, f) {
if(a.constructor == String) {
var d = {};
var r = /(\w+?)(?:=)([^\s;]+)/g;
while(r.exec(a)) {
d[RegExp.$1] = f && f[RegExp.$1] ? f[RegExp.$1](decodeURIComponent(RegExp.$2)) : decodeURIComponent(RegExp.$2);
}
return d;
}
if(a.constructor == Object) {
var d = "";
for(var i in a) {
d += i + "=" + encodeURIComponent(f && f[i] ? f[i](a[i]) : a[i]) + "; ";
}
return d;
}
}; var _rewriteCookie = function(a, e, p, d, s) {
for(var i in a) {
document.cookie = (i + "=" + encodeURIComponent(a[i])) + (e ? "; expires=" + new Date(new Date().getTime() + e * 1000).toGMTString() + "; max-age=" + e : "") + (p ? "; path=" + p : "") + (d ? "; domain=" + d : "") + (s ? "; secure" : "");
}
}; var _readAllCookie = function() {
return _rewriteAccess(document.cookie);
}; var _enabledCookie = function() {
document.cookie = "enabledCookie=enabledCookie";
return document.cookie.indexOf("enabledCookie=enabledCookie") > -1 ? true : false;
}; //扩展函数
var _common = function(n, p) {
try {
return Is.bin.common[n].call(this, this, p || {});
} catch(error) {
throw new Error("'" + n + "' 插件未注册");
}
}; var _action = function(n, p) {
try {
return Is.bin.action[n].call(this, this, p || {});
} catch(error) {
throw new Error("'" + n + "' 插件未注册");
}
}; var _control = function(n, p) {
try {
return Is.bin.control[n].call(this, this, p || {});
} catch(error) {
throw new Error("'" + n + "' 插件未注册");
}
}; var _plugins = function(n, p) {
try {
return Is.bin.plugins[n].call(this, this, p || {});
} catch(error) {
throw new Error("'" + n + "' 插件未注册");
}
}; //错误处理
var _error = function(d, u, l) {
alert(u +
"\n__________________________________________________" +
"\n" +
"\n行号:" + l +
"\n描述:" + d);
return true;
}; //添加引用:见楼下
};
}
if(!Is) { ... //继楼上:定义原型对象
Is.min = function() {
//添加引用
this.$ = _$ ;
this.getElementByStyle = _getElementByStyle ;
this.getElementBySite = _getElementBySite ;
this.getDocumentByScroll = _getDocumentByScroll ;
this.getDocumentBySize = _getDocumentBySize ;
this.getBrowserByType = _getBrowserByType ;
this.ergodicSibling = _ergodicSibling ;
this.ergodicElement = _ergodicElement ;
this.bubbleElement = _bubbleElement ;
this.attachEvent = _attachEvent ;
this.detachEvent = _detachEvent ;
this.cancelBubble = _cancelBubble ;
this.cancelDefault = _cancelDefault ;
this.createElement = _createElement ;
this.createAnimate = _createAnimate ;
this.createRequest = _createRequest ;
this.rewriteAccess = _rewriteAccess ;
this.rewriteCookie = _rewriteCookie ;
this.readAllCookie = _readAllCookie ;
this.enabledCookie = _enabledCookie ;
this.common = _common ;
this.action = _action ;
this.control = _control ;
this.plugins = _plugins ;
this.error = _error ;
} //定义默认插件
(function() { /**************************************************
* Action Bin Goto
*/
var _bin = function(that, p) {
try {
window.location.href = encodeURI(p);
} catch(error) {
throw new Error("'goto' 插件未知错误");
}
};
Is.bin.action["goto"] = _bin;
Is.bin.action["跳转"] = _bin;
/**************************************************/
/**************************************************
* Action Bin Open
*/
var _bin = function(that, p) {
try {
window.open(encodeURI(p));
} catch(error) {
throw new Error("'open' 插件未知错误");
}
};
Is.bin.action["open"] = _bin;
Is.bin.action["打开"] = _bin;
/**************************************************/
/**************************************************
* Action Bin Request
*
* "Cache-Control" : "no-cache"
* "Content-Type" : "text/html; charset=coding"
* "Content-Type" : "application/x-www-form-urlencoded;"
*/
var _bin = function(that, p/* method, action, header, access, readyState, readyText, readyXML */) {
try {
var r = that.createRequest();
r.open(p.method, encodeURI(p.action));
r.onreadystatechange = function() {
if(r.readyState == 4 && r.status == 200) {
if(p.readyText) {
p.readyText(r.responseText);
}
if(p.readyXML) {
p.readyXML(r.responseXML);
}
} else if(r.readyState == 4) {
if(p.readyState) {
p.readyState(r.status, r.statusText);
}
}
};
for(var i in p.header) {
r.setRequestHeader(i, p.header[i]);
}
r.send(p.access);
} catch(error) {
throw new Error("'request' 插件未知错误");
}
};
Is.bin.action["request"] = _bin;
Is.bin.action["请求"] = _bin;
/**************************************************/
/**************************************************
* Action Bin SelectAll
*/
var _bin = function(that, p/* root, button */) {
try {
var r = that.$(p.root);
var b = that.$(p.button);
var a = r.getAttribute("selectall");
that.ergodicElement(r, function(e) {
if(/input/i.test(e.tagName) && /checkbox/i.test(e.type)) {
e.checked = !a;
}
});
if(b) {
if(/input/i.test(b.tagName) && /checkbox/i.test(b.type)) {
b.checked = !a;
} else {
b.innerHTML = !a ? "取消" + b.innerHTML : b.innerHTML.substring(2);
}
}
if(a) {
r.removeAttribute("selectall");
} else {
r.setAttribute("selectall", "selectall");
}
} catch(error) {
throw new Error("'selectall' 插件未知错误");
}
};
Is.bin.action["selectall"] = _bin;
Is.bin.action["全选"] = _bin;
/**************************************************/
/**************************************************
* Action Bin Drag
*/
var _bin = function(that, p/* event, target, keepLeft, keepTop, display, execute, window */) {
try {
var w = p.window || window;
var t = that.$(p.target, w);
var f = function(event) {
var e = event || w.event;
var $k = e.clientX - $i + $e;
var $l = e.clientY - $j + $f;
if(!p.keepLeft) {
t.style.left = ($k < $a ? $a : $k + $g > $a + $c ? $c + $a - $g : $k) + "px";
}
if(!p.keepTop) {
t.style.top = ($l < $b ? $b : $l + $h > $b + $d ? $d + $b - $h : $l) + "px";
}
if(p.display) {
p.display(t);
}
that.cancelBubble(e);
that.cancelDefault(e);
};
var $a = t.parentNode == w.document.body ? that.getDocumentByScroll(w).x : t.parentNode.scrollLeft;
var $b = t.parentNode == w.document.body ? that.getDocumentByScroll(w).y : t.parentNode.scrollTop ;
var $c = t.parentNode == w.document.body ? that.getDocumentBySize(w).width : parseInt(that.getElementByStyle(t.parentNode, w).width) ;
var $d = t.parentNode == w.document.body ? that.getDocumentBySize(w).height : parseInt(that.getElementByStyle(t.parentNode, w).height);
var $e = t.offsetLeft;
var $f = t.offsetTop ;
var $g = t.offsetWidth ;
var $h = t.offsetHeight;
var $i = p.event.clientX;
var $j = p.event.clientY;
that.attachEvent(w.document, {mousemove : f});
that.attachEvent(w.document, {mouseup : function() {if(p.execute) {p.execute(t)} that.detachEvent(w.document, {mousemove : f})}});
that.attachEvent(t , {mouseup : function() {if(p.execute) {p.execute(t)} that.detachEvent(w.document, {mousemove : f})}});
that.cancelBubble(p.event);
that.cancelDefault(p.event);
} catch(error) {
throw new Error("'drag' 插件未知错误");
}
};
Is.bin.action["drag"] = _bin;
Is.bin.action["拖动"] = _bin;
/**************************************************/
/**************************************************
* Action Bin Zoom
*/
//见楼下……
/**************************************************/
})();
}
/**************************************************
* Action Bin Zoom
*/
var _bin = function(that, p/* event, target, keepCenter, keepRatio, keepWidth, keepHeight, maxWidth, maxHeight, minWidth, minHeight, display, execute, window */) {
try {
var w = p.window || window;
var t = that.$(p.target, w);
var f = function(event) {
var e = event || w.event;
var $s = e.clientX;
var $t = e.clientY;
var $u = p.keepRatio && $m > $n ? ($q == $r ? $o + $t - $p : $o - $t + $p) : $s;
var $v = p.keepRatio && $m <= $n ? ($q == $r ? $p + $s - $o : $p - $s + $o) : $t;
var $w = $k - ($q ? $o - $u : p.keepCenter ? $u - $o : 0);
var $x = $l - ($r ? $p - $v : p.keepCenter ? $v - $p : 0);
var $y = $m + ($q ? $o - $u : $u - $o) * (p.keepCenter ? 2 : 1);
var $z = $n + ($r ? $p - $v : $v - $p) * (p.keepCenter ? 2 : 1);
if(p.keepRatio && ($w < $e || $x < $f || $e + $g < $w + $y || $f + $h < $x + $z || $y < p.minWidth || $z < p.minHeight)) {
return;
}
if(!p.keepWidth && p.minWidth <= $y && $y <= p.maxWidth && $e <= $w && $w + $y <= $e + $g) {
t.style.left = $w + "px";
t.style.width = $y + "px";
}
if(!p.keepHeight && p.minHeight <= $z && $z <= p.maxHeight && $f <= $x && $x + $z <= $f + $h) {
t.style.top = $x + "px";
t.style.height = $z + "px";
}
if(p.display) {
p.display(t);
}
that.cancelBubble(e);
that.cancelDefault(e);
};
var $a = that.getDocumentByScroll(w).x;
var $b = that.getDocumentByScroll(w).y;
var $c = that.getDocumentBySize(w).width ;
var $d = that.getDocumentBySize(w).height;
var $e = t.parentNode == w.document.body ? $a : t.parentNode.scrollLeft;
var $f = t.parentNode == w.document.body ? $b : t.parentNode.scrollTop ;
var $g = t.parentNode == w.document.body ? $c : parseInt(that.getElementByStyle(t.parentNode, w).width) ;
var $h = t.parentNode == w.document.body ? $d : parseInt(that.getElementByStyle(t.parentNode, w).height);
var $i = that.getElementBySite(t, w).left;
var $j = that.getElementBySite(t, w).top ;
var $k = t.offsetLeft;
var $l = t.offsetTop ;
var $m = t.offsetWidth ;
var $n = t.offsetHeight;
var $o = p.event.clientX;
var $p = p.event.clientY;
var $q = $o <= ($i - $a + $m / 2) ? 1 : 0;
var $r = $p <= ($j - $b + $n / 2) ? 1 : 0;
p.maxWidth = p.maxWidth || Infinity;
p.maxHeight = p.maxHeight || Infinity;
p.minWidth = p.minWidth || 50;
p.minHeight = p.minHeight || 50;
that.attachEvent(w.document, {mousemove : f});
that.attachEvent(w.document, {mouseup : function() {that.detachEvent(w.document, {mousemove : f}); if(p.execute) {p.execute(t)}}});
that.attachEvent(t , {mouseup : function() {that.detachEvent(w.document, {mousemove : f}); if(p.execute) {p.execute(t)}}});
that.cancelBubble(p.event);
that.cancelDefault(p.event);
} catch(error) {
throw new Error("'zoom' 插件未知错误");
}
};
Is.bin.action["zoom"] = _bin;
Is.bin.action["缩放"] = _bin;
/**************************************************/
简单使用说明:创建类实例:is = Is.min();
调用实例方法:is.方法名(参数列表);
调用插件:
常用插件 is.common("插件名(中文或英文)", {参数对象});
行为插件 is.action("插件名(中文或英文)", {参数对象});
控件插件 is.control("插件名(中文或英文)", {参数对象});
组件插件 is.plugins("插件名(中文或英文)", {参数对象});自定义插件: var _bin = function(that/* 实例对象 */, p/* 参数对象 */) {
try {
//代码段
} catch(error) {
throw new Error("'插件名' 插件未知错误");
}
};
注册插件
Is.bin.插件盒子["英文插件名"] = _bin;
Is.bin.插件盒子["中文插件名"] = _bin;
上边这里写错了,应该是:is = new Is.min();