1. var GLOBAL = {};
  2. GLOBAL.namespace = function(str) {
  3. var arr = str.split("."), o = GLOBAL,i;
  4. for (i = (arr[0] = "GLOBAL") ? 1 : 0; i < arr.length; i++) {
  5. o[arr[i]] = o[arr[i]] || {};
  6. o = o[arr[i]];
  7. }
  8. };
  9. //Dom相关
  10. GLOBAL.namespace("Dom");
  11.  
  12. GLOBAL.Dom.getNextNode = function (node) {
  13. node = typeof node == "string" ? document.getElementById(node) : node;
  14. var nextNode = node.nextSibling;
  15. if (!nextNode) {
  16. return null;
  17. }
  18. if (!document.all) {
  19. while (true) {
  20. if (nextNode.nodeType == 1) {
  21. break;
  22.  
  23. } else {
  24. if (nextNode.nextSibling) {
  25. nextNode = nextNode.nextSibling;
  26. } else {
  27. break;
  28. }
  29. }
  30. }
  31. return nextNode;
  32. }
  33. }
  34.  
  35. GLOBAL.Dom.setOpacity = function(node, level) {
  36. node = typeof node == "string" ? document.getElementById(node) : node;
  37. if (document.all) {
  38. node.style.filter = 'alpha(opacity=' + level + ')';
  39. } else {
  40. node.style.opacity = level / 100;
  41. }
  42. };
  43.  
  44. GLOBAL.Dom.getElementsByClassName = function (str, root, tag) {
  45. if (root) {
  46. root = typeof root == "string" ? document.getElementById(root) : root;
  47. } else {
  48. root = document.body;
  49. }
  50. tag = tag || "*";
  51. var els = root.getElementsByTagName(tag), arr = [];
  52. for (var i = 0, n = els.length; i < n; i++) {
  53. for (var j = 0, k = els[i].className.split(" "), l = k.length; j < l; j++) {
  54. if (k[j] == str) {
  55. arr.push(els[i]);
  56. break;
  57. }
  58. }
  59. }
  60. return arr;
  61. }
  62. GLOBAL.namespace("Event");
  63. GLOBAL.Event.stopPropagation = function(e) {
  64. e = window.event || e;
  65. if (document.all) {
  66. e.cancelBubble = true;
  67. } else {
  68. e.stopPropagation();
  69. }
  70. };
  71. GLOBAL.Event.getEventTarget = function(e) {
  72. e = window.event || e;
  73. return e.srcElement || e.target;
  74. };
  75.  
  76. GLOBAL.Event.on = function(node, eventType, handler) {
  77. node = typeof node == "string" ? document.getElementById(node) : node;
  78. if (document.all) {
  79. node.attachEvent("on" + eventType, handler);
  80. } else {
  81. node.addEventListener(eventType, handler, false);
  82. }
  83. };
  84.  
  85. //Lang相关
  86. GLOBAL.namespace("Lang");
  87. GLOBAL.Lang.trim = function(ostr) {
  88. return ostr.replace(/^\s+|\s+$/g, "");
  89. };
  90.  
  91. GLOBAL.Lang.isNumber = function(s) {
  92. return !isNaN(s);
  93. };
  94.  
  95. function isString(s) {
  96. return typeof s === "string";
  97. }
  98.  
  99. function isBoolean(s) {
  100. return typeof s === "boolean";
  101. }
  102.  
  103. function isFunction(s) {
  104. return typeof s === "function";
  105. }
  106.  
  107. function isNull(s) {
  108. return s === null;
  109. }
  110.  
  111. function isUndefined(s) {
  112. return typeof s === "undefined";
  113. }
  114.  
  115. function isEmpty(s) {
  116. return /^\s*$/.test(s);
  117. }
  118.  
  119. function isArray(s) {
  120. return s instanceof Array;
  121. }
  122.  
  123. GLOBAL.Dom.get = function (node) {
  124. node = typeof node === "string" ? document.getElementById(node) : node;
  125. return node;
  126. }
  127.  
  128. function $(node) {
  129. node = typeof node == "string" ? document.getElementById(node) : node;
  130. return node;
  131. }
  132.  
  133. GLOBAL.Lang.extend = function(subClass, superClass) {
  134. var F = function() {
  135. };
  136. F.prototype = superClass.prototype;
  137. subClass.prototype = new F();
  138. subClass.prototype.constructor = subClass;
  139. subClass.superClass = subClass.prototype;
  140. if (superClass.prototype.constructor == Object.prototype.constructor) {
  141. superClass.prototype.constructor = superClass;
  142. }
  143. };
  144.  
  145. GLOBAL.namespace("Cookie");
  146. GLOBAL.Cookie = {
  147. read: function (name) {
  148. var cookieStr = ";" + document.cookie + ";";
  149. var index = cookieStr.indexOf(";" + name + "=");
  150. if (index != -1) {
  151. var s = cookieStr.substring(index + name.length + 3, cookieStr.length);
  152. return unescape(s.substring(0, s.indexOf(";")));
  153. } else {
  154. return null;
  155. }
  156. },
  157. set: function (name, value, expires) {
  158. var expDays = expires * 24 * 60 * 60 * 1000;
  159. var expDate = new Date();
  160. expDate.setTime(expDate.getTime() + expDays);
  161. var expString = expires ? ";expires=" + expDate.toGMTString() : "";
  162. var pathString = ";path=/";
  163. document.cookie = name + "=" + escape(value) + expString + pathString;
  164. },
  165. del: function (name, value, expires) {
  166. var exp = new Date(new Date().getTime() - 1);
  167. var s = this.read(name);
  168. if (s != null) {
  169. document.cookie = name + "=" + s + ";expires=" + exp.toGMTString() + ";path=/";
  170. }
  171. }
  172. };

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. ODBC驱动程序丢失解决方法

    今天运行SqlDbx连接数据库的时候报错,提示没有找到相应的ODBC driver,打开ODBC管理面板一看,发现里面的驱动程序都不见了.这时想起今天卸载了一个成本核算软件后成这样的,网上搜索一下只需 ...

  2. SAP UI5和CRM WebUI的View和Controller是如何绑定的

    UI5 例如我在UI5的界面上画一个按钮,点击之后弹出一个Alert dialog. 在XML view里只定义了controller的名称和事件处理函数的名称.那么按钮被点击之后,controlle ...

  3. Kubernetes解决了Docker使用中的哪些问题?

    kubernetes是谷歌开源的容器集群管理系统,是Google多年大规模容器管理技术Borg的开源版本 (1)基于容器的应用部署.维护和滚动升级 (2)网络,建立容器之间的通信子网如隧道.路由等,解 ...

  4. 2017.10.27 C语言精品集

    第一章 程序设计和C语言 1.1 什么是计算机程序? @ ······ 所谓程序,就是一组计算机能识别和执行的指令.每一条指令使计算机执行特定的操作. 计算机的一切操作都是由程序控制的.所以计算机的本 ...

  5. C语言中%p,%u,%lu都有什么用处

    %p表示输出这个指针, %d表示后面的输出类型为有符号的10进制整形, %u表示无符号10进制整型, %lu表示输出无符号长整型整数 (long unsigned)

  6. MAC os x 系统java开发环境搭建教程

    https://jingyan.baidu.com/article/3d69c55147a3baf0cf02d7ca.html

  7. fluent Python

    1.1 Python风格的纸牌 Python collections模块中的内置模块:namedtuple https://www.liaoxuefeng.com/wiki/0013747381250 ...

  8. layui table 用法

    1.使用模板列 改变样式 获取嵌套数据{ field: '', width: '12%', title: '响应状态', sort: true, templet: function (d) { if ...

  9. matlab 读取文件(mat)存储为json文件

    fid= fopen('reqJosn.json', 'w+'); load('request-set-10.mat'); requests = requests.request; requestNu ...

  10. 第9章 初识HAL固件库

    本章参考资料:<STM32F76xxx参考手册>.<STM32F7xx规格书>.<Cortex-M3权威指南>, STM32 HAL库帮助文档:<STM32F ...