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多个版本或冲突解决方法. < ...
随机推荐
- ODBC驱动程序丢失解决方法
今天运行SqlDbx连接数据库的时候报错,提示没有找到相应的ODBC driver,打开ODBC管理面板一看,发现里面的驱动程序都不见了.这时想起今天卸载了一个成本核算软件后成这样的,网上搜索一下只需 ...
- SAP UI5和CRM WebUI的View和Controller是如何绑定的
UI5 例如我在UI5的界面上画一个按钮,点击之后弹出一个Alert dialog. 在XML view里只定义了controller的名称和事件处理函数的名称.那么按钮被点击之后,controlle ...
- Kubernetes解决了Docker使用中的哪些问题?
kubernetes是谷歌开源的容器集群管理系统,是Google多年大规模容器管理技术Borg的开源版本 (1)基于容器的应用部署.维护和滚动升级 (2)网络,建立容器之间的通信子网如隧道.路由等,解 ...
- 2017.10.27 C语言精品集
第一章 程序设计和C语言 1.1 什么是计算机程序? @ ······ 所谓程序,就是一组计算机能识别和执行的指令.每一条指令使计算机执行特定的操作. 计算机的一切操作都是由程序控制的.所以计算机的本 ...
- C语言中%p,%u,%lu都有什么用处
%p表示输出这个指针, %d表示后面的输出类型为有符号的10进制整形, %u表示无符号10进制整型, %lu表示输出无符号长整型整数 (long unsigned)
- MAC os x 系统java开发环境搭建教程
https://jingyan.baidu.com/article/3d69c55147a3baf0cf02d7ca.html
- fluent Python
1.1 Python风格的纸牌 Python collections模块中的内置模块:namedtuple https://www.liaoxuefeng.com/wiki/0013747381250 ...
- layui table 用法
1.使用模板列 改变样式 获取嵌套数据{ field: '', width: '12%', title: '响应状态', sort: true, templet: function (d) { if ...
- matlab 读取文件(mat)存储为json文件
fid= fopen('reqJosn.json', 'w+'); load('request-set-10.mat'); requests = requests.request; requestNu ...
- 第9章 初识HAL固件库
本章参考资料:<STM32F76xxx参考手册>.<STM32F7xx规格书>.<Cortex-M3权威指南>, STM32 HAL库帮助文档:<STM32F ...