common.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808
  1. /// <reference path="zepto.min.js" />
  2. /// <reference path="jquery-1.8.3.min.js" />
  3. /// <reference path="zepto.animate.js" />
  4. (function (window, undefined) {
  5. /* 命名空间 */
  6. var jc = {};
  7. /* require */
  8. jc.require = { url: [], success: null };
  9. /* 判断客户端 */
  10. jc.isMobile = !!(/AppleWebKit.*Mobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent)));
  11. /* 存放所有Ready要执行的函数 */
  12. jc.fnInit = [];
  13. /* 存放所有Scroll要执行的函数 */
  14. jc.fnScroll = [];
  15. /* 存放所有Resize要执行的函数 */
  16. jc.fnResize = [];
  17. /* 存放所有UI */
  18. jc.ui = {};
  19. /* 存放UI所有属性 */
  20. jc.tmpUiValue = {}
  21. /* 默认层级 */
  22. jc.zIndex = {
  23. now: 10000,
  24. get: function () {
  25. return this.now;
  26. },
  27. plus: function () {
  28. this.now++;
  29. return this.get();
  30. }
  31. }
  32. /* 创建dom */
  33. jc.createDOM = function (json) {
  34. var div = document.createElement("div");
  35. for (var attr in json) {
  36. var curAttr = attr;
  37. if (curAttr == "classname") {
  38. curAttr = "class";
  39. }
  40. else {
  41. curAttr = curAttr.replace(/([A-Z])/g, "-$1").toLowerCase();
  42. }
  43. div.setAttribute(curAttr, json[attr]);
  44. }
  45. return div;
  46. }
  47. /* ui继承 */
  48. jc.uiExtend = function (uiName, obj, asyn) {
  49. jc.tmpUiValue[uiName] = function ($element, _element, uiName) {
  50. this.$element = $element;
  51. this._element = _element;
  52. this.uiName = uiName;
  53. this.className = "J_" + this.uiName;
  54. this.isInit = false;
  55. };
  56. for (var attr in obj) {
  57. jc.tmpUiValue[uiName].prototype[attr] = obj[attr];
  58. }
  59. if (asyn) {
  60. if ($.isReady) {
  61. jc.uiInit(uiName);
  62. }
  63. else {
  64. jc.log("[" + uiName + "] is not asyn");
  65. }
  66. }
  67. };
  68. /* 异步加载文件 */
  69. jc.use = {
  70. reg: /[^a-zA-Z0-9]/g,
  71. queue: [],
  72. count: 0,
  73. cache: {},
  74. isLoad: false,
  75. loadSuccess: function (queue) {
  76. var url = queue.url[queue.progress];
  77. this.cache[url.replace(this.reg, '')] = true;
  78. if (queue.progress < queue.url.length - 1) {
  79. queue.progress++;
  80. this.load(queue);
  81. }
  82. else {
  83. if (queue.success) queue.success();
  84. this.isLoad = false;
  85. if (this.count < this.queue.length - 1) {
  86. this.count++;
  87. this.load(this.queue[this.count]);
  88. }
  89. }
  90. },
  91. load: function (queue) {
  92. var _this = this;
  93. this.isLoad = true;
  94. var element = null;
  95. var url = queue.url[queue.progress];
  96. /* 如果之前加载过 */
  97. if (this.cache[url.replace(this.reg, '')]) {
  98. this.loadSuccess(queue);
  99. return false;
  100. }
  101. if (url.indexOf(".js") != -1) {
  102. element = document.createElement("script");
  103. element.src = url;
  104. element.type = "text/javascript";
  105. }
  106. else if (url.indexOf(".css") != -1) {
  107. element = document.createElement("link");
  108. element.href = url;
  109. element.rel = "stylesheet";
  110. }
  111. queue.element = element;
  112. if (navigator.userAgent.indexOf('MSIE') != -1) {
  113. element.onreadystatechange = function () {
  114. if (this.readyState && this.readyState == "loading") {
  115. return;
  116. }
  117. else {
  118. element.onreadystatechange = null;
  119. _this.loadSuccess(queue);
  120. }
  121. };
  122. }
  123. else {
  124. element.onload = element.onerror = function () {
  125. _this.loadSuccess(queue);
  126. }
  127. }
  128. document.getElementsByTagName("head")[0].appendChild(element);
  129. },
  130. get: function (url, success) {
  131. if (!url || !url.length) {
  132. if (success) success();
  133. return false;
  134. }
  135. this.queue.push({ url: $.isArray(url) ? url : [url], success: success, progress: 0, error: [] });
  136. if (!this.isLoad) {
  137. this.load(this.queue[this.count]);
  138. }
  139. }
  140. };
  141. /* 判断UI是否存在 返回个数 */
  142. jc.hasUI = function (uiName) {
  143. if (typeof uiName != "string" || !jc.ui[uiName]) return 0;
  144. if (jc.ui[uiName].length) return jc.ui[uiName].length;
  145. }
  146. /* 寻找目标插件 */
  147. jc.uiUpdate = function () {
  148. /* 判断本页面是否启用懒加载 */
  149. if (document.body.getAttribute("data-lazyload")) {
  150. jc.lazyload.init();
  151. };
  152. /* 取出所有的DIV元素 */
  153. var element = document.querySelectorAll ? document.body.querySelectorAll('div[data-ui]') : document.body.getElementsByTagName("div");
  154. for (var i = 0, l = element.length; i < l; i++) {
  155. var curElement = element[i];
  156. /* 如果已存在ui */
  157. if (curElement.isSetup) continue;
  158. jc.uiSetup(curElement);
  159. }
  160. jc.uiInitAll();
  161. };
  162. /* 装载插件 */
  163. jc.uiSetup = function (element) {
  164. var plugName = element.getAttribute("data-ui");
  165. if (!plugName) return false;
  166. /* 如果没有这个UI 先写一个 */
  167. if (!jc.ui[plugName]) {
  168. jc.ui[plugName] = {
  169. length: 0
  170. }
  171. }
  172. /* 增加元素 */
  173. var curUI = jc.ui[plugName];
  174. /* 增加属性 看看有没有写业务 */
  175. if (jc.tmpUiValue[plugName]) {
  176. /* 添加标识 uiFlag 作用就是 防止重复 jc.update */
  177. element.isSetup = plugName;
  178. /* 当前暂存对象 */
  179. var tmpUiValue = jc.tmpUiValue[plugName];
  180. curUI[curUI.length] = new tmpUiValue($(element), element, plugName);
  181. /* 判断对象是否有 scroll 如果有就加到队列 */
  182. if (tmpUiValue.prototype.scroll) {
  183. jc.fnScroll.push(curUI[curUI.length]);
  184. }
  185. /* 判断对象是否有 resize 如果有就加到队列 */
  186. if (tmpUiValue.prototype.resize) {
  187. jc.fnResize.push(curUI[curUI.length]);
  188. }
  189. /* 自增 */
  190. curUI.length++;
  191. }
  192. return plugName;
  193. }
  194. /* 初始化全部控件 */
  195. jc.uiInitAll = function () {
  196. for (var attr in jc.ui) {
  197. jc.uiInit(attr);
  198. }
  199. }
  200. /* 初始化控件(单个) */
  201. jc.uiInit = function (uiName) {
  202. var info = jc.tools.getWindowInfo();
  203. var curUi = jc.ui[uiName];
  204. /* 如果元素数量不等于0 */
  205. if (jc.hasUI(uiName)) {
  206. for (var i = 0, l = curUi.length; i < l; i++) {
  207. /* 写上方法 */
  208. curUi.each = function (fn) {
  209. for (var i = 0, l = this.length; i < l; i++) {
  210. if (fn) fn.call(this[i], this[i].$element);
  211. }
  212. }
  213. curUi.filter = function (term, fnName, a, b, c, d, e, f, g) {/* token=a */
  214. var attr = $.trim(term).split("=");
  215. if (attr.length < 2) return;
  216. for (var i = 0, l = this.length; i < l; i++) {
  217. if (this[i]._element.getAttribute("data-" + $.trim(attr[0])) === $.trim(attr[1])) {
  218. if (this[i][fnName]) {
  219. this[i][fnName](a, b, c, d, e, f, g);
  220. }
  221. }
  222. }
  223. }
  224. curUi.trigger = function (fnName, a, b, c, d, e, f, g) {
  225. for (var i = 0, l = this.length; i < l; i++) {
  226. if (this[i][fnName]) this[i][fnName](a, b, c, d, e, f, g);
  227. }
  228. }
  229. var curUiOnly = curUi[i];
  230. /* getString */
  231. curUiOnly.getString = function (text, defalutText) {
  232. return (text || (defalutText || ""));
  233. }
  234. /* getTemplate */
  235. curUiOnly.getTemplate = function (data, fnSuccess) {
  236. if (this.template) {
  237. var html = this.template(data);
  238. if (fnSuccess) fnSuccess(html);
  239. }
  240. else {
  241. jc.data.jsonp(window.static + "template/" + uiName + ".js", function (result) {
  242. curUiOnly.template = result;
  243. var html = curUiOnly.template(data);
  244. if (fnSuccess) fnSuccess(html);
  245. });
  246. }
  247. }
  248. /* getString */
  249. curUiOnly.getString = function (text, defalutText) {
  250. return (text || (defalutText || ""));
  251. }
  252. if (curUiOnly.init && !curUiOnly.isInit) {
  253. /* 如果有依赖文件先加载依赖文件 */
  254. if (curUiOnly.use) {
  255. jc.use.get(curUiOnly.use, function () {
  256. curUiOnly.init(info);
  257. curUiOnly.isInit = true;
  258. });
  259. }
  260. else {
  261. curUiOnly.init(info);
  262. curUiOnly.isInit = true;
  263. }
  264. }
  265. }
  266. }
  267. }
  268. /* 删除控件 */
  269. jc.uiRemove = function (uiName, features) {
  270. if (!uiName) return false;
  271. //console.log(uiName)
  272. for (var attr in jc.ui) {
  273. var cur = jc.ui[attr];
  274. if (uiName != attr) continue;
  275. if (!features) {
  276. delete cur;
  277. }
  278. if (typeof (features) == "object") {
  279. for (var i = 0, l = cur.length; i < l; i++) {
  280. if (cur[i]._element == features) {
  281. delete cur[i];
  282. cur.length--;
  283. }
  284. }
  285. }
  286. }
  287. }
  288. /* 初始化控件*/
  289. jc.fnInit.push(function () {
  290. //jc.uiSelectAll;
  291. jc.use.get(jc.require.url, function () {
  292. if (jc.require.success) jc.require.success();
  293. jc.uiUpdate();
  294. if (jc.uiReady) jc.uiReady();
  295. });
  296. });
  297. /* 工具方法 */
  298. jc.tools = {
  299. formatDate: function (timestamp, format) {
  300. var newDate = new Date(timestamp);
  301. var date = {
  302. "Y+": newDate.getUTCFullYear(),
  303. "M+": newDate.getMonth() + 1,
  304. "d+": newDate.getDate(),
  305. "h+": newDate.getHours(),
  306. "m+": newDate.getMinutes(),
  307. "s+": newDate.getSeconds(),
  308. "q+": Math.floor((newDate.getMonth() + 3) / 3),
  309. "S+": newDate.getMilliseconds()
  310. };
  311. if (!format) {
  312. format = "YYYY年M月dd日";
  313. }
  314. if (/(y+)/i.test(format)) {
  315. format = format.replace(RegExp.$1, (newDate.getFullYear() + '').substr(4 - RegExp.$1.length));
  316. }
  317. for (var k in date) {
  318. if (new RegExp("(" + k + ")").test(format)) {
  319. format = format.replace(RegExp.$1, RegExp.$1.length == 1
  320. ? date[k] : ("00" + date[k]).substr(("" + date[k]).length));
  321. }
  322. }
  323. return format;
  324. },
  325. eventListener: {
  326. add: function (obj, evType, fn) {
  327. obj.addEventListener ? obj.addEventListener(evType, fn, false) : obj.attachEvent("on" + evType, fn);
  328. },
  329. remove: function (obj, evType, fn) {
  330. obj.removeEventListener ? obj.removeEventListener(evType, fn, false) : obj.detachEvent("on" + evType, fn);
  331. }
  332. },
  333. range: function (iNow, iMin, iMax) {
  334. if (iNow > iMax) return iMax;
  335. else if (iNow < iMin) return iMin;
  336. return iNow;
  337. },
  338. getWindowInfo: function () {
  339. var result = {
  340. scrollTop: (document.documentElement.scrollTop || document.body.scrollTop),
  341. scrollLeft: (document.documentElement.scrollLeft || document.body.scrollLeft),
  342. scrollHeight: (document.documentElement.scrollHeight || document.body.scrollHeight),
  343. scrollWidth: (document.documentElement.scrollWidth || document.body.scrollWidth),
  344. windowWidth: (document.documentElement.clientWidth || document.body.clientWidth),
  345. windowHeight: (document.documentElement.clientHeight || document.body.clientHeight)
  346. }
  347. return result;
  348. },
  349. hasTransform: function () {
  350. if (!window.getComputedStyle) {
  351. return false;
  352. }
  353. var el = document.createElement('p'),
  354. has3d,
  355. transforms = {
  356. 'webkitTransform': '-webkit-transform',
  357. 'OTransform': '-o-transform',
  358. 'msTransform': '-ms-transform',
  359. 'MozTransform': '-moz-transform',
  360. 'transform': 'transform'
  361. };
  362. // Add it to the body to get the computed style.
  363. document.body.insertBefore(el, null);
  364. for (var t in transforms) {
  365. if (el.style[t] !== undefined) {
  366. el.style[t] = "translate3d(1px,1px,1px)";
  367. has3d = window.getComputedStyle(el).getPropertyValue(transforms[t]);
  368. }
  369. }
  370. document.body.removeChild(el);
  371. return (has3d !== undefined && has3d.length > 0 && has3d !== "none");
  372. },
  373. setStyleToCss3Hack: function (obj, styleName, value) {
  374. styleName = styleName.charAt(0).toUpperCase() + styleName.substring(1);
  375. obj.style['Webkit' + styleName] = value;
  376. obj.style['Moz' + styleName] = value;
  377. obj.style['ms' + styleName] = value;
  378. obj.style['O' + styleName] = value;
  379. obj.style[name] = value;
  380. }
  381. };
  382. /* 延迟加载 */
  383. jc.lazyload = {
  384. queue: [],
  385. push: function (element) {
  386. var dataSrc = element.getAttribute("data-src");
  387. if (!dataSrc) return;
  388. var $element = $(element);
  389. var top = $element.offset().top;
  390. var height = $(element).height();
  391. if (this.check(top, height)) {
  392. element.src = dataSrc;
  393. }
  394. else {
  395. this.queue.push({
  396. element: element,
  397. $element: $element,
  398. top: top,
  399. src: dataSrc,
  400. height: height,
  401. success: false
  402. });
  403. element.style.opacity = "0";
  404. element.style.filter = "alpha(opacity=0)";
  405. }
  406. },
  407. check: function (top, height) {
  408. var info = jc.tools.getWindowInfo();
  409. if (top >= info.scrollTop - height && top < (info.scrollTop + info.windowHeight)) {
  410. return true;
  411. }
  412. else {
  413. return false;
  414. }
  415. },
  416. listener: function () {
  417. if (this.queue.length) {
  418. for (var i = 0, l = this.queue.length; i < l; i++) {
  419. var cur = this.queue[i];
  420. if (cur.success) continue;
  421. if (this.check(cur.top, cur.height)) {
  422. cur.element.src = cur.src;
  423. cur.$element.stop().animate({ opacity: 1 }, "slow");
  424. cur.success = true;
  425. }
  426. }
  427. }
  428. },
  429. init: function () {
  430. var _this = this;
  431. jc.tools.eventListener.add(window, "scroll", function () {
  432. _this.listener();
  433. });
  434. jc.tools.eventListener.add(window, "resize", function () {
  435. _this.listener();
  436. });
  437. var img = document.getElementsByTagName("img");
  438. if (!img.length) return;
  439. for (var i = 0, l = img.length; i < l; i++) {
  440. this.push(img[i]);
  441. }
  442. }
  443. }
  444. /* hash */
  445. jc.hash = {
  446. now: {},
  447. getObject: function () {
  448. this.update();
  449. return this.now;
  450. },
  451. stringify: function (obj) {
  452. var tmp = [];
  453. obj = obj ? obj : this.now;
  454. for (var attr in obj) {
  455. if (obj[attr] == "undefined") {
  456. obj[attr] = "";
  457. }
  458. tmp.push(attr + "=" + obj[attr]);
  459. }
  460. return tmp.join(";");
  461. },
  462. update: function () {
  463. var hash = window.location.hash.substr(1);
  464. var split = hash.split(";");
  465. for (var i = 0, l = split.length; i < l; i++) {
  466. var key = split[i].split("=");
  467. if (key.length === 2) {
  468. this.now[key[0]] = key[1];
  469. }
  470. }
  471. },
  472. write: function () {
  473. window.location.hash = "#" + this.stringify();
  474. },
  475. get: function (keyName) {
  476. this.update();
  477. return this.now[keyName] ? this.now[keyName] : '';
  478. },
  479. set: function (keyName, value) {
  480. this.now[keyName] = value;
  481. },
  482. remove: function (keyName) {
  483. if (this.now[keyName]) delete this.now[keyName];
  484. }
  485. }
  486. /* param */
  487. jc.param = {
  488. now: {},
  489. getObject: function () {
  490. this.update();
  491. return this.now;
  492. },
  493. stringify: function (obj) {
  494. var tmp = [];
  495. obj = obj ? obj : this.now;
  496. for (var attr in obj) {
  497. if (obj[attr] == "undefined") {
  498. obj[attr] = "";
  499. }
  500. tmp.push(attr + "=" + obj[attr]);
  501. }
  502. return tmp.join("&");
  503. },
  504. update: function () {
  505. var hash = window.location.search.substr(1);
  506. var split = hash.split("&");
  507. for (var i = 0, l = split.length; i < l; i++) {
  508. var key = split[i].split("=");
  509. if (key.length === 2) {
  510. this.now[key[0]] = key[1];
  511. }
  512. }
  513. },
  514. get: function (keyName) {
  515. this.update();
  516. return this.now[keyName] ? this.now[keyName] : '';
  517. },
  518. set: function (keyName, value) {
  519. this.now[keyName] = value;
  520. },
  521. remove: function (keyName) {
  522. if (this.now[keyName]) delete this.now[keyName];
  523. }
  524. }
  525. /* 碰撞检测 */
  526. jc.overlap = function (obj1, obj2) {
  527. if ($(obj1).offset().left > $(obj2).offset().left - obj1.offsetWidth && $(obj1).offset().top > $(obj2).offset().top - obj1.offsetHeight && $(obj1).offset().top < $(obj2).offset().top + obj2.offsetHeight && $(obj1).offset().left < $(obj2).offset().left + obj2.offsetWidth) {
  528. return true;
  529. }
  530. };
  531. /* cookie */
  532. jc.cookie = {
  533. add: function (name, value, path, days) {//四个参数,第一个是cookie的名称,第二个是值,第三个是路径, 第四个是保存天数
  534. var expDays = days || 30; // 默认保存30天
  535. var exp = new Date(); //new Date("December 31, 9998");
  536. exp.setTime(exp.getTime() + expDays * 24 * 60 * 60 * 1000);
  537. document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString() + ((!path) ? ";path=/" : ";path=" + path);
  538. },
  539. get: function (name) {
  540. var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
  541. if (arr != null) return unescape(arr[2]);
  542. return null;
  543. },
  544. remove: function (name, path) {
  545. var exp = new Date();
  546. exp.setTime(exp.getTime() + (-1 * 24 * 60 * 60 * 1000));
  547. var cval = jc.cookie.get(name);
  548. document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString() + ((!path) ? ";path=/" : ";path=" + path);
  549. }
  550. };
  551. /* rem */
  552. jc.rem = {
  553. nowPx: 50,
  554. state: false,
  555. _fnResize: function () {
  556. var _width = document.documentElement.clientWidth || document.body.clientWidth;
  557. var zoom = _width / 320, fontsizerem = zoom * 50;
  558. if (_width < 320) fontsizerem = 50;
  559. var root = document.getElementById("root");
  560. if (!root) {
  561. var root = document.createElement("STYLE");
  562. root.id = "root"
  563. root.type = "text/css";
  564. document.head.appendChild(root);
  565. }
  566. root.innerHTML = 'html{font-size:' + fontsizerem + 'px;}';
  567. jc.rem.nowPx = fontsizerem;
  568. },
  569. on: function () {
  570. this.state = true;
  571. if (window.addEventListener) {
  572. window.addEventListener("resize", this._fnResize);
  573. this._fnResize();
  574. }
  575. },
  576. off: function () {
  577. this.state = false;
  578. if (window.removeEventListener) {
  579. window.removeEventListener("resize", this._fnResize);
  580. document.documentElement.style.cssText = "";
  581. }
  582. },
  583. pxToRem: function (px, def) {
  584. return (parseFloat(px) / (def ? 50 : this.nowPx)) + "rem";
  585. },
  586. remToPx: function (rem, def) {
  587. return (parseFloat(rem) * (def ? 50 : this.nowPx)) + "px";
  588. },
  589. log: function (iMin, iMax) {
  590. if ((iMin > iMax) || !iMin || !iMax || !window.console) return;
  591. var sLog = "/*\n";
  592. for (var i = iMin; i <= iMax; i++) {
  593. sLog += "* " + i + "px == " + this.pxToRem(i) + "\n";
  594. }
  595. console.log(sLog + "*/");
  596. }
  597. };
  598. /* jsonp */
  599. jc.data = {
  600. queue: [], //队列存放 每一条信息 {url:xxxx,data:{a:1,b2,c3},success:fn};
  601. count: 0,
  602. script: null,
  603. setup: function (str) {
  604. this.queue[this.count - 1].success(str);
  605. /* 销毁 递归 */
  606. document.head.removeChild(this.script);
  607. this.script = null;
  608. if (this.count < this.queue.length) {
  609. var cur = this.queue[this.count];
  610. this.load(cur.url, cur.data, cur.success);
  611. this.count++;
  612. }
  613. },
  614. load: function (url, data, success) {
  615. this.script = document.createElement("script");
  616. this.script.type = "text/javascript";
  617. var attribute = [];
  618. if (typeof data == "object") {
  619. for (var attr in data) {
  620. attribute.push(attr + "=" + data[attr]);
  621. }
  622. /* 增加随机数 防止缓存 */
  623. attribute.push("r=" + parseInt(Math.random() * 10000));
  624. /* 增加jsonp的标识 */
  625. attribute.push("jsonp=" + "jc.data.setup");
  626. }
  627. this.script.src = url + (attribute.length ? "?" + attribute.join("&") : "");
  628. document.head.appendChild(this.script);
  629. },
  630. jsonp: function (url, data, success) {
  631. /* 处理传参 */
  632. if ($.isFunction(data)) {
  633. success = data;
  634. data = "";
  635. }
  636. this.queue.push({ url: url, data: data, success: success });
  637. if (!this.script) {
  638. var cur = this.queue[this.count]
  639. this.load(cur.url, cur.data, cur.success);
  640. this.count++;
  641. }
  642. }
  643. };
  644. /* 是否启用自定义滚动条 */
  645. jc.fnInit.push(function () {
  646. if ($("html").niceScroll && !jc.isMobile) {
  647. $("html").niceScroll({ zindex: 9999, autohidemode: false, cursorwidth: "4px", cursorcolor: "#333", cursorborder: 0, cursoropacitymax: 0.8 });
  648. }
  649. });
  650. /* 处理reday事件 */
  651. $(function () {
  652. if (!jc.fnInit.length) return;
  653. for (var i = 0, l = jc.fnInit.length; i < l; i++) {
  654. jc.fnInit[i]();
  655. }
  656. });
  657. /* 处理resize事件 */
  658. $(window).resize(function () {
  659. var info = jc.tools.getWindowInfo();
  660. for (var i = 0, l = jc.fnResize.length; i < l; i++) {
  661. jc.fnResize[i].resize(info);
  662. }
  663. });
  664. /* 处理scroll事件 */
  665. jc.fixScollTime = null;
  666. $(window).scroll(function () {
  667. var info = jc.tools.getWindowInfo();
  668. /* 防止快速执行 */
  669. clearTimeout(jc.fixScollTime);
  670. jc.fixScollTime = setTimeout(function () {
  671. for (var i = 0, l = jc.fnScroll.length; i < l; i++) {
  672. jc.fnScroll[i].scroll(info);
  673. }
  674. }, 1);
  675. });
  676. window.jc = jc;
  677. })(window);