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. 利用批处理结合Msbuild实现快速编译

    我们经常在用vs2005做项目的时候会把一个项目分成几个模块(不管是对于功能上,还是系统构架上面),为的是以后部署,还有修改维护时候的方便.这样就会带来一个问题,随着模块的增加(这里所说得每个模块就是 ...

  2. CORS跨域请求的限制和解决

    我们模拟一个跨域的请求,一个是8888,一个是8887 //server.js const http = require('http'); const fs = require('fs'); http ...

  3. centos 开启http代理tinyproxy

    一.前言 就算有一些公司想到要进行压力测试也是用一些微软,官网出的一些软件,一个ip发起很多访问.等有一天黑客攻击来了发现还是顶不住.华盟君认为知此知彼才是压力测试的关键点,应当模拟黑客手法进行压力测 ...

  4. node.js 练习2 (调用函数)

    1. 调用本地 函数 (1)  创建 n2-1.js ,并输入代码 (2) 运行localhhost:8000 (3)在浏览器中 查看 (4)在cmd中查看 2.调用外部 函数 (1) 创建n2-2. ...

  5. 安装ubuntu-tweak

    第一步:添加tweak源 sudo add-apt-repository ppa:tualatrix/ppa   第二步:更新 sudo apt-get update   第三步:安装ubuntu-t ...

  6. cudaMemcpy2D

  7. python 多进程,多线程,协程

    在我们实际编码中,会遇到一些并行的任务,因为单个任务无法最大限度的使用计算机资源.使用并行任务,可以提高代码效率,最大限度的发挥计算机的性能.python实现并行任务可以有多进程,多线程,协程等方式. ...

  8. python备份mysql数据库

    介绍使用python结合mysqldump对mysql数据库进行备份 import os import sys import configparser import time def test_fil ...

  9. linux数据库copy方法

    相信大多数程序员都会遇到数据库copy的问题,下面就总结几种常见的方法,针对有mysql基础的同学参考 方法一:利用sqlyog的copy database的功能,如图 这种最简单,速度比较慢: 方法 ...

  10. 正则(re 模块)

    就其本质而言,正则表达式(或 RE)是一种小型的.高度专业化的编程语言,(在Python中)它内嵌在Python中,并通过 re 模块实现.正则表达式模式被编译成一系列的字节码,然后由用 C 编写的匹 ...