common_t.js


  1. /**
  2. * 通用工具组件 对原有的工具进行封装,自定义某方法统一处理<br>
  3. * ^_^
  4. *
  5. * Author: em.D
  6. * Date: 2016-05-17
  7. * Version: 0.0.1
  8. */
  9. function send_http() {
  10. $(selector)..get(URL, data, function(data,status,xhr) {}, dataType);
  11. $(selector).post(URL, data, function(data,status,xhr) {}, dataType)
  12. $(selector).getJSON(url, data, function(data,status,xhr) {});
  13. }
  14. function all_ajax() {
  15. $.ajax({
  16. url: "xx.do",
  17. type: "post",
  18. data: {},
  19. //async: false, //设置为同步,默认为异步(一般不需要)
  20. cache: false,
  21. dataType: "json",
  22. //password: "",
  23. timeout: 1000 * 10, // 毫秒
  24. beforeSend: function(XMLHttpRequest) {
  25. // ShowLoading();
  26. },
  27. success: function(data) {
  28. if (data != null) {
  29. if ("success" == data.result) {
  30. // TODO
  31. } else {
  32. // $.messager.alert("系统提示", "操作失败,请重试", "info");
  33. }
  34. // console.log("result = " + data.result + ",msg=" +
  35. // data.msg);//IE不支持console输出
  36. } else {
  37. // $.messager.alert("系统提示","返回结果为空!","info");
  38. }
  39. },
  40. complete: function(XMLHttpRequest, textStatus) {
  41. // alert("textStatus="+textStatus);
  42. // closeLoading();//关闭进度条
  43. },
  44. error: function(XMLHttpRequest, textStatus, errorThrown) {
  45. // closeLoading();//关闭进度条
  46. if ("error" == textStatus) {
  47. // $.messager.alert("系统提示", "服务器未响应,请稍候再试", "info");
  48. } else {
  49. // $.messager.alert("系统提示", "请求失败,textStatus="+textStatus,
  50. // "info");
  51. }
  52. },
  53. });
  54. }
  55. ;
  56. (function() {
  57. $.extend({
  58. log: function(message) {
  59. var now = new Date(),
  60. y = now.getFullYear(),
  61. m = now.getMonth() + 1, // !JavaScript中月分是从0开始的
  62. d = now.getDate(),
  63. h = now.getHours(),
  64. min = now.getMinutes(),
  65. s = now.getSeconds(), time = y + '/' + m + '/' + d + ' ' + h + ':' + min + ':' + s;
  66. console.log(time + ' My Log: ' + message);
  67. }
  68. });
  69. //$.log('initializing...'); // 调用
  70. em = {};
  71. em.ajax = (function(params) {
  72. var pp = {
  73. error: function(XMLHttpRequest, textStatus, errorThrown) {
  74. console.log("数据请求异常,异常状态:" + XMLHttpRequest.status);
  75. }
  76. };
  77. $.extend(pp, params);
  78. $.ajax(pp);
  79. });
  80. /**
  81. * 表单提交
  82. * @param from 表单ID
  83. * @param params ajax参数
  84. *
  85. * @author em.D
  86. */
  87. em.ajaxSubmit = (function(form, params) {// form 表单ID. params ajax参数
  88. var pp = {
  89. // clearForm: true,
  90. // resetForm: true,
  91. error: function(XMLHttpRequest, textStatus, errorThrown) {
  92. console.log("数据请求异常,异常状态:" + XMLHttpRequest.status);
  93. }
  94. };
  95. $.extend(pp, params);
  96. $(form).ajaxSubmit(pp);
  97. });
  98. CommonUtil = {
  99. /**
  100. * ajax同步请求 返回一个html内容 dataType=html. 默认为html格式 如果想返回json.
  101. * CommonUtil.ajax(url, data, "json")
  102. *
  103. * @author em.D
  104. */
  105. ajax: function(url, data, dataType) {
  106. if (!CommonUtil.notNull(dataType)) {
  107. dataType = "html";
  108. }
  109. var html = '没有结果!';
  110. // 所以AJAX都必须使用em.ajax..这里经过再次封装,统一处理..同时继承ajax所有属性
  111. if (url.indexOf("?") > -1) {
  112. url = url + "&_t=" + new Date();
  113. } else {
  114. url = url + "?_t=" + new Date();
  115. }
  116. em.ajax({
  117. type: "post",
  118. url: url,
  119. data: data,
  120. dataType: dataType, // 这里的dataType就是返回回来的数据格式了html,xml,json
  121. async: false,
  122. cache: false, // 设置是否缓存,默认设置成为true,当需要每次刷新都需要执行数据库操作的话,需要设置成为false
  123. traditional: true, // struts2数组参数异常
  124. //contentType: "application/json",
  125. success: function(data) {
  126. html = data;
  127. }
  128. });
  129. return html;
  130. },
  131. ajaxAsync: function(type, url, param, dataType, callback) {
  132. if (!CommonUtil.notNull(type)) {
  133. type = "get";
  134. }
  135. if (!CommonUtil.notNull(dataType)) {
  136. dataType = "html";
  137. }
  138. if (url.indexOf("?") > -1) {
  139. url = url + "&_t=" + new Date();
  140. } else {
  141. url = url + "?_t=" + new Date();
  142. }
  143. //(callback && typeof(callback)==="function") && callback();
  144. if(!(typeof callback == "function")) {
  145. callback = function(data) {
  146. $.log("ajaxAsync执行失败,callback不是函数!");
  147. }
  148. }
  149. em.ajax({
  150. type: type,
  151. url: url,
  152. data: param,
  153. dataType: dataType,
  154. async: true,
  155. cache: false,
  156. success: callback
  157. });
  158. },
  159. /**
  160. * 获取地址栏参数
  161. */
  162. getURLParam: function(name) {
  163. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  164. var url = window.location.search.substring(1).match(reg);
  165. if (url != null) {
  166. return decodeURI(url[2]); // decodeURI | unescape
  167. }
  168. return null;
  169. },
  170. /**
  171. * 判断某对象不为空..返回true 否则 false
  172. *
  173. * @author em.D
  174. */
  175. notNull: function(obj) {
  176. if (obj === null) {
  177. return false;
  178. } else if (obj === undefined) {
  179. return false;
  180. } else if (obj === "undefined") {
  181. return false;
  182. } else if (obj === "") {
  183. return false;
  184. } else if (obj === "[]") {
  185. return false;
  186. } else if (obj === "{}") {
  187. return false;
  188. } else {
  189. return true;
  190. }
  191. },
  192. /**
  193. * 判断某对象不为空..返回obj 否则 ""
  194. *
  195. * @author em.D
  196. */
  197. notEmpty: function(obj) {
  198. if (obj === null) {
  199. return "";
  200. } else if (obj === undefined) {
  201. return "";
  202. } else if (obj === "undefined") {
  203. return "";
  204. } else if (obj === "") {
  205. return "";
  206. } else if (obj === "[]") {
  207. return "";
  208. } else if (obj === "{}") {
  209. return "";
  210. } else {
  211. return obj;
  212. }
  213. },
  214. /**
  215. * 判断参数(String,Array,Object)是否为undefined或者值为空, true: 为空
  216. */
  217. isEmptyValue: function(value) {
  218. var type;
  219. if(value == null) { // 等同于 value === undefined || value === null
  220. return true;
  221. }
  222. type = Object.prototype.toString.call(value).slice(8, -1);
  223. switch(type) {
  224. case 'String':
  225. return !$.trim(value);
  226. case 'Array':
  227. return !value.length;
  228. case 'Object':
  229. return $.isEmptyObject(value); // 普通对象使用 for...in 判断,有 key 即为 false
  230. default:
  231. return false; // 其他对象均视作非空
  232. }
  233. },
  234. /**
  235. * 阻止事件冒泡
  236. */
  237. preventBubble: function() {
  238. /*
  239. * return false 在事件的处理中,可以阻止默认事件和冒泡事件。
  240. * event.preventDefault()在事件的处理中,可以阻止默认事件但是允许冒泡事件的发生。
  241. * event.stopPropagation()在事件的处理中,可以阻止冒泡但是允许默认事件的发生。
  242. */
  243. var e = arguments.callee.caller.arguments[0] || event; // 若省略此句,下面的e改为event,IE运行可以,但是其他浏览器就不兼容
  244. if (e && e.stopPropagation) {
  245. // this code is for Mozilla and Opera
  246. e.stopPropagation();
  247. } else if (window.event) {
  248. // this code is for IE
  249. window.event.cancelBubble = true;
  250. }
  251. },
  252. loadingImg: function() {
  253. var html = '<div class="alert alert-warning">'
  254. + '<button type="button" class="close" data-dismiss="alert">'
  255. + '<i class="ace-icon fa fa-times"></i></button><div style="text-align:center">'
  256. //+ '<img src="' + rootPath + '/images/loading.gif"/><div>'
  257. + '<img src="images/loading.gif"/><div>'
  258. + '</div>';
  259. return html;
  260. },
  261. /**
  262. * html标签转义
  263. *
  264. * @author em.D
  265. */
  266. htmlspecialchars: function(str) {
  267. var s = "";
  268. if (str.length == 0)
  269. return "";
  270. for (var i = 0; i < str.length; i++) {
  271. switch (str.substr(i, 1)) {
  272. case "<":
  273. s += "<";
  274. break;
  275. case ">":
  276. s += ">";
  277. break;
  278. case "&":
  279. s += "&";
  280. break;
  281. case " ":
  282. if (str.substr(i + 1, 1) == " ") {
  283. s += "  ";
  284. i++;
  285. } else
  286. s += " ";
  287. break;
  288. case "\"":
  289. s += """;
  290. break;
  291. case "\n":
  292. s += "";
  293. break;
  294. default:
  295. s += str.substr(i, 1);
  296. break;
  297. }
  298. }
  299. },
  300. /**
  301. * in_array判断一个值是否在数组中
  302. */
  303. in_array: function(array, string) {
  304. for (var s = 0; s < array.length; s++) {
  305. thisEntry = array[s].toString();
  306. if (thisEntry == string) {
  307. return true;
  308. }
  309. }
  310. return false;
  311. },
  312. formatNum: function(num) {
  313. var patt = new RegExp(/(\+|-)?(\d+)(\.\d+)?/g);
  314. if (!patt.test(num)) {
  315. return num;
  316. }
  317. var a = RegExp.$1, b = RegExp.$2, c = RegExp.$3;
  318. var re = new RegExp("(\\d)(\\d{3})(,|$)");
  319. while (re.test(b)) {
  320. b = b.replace(re, "$1,$2$3");
  321. }
  322. return a + "" + b + "" + c;
  323. },
  324. setLstorageVal: function(key, value) {
  325. window.localStorage['emSsnsrg_' + key] = value;
  326. },
  327. getLstorageVal: function(key) {
  328. if(window.localStorage['emSsnsrg_'+key])
  329. return window.localStorage['emSsnsrg_' + key];
  330. else if(window.localStorage['emSsnsrg_' + key])
  331. return window.localStorage['emSsnsrg_' + key];
  332. else
  333. return "";
  334. },
  335. clearLstorageVal: function(key) {
  336. if(key)
  337. window.localStorage.removeItem('emSsnsrg_' + key);
  338. else
  339. window.localStorage.clear();
  340. },
  341. setStorageVal: function(key, value) {
  342. window.sessionStorage['emSsnsrg_'+key] = value;
  343. },
  344. getStorageVal: function(key) {
  345. if(sessionStorage['emSsnsrg_' + key])
  346. return sessionStorage['emSsnsrg_' + key];
  347. else if(window.sessionStorage['emSsnsrg_' + key])
  348. return window.sessionStorage['emSsnsrg_' + key];
  349. else
  350. return "";
  351. },
  352. clearStorageVal: function(key) {
  353. if(key)
  354. window.sessionStorage.removeItem('emSsnsrg_' + key);
  355. else
  356. window.sessionStorage.clear();
  357. }
  358. };
  359. })();
  360. // 表单json格式化方法……不使用&拼接
  361. (function($) {
  362. var my_blink_plug_name = "myblink";
  363. /**
  364. *
  365. *
  366. $("div").myblink({
  367. interval: 300, // 闪动间隔时间,默认为100
  368. blink_count: 3, // 最大闪动次数,0表示无限
  369. before_blink: function (obj){ // 闪动前回调方法
  370. $(obj).css({color: "red"});
  371. },
  372. after_blink: function (obj){ // 闪动结束回调方法
  373. $(obj).css({color: "black"});
  374. }
  375. });
  376. $("div").fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100);
  377. */
  378. $.fn[my_blink_plug_name] = function(options) {
  379. var defaults = {
  380. interval: 100,
  381. blink_count: 0,
  382. before_blink: function(obj) {},
  383. after_blink: function(obj) {}
  384. };
  385. this.settings = $.extend({}, defaults, options);
  386. var _this = this;
  387. var c = 0;
  388. _this.settings.before_blink(_this);
  389. var myVar = setInterval(function() {
  390. if (_this.css("visibility") == "visible") {
  391. _this.css('visibility', 'hidden');
  392. } else {
  393. _this.css('visibility', 'visible');
  394. if(_this.settings.blink_count > 0) {
  395. c ++;
  396. if(c == _this.settings.blink_count){
  397. clearInterval(myVar);
  398. _this.settings.after_blink(_this);
  399. }
  400. }
  401. }
  402. }, _this.settings.interval);
  403. return this;
  404. };
  405. $.fx.step["backgroundPosition"] = function(fx) {
  406. if (typeof fx.end == 'string') {
  407. fx.start = getBgPos(fx.elem);
  408. // fx.end原本是一个string,这里将它转换成数组,就不会再进入这个if,也方便我们下面的计算
  409. // 例 "0px -21px"
  410. fx.end = [parseFloat(fx.end.split(" ")[0]), parseFloat(fx.end.split(" ")[1])];
  411. }
  412. // 这里fx.pos是根据传入的时间参数,从0到1变化的浮点数
  413. var nowPosX = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit;
  414. var nowPosY = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit;
  415. fx.elem.style.backgroundPosition = nowPosX + ' ' + nowPosY;
  416. /**
  417. * 获取backgroundPosition数组[top, left],没有单位
  418. */
  419. function getBgPos(elem) {
  420. var top = 0.0;
  421. var left = 0.0;
  422. if ($(elem).css("backgroundPosition")) {
  423. // 例 "0px -21px"
  424. top = parseFloat($(elem).css("backgroundPosition").split(" ")[0]);
  425. left = parseFloat($(elem).css("backgroundPosition").split(" ")[1]);
  426. } else {
  427. top = parseFloat($(elem).css("backgroundPositionX"));
  428. left = parseFloat($(elem).css("backgroundPositionY"));
  429. }
  430. return [top, left];
  431. }
  432. };
  433. /* end */
  434. /**
  435. * <pre>
  436. * 自定义jquery函数,完成将form 数据转换为 json格式
  437. *
  438. * // 将 form 数据转换 json格式
  439. * var params = $("#searchForm").serializeJson(); <pre>
  440. *
  441. * @author em.D
  442. *
  443. */
  444. $.fn.serializeJson = function() {
  445. var serializeObj = {}; // 目标对象
  446. var array = this.serializeArray(); // 转换数组格式
  447. // var str=this.serialize();
  448. $(array).each(function() { // 遍历数组的每个元素 {name: xx , value: xxx}
  449. if (serializeObj[this.name]) { // 判断对象中是否已经存在 name,如果存在name
  450. if ($.isArray(serializeObj[this.name])) {
  451. serializeObj[this.name].push(this.value); // 追加一个值 hobby: ['音乐','体育']
  452. } else {
  453. // 将元素变为 数组 ,hobby: ['音乐','体育']
  454. serializeObj[this.name] = [serializeObj[this.name], this.value ];
  455. }
  456. } else {
  457. serializeObj[this.name] = this.value; // 如果元素name不存在,添加一个属性 name:value
  458. }
  459. });
  460. return serializeObj;
  461. };
  462. /**
  463. * 限制只能输入数字和字母
  464. */
  465. $.fn.onlyNumAlpha = function() {
  466. $(this).keypress(function(event) {
  467. var eventObj = event || e;
  468. var keyCode = eventObj.keyCode || eventObj.which;
  469. if ((keyCode >= 48 && keyCode <= 57) || (keyCode >= 65 && keyCode <= 90) || (keyCode >= 97 && keyCode <= 122))
  470. return true;
  471. else
  472. return false;
  473. }).focus(function() {
  474. this.style.imeMode = 'disabled';
  475. }).bind("paste", function() {
  476. var clipboard = window.clipboardData.getData("Text");
  477. if (/^(\d|[a-zA-Z])+$/.test(clipboard))
  478. return true;
  479. else
  480. return false;
  481. });
  482. };
  483. $.fn.rowspan = function(colIdx) {
  484. return this.each(function() {
  485. var that;
  486. $('tr', this).each(function(row) {
  487. $('td:eq(' + colIdx + ')', this).each(function(col) {
  488. if ($(this).html() == $(that).html()) {
  489. rowspan = $(that).attr("rowSpan");
  490. if (rowspan == undefined) {
  491. $(that).attr("rowSpan", 1);
  492. rowspan = $(that).attr("rowSpan");
  493. }
  494. rowspan = Number(rowspan) + 1;
  495. $(that).attr("rowSpan", rowspan); // do your action for the colspan cell here
  496. $(this).hide(); // .remove(); // do your action for the old cell here
  497. } else {
  498. that = this;
  499. }
  500. that = (that == null) ? this: that; // set the that if not already set
  501. });
  502. });
  503. });
  504. };
  505. /**
  506. * [numFormat 数字添加千位分隔符]
  507. * @return {[String]} [123,123,123]
  508. */
  509. Number.prototype.numFormat = function() {
  510. if (!CommonUtil.notNull(this)) {
  511. return "0";
  512. }
  513. var patt = new RegExp(/(\+|-)?(\d+)(\.\d+)?/g);
  514. if (!patt.test(this)) {
  515. return this;
  516. }
  517. var a = RegExp.$1,
  518. b = RegExp.$2,
  519. c = RegExp.$3;
  520. var re = new RegExp("(\\d)(\\d{3})(,|$)");
  521. while (re.test(b)) {
  522. b = b.replace(re, "$1,$2$3");
  523. }
  524. return a + "" + b + "" + c;
  525. }; String.prototype.trim = function() {
  526. return this.replace(/^\s+/, '').replace(/\s+$/, '');
  527. };
  528. String.prototype.numFormat = function() {
  529. if (!CommonUtil.notNull(this)) {
  530. return "0";
  531. }
  532. var patt = new RegExp(/(\+|-)?(\d+)(\.\d+)?/g);
  533. if (!patt.test(this)) {
  534. return this;
  535. }
  536. var a = RegExp.$1, b = RegExp.$2, c = RegExp.$3;
  537. var re = new RegExp("(\\d)(\\d{3})(,|$)");
  538. while (re.test(b)) {
  539. b = b.replace(re, "$1,$2$3");
  540. }
  541. return a + "" + b + "" + c;
  542. };
  543. /**
  544. * [format 对Date的扩展,将 Date 转化为指定格式的String]
  545. *
  546. // 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字), 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符
  547. *
  548. * @param {[string]} format [yyyy-MM-dd hh:mm:ss:S q]
  549. * @return {[string]} [格式化之后的日期对象]
  550. */
  551. // (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
  552. // (new Date()).Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18
  553. Date.prototype.format = function(format) {
  554. var o = {
  555. "M+" : this.getMonth() + 1, // month
  556. "d+" : this.getDate(), // day
  557. "h+" : this.getHours(), // hour
  558. "m+" : this.getMinutes(), // minute
  559. "s+" : this.getSeconds(), // second
  560. "q+" : Math.floor((this.getMonth() + 3) / 3), // quarter
  561. "S" : this.getMilliseconds()// millisecond
  562. };
  563. if (/(y+)/.test(format)) {
  564. format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  565. }
  566. for ( var k in o) {
  567. if (new RegExp("(" + k + ")").test(format)) {
  568. format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
  569. }
  570. }
  571. return format;
  572. };
  573. /**
  574. * 对Date的扩展,将 Date 转化为指定格式的String
  575. * 月(M)、日(d)、12小时(h)、24小时(H)、分(m)、秒(s)、周(E)、季度(q) 可以用 1-2 个占位符
  576. * 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
  577. * eg:
  578. * (new Date()).pattern("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
  579. * (new Date()).pattern("yyyy-MM-dd E HH:mm:ss") ==> 2009-03-10 二 20:09:04
  580. * (new Date()).pattern("yyyy-MM-dd EE hh:mm:ss") ==> 2009-03-10 周二 08:09:04
  581. * (new Date()).pattern("yyyy-MM-dd EEE hh:mm:ss") ==> 2009-03-10 星期二 08:09:04
  582. * (new Date()).pattern("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18
  583. * var date = new Date();
  584. * window.alert(date.pattern("yyyy-MM-dd hh:mm:ss"));
  585. */
  586. Date.prototype.pattern=function(fmt) {
  587. var o = {
  588. "M+" : this.getMonth()+1, //月份
  589. "d+" : this.getDate(), //日
  590. "h+" : this.getHours()%12 == 0 ? 12 : this.getHours()%12, //小时
  591. "H+" : this.getHours(), //小时
  592. "m+" : this.getMinutes(), //分
  593. "s+" : this.getSeconds(), //秒
  594. "q+" : Math.floor((this.getMonth()+3)/3), //季度
  595. "S" : this.getMilliseconds() //毫秒
  596. };
  597. var week = {
  598. "0" : "/u65e5",
  599. "1" : "/u4e00",
  600. "2" : "/u4e8c",
  601. "3" : "/u4e09",
  602. "4" : "/u56db",
  603. "5" : "/u4e94",
  604. "6" : "/u516d"
  605. };
  606. if(/(y+)/.test(fmt)){
  607. fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
  608. }
  609. if(/(E+)/.test(fmt)){
  610. fmt=fmt.replace(RegExp.$1, ((RegExp.$1.length>1) ? (RegExp.$1.length>2 ? "/u661f/u671f" : "/u5468") : "")+week[this.getDay()+""]);
  611. }
  612. for(var k in o){
  613. if(new RegExp("("+ k +")").test(fmt)){
  614. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
  615. }
  616. }
  617. return fmt;
  618. } Array.prototype.max = function() { // 最大值
  619. return Math.max.apply({}, this);
  620. };
  621. Array.prototype.min = function() { // 最小值
  622. return Math.min.apply({}, this);
  623. };
  624. Array.prototype.indexOf = function(el) {
  625. for (var i = 0, n = this.length; i < n; i++) {
  626. if (this[i] === el) {
  627. return i;
  628. }
  629. }
  630. return -1;
  631. };
  632. /**
  633. * 删除数组指定下标或指定对象
  634. */
  635. Array.prototype.remove = function(obj) {
  636. for (var i = 0; i < this.length; i++) {
  637. var temp = this[i];
  638. if (!isNaN(obj)) {
  639. temp = i;
  640. }
  641. if (temp == obj) {
  642. for (var j = i; j < this.length; j++) {
  643. this[j] = this[j + 1];
  644. }
  645. this.length = this.length - 1;
  646. }
  647. }
  648. };
  649. // 局部作用域中使用$来引用jQuery
  650. })(jQuery);
  651. /*
  652. * ! [Cookie基本操作]
  653. * @param {[Windo]} win [description]
  654. * @param {[Document]} doc) { var exp, strsec; var getsec [description]
  655. * @return {[type]} [description]
  656. */
  657. var EmCookie = (function(win, doc) {
  658. var exp,
  659. strsec;
  660. var getsec = function(str) {
  661. var str1 = str.substring(1, str.length) * 1;
  662. var str2 = str.substring(0, 1);
  663. if (str2 == "s") {
  664. return str1 * 1000;
  665. } else if (str2 == "h") {
  666. return str1 * 60 * 60 * 1000;
  667. } else if (str2 == "d") {
  668. return str1 * 24 * 60 * 60 * 1000;
  669. }
  670. };
  671. /**
  672. * [get 获取Cookie]
  673. * @param {[String]} name [Cookie名称]
  674. * @return {[Object]} [Cookie对应的值]
  675. */
  676. var get = function(name) {
  677. var arr,
  678. reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
  679. if (arr = doc.cookie.match(reg)) {
  680. return unescape(arr[2]);
  681. } else {
  682. return null;
  683. }
  684. };
  685. /**
  686. * [set 设置Cookie,默认设置30天]
  687. * @param {[String]} name [Cookie名称]
  688. * @param {[Object]} value [Cookie值]
  689. * @param {[Date]} time [过期时间,s20是代表20秒,h是指小时,如12小时则是:h12,d是天数,30天则:d30]
  690. */
  691. var set = function(name, value, time) {
  692. exp = new Date();
  693. if (CommonUtil.notNull(time)) {
  694. strsec = getsec(time);
  695. } else {
  696. strsec = getsec("d30");
  697. }
  698. exp.setTime(exp.getTime() + strsec * 1);
  699. doc.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
  700. };
  701. /**
  702. * [remove 删除Cookie]
  703. * @param {[String]} name [Cookie名称]
  704. */
  705. var remove = function(name) {
  706. exp = new Date();
  707. exp.setTime(exp.getTime() - 1);
  708. var cval = get(name);
  709. if (cval != null) {
  710. doc.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
  711. }
  712. };
  713. var clear = function() {
  714. var keys = document.cookie.match(/[^ =;]+(?=\=)/g);
  715. if (keys) {
  716. for (var i = keys.length; i--;)
  717. document.cookie = keys[i] + '=0;expires=' + new Date(0).toUTCString();// + "; path=/yxw/";
  718. }
  719. };
  720. //document.cookie;
  721. return {
  722. get: get,
  723. set: set,
  724. remove: remove,
  725. clear: clear
  726. }
  727. }(window, document));var matched,
  728. browser;
  729. jQuery.uaMatch = function( ua ) {
  730. ua = ua.toLowerCase();
  731. var match = /(chrome)[ \/]([\w.]+)/.exec( ua )
  732. || /(webkit)[ \/]([\w.]+)/.exec( ua )
  733. || /(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua )
  734. || /(msie) ([\w.]+)/.exec( ua )
  735. || ua.indexOf("compatible") < 0
  736. && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua )
  737. || [];
  738. return {
  739. browser: match[ 1 ] || "",
  740. version: match[ 2 ] || "0"
  741. };
  742. };
  743. matched = jQuery.uaMatch( navigator.userAgent );
  744. browser = {};
  745. if (matched.browser) {
  746. browser[matched.browser] = true;
  747. browser.version = matched.version;
  748. }
  749. // Chrome is Webkit, but Webkit is also Safari.
  750. if ( browser.chrome ) {
  751. browser.webkit = true;
  752. } else if ( browser.webkit ) {
  753. browser.safari = true;
  754. }
  755. jQuery.browser = browser;
  756. /*
  757. //下面是直接写的判断,上面jq的获取方法
  758. if (matched.browser == 'mozilla') {
  759. $('#Online-message .liuyan').css({'padding-left': '0px','padding-right': '0px'})
  760. }
  761. if (!$.support.leadingWhitespace) {
  762. $("#browser_ie").show();
  763. }
  764. */
  765. /*
  766. * 浏览器全屏
  767. */
  768. function fullScreen() {
  769. var el = document.documentElement;
  770. var rfs = el.requestFullScreen || el.webkitRequestFullScreen;
  771. if (typeof rfs != "undefined" && rfs) {
  772. rfs.call(el);
  773. } else if (typeof window.ActiveXObject != "undefined") {
  774. var wscript = new ActiveXObject("WScript.Shell");
  775. if (wscript != null) {
  776. wscript.SendKeys("{F11}");
  777. }
  778. } else if (el.msRequestFullscreen) {
  779. el.msRequestFullscreen();
  780. } else if (el.oRequestFullscreen) {
  781. el.oRequestFullscreen();
  782. } else {
  783. swal({
  784. title : "浏览器不支持全屏调用!",
  785. text : "请更换浏览器或按F11键切换全屏!(3秒后自动关闭)",
  786. type : "error",
  787. timer : 3000
  788. });
  789. }
  790. }
  791. /*
  792. * 浏览器退出全屏
  793. */
  794. function exitFullScreen() {
  795. var el = document;
  796. var cfs = el.cancelFullScreen
  797. || el.webkitCancelFullScreen
  798. || el.exitFullScreen;
  799. if (typeof cfs != "undefined" && cfs) {
  800. cfs.call(el);
  801. } else if (typeof window.ActiveXObject != "undefined") {
  802. var wscript = new ActiveXObject("WScript.Shell");
  803. if (wscript != null) {
  804. wscript.SendKeys("{F11}");
  805. }
  806. } else if (el.msExitFullscreen) {
  807. el.msExitFullscreen();
  808. } else if (el.oRequestFullscreen) {
  809. el.oCancelFullScreen();
  810. } else {
  811. swal({
  812. title : "浏览器不支持全屏调用!",
  813. text : "请更换浏览器或按F11键切换全屏!(3秒后自动关闭)",
  814. type : "error",
  815. timer : 3000
  816. });
  817. }
  818. }
  819. Scaling = {};
  820. ;(function(win, doc, $){
  821. Scaling.zoom = function() {
  822. var ww = $(window).width();
  823. if(!$.browser.webkit) {
  824. if(ww < 1370 && ww > 1030) {
  825. $('body').addClass("scaling1366");
  826. } else if (ww < 1030 && ww < 965) {
  827. $('body').addClass("scaling1024");
  828. } else if (ww < 965 && ww < 0) {
  829. $('body').addClass("scaling960");
  830. }
  831. }
  832. }
  833. } (window, document, jQuery));
  834. // JavaScript Document
  835. // 通告无缝滚动
  836. ;(function($) {
  837. /** 调用Demo:
  838. $("#largeEarlyWarningCon").myScroll({
  839. speed: 40, // 数值越大,速度越慢
  840. rowHeight: 26 // li的高度
  841. });
  842. */
  843. $.fn.myScroll = function(options) {
  844. var defaults = {
  845. speed: 40,
  846. rowHeight: 24
  847. };
  848. var opts = $.extend({}, defaults, options),
  849. intId = [];
  850. function marquee(obj, step) {
  851. obj.find("ul").animate({
  852. marginTop: '-=1'
  853. }, 0, function() {
  854. var s = Math.abs(parseInt($(this).css("margin-top")));
  855. if (s >= step) {
  856. $(this).find("li").slice(0, 1).appendTo($(this));
  857. $(this).css("margin-top", 0);
  858. }
  859. });
  860. }
  861. this.each(function(i) {
  862. var sh = opts["rowHeight"],
  863. speed = opts["speed"],
  864. _this = $(this);
  865. intId[i] = setInterval(function() {
  866. if (_this.find("ul").height() <= _this.height()) {
  867. clearInterval(intId[i]);
  868. } else {
  869. marquee(_this, sh);
  870. }
  871. }, speed);
  872. _this.hover(function() {
  873. clearInterval(intId[i]);
  874. }, function() {
  875. intId[i] = setInterval(function() {
  876. if (_this.find("ul").height() <= _this.height()) {
  877. clearInterval(intId[i]);
  878. } else {
  879. marquee(_this, sh);
  880. }
  881. }, speed);
  882. });
  883. });
  884. }
  885. })(jQuery);

一些通用的js工具类,添加自定义插件的更多相关文章

  1. 分享非常好用的前端分页js工具类 灵活 简单易懂

    分享自己封装的前端分页js工具类  下面是默认样式效果截图 可以随意更改js及css 很灵活 /** * pageSize, 每页显示数 * pageIndex, 当前页数 * pageCount 总 ...

  2. Java中使用最频繁及最通用的Java工具类

    在Java中,工具类定义了一组公共方法,Java中使用最频繁及最通用的Java工具类. 一. org.apache.commons.io.IOUtils closeQuietly:关闭一个IO流.so ...

  3. JS 工具类

    之前工作用的JavaScript比较多,总结了一下工具类,和大家分享一下,有不足之处还请多多见谅!! 1. 数组工具类(arrayUtils) var arrayUtils = {}; (functi ...

  4. Rhino+envjs-1.2.js 在java运行网站js 工具类

    java爬虫遇到个页面加密的东西,找了些资料学习学习 做了个java运行js的工具类,希望对大家有用,其中用到client(获取js)可以自行换成自己的client.主要是用了 Rhino就是Java ...

  5. js工具类的封装

    common.js原生js实现的大多工具方法都将放在common文件中 布局rem.js,vue开发时,我们只需要将rem.js再main.js中import 引入即可 (function(win, ...

  6. js工具类大全

    /********** 日期处理函数 *********/<script type="text/javascript" src="${springMacroRequ ...

  7. js工具类 ----正则

    function(value){  if(value){   var reg=new RegExp("^[a-zA-Z0-9_-]+$");   return reg.test(v ...

  8. 一个很好的通用 excel 导出工具类

    此类用主要 jxl +注解+流 实现扩展性很强,jxl性能会比poi好一点,值得我们学习. package oa.common.utils; import java.io.OutputStream; ...

  9. JS工具类

    封装了开发中常用的操作 并添加了一些扩展方法供调用 var util = { //获取Url中的参数(不支持中文) getParams: function() { var url = location ...

随机推荐

  1. JavaWeb_(Hibernate框架)Hibernate中重要的api

    Hibernate中重要的api Configuration SessionFactory Session(重点) Transaction 在Dao层中UserDao.java使用Hibernate向 ...

  2. springboot的@EnableAutoConfiguration起作用的原理

    通常我们启动一个springboot项目会在启动方法中增加@SpringBootApplicatoin注解,该注解中包含了@EnableAutoConfiguration @Target(Elemen ...

  3. where in 的参数化查询实现

    身为一名小小的程序猿,在日常开发中不可以避免的要和where in和like打交道,在大多数情况下我们传的参数不多简单做下单引号.敏感字符转义之后就直接拼进了SQL,执行查询,搞定.若有一天你不可避免 ...

  4. 【React自制全家桶】九、Redux入手

    一.React项目中为什么要用Redux 上图: 左图当使用纯React开发稍微大点的项目,因为React数据是瀑布式的,只能通过父子组件传递数据,所以实现关系不大的两React的组件之间的数据传递就 ...

  5. 简单说 JavaScript实现雪花飘落效果

    说明 这次实现的雪花飘落的效果很简单,主要是为了练习练习JavaScript中的定时器,setTimeout 和 setInterval. 效果图 解释setTimeout() setTimeout函 ...

  6. 小D课堂 - 新版本微服务springcloud+Docker教程_汇总

    小D课堂 - 新版本微服务springcloud+Docker教程_1_01课程简介 小D课堂 - 新版本微服务springcloud+Docker教程_1_02技术选型 小D课堂 - 新版本微服务s ...

  7. c++ qsort函数应用

    C++ qsort在"iostream" c在头文件stdlib.h中,strcmp在string.h中.下列例子默认从小到大排序即(a>b返回>0),反之从小到大排序 ...

  8. Redis 高级应用

    Redis SAVE 命令用于创建当前数据库的备份 该命令将在 redis 安装目录中创建dump.rdb文件. 如果需要恢复数据,只需将备份文件 (dump.rdb) 移动到 redis 安装目录并 ...

  9. gcc posix sjij for MSYS 9.2.1+

    mingw gcc 32位 版本 9.2.1 以上的 以后都在 github 上发布 https://github.com/qq2225936589/gcc-i686-posix-sjlj-for-M ...

  10. Python排序搜索基本算法之归并排序实例分析

    Python排序搜索基本算法之归并排序实例分析 本文实例讲述了Python排序搜索基本算法之归并排序.分享给大家供大家参考,具体如下: 归并排序最令人兴奋的特点是:不论输入是什么样的,它对N个元素的序 ...