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库的更多相关文章

  1. 【转载】写一个js库需要怎样的知识储备和技术程度?

    作者:小爝链接:https://www.zhihu.com/question/30274750/answer/118846177来源:知乎著作权归作者所有,转载请联系作者获得授权. 1,如何编写健壮的 ...

  2. js库写法

    前言: 现在javascript库特别多,其写法各式各样,总结几种我们经常见到的,作为自己知识的积累.而目前版本的 JavaScript 并未提供一种原生的.语言级别的模块化组织模式,而是将模块化的方 ...

  3. 如何在Webstorm中添加js库 (青瓷H5游戏引擎)

    js等动态语言编码最大的缺点就是没有智能补全代码,webstorm做到了. qici_engine作为开发使用的库,如果能智能解析成提示再好不过了,经测试80%左右都有提示,已经很好了. 其他js库同 ...

  4. 使用模块化工具打包自己开发的JS库(webpack/rollup)对比总结

    打包JS库demo项目地址:https://github.com/BothEyes1993/bes-jstools 背景 最近有个需求,需要为小程序写一个SDK,监控小程序的后台接口调用和页面报错(类 ...

  5. 前端之Vue.js库的使用

    vue.js简介 Vue.js读音 /vjuː/, 类似于 view Vue.js是前端三大新框架:Angular.js.React.js.Vue.js之一,Vue.js目前的使用和关注程度在三大框架 ...

  6. 发布兼容TS的JS库到nexus和npmjs

    一. 前言 由于node以及绝大多数前端库都是用JavaScript(以下简称JS)语言实现,而Angular是用TypeScript(以下简称TS)实现,虽然TS是JS的超集,但是由于TS和JS对于 ...

  7. 如何写JS库,JS库写法

    前言: 现在javascript库特别多,其写法各式各样,总结几种我们经常见到的,作为自己知识的积累.而目前版本的 JavaScript 并未提供一种原生的.语言级别的模块化组织模式,而是将模块化的方 ...

  8. js库

    lanchpad用的js库 http://lesscss.org/ https://github.com/EightMedia/hammer.js/wiki/Getting-Started http: ...

  9. 解决jQuery多个版本,与其他js库冲突方法

    jQuery多个版本或和其他js库冲突主要是常用的$符号的问题,这个问题 jquery早早就有给我们预留处理方法了,下面一起来看看解决办法. 1.同一页面jQuery多个版本或冲突解决方法. < ...

随机推荐

  1. C++ POD类型

    POD( Plain Old Data)概念: Arithmetic types (3.9.1), enumeration types, pointer types, and pointer to m ...

  2. Selenium入门17 selenium IDE安装及使用

    selenium IDE是firefox浏览器的一个插件,支持脚本的录制回放,关键字驱动的.界面跟robotframework很像. 实际测试中不用录制回放,不过初学者拿来看看元素是如何定位的还是有用 ...

  3. 【PHP 基础类库】Prototype 原型版教学文章!

    前言 大家好我是:石不易,今天我为大家带来了PHP基础类库原型版的教学文章,至此本人的作品线已分为三大类,分别是:JavaScript前端框架(封装库).PHP模板引擎.以及PHP基础类库.该类库历时 ...

  4. mm struct与pgd

    假如该vm_area_struct描述的是一个文件映射的虚存空间,成员vm_file便指向被映射的文件的file结构,vm_pgoff是该虚存空间起始地址在vm_file文件里面的文件偏移,单位为物理 ...

  5. MySQL 数据库和一些常用命令的使用

        常用命令总结: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 3 ...

  6. P1316 丢瓶盖

    题目描述 陶陶是个贪玩的孩子,他在地上丢了A个瓶盖,为了简化问题,我们可以当作这A个瓶盖丢在一条直线上,现在他想从这些瓶盖里找出B个,使得距离最近的2个距离最大,他想知道,最大可以到多少呢? 输入输出 ...

  7. python_3_coding

    # -*- coding:utf-8 -*- 也可以换成下划线 用于声明文件编码,python3本身就是utf-8类型,不用声明 name="你好,世界"#utf-8格式能显示汉字 ...

  8. web攻击技术与防护

    一.跨站脚本攻击(XSS) 跨站脚本攻击是指通过存在安全漏洞的Web网站注册用户的浏览器运行非法的HTML标签或JavaScript进行的一种攻击.动态创建的HTML部分有可能隐藏着安全漏洞.就这样, ...

  9. ES6初识-Proxy和Reflect

    { let obj={ time:'2017-03-11', name:'net', _r:123 };   let monitor=new Proxy(obj,{ // 拦截对象属性的读取 get( ...

  10. 第34-2题:LeetCode113. Path Sum II

    题目 给定一个二叉树和一个目标和,找到所有从根节点到叶子节点路径总和等于给定目标和的路径. 说明: 叶子节点是指没有子节点的节点. 示例: 给定如下二叉树,以及目标和 sum = 22, 5 / \ ...