/*
源码作者: 石不易(Louis Shi)
联系方式: http://www.shibuyi.net
===================================================================================================
程序名称: JavaScript 封装库 BETA 1.0 版
迭代版本: Prototype
功能总数: 44 个
新增总数: 30 个
删除总数: 0 个
追加功能:
1. 元素隐藏与显示
2. 表单 value 属性获取
3. 实现 mouseover / mouseout / mousemove / mousedown / mouseup / scroll / resize / load / mousewheel 等事件
4. 实现 元素居中 / 下拉菜单 / 元素拖拽 / 遮罩锁屏 / 禁止溢出 等特效
...
优化功能:
1. 实现元素节点直传
2. 完善 id 多节点获取
3. 完善 css 设置, 支持滤镜
4. 完善 class 选择器, 支持多选择器添加和移除
5. 完善 rule 样式规则, 支持多规则的添加和移除
6. 实现二级子方法
7. 实现代码分层至 Tool 工具库
...
删除功能:

*/ // 实例化封装库
function $(_this) {
return new Base(_this);
} // 封装库构造方法
function Base(_this) {
this.elements = []; // 初始化元素列表
if (typeof _this == 'object') this.elements.push(_this);
} // 获取元素节点
Base.prototype.getNodes = function () {
if (this.elements.length == 0) return '暂无任何元素节点';
if (this.elements.length == 1) return this.elements[0];
return this.elements;
}; // 获取 id 元素节点
Base.prototype.getId = function (id) {
if (id instanceof Array) { // 集群
for (var i = 0; i < id.length; i ++) {
this.getId(id[i]);
}
} else { // 单个
var node = {};
node = document.getElementById(id);
if (!node) return this;
for (var i = 0; i < this.elements.length; i ++) {
if (this.elements[i] == node) return this;
}
this.elements.push(node);
}
return this;
}; // 获取 name 元素节点
Base.prototype.getName = function (name, positionId) {
var nodes = {};
if (typeof positionId != 'undefined') { // 局部
nodes = $().getTagName('*', positionId).getNodes();
} else { // 全局
nodes = document.getElementsByName(name);
}
for (var i = 0; i < nodes.length; i ++) {
if (nodes[i].name == name) this.elements.push(nodes[i]);
}
return this;
}; // 获取 tagName 元素节点
Base.prototype.getTagName = function (tagName, positionId) {
var nodes = {};
if (typeof positionId != 'undefined') { // 局部
nodes = $().getId(positionId).getNodes().getElementsByTagName(tagName);
} else { // 全局
nodes = document.getElementsByTagName(tagName);
}
for (var i = 0; i < nodes.length; i ++) {
this.elements.push(nodes[i]);
}
return this;
}; // 获取 class 元素节点
Base.prototype.getClass = function (className, positionId) {
var nodes = {}, results = [];
if (typeof positionId != 'undefined') { // 局部
nodes = $().getTagName('*', positionId);
results = $().getClass.hasClass.call(nodes, className);
} else { // 全局
nodes = $().getTagName('*');
results = $().getClass.hasClass.call(nodes, className);
}
nodes = nodes.getNodes();
for (var i = 0; i < results.length; i ++) {
if (results[i]) this.elements.push(nodes[i]);
}
return this;
}; // getClass 附属方法: 检测 class
Base.prototype.getClass.hasClass = function (className) {
var results = [];
for (var i = 0; i < this.elements.length; i ++) {
results.push((new RegExp('(^|\\s+)' + className + '(\\s+|$)')).test(this.elements[i].className));
}
return results;
}; // 获取与设置 innerHTML(双标记)
Base.prototype.html = function (text) {
if (typeof text != 'undefined') { // 设置
for (var i = 0; i < this.elements.length; i ++) {
this.elements[i].innerHTML = text;
}
} else { // 获取
var html = [];
for (var i = 0; i < this.elements.length; i ++) {
html.push(this.elements[i].innerHTML);
}
if (html.length == 1) return html[0];
return html;
}
return this;
}; // 获取与设置 value(表单)
Base.prototype.value = function (text) {
if (typeof text != 'undefined') { // 设置
for (var i = 0; i < this.elements.length; i ++) {
if (typeof this.elements[i].value != 'undefined') this.elements[i].value = text;
}
} else { // 获取
var value = [];
for (var i = 0; i < this.elements.length; i ++) {
if (typeof this.elements[i].value != 'undefined') value.push(this.elements[i].value);
}
if (value.length == 1) return value[0];
return value;
}
return this;
}; // 获取与设置 CSS
Base.prototype.css = function (cssKey, cssValue) {
if (typeof cssValue != 'undefined' || cssKey instanceof Array) { // 设置
if (cssKey instanceof Array) { // 集群
var _cssKey = '', _cssValue = '', pattern = /^\s*([a-z]+)\s*=\s*([\w#=\s\(\.\)\-\'\"\/\\]+)\s*$/i;
for (var i = 0; i < cssKey.length; i ++) {
if (pattern.test(cssKey[i])) {
_cssKey = pattern.exec(cssKey[i])[1];
_cssValue = pattern.exec(cssKey[i])[2];
for (var j = 0; j < this.elements.length; j ++) {
this.elements[j].style[_cssKey] = _cssValue;
}
}
}
} else { // 单个
for (var i = 0; i < this.elements.length; i ++) {
this.elements[i].style[cssKey] = cssValue;
}
}
} else { // 获取
var css = [], _cssValue = '';
for (var i = 0; i < this.elements.length; i ++) {
_cssValue = Tool.getStyle(this.elements[i], cssKey);
if (typeof _cssValue != 'undefined') css.push(_cssValue);
}
if (css.length == 1) return css[0];
return css;
}
return this;
}; // 添加 class
Base.prototype.addClass = function (className) {
if (className instanceof Array) { // 集群
for (var i = 0; i < className.length; i ++) {
this.addClass(className[i]);
}
} else { // 单个
var results = this.getClass.hasClass.call(this, className);
var space = '';
for (var i = 0; i < results.length; i ++) {
if (this.elements[i].className != '') space = ' ';
if (!results[i]) this.elements[i].className += space + className;
}
}
return this;
}; // 移除 class
Base.prototype.removeClass = function (className) {
if (className instanceof Array) { // 集群
for (var i = 0; i < className.length; i ++) {
this.removeClass(className[i]);
}
} else { // 单个
var results = this.getClass.hasClass.call(this, className);
for (var i = 0; i < results.length; i ++) {
if (results[i]) this.elements[i].className = this.elements[i].className.replace(new RegExp('(^|\\s)' + className + '(\\s|$)'), '');
}
}
return this;
}; // 添加 rule
Base.prototype.addRule = function (ruleName, ruleText, positionIndex, sheetIndex) {
if (ruleName instanceof Array) { // 集群
if (!ruleText instanceof Array || ruleName.length != ruleText.length) return this;
for (var i = 0; i < ruleName.length; i ++) {
this.addRule(ruleName[i], ruleText[i], positionIndex, sheetIndex);
}
} else { // 单个
var rule = this.addRule.checkRule(positionIndex, sheetIndex);
if (typeof rule.sheetObject != 'undefined') {
if ((positionIndexMax = Tool.getRules(rule.sheetObject).length) < rule.positionIndex) rule.positionIndex = positionIndexMax;
Tool.addRule(rule.sheetObject, ruleName, ruleText, rule.positionIndex);
}
}
return this;
}; // addRule 附属方法: rule 容错处理
Base.prototype.addRule.checkRule = function (positionIndex, sheetIndex, positionLength) {
if (typeof positionIndex == 'undefined' || isNaN(positionIndex)) positionIndex = 0;
if (typeof sheetIndex == 'undefined' || isNaN(sheetIndex)) sheetIndex = 0;
if (typeof positionLength == 'undefined' || isNaN(positionLength)) positionLength = 1;
return {
positionIndex : positionIndex,
positionLength : positionLength,
sheetObject : document.styleSheets[sheetIndex]
}
}; // 删除 rule
Base.prototype.removeRule = function (positionIndex, positionLength, sheetIndex) {
var rule = this.addRule.checkRule(positionIndex, sheetIndex, positionLength);
if ((positionIndexMax = Tool.getRules(rule.sheetObject).length) <= rule.positionIndex || (positionIndexMax - rule.positionIndex) < rule.positionLength) return this;
for (var i = 0; i < rule.positionLength; i ++) {
Tool.removeRule(rule.sheetObject, rule.positionIndex);
}
return this;
}; // 显示元素
Base.prototype.show = function () {
for (var i = 0; i < this.elements.length; i ++) {
$(this.elements[i]).css('display', 'block');
}
return this;
}; // 隐藏元素
Base.prototype.hide = function () {
for (var i = 0; i < this.elements.length; i ++) {
$(this.elements[i]).css('display', 'none');
}
return this;
}; // 鼠标 click 事件
Base.prototype.click = function (method) {
if (method instanceof Function) {
for (var i = 0; i < this.elements.length; i ++) {
this.elements[i].onclick = function (eventObject) {
method.call(this, Tool.getEvent(eventObject));
};
}
}
return this;
}; // 鼠标 mouseover 事件
Base.prototype.mouseover = function (method) {
if (method instanceof Function) {
for (var i = 0; i < this.elements.length; i ++) {
this.elements[i].onmouseover = function (eventObject) {
method.call(this, Tool.getEvent(eventObject));
};
}
}
return this;
}; // 鼠标 mouseout 事件
Base.prototype.mouseout = function (method) {
if (method instanceof Function) {
for (var i = 0; i < this.elements.length; i ++) {
this.elements[i].onmouseout = function (eventObject) {
method.call(this, Tool.getEvent(eventObject));
};
}
}
return this;
}; // 鼠标 mousedown 事件
Base.prototype.mousedown = function (method) {
if (method instanceof Function) {
for (var i = 0; i < this.elements.length; i ++) {
this.elements[i].onmousedown = function (eventObject) {
method.call(this, Tool.getEvent(eventObject));
};
}
}
return this;
}; // 鼠标 mousemove 事件
Base.prototype.mousemove = function (method) {
if (method instanceof Function) {
for (var i = 0; i < this.elements.length; i ++) {
this.elements[i].onmousemove = function (eventObject) {
method.call(this, Tool.getEvent(eventObject));
};
}
}
return this;
}; // 鼠标 mouseup 事件
Base.prototype.mouseup = function (method) {
if (method instanceof Function) {
for (var i = 0; i < this.elements.length; i ++) {
this.elements[i].onmouseup = function (eventObject) {
method.call(this, Tool.getEvent(eventObject));
};
}
}
return this;
}; // 鼠标 mousewheel 事件
Base.prototype.mousewheel = function (method) {
if (method instanceof Function) {
for (var i = 0; i < this.elements.length; i ++) {
Tool.mousewheelEvent(this.elements[i], method);
}
}
return this;
}; // 元素 load 事件
Base.prototype.load = function (method) {
if (method instanceof Function) {
for (var i = 0; i < this.elements.length; i ++) {
this.elements[i].onload = function (eventObject) {
method.call(this, Tool.getEvent(eventObject));
};
}
}
return this;
}; // 元素 scroll 事件
Base.prototype.scroll = function (method) {
if (method instanceof Function) {
for (var i = 0; i < this.elements.length; i ++) {
this.elements[i].onscroll = function (eventObject) {
method.call(this, Tool.getEvent(eventObject));
};
}
}
return this;
}; // 窗口 resize 事件
Base.prototype.resize = function (method) {
if (method instanceof Function) {
window.onresize = function (eventObject) {
method.call(this, Tool.getEvent(eventObject));
};
}
return this;
}; // 鼠标 hover 特效
Base.prototype.hover = function (overMethod, outMethod) {
this.mouseover(overMethod);
this.mouseout(outMethod);
return this;
}; // 元素居中显示特效
Base.prototype.center = function () {
var innerRectangle = Tool.getInnerRectangle();
var rectangle = {}, fixedX = 0, fixedY = 0, minX = 0, minY = 0, maxX = 0, maxY = 0;
for (var i = 0; i < this.elements.length; i ++) {
this.center.absolutePosition(this.elements[i]);
rectangle = this.center.getRectangle(this.elements[i]);
maxX = innerRectangle.innerWidth - rectangle.width;
maxY = innerRectangle.innerHeight - rectangle.height;
fixedX = maxX / 2;
fixedY = maxY / 2;
if (fixedX < minX) {
fixedX = minX;
} else if (fixedX > maxX) {
fixedX = maxX;
}
if (fixedY < minY) {
fixedY = minY;
} else if (fixedY > maxY) {
fixedY = maxY;
}
$(this.elements[i]).css(['left = ' + fixedX + 'px', 'top = ' + fixedY + 'px']);
}
return this;
}; // center 隶属方法: 获取元素长度
Base.prototype.center.getRectangle = function (elementNode) {
var _this = $(elementNode);
var width = _this.css('width');
var height = _this.css('height');
var display = _this.css('display');
if (display != 'none' || width == 'auto' || height == 'auto') {
_this.show();
width = elementNode.offsetWidth;
height = elementNode.offsetHeight;
}
width = this.split(width, 'px');
height = this.split(height, 'px');
return {
width : width,
height : height
}
}; // center 隶属方法: 裁剪字符串
Base.prototype.center.split = function (string, pattern) {
if (typeof string == 'string') {
if (string.indexOf(pattern) != -1) string = string.replace(pattern, '');
}
return string;
}; // center 隶属方法: 元素设置绝对定位
Base.prototype.center.absolutePosition = function (elementNode) {
if ($(elementNode).css('position') != 'absolute') {
$(elementNode).css(['position = absolute', 'left = 0', 'top = 0']);
}
}; // 屏幕遮罩特效: 锁屏
Base.prototype.lock = function () {
var screenLock = $().getId('screen_lock').getNodes(); // 获取锁屏节点
// 锁屏节点智能生成
if (typeof screenLock == 'object') { // 存在
this.lock.comment(screenLock); // 清除注释
if (this.lock.trim($(screenLock).html()).length != 0) {
this.lock.deleteElement('id = screen_lock');
screenLock = this.lock.createElement('div', 'id = screen_lock');
}
} else { // 不存在
screenLock = this.lock.createElement('div', 'id = screen_lock'); // 创建锁屏节点
} $(document.documentElement).css('overflow', 'hidden');
Tool.scrollInitialization();
var innerRectangle = Tool.getInnerRectangle();
this.center.absolutePosition(screenLock);
var _this = $(screenLock);
// 锁屏样式
_this.css([
'width = ' + innerRectangle.innerWidth + 'px',
'height = ' + innerRectangle.innerHeight +'px',
'backgroundColor = black',
'opacity = 0.4', // W3C 透明效果
'filter = alpha(opacity = 40)', // IE 6/7/8 透明效果
'zIndex = 10'
]).show();
// IE 6/7/8 与 Chrome 鼠标滚轮 BUG 处理
_this.mousedown(function () { // 禁用 IE 6/7/8 鼠标默认行为
_this.mousemove(function (eventObject) {
Tool.preventEventDefault(eventObject);
});
_this.mouseup(function () {
_this.mousedown(function () {
return null;
});
_this.mouseup(function () {
return null;
});
});
}); _this.mousewheel(function (eventObject) { // Chrome 禁用鼠标滚轮
Tool.preventEventDefault(eventObject);
}); return this;
}; // 屏幕遮罩特效: 销锁
Base.prototype.unlock = function () {
var screenLock = $().getId('screen_lock').getNodes();
if (typeof screenLock == 'object') {
$(screenLock).hide();
$(document.documentElement).css('overflow', 'auto');
}
return this;
}; // lock 隶属方法: 匹配元素属性
Base.prototype.lock.matchAttribute = function (pattern, attribute, elementNode) {
if (pattern.test(attribute)) {
var attributeKey = pattern.exec(attribute)[1];
var attributeValue = pattern.exec(attribute)[2];
if (attributeKey == 'class') attributeKey = 'className';
if (typeof elementNode == 'object') elementNode[attributeKey] = attributeValue;
return {
attributeKey : attributeKey,
attributeValue : attributeValue
}
}
}; // lock 隶属方法: 创建元素
Base.prototype.lock.createElement = function (elementName, attribute, html, parentElement) {
if (typeof parentElement == 'undefined') parentElement = document.body;
var elementNode = document.createElement(elementName);
if (typeof attribute != 'undefined') {
var pattern = /^\s*([a-z]+)\s*=\s*([\w\-\s\.\\\/\=\(\)]+)\s*$/i;
if (attribute instanceof Array) {
for (var i = 0; i < attribute.length; i ++) {
this.matchAttribute(pattern, attribute[i], elementNode);
}
} else {
this.matchAttribute(pattern, attribute, elementNode);
}
}
if (typeof html == 'string') {
$(elementNode).html(html);
}
parentElement.appendChild(elementNode);
return elementNode;
}; // lock 隶属方法: 删除元素
Base.prototype.lock.deleteElement = function (attribute) {
if (typeof attribute != 'undefined') {
if (attribute instanceof Array) {
for (var i = 0; i < attribute.length; i ++) {
this.deleteElement(attribute[i]);
}
} else {
var pattern = /^\s*(id|class|className|name)\s*=\s*([\w\-\s\.\\\/\=\(\)]+)\s*$/i;
var nodes = [], parentElement = {};
if (pattern.test(attribute)) {
arrtibuteObject = $().lock.matchAttribute(pattern, attribute);
switch (arrtibuteObject.attributeKey) {
case 'id' :
nodes = $().getId(arrtibuteObject.attributeValue).getNodes();
break; case 'name':
nodes = $().getName(arrtibuteObject.attributeValue).getNodes();
break; case 'className' :
nodes = $().getClass(arrtibuteObject.attributeValue).getNodes();
break;
}
} else { // tagName
nodes = $().getTagName(attribute).getNodes();
}
if (nodes instanceof Array) {
for (var i = 0; i < nodes.length; i ++) {
parentElement = nodes[i].parentNode;
if (typeof parentElement == 'undefined') continue;
parentElement.removeChild(nodes[i]);
}
} else {
parentElement = nodes.parentNode;
if (typeof parentElement == 'undefined') return false;
parentElement.removeChild(nodes);
}
}
}
}; // lock 隶属方法: 清除字符串首位空格
Base.prototype.lock.trim = function (string) {
var leftPattern = /^([\s ]+)/;
var rightPattern = /([\s ]+)$/;
if (leftPattern.test(string)) string = string.replace(leftPattern, '');
if (rightPattern.test(string)) string = string.replace(rightPattern, '');
return string;
}; // lock 隶属方法: 清除元素内部注释
Base.prototype.lock.comment = function (elementNode) {
if (elementNode.id != '') var nodes = $().getTagName('!', elementNode.id).getNodes(); // IE 6/7/8
if (typeof nodes != 'object') nodes = elementNode.childNodes; // W3C
for (var i = 0; i < nodes.length; i ++) {
if (nodes[i].nodeType == 8) elementNode.removeChild(nodes[i]);
}
return elementNode;
}; // lock 隶属方法: 清除元素内部空白文本节点
Base.prototype.lock.spaceNode = function (elementNode) {
var nodes = elementNode.childNodes;
for (var i = 0; i < nodes.length; i ++) {
if (nodes[i].nodeType == 3 && /^([ \s]+)$/.test(nodes[i].nodeValue)) elementNode.removeChild(nodes[i]);
}
return elementNode;
}; // 元素拖拽特效
Base.prototype.drag = function (mode) {
if (typeof mode == 'undefined') mode = true;
this.mousedown(function (eventObject) {
// 拖拽模式选择: true 拖拽元素自身、false 拖拽父级元素
var _this = mode ? this : this.parentNode; $().lock.comment(_this);
if ($().lock.trim($(_this).html()).length == 0) Tool.preventEventDefault(eventObject); // 兼容 Firefox 低版本拖拽 BUG // 设置绝对定位
$().center.absolutePosition(_this); // 捕获鼠标当前坐标
var mouseX = eventObject.clientX;
var mouseY = eventObject.clientY; // 获取元素外边距
var outerRectangle = $().drag.getOuterRectangle(_this); // 获取固定距离
var fixedX = mouseX - outerRectangle.outerX;
var fixedY = mouseY - outerRectangle.outerY; var innerRectangle = Tool.getInnerRectangle();
var rectangle = $().center.getRectangle(_this); // 设置容错距离
var minX = 0, minY = 0, maxX = 0, maxY = 0;
maxX = innerRectangle.innerWidth - rectangle.width;
maxY = innerRectangle.innerHeight - rectangle.height; // 兼容 IE 6/7/8 拖拽 BUG
Tool.setCaptureIE(_this); $(document).mousemove(function (eventObject) {
// 捕获鼠标当前坐标
mouseX = eventObject.clientX;
mouseY = eventObject.clientY; // 获取元素位置
var moveX = mouseX - fixedX;
var moveY = mouseY - fixedY; if (moveX < minX) {
moveX = minX;
} else if (moveX > maxX) {
moveX = maxX;
} if (moveY < minY) {
moveY = minY;
} else if (moveY > maxY) {
moveY = maxY;
} $(_this).css(['left = ' + moveX + 'px', 'top = ' + moveY + 'px']);
});
$(document).mouseup(function () {
// 兼容 IE 6/7/8 拖拽 BUG
Tool.releaseCaptureIE(_this);
$(document).mousemove(function () {
return null;
});
return null;
});
});
return this;
}; // drag 隶属方法: 获取元素外边距
Base.prototype.drag.getOuterRectangle = function (elementNode) {
var _this = $(elementNode);
var outerX = _this.css('left');
var outerY = _this.css('top');
var display = _this.css('display'); if (display != 'none' || outerX == 'auto' || outerY == 'auto') {
_this.show();
outerX = elementNode.offsetLeft;
outerY = elementNode.offsetTop;
} outerX = _this.center.split(outerX, 'px');
outerY = _this.center.split(outerY, 'px'); return {
outerX : outerX,
outerY : outerY
}
}; // 防止元素溢出
Base.prototype.overflow = function () {
var innerRectangle = Tool.getInnerRectangle();
var outerRectangle = {}, rectangle = {}, minX = 0, minY = 0, maxX = 0, maxY = 0;
for (var i = 0; i < this.elements.length; i ++) {
this.center.absolutePosition(this.elements[i]);
outerRectangle = this.drag.getOuterRectangle(this.elements[i]);
rectangle = this.center.getRectangle(this.elements[i]);
maxX = innerRectangle.innerWidth - rectangle.width;
maxY = innerRectangle.innerHeight - rectangle.height; if (outerRectangle.outerX < minX) {
outerRectangle.outerX = minX;
} else if (outerRectangle.outerX > maxX) {
outerRectangle.outerX = maxX;
}
if (outerRectangle.outerY < minY) {
outerRectangle.outerY = minY;
} else if (outerRectangle.outerY > maxY) {
outerRectangle.outerY = maxY;
} $(this.elements[i]).css(['left = ' + outerRectangle.outerX + 'px', 'top = ' + outerRectangle.outerY + 'px']);
}
return this;
};
 /*
源码作者: 石不易(Louis Shi)
联系方式: http://www.shibuyi.net
===================================================================================================
程序名称: JavaScript 工具库(跨浏览器兼容) BETA 1.0 版
迭代版本: 无
功能总数: 17 个
功能介绍:
1. 实现获取计算样式
2. 样式规则添加和移除
3. 获取事件对象 event
4. 取消事件默认行为与冒泡处理
5. 现代事件绑定添加和移除
...
*/
var Tool = { // 跨浏览器获取计算后的样式
getStyle : function (elementNode, cssKey) {
if (typeof window.getComputedStyle != 'undefined') { // W3C
return window.getComputedStyle(elementNode, null)[cssKey];
} else if (typeof elementNode.currentStyle != 'undefined') { // IE 6/7/8
return elementNode.currentStyle[cssKey];
}
}, // 跨浏览器添加 rule
addRule : function (sheetObject, ruleName, ruleText, positionIndex) {
if (typeof sheetObject.insertRule != 'undefined') { // W3C
sheetObject.insertRule(ruleName + ' {' + ruleText + '}', positionIndex);
} else if (typeof sheetObject.addRule != 'undefined') { // IE 6/7/8
sheetObject.addRule(ruleName, ruleText, positionIndex);
}
}, // 跨浏览器移除 rule
removeRule : function (sheetObject, positionIndex) {
if (typeof sheetObject.deleteRule != 'undefined') { // W3C
sheetObject.deleteRule(positionIndex);
} else if (typeof sheetObject.removeRule != 'undefined') { // IE 6/7/8
sheetObject.removeRule(positionIndex);
}
}, // 跨浏览器获取rule集合
getRules : function (sheetObject) {
if (typeof sheetObject.cssRules != 'undefined') { // W3C
return sheetObject.cssRules;
} else if (typeof sheetObject.rules != 'udnefined') { // IE 6/7/8
return sheetObject.rules;
}
}, // 数组排序
sort : function () {
return {
minToMax : function (min, max) { // 正序: 从小到大排序
if (min < max) {
return -1;
} else if (min > max) {
return 1;
} else {
return 0;
}
},
maxToMin : function (min, max) { // 倒序: 从大到小排序
if (min < max) {
return 1;
} else if (min > max) {
return -1;
} else {
return 0;
}
}
}
}, // 跨浏览器获取 event 对象
getEvent : function (eventObject) {
if (typeof eventObject == 'object') return eventObject; // W3C
return window.event; // IE 6/7/8
}, // 跨浏览器获取事件绑定所属元素引用
getEventTarget : function (eventObject) {
eventObject = this.getEvent(eventObject);
if (typeof eventObject.target != 'undefined') { // W3C
return eventObject.target;
} else if (typeof eventObject.srcElement != 'undefined') { // IE 6/7/8
return eventObject.srcElement;
}
}, // 跨浏览器取消事件默认行为
preventEventDefault : function (eventObject) {
eventObject = this.getEvent(eventObject);
if (typeof eventObject.cancelable != 'undefined' && typeof eventObject.preventDefault != 'undefined') { // W3C
if (eventObject.cancelable) eventObject.preventDefault();
} else { // IE 6/7/8
eventObject.returnValue = false;
}
}, // 跨浏览器取消事件冒泡
cancelEventPropagation : function (eventObject) {
eventObject = this.getEvent(eventObject);
if (typeof eventObject.bubbles != 'undefined' && typeof eventObject.stopPropagation != 'undefined') { // W3C
if (eventObject.bubbles) eventObject.stopPropagation();
} else if (typeof eventObject.cancelBubble != 'undefined') { // IE 6/7/8
eventObject.cancelBubble = true;
}
}, // 事件名称容错处理
checkEventName : function (eventName) {
if (typeof eventName == 'string' && eventName.indexOf('on') == 0) eventName = eventName.substring(2, eventName.length);
return eventName;
}, // 跨浏览器现代事件绑定: 注册事件
loginEvent : function (elementNode, eventName, method) {
eventName = this.checkEventName(eventName);
if (typeof elementNode.addEventListener != 'undefined') { // W3C
elementNode.addEventListener(eventName, method, false);
} else if (typeof elementNode.attachEvent != 'undefined') { // IE 6/7/8
elementNode.attachEvent('on' + eventName, method);
}
}, // 款浏览器现代事件绑定: 注销事件
logoutEvent : function (elementNode, eventName, method) {
eventName = this.checkEventName(eventName);
if (typeof elementNode.removeEventListener != 'undefined') { // W3C
elementNode.removeEventListener(eventName, method, false);
} else if (typeof elementNode.detachEvent != 'undefined') { // IE 6/7/8
elementNode.detachEvent('on' + eventName, method);
}
}, // 跨浏览器绑定鼠标滚轮事件
mousewheelEvent : function (elementNode, method) {
if (typeof elementNode.onmousewheel != 'undefined') { // 非 Firefox
elementNode.onmousewheel = function (eventObject) {
method.call(this, Tool.getEvent(eventObject));
};
} else { // Firefox
this.loginEvent(elementNode, 'DOMMouseScroll', method);
}
}, // 跨浏览器获取网页可视区长度
getInnerRectangle : function () {
var width = 0; height = 0;
if (typeof window.innerWidth != 'undefined' && typeof window.innerHeight != 'undefined') { // W3C
width = window.innerWidth;
height = window.innerHeight;
} else { // IE 6/7/8
width = document.documentElement.clientWidth;
height = document.documentElement.clientHeight;
}
return {
innerWidth : width,
innerHeight : height
}
}, // 跨浏览器滚动条重置
scrollInitialization : function () {
document.documentElement.scrollTop = 0; // 非 Chrome / Safari
document.documentElement.scrollLeft = 0; // 非 Chrome / Safari
document.body.scrollTop = 0; // Chrome / Safari
document.body.scrollLeft = 0; // Chrome / Safari
}, // IE 浏览器独占: 监听鼠标点击
setCaptureIE : function (elementNode) {
if (typeof elementNode.setCapture != 'undefined') {
elementNode.setCapture();
}
}, // IE 浏览器独占: 监听释放鼠标
releaseCaptureIE : function (elementNode) {
if (typeof elementNode.releaseCapture != 'undefined') {
elementNode.releaseCapture();
}
}
};

关于 BETA 1.0 原型版核心源码与实例演示的获取请移动至官网下载!

 

感谢大家积极评测给予意见!

官网地址:http://www.shibuyi.net

CNBlogs 博客:http://www.cnblogs.com/shibuyi/

CSDN 博客:http://blog.csdn.net/louis_shi/

ITeye 博客:http://shibuyi.iteye.com/

【JavaScript 封装库】BETA 1.0 测试版发布!的更多相关文章

  1. 【JavaScript 封装库】BETA 4.0 测试版发布!

    /* 源码作者: 石不易(Louis Shi) 联系方式: http://www.shibuyi.net =============================================== ...

  2. 【JavaScript 封装库】BETA 3.0 测试版发布!

    /* 源码作者: 石不易(Louis Shi) 联系方式: http://www.shibuyi.net =============================================== ...

  3. 【JavaScript 封装库】BETA 2.0 测试版发布!

    /* 源码作者: 石不易(Louis Shi) 联系方式: http://www.shibuyi.net =============================================== ...

  4. 【JavaScript 封装库】BETA 5.0 测试版发布!

    JavaScript 前端框架(封装库) BETA 5.0 已于10月10日正式发布,今天开始提供 BETA 5.0 的 API 参考文献.相较于之前 5 个版本的发布都是草草的提供源代码,并没有很多 ...

  5. 【JavaScript 封装库】Prototype 原型版发布!

    /* 源码作者: 石不易(Louis Shi) 联系方式: http://www.shibuyi.net =============================================== ...

  6. Android Q Beta 6 终极测试版发布!

    前言 当今手机市场可谓是百花齐放,但手机系统却屈指可数,其中Android和iOS就占据了整个手机系统市场的99%,单单Android就占据了整个手机系统市场的86%,可谓是占据绝对优势.     其 ...

  7. Cocos3.0测试版发布(中文)

    最新的cocos2d-x 3.0版本,我们的目标不仅是改进渲染机制,增加对2.5D的支持,基于组件的系统功能,和更好的Label功能.同时 我们希望能够进一步优化引擎,并且使用更友好的C++ API ...

  8. MongoDB 可视化管理工具 MongoCola-1.1.0 测试版发布

    首先,感谢大家对于本工具的支持. 经过一周的努力,最新版的工具测试版出炉了,这个版本是一个很重要的版本. 为什么说这个版本重要?以前的工具,只支持一个视图窗口,也就是说了,一次只能看一个数据集的数据. ...

  9. 第一百三十节,JavaScript,封装库--连缀

    JavaScript,封装库--连缀 学习要点: 1.连缀介绍 2.改写库对象 本章我们重点来介绍,在调用库的时候,我们需要能够在前台调用的时候可以同时设置多个操作,比如设置CSS,设置innerHT ...

随机推荐

  1. day_02 循环格式化输出编码运算符

    1.while循环 语法 while 条件: 循环体 else: 当条件不成立的时候执行这里,和break没关系 如果循环是通过break退出的. 那么while后面的else将不会被执行, 只有在w ...

  2. sysbench 安装、使用和测试

    摘要:      sysbench是一个开源的.模块化的.跨平台的多线程性能测试工具,可以用来进行CPU.内存.磁盘I/O.线程.数据库的性能测试.目前支持的数据库有MySQL.Oracle和Post ...

  3. Jenkins自动化CI CD流水线之4--Master-Slave架构

    一.介绍 jenkins的Master-slave分布式架构主要是为了解决jenkins单点构建任务多.负载较高.性能不足的场景. Master/Slave相当于Server和agent的概念.Mas ...

  4. C语言标准库函数memcpy和memmove的区别以及内存重叠问题处理

    ①memcpy()和memmove()都是C语言中的标准库函数,定义在头文件string.h中,作用是拷贝一定长度的内存的内容,原型分别如下: void *memcpy(void *dst, cons ...

  5. java中使用nextLine(); 没有输入就自动跳过的问题?

    [问题分析] 必要的知识:in.nextLine();不能放在in.nextInt();代码段后面否则in.nextLine();会读入"\n"字符,但"\n" ...

  6. Java——socket

    Server: import java.io.IOException; import java.net.ServerSocket; import java.net.Socket; public cla ...

  7. OS---存储器

    1.存储器的层次结构 1.1 概述 理想情况下,存储器应当速度非常快.并且与处理器的速度匹配.容量大且价格低廉: 实际情况,无法满足上述三个条件: 于是在现在OS中,存储器采用  层次结构  来组织: ...

  8. sqoop导入数据

    来源https://www.cnblogs.com/qingyunzong/p/8807252.html 一.概述 sqoop 是 apache 旗下一款“Hadoop 和关系数据库服务器之间传送数据 ...

  9. 安装、使用eclipse+CDT编译C++程序

    我想安装.使用eclipse+CDT的初衷在看live555的源码,需要方便管理源码的工具: 使用eclipse编译和管理live555源码 http://blog.csdn.net/nkmnkm/a ...

  10. [转]25个HTML5和JavaScript游戏引擎库

    本文转自:http://www.open-open.com/news/view/27c6ed 1. The GMP JavaScript Game Engine GMP是一个基于精灵2-D游戏,它可以 ...