global js库
var GLOBAL = {};
GLOBAL.namespace = function(str) {
var arr = str.split("."), o = GLOBAL,i;
for (i = (arr[0] = "GLOBAL") ? 1 : 0; i < arr.length; i++) {
o[arr[i]] = o[arr[i]] || {};
o = o[arr[i]];
}
};
//Dom相关
GLOBAL.namespace("Dom");
GLOBAL.Dom.getNextNode = function (node) {
node = typeof node == "string" ? document.getElementById(node) : node;
var nextNode = node.nextSibling;
if (!nextNode) {
return null;
}
if (!document.all) {
while (true) {
if (nextNode.nodeType == 1) {
break;
} else {
if (nextNode.nextSibling) {
nextNode = nextNode.nextSibling;
} else {
break;
}
}
}
return nextNode;
}
}
GLOBAL.Dom.setOpacity = function(node, level) {
node = typeof node == "string" ? document.getElementById(node) : node;
if (document.all) {
node.style.filter = 'alpha(opacity=' + level + ')';
} else {
node.style.opacity = level / 100;
}
};
GLOBAL.Dom.getElementsByClassName = function (str, root, tag) {
if (root) {
root = typeof root == "string" ? document.getElementById(root) : root;
} else {
root = document.body;
}
tag = tag || "*";
var els = root.getElementsByTagName(tag), arr = [];
for (var i = 0, n = els.length; i < n; i++) {
for (var j = 0, k = els[i].className.split(" "), l = k.length; j < l; j++) {
if (k[j] == str) {
arr.push(els[i]);
break;
}
}
}
return arr;
}
GLOBAL.namespace("Event");
GLOBAL.Event.stopPropagation = function(e) {
e = window.event || e;
if (document.all) {
e.cancelBubble = true;
} else {
e.stopPropagation();
}
};
GLOBAL.Event.getEventTarget = function(e) {
e = window.event || e;
return e.srcElement || e.target;
};
GLOBAL.Event.on = function(node, eventType, handler) {
node = typeof node == "string" ? document.getElementById(node) : node;
if (document.all) {
node.attachEvent("on" + eventType, handler);
} else {
node.addEventListener(eventType, handler, false);
}
};
//Lang相关
GLOBAL.namespace("Lang");
GLOBAL.Lang.trim = function(ostr) {
return ostr.replace(/^\s+|\s+$/g, "");
};
GLOBAL.Lang.isNumber = function(s) {
return !isNaN(s);
};
function isString(s) {
return typeof s === "string";
}
function isBoolean(s) {
return typeof s === "boolean";
}
function isFunction(s) {
return typeof s === "function";
}
function isNull(s) {
return s === null;
}
function isUndefined(s) {
return typeof s === "undefined";
}
function isEmpty(s) {
return /^\s*$/.test(s);
}
function isArray(s) {
return s instanceof Array;
}
GLOBAL.Dom.get = function (node) {
node = typeof node === "string" ? document.getElementById(node) : node;
return node;
}
function $(node) {
node = typeof node == "string" ? document.getElementById(node) : node;
return node;
}
GLOBAL.Lang.extend = function(subClass, superClass) {
var F = function() {
};
F.prototype = superClass.prototype;
subClass.prototype = new F();
subClass.prototype.constructor = subClass;
subClass.superClass = subClass.prototype;
if (superClass.prototype.constructor == Object.prototype.constructor) {
superClass.prototype.constructor = superClass;
}
};
GLOBAL.namespace("Cookie");
GLOBAL.Cookie = {
read: function (name) {
var cookieStr = ";" + document.cookie + ";";
var index = cookieStr.indexOf(";" + name + "=");
if (index != -1) {
var s = cookieStr.substring(index + name.length + 3, cookieStr.length);
return unescape(s.substring(0, s.indexOf(";")));
} else {
return null;
}
},
set: function (name, value, expires) {
var expDays = expires * 24 * 60 * 60 * 1000;
var expDate = new Date();
expDate.setTime(expDate.getTime() + expDays);
var expString = expires ? ";expires=" + expDate.toGMTString() : "";
var pathString = ";path=/";
document.cookie = name + "=" + escape(value) + expString + pathString;
},
del: function (name, value, expires) {
var exp = new Date(new Date().getTime() - 1);
var s = this.read(name);
if (s != null) {
document.cookie = name + "=" + s + ";expires=" + exp.toGMTString() + ";path=/";
}
}
};
global js库的更多相关文章
- 【转载】写一个js库需要怎样的知识储备和技术程度?
作者:小爝链接:https://www.zhihu.com/question/30274750/answer/118846177来源:知乎著作权归作者所有,转载请联系作者获得授权. 1,如何编写健壮的 ...
- js库写法
前言: 现在javascript库特别多,其写法各式各样,总结几种我们经常见到的,作为自己知识的积累.而目前版本的 JavaScript 并未提供一种原生的.语言级别的模块化组织模式,而是将模块化的方 ...
- 如何在Webstorm中添加js库 (青瓷H5游戏引擎)
js等动态语言编码最大的缺点就是没有智能补全代码,webstorm做到了. qici_engine作为开发使用的库,如果能智能解析成提示再好不过了,经测试80%左右都有提示,已经很好了. 其他js库同 ...
- 使用模块化工具打包自己开发的JS库(webpack/rollup)对比总结
打包JS库demo项目地址:https://github.com/BothEyes1993/bes-jstools 背景 最近有个需求,需要为小程序写一个SDK,监控小程序的后台接口调用和页面报错(类 ...
- 前端之Vue.js库的使用
vue.js简介 Vue.js读音 /vjuː/, 类似于 view Vue.js是前端三大新框架:Angular.js.React.js.Vue.js之一,Vue.js目前的使用和关注程度在三大框架 ...
- 发布兼容TS的JS库到nexus和npmjs
一. 前言 由于node以及绝大多数前端库都是用JavaScript(以下简称JS)语言实现,而Angular是用TypeScript(以下简称TS)实现,虽然TS是JS的超集,但是由于TS和JS对于 ...
- 如何写JS库,JS库写法
前言: 现在javascript库特别多,其写法各式各样,总结几种我们经常见到的,作为自己知识的积累.而目前版本的 JavaScript 并未提供一种原生的.语言级别的模块化组织模式,而是将模块化的方 ...
- js库
lanchpad用的js库 http://lesscss.org/ https://github.com/EightMedia/hammer.js/wiki/Getting-Started http: ...
- 解决jQuery多个版本,与其他js库冲突方法
jQuery多个版本或和其他js库冲突主要是常用的$符号的问题,这个问题 jquery早早就有给我们预留处理方法了,下面一起来看看解决办法. 1.同一页面jQuery多个版本或冲突解决方法. < ...
随机推荐
- 【BZOJ1858】[SCOI2010] 序列操作(ODT裸题)
点此看题面 大致题意: 给你一个\(01\)序列,让你支持区间赋值.区间取反.区间求和以及求一段区间内最多有多少连续的\(1\)这些操作. \(ODT\) 这道题正解似乎是线段树,但码量较大,而且细节 ...
- 2017.9.30 Java中引用类型变量的创建及使用&循环的高级
今日内容介绍 1.引用类型变量的创建及使用 2.流程控制语句之选择语句 3.流程控制语句之循环语句 4.循环高级 ###01创建引用类型变量公式 * A: 创建引用类型变量公式 ...
- CentOS上安装mongodb
安装mongodb pymongo修改yum源vi /etc/yum.repos.d/10gen.repo[10gen]name=10gen Repositorybaseurl=http://down ...
- 矩阵——特征向量(Eigenvector)
原文链接 矩阵的基础内容以前已经提到,今天我们来看看矩阵的重要特性——特征向量. 矩阵是个非常抽象的数学概念,很多人到了这里往往望而生畏.比如矩阵的乘法为什么有这样奇怪的定义?实际上是由工程实际需要定 ...
- deep learning书的阅读
最近坚持读书,虽然大多数读的都是一些闲书,传记.历史或者散文之类的书籍,但是也读了点专业书.闲书是散时间读的,放车里,有时间就拿起来读读,专业书则更多的靠得是专注.因为我给自己的规定是一定时间内读完几 ...
- SqlServer中怎么删除重复的记录(表中没有id)
SqlServer中怎么删除重复的记录(表中没有id) 其实我在别的网址也查到过删除重复的记录,不知道我是我SqlServer2012版本太低还是啥原因 delete from scwhere (c# ...
- jsonp 请求和回传实现
JSONP最主要的是可以解决跨域问题,不然谁会没事用这种格式. 下面是我用JSONP的一些心得体会: JSONP是JSON with Padding的略称.它是一个非官方的协议,它允许在服务器端集成S ...
- cncert阅读报告
信息安全阅读报告 Problem 1: 国家计算机网络应急技术处理协调中心(简称“国家互联网应急中心”,英文缩写为“CNCERT”或“CNCERT/CC”)作为我国非政府层面网络安全应急体系核心技术协 ...
- .NET领域驱动设计系列(12)
[.NET领域驱动设计实战系列]专题十一:.NET 领域驱动设计实战系列总结 摘要: 一.引用 其实在去年本人已经看过很多关于领域驱动设计的书籍了,包括Microsoft .NET企业级应用框架设计. ...
- PHP 微信公众号真正正确的客服头像上传
首先我们来看官方文档 这TM的搞笑呢 什么破玩意儿! 需要条件 1 需要有一个客服的账号 (废话) 2 一致jpg格式的图片(扯蛋) 完整流程 1 获取access_token 2获取账号 3 $ur ...