api.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889
  1. /*
  2. * APICloud JavaScript Library
  3. * Copyright (c) 2014 apicloud.com
  4. */
  5. (function(window) {
  6. var u = {};
  7. var isAndroid = (/android/gi).test(navigator.appVersion);
  8. var uzStorage = function() {
  9. var ls = window.localStorage;
  10. if (isAndroid) {
  11. ls = os.localStorage();
  12. }
  13. return ls;
  14. };
  15. function parseArguments(url, data, fnSuc, dataType) {
  16. if (typeof(data) == 'function') {
  17. dataType = fnSuc;
  18. fnSuc = data;
  19. data = undefined;
  20. }
  21. if (typeof(fnSuc) != 'function') {
  22. dataType = fnSuc;
  23. fnSuc = undefined;
  24. }
  25. return {
  26. url: url,
  27. data: data,
  28. fnSuc: fnSuc,
  29. dataType: dataType
  30. };
  31. }
  32. u.trim = function(str) {
  33. if (String.prototype.trim) {
  34. return str == null ? "" : String.prototype.trim.call(str);
  35. } else {
  36. return str.replace(/(^\s*)|(\s*$)/g, "");
  37. }
  38. };
  39. u.trimAll = function(str) {
  40. return str.replace(/\s*/g, '');
  41. };
  42. u.isElement = function(obj) {
  43. return !!(obj && obj.nodeType == 1);
  44. };
  45. u.isArray = function(obj) {
  46. if (Array.isArray) {
  47. return Array.isArray(obj);
  48. } else {
  49. return obj instanceof Array;
  50. }
  51. };
  52. u.isEmptyObject = function(obj) {
  53. if (JSON.stringify(obj) === '{}') {
  54. return true;
  55. }
  56. return false;
  57. };
  58. u.addEvt = function(el, name, fn, useCapture) {
  59. if (!u.isElement(el)) {
  60. console.warn('$api.addEvt Function need el param, el param must be DOM Element');
  61. return;
  62. }
  63. useCapture = useCapture || false;
  64. if (el.addEventListener) {
  65. el.addEventListener(name, fn, useCapture);
  66. }
  67. };
  68. u.rmEvt = function(el, name, fn, useCapture) {
  69. if (!u.isElement(el)) {
  70. console.warn('$api.rmEvt Function need el param, el param must be DOM Element');
  71. return;
  72. }
  73. useCapture = useCapture || false;
  74. if (el.removeEventListener) {
  75. el.removeEventListener(name, fn, useCapture);
  76. }
  77. };
  78. u.one = function(el, name, fn, useCapture) {
  79. if (!u.isElement(el)) {
  80. console.warn('$api.one Function need el param, el param must be DOM Element');
  81. return;
  82. }
  83. useCapture = useCapture || false;
  84. var that = this;
  85. var cb = function() {
  86. fn && fn();
  87. that.rmEvt(el, name, cb, useCapture);
  88. };
  89. that.addEvt(el, name, cb, useCapture);
  90. };
  91. u.dom = function(el, selector) {
  92. if (arguments.length === 1 && typeof arguments[0] == 'string') {
  93. if (document.querySelector) {
  94. return document.querySelector(arguments[0]);
  95. }
  96. } else if (arguments.length === 2) {
  97. if (el.querySelector) {
  98. return el.querySelector(selector);
  99. }
  100. }
  101. };
  102. u.domAll = function(el, selector) {
  103. if (arguments.length === 1 && typeof arguments[0] == 'string') {
  104. if (document.querySelectorAll) {
  105. return document.querySelectorAll(arguments[0]);
  106. }
  107. } else if (arguments.length === 2) {
  108. if (el.querySelectorAll) {
  109. return el.querySelectorAll(selector);
  110. }
  111. }
  112. };
  113. u.byId = function(id) {
  114. return document.getElementById(id);
  115. };
  116. u.first = function(el, selector) {
  117. if (arguments.length === 1) {
  118. if (!u.isElement(el)) {
  119. console.warn('$api.first Function need el param, el param must be DOM Element');
  120. return;
  121. }
  122. return el.children[0];
  123. }
  124. if (arguments.length === 2) {
  125. return this.dom(el, selector + ':first-child');
  126. }
  127. };
  128. u.last = function(el, selector) {
  129. if (arguments.length === 1) {
  130. if (!u.isElement(el)) {
  131. console.warn('$api.last Function need el param, el param must be DOM Element');
  132. return;
  133. }
  134. var children = el.children;
  135. return children[children.length - 1];
  136. }
  137. if (arguments.length === 2) {
  138. return this.dom(el, selector + ':last-child');
  139. }
  140. };
  141. u.eq = function(el, index) {
  142. return this.dom(el, ':nth-child(' + index + ')');
  143. };
  144. u.not = function(el, selector) {
  145. return this.domAll(el, ':not(' + selector + ')');
  146. };
  147. u.prev = function(el) {
  148. if (!u.isElement(el)) {
  149. console.warn('$api.prev Function need el param, el param must be DOM Element');
  150. return;
  151. }
  152. var node = el.previousSibling;
  153. if (node.nodeType && node.nodeType === 3) {
  154. node = node.previousSibling;
  155. return node;
  156. }
  157. };
  158. u.next = function(el) {
  159. if (!u.isElement(el)) {
  160. console.warn('$api.next Function need el param, el param must be DOM Element');
  161. return;
  162. }
  163. var node = el.nextSibling;
  164. if (node.nodeType && node.nodeType === 3) {
  165. node = node.nextSibling;
  166. return node;
  167. }
  168. };
  169. u.closest = function(el, selector) {
  170. if (!u.isElement(el)) {
  171. console.warn('$api.closest Function need el param, el param must be DOM Element');
  172. return;
  173. }
  174. var doms, targetDom;
  175. var isSame = function(doms, el) {
  176. var i = 0,
  177. len = doms.length;
  178. for (i; i < len; i++) {
  179. if (doms[i].isEqualNode(el)) {
  180. return doms[i];
  181. }
  182. }
  183. return false;
  184. };
  185. var traversal = function(el, selector) {
  186. doms = u.domAll(el.parentNode, selector);
  187. targetDom = isSame(doms, el);
  188. while (!targetDom) {
  189. el = el.parentNode;
  190. if (el != null && el.nodeType == el.DOCUMENT_NODE) {
  191. return false;
  192. }
  193. traversal(el, selector);
  194. }
  195. return targetDom;
  196. };
  197. return traversal(el, selector);
  198. };
  199. u.contains = function(parent, el) {
  200. var mark = false;
  201. if (el === parent) {
  202. mark = true;
  203. return mark;
  204. } else {
  205. do {
  206. el = el.parentNode;
  207. if (el === parent) {
  208. mark = true;
  209. return mark;
  210. }
  211. } while (el === document.body || el === document.documentElement);
  212. return mark;
  213. }
  214. };
  215. u.remove = function(el) {
  216. if (el && el.parentNode) {
  217. el.parentNode.removeChild(el);
  218. }
  219. };
  220. u.attr = function(el, name, value) {
  221. if (!u.isElement(el)) {
  222. console.warn('$api.attr Function need el param, el param must be DOM Element');
  223. return;
  224. }
  225. if (arguments.length == 2) {
  226. return el.getAttribute(name);
  227. } else if (arguments.length == 3) {
  228. el.setAttribute(name, value);
  229. return el;
  230. }
  231. };
  232. u.removeAttr = function(el, name) {
  233. if (!u.isElement(el)) {
  234. console.warn('$api.removeAttr Function need el param, el param must be DOM Element');
  235. return;
  236. }
  237. if (arguments.length === 2) {
  238. el.removeAttribute(name);
  239. }
  240. };
  241. u.hasCls = function(el, cls) {
  242. if (!u.isElement(el)) {
  243. console.warn('$api.hasCls Function need el param, el param must be DOM Element');
  244. return;
  245. }
  246. if (el.className.indexOf(cls) > -1) {
  247. return true;
  248. } else {
  249. return false;
  250. }
  251. };
  252. u.addCls = function(el, cls) {
  253. if (!u.isElement(el)) {
  254. console.warn('$api.addCls Function need el param, el param must be DOM Element');
  255. return;
  256. }
  257. if ('classList' in el) {
  258. el.classList.add(cls);
  259. } else {
  260. var preCls = el.className;
  261. var newCls = preCls + ' ' + cls;
  262. el.className = newCls;
  263. }
  264. return el;
  265. };
  266. u.removeCls = function(el, cls) {
  267. if (!u.isElement(el)) {
  268. console.warn('$api.removeCls Function need el param, el param must be DOM Element');
  269. return;
  270. }
  271. if ('classList' in el) {
  272. el.classList.remove(cls);
  273. } else {
  274. var preCls = el.className;
  275. var newCls = preCls.replace(cls, '');
  276. el.className = newCls;
  277. }
  278. return el;
  279. };
  280. u.toggleCls = function(el, cls) {
  281. if (!u.isElement(el)) {
  282. console.warn('$api.toggleCls Function need el param, el param must be DOM Element');
  283. return;
  284. }
  285. if ('classList' in el) {
  286. el.classList.toggle(cls);
  287. } else {
  288. if (u.hasCls(el, cls)) {
  289. u.removeCls(el, cls);
  290. } else {
  291. u.addCls(el, cls);
  292. }
  293. }
  294. return el;
  295. };
  296. u.val = function(el, val) {
  297. if (!u.isElement(el)) {
  298. console.warn('$api.val Function need el param, el param must be DOM Element');
  299. return;
  300. }
  301. if (arguments.length === 1) {
  302. switch (el.tagName) {
  303. case 'SELECT':
  304. var value = el.options[el.selectedIndex].value;
  305. return value;
  306. break;
  307. case 'INPUT':
  308. return el.value;
  309. break;
  310. case 'TEXTAREA':
  311. return el.value;
  312. break;
  313. }
  314. }
  315. if (arguments.length === 2) {
  316. switch (el.tagName) {
  317. case 'SELECT':
  318. el.options[el.selectedIndex].value = val;
  319. return el;
  320. break;
  321. case 'INPUT':
  322. el.value = val;
  323. return el;
  324. break;
  325. case 'TEXTAREA':
  326. el.value = val;
  327. return el;
  328. break;
  329. }
  330. }
  331. };
  332. u.prepend = function(el, html) {
  333. if (!u.isElement(el)) {
  334. console.warn('$api.prepend Function need el param, el param must be DOM Element');
  335. return;
  336. }
  337. el.insertAdjacentHTML('afterbegin', html);
  338. return el;
  339. };
  340. u.append = function(el, html) {
  341. if (!u.isElement(el)) {
  342. console.warn('$api.append Function need el param, el param must be DOM Element');
  343. return;
  344. }
  345. el.insertAdjacentHTML('beforeend', html);
  346. return el;
  347. };
  348. u.before = function(el, html) {
  349. if (!u.isElement(el)) {
  350. console.warn('$api.before Function need el param, el param must be DOM Element');
  351. return;
  352. }
  353. el.insertAdjacentHTML('beforebegin', html);
  354. return el;
  355. };
  356. u.after = function(el, html) {
  357. if (!u.isElement(el)) {
  358. console.warn('$api.after Function need el param, el param must be DOM Element');
  359. return;
  360. }
  361. el.insertAdjacentHTML('afterend', html);
  362. return el;
  363. };
  364. u.html = function(el, html) {
  365. if (!u.isElement(el)) {
  366. console.warn('$api.html Function need el param, el param must be DOM Element');
  367. return;
  368. }
  369. if (arguments.length === 1) {
  370. return el.innerHTML;
  371. } else if (arguments.length === 2) {
  372. el.innerHTML = html;
  373. return el;
  374. }
  375. };
  376. u.text = function(el, txt) {
  377. if (!u.isElement(el)) {
  378. console.warn('$api.text Function need el param, el param must be DOM Element');
  379. return;
  380. }
  381. if (arguments.length === 1) {
  382. return el.textContent;
  383. } else if (arguments.length === 2) {
  384. el.textContent = txt;
  385. return el;
  386. }
  387. };
  388. u.offset = function(el) {
  389. if (!u.isElement(el)) {
  390. console.warn('$api.offset Function need el param, el param must be DOM Element');
  391. return;
  392. }
  393. var sl = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
  394. var st = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
  395. var rect = el.getBoundingClientRect();
  396. return {
  397. l: rect.left + sl,
  398. t: rect.top + st,
  399. w: el.offsetWidth,
  400. h: el.offsetHeight
  401. };
  402. };
  403. u.css = function(el, css) {
  404. if (!u.isElement(el)) {
  405. console.warn('$api.css Function need el param, el param must be DOM Element');
  406. return;
  407. }
  408. if (typeof css == 'string' && css.indexOf(':') > 0) {
  409. el.style && (el.style.cssText += ';' + css);
  410. }
  411. };
  412. u.cssVal = function(el, prop) {
  413. if (!u.isElement(el)) {
  414. console.warn('$api.cssVal Function need el param, el param must be DOM Element');
  415. return;
  416. }
  417. if (arguments.length === 2) {
  418. var computedStyle = window.getComputedStyle(el, null);
  419. return computedStyle.getPropertyValue(prop);
  420. }
  421. };
  422. u.jsonToStr = function(json) {
  423. if (typeof json === 'object') {
  424. return JSON && JSON.stringify(json);
  425. }
  426. };
  427. u.strToJson = function(str) {
  428. if (typeof str === 'string') {
  429. return JSON && JSON.parse(str);
  430. }
  431. };
  432. u.setStorage = function(key, value) {
  433. if (arguments.length === 2) {
  434. var v = value;
  435. if (typeof v == 'object') {
  436. v = JSON.stringify(v);
  437. v = 'obj-' + v;
  438. } else {
  439. v = 'str-' + v;
  440. }
  441. var ls = uzStorage();
  442. if (ls) {
  443. ls.setItem(key, v);
  444. }
  445. }
  446. };
  447. u.getStorage = function(key) {
  448. var ls = uzStorage();
  449. if (ls) {
  450. var v = ls.getItem(key);
  451. if (!v) {
  452. return;
  453. }
  454. if (v.indexOf('obj-') === 0) {
  455. v = v.slice(4);
  456. return JSON.parse(v);
  457. } else if (v.indexOf('str-') === 0) {
  458. return v.slice(4);
  459. }
  460. }
  461. };
  462. u.rmStorage = function(key) {
  463. var ls = uzStorage();
  464. if (ls && key) {
  465. ls.removeItem(key);
  466. }
  467. };
  468. u.clearStorage = function() {
  469. var ls = uzStorage();
  470. if (ls) {
  471. ls.clear();
  472. }
  473. };
  474. /*by king*/
  475. u.fixIos7Bar = function(el) {
  476. return u.fixStatusBar(el);
  477. };
  478. u.fixStatusBar = function(el) {
  479. if (!u.isElement(el)) {
  480. console.warn('$api.fixStatusBar Function need el param, el param must be DOM Element');
  481. return 0;
  482. }
  483. el.style.paddingTop = api.safeArea.top + 'px';
  484. return el.offsetHeight;
  485. };
  486. u.fixTabBar = function(el) {
  487. if (!u.isElement(el)) {
  488. console.warn('$api.fixTabBar Function need el param, el param must be DOM Element');
  489. return 0;
  490. }
  491. el.style.paddingBottom = api.safeArea.bottom + 'px';
  492. return el.offsetHeight;
  493. }
  494. u.toast = function(title, text, time) {
  495. var opts = {};
  496. var show = function(opts, time) {
  497. api.showProgress(opts);
  498. setTimeout(function() {
  499. api.hideProgress();
  500. }, time);
  501. };
  502. if (arguments.length === 1) {
  503. var time = time || 500;
  504. if (typeof title === 'number') {
  505. time = title;
  506. } else {
  507. opts.title = title + '';
  508. }
  509. show(opts, time);
  510. } else if (arguments.length === 2) {
  511. var time = time || 500;
  512. var text = text;
  513. if (typeof text === "number") {
  514. var tmp = text;
  515. time = tmp;
  516. text = null;
  517. }
  518. if (title) {
  519. opts.title = title;
  520. }
  521. if (text) {
  522. opts.text = text;
  523. }
  524. show(opts, time);
  525. }
  526. if (title) {
  527. opts.title = title;
  528. }
  529. if (text) {
  530. opts.text = text;
  531. }
  532. time = time || 500;
  533. show(opts, time);
  534. };
  535. u.post = function( /*url,data,fnSuc,dataType*/ ) {
  536. var argsToJson = parseArguments.apply(null, arguments);
  537. var json = {};
  538. var fnSuc = argsToJson.fnSuc;
  539. argsToJson.url && (json.url = argsToJson.url);
  540. argsToJson.data && (json.data = argsToJson.data);
  541. if (argsToJson.dataType) {
  542. var type = argsToJson.dataType.toLowerCase();
  543. if (type == 'text' || type == 'json') {
  544. json.dataType = type;
  545. }
  546. } else {
  547. json.dataType = 'json';
  548. }
  549. json.method = 'post';
  550. api.ajax(json,
  551. function(ret, err) {
  552. if (ret) {
  553. fnSuc && fnSuc(ret);
  554. }
  555. }
  556. );
  557. };
  558. u.get = function( /*url,fnSuc,dataType*/ ) {
  559. var argsToJson = parseArguments.apply(null, arguments);
  560. var json = {};
  561. var fnSuc = argsToJson.fnSuc;
  562. argsToJson.url && (json.url = argsToJson.url);
  563. if (argsToJson.dataType) {
  564. vartype = argsToJson.dataType.toLowerCase();
  565. if (type == 'text' || type == 'json') {
  566. json.dataType = type;
  567. }
  568. } else {
  569. json.dataType = 'text';
  570. }
  571. json.method = 'get';
  572. api.ajax(json,
  573. function(ret, err) {
  574. if (ret) {
  575. fnSuc && fnSuc(ret);
  576. }
  577. }
  578. );
  579. };
  580. /*end*/
  581. window.$api = u;
  582. setFixStatusBar = function() {
  583. var systemType = api.systemType;
  584. var systemVersion = api.systemVersion;
  585. var h = api.safeArea.top + 'px';
  586. if (systemType == 'ios') {
  587. $api.fixStatusBar($api.dom('body'));
  588. $('.topbar').css("height", h);
  589. $('.page').css("margin-top", h);
  590. $('body').css("margin-top", "-0.05rem");
  591. } else {
  592. $api.fixStatusBar($api.dom('body'));
  593. $('.topbar').css("height", h);
  594. $('.page').css("margin-top", h);
  595. $('body').css("margin-top", "-0.05rem");
  596. }
  597. }
  598. setIosTopBar = function() {
  599. var systemType = api.systemType;
  600. var systemVersion = api.systemVersion;
  601. var h = api.safeArea.top + 'px';
  602. if (systemType == 'ios') {
  603. $api.fixStatusBar($api.dom('body'));
  604. $('.topbar').css("height", h);
  605. $('.page').css("margin-top", h);
  606. $('body').css("margin-top", "-0.05rem");
  607. } else {
  608. $api.fixStatusBar($api.dom('body'));
  609. $('.topbar').css("height", h);
  610. $('.page').css("margin-top", h);
  611. $('body').css("margin-top", "-0.05rem");
  612. }
  613. }
  614. setBackDisable = function() {
  615. var systemType = api.systemType;
  616. if (systemType == 'ios') {
  617. api.setWinAttr({
  618. slidBackEnabled: false
  619. });
  620. } else {
  621. var backSecond = 0;
  622. api.addEventListener({
  623. name: 'keyback'
  624. }, function(ret, err) {
  625. var curSecond = (new Date().getTime()) / 1000;
  626. if (Math.abs(curSecond - backSecond) > 2) {
  627. backSecond = curSecond;
  628. api.toast({
  629. msg: '再按一次退出',
  630. duration: 2000,
  631. location: 'bottom'
  632. });
  633. } else {
  634. api.closeWidget({
  635. id: 'A6007457911931',
  636. retData: {
  637. name: 'closeWidget'
  638. },
  639. silent: true
  640. });
  641. }
  642. });
  643. }
  644. }
  645. setTimeCloseWin = function(winname) {
  646. setTimeout(function() {
  647. api.closeWin({
  648. name: winname
  649. });
  650. }, 800);
  651. }
  652. limitNumber = function(txt, num) {
  653. var str = txt;
  654. str = str.substr(0, num) + '...';
  655. return str;
  656. }
  657. statInputNum = function(textArea, numItem) {
  658. // body...
  659. var max = numItem.text(),
  660. curLength;
  661. textArea[0].setAttribute("maxlength", max);
  662. curLength = textArea.val().length;
  663. numItem.text(max - curLength);
  664. textArea.on('input propertychange', function() {
  665. numItem.text(max - $(this).val().length);
  666. })
  667. }
  668. errcode = function(res, code) {
  669. switch (code) {
  670. case 2000:
  671. $api.rmStorage("storeid");
  672. $api.rmStorage("memberid");
  673. $api.rmStorage("agent_id");
  674. $api.rmStorage("accesstoken");
  675. api.openWin({
  676. name: 'login',
  677. url: 'widget://login.html',
  678. bounces: false,
  679. pageParam: {
  680. keyid: true
  681. }
  682. })
  683. break;
  684. case 1001:
  685. api.toast({
  686. msg: res.msg
  687. })
  688. break;
  689. case 3000:
  690. api.toast({
  691. msg: '系统开小差了'
  692. })
  693. break;
  694. case 999:
  695. api.toast({
  696. msg: res.msg
  697. })
  698. break;
  699. default:
  700. api.toast({
  701. msg: '发生了不知名的错误' + code
  702. })
  703. break;
  704. }
  705. }
  706. gallery_qz = function(img) {
  707. img = img.replace('thumb/', '');
  708. var _html = '<div class="weui-gallery" data-imgurl="' + img + '" style="display: block;">';
  709. _html += '<span class="weui-gallery__img" style="background-image: url(' + img + ');"></span>';
  710. _html += '<div class="weui-gallery__opr">';
  711. _html += '<a href="javascript:$(\'.weui-gallery\').remove()" class="weui-gallery__del">';
  712. _html += '<i class="weui-icon-cancel" style="font-size: 1rem;"></i></a></div></div>';
  713. $("body").prepend(_html);
  714. }
  715. gallery_adv = function(img, function_name, id, oid) {
  716. // body...
  717. var _html = '<div class="weui-gallery" style="display: block;background-color: rgba(0, 0, 0, 0.18);">';
  718. _html += '<a href="javascript:' + function_name + '(' + id + ', ' + oid +
  719. ')"><span class="weui-gallery__img" style="background-image: url(' + img + ');"></span></a>';
  720. _html += '<div class="weui-gallery__opr" style="background-color: rgba(0, 0, 0, 0);">';
  721. _html += '<a href="javascript:color()" class="weui-gallery__del">';
  722. _html += '<i class="weui-icon-cancel" style="font-size: 1rem;"></i></a></div></div>';
  723. $("body").prepend(_html);
  724. }
  725. toast_weui = function(e) {
  726. // body...
  727. var _html = '<div class="js_dialog" id="iosDialog2_qz" style="display: block;">';
  728. _html += '<div class="weui-mask"></div>';
  729. _html += '<div class="weui-dialog">';
  730. _html += '<div class="weui-dialog__bd">购物前请确认<h2 style="margin: 8px 0;color: #d9251c;">' + e +
  731. '</h2>是否是您入住的酒店</div>';
  732. _html += '<div class="weui-dialog__ft">';
  733. _html +=
  734. '<a href="javascript:api.closeWin();" class="weui-dialog__btn m-bottom back-btn weui-dialog__btn_default" style="background: #777;">返回确认</a>';
  735. _html +=
  736. '<a href="javascript:$(\'#iosDialog2_qz\').remove();" class="weui-dialog__btn m-bottom weui-dialog__btn_primary">确认无误</a></div></div></div>';
  737. $("body").prepend(_html);
  738. }
  739. toast_loding_show = function(e) {
  740. var _html = '<div id="loadingToast_k" class="loadingToast_k">';
  741. _html += '<div class="weui-mask_transparent"></div>';
  742. _html += '<div class="weui-toast">';
  743. _html += '<i class="weui-loading weui-icon_toast"></i>';
  744. _html += '<p class="weui-toast__content">数据加载中</p></div></div>';
  745. $("body").prepend(_html);
  746. }
  747. toast_loding_hide = function() {
  748. $(".loadingToast_k").remove();
  749. }
  750. hasPermission = function(one_per) {
  751. var perms = new Array();
  752. if (one_per) {
  753. perms.push(one_per);
  754. } else {
  755. api.toast({
  756. msg: '系统开小差了'
  757. });
  758. return;
  759. }
  760. var rets = api.hasPermission({
  761. list: perms
  762. });
  763. if (!one_per) {
  764. api.toast({
  765. msg: '判断结果:' + JSON.stringify(rets)
  766. });
  767. return;
  768. }
  769. return rets;
  770. }
  771. reqPermission = function(one_per, callback) {
  772. var perms = new Array();
  773. if (one_per) {
  774. perms.push(one_per);
  775. } else {
  776. api.toast({
  777. msg: '系统开小差了'
  778. });
  779. return;
  780. }
  781. api.requestPermission({
  782. list: perms,
  783. code: 100001
  784. }, function(ret, err) {
  785. if (callback) {
  786. callback(ret);
  787. return;
  788. }
  789. console.log(JSON.stringify(ret));
  790. })
  791. }
  792. function_name = function() {
  793. $('body').imagesLoaded()
  794. .always(function(instance) {
  795. // console.log('all images loaded');
  796. })
  797. .done(function(instance) {
  798. // console.log('all images successfully loaded');
  799. })
  800. .fail(function() {
  801. // console.log('all images loaded, at least one is broken');
  802. })
  803. .progress(function(instance, image) {
  804. // var result = image.isLoaded ? 'loaded' : 'broken';
  805. // console.log( 'image is ' + result + ' for ' + image.img.src );
  806. // console.log(image)
  807. // image.img.parentNode.className = image.isLoaded ? '' : 'is-broken';
  808. if (!image.isLoaded) {
  809. // image.img.className = 'is-broken';
  810. image.img.src = 'http://www2.qzaiwang.com/static/home/images/logo2.png'
  811. }
  812. });
  813. }
  814. qz_update = function() {
  815. var mam = api.require('mam');
  816. mam.checkUpdate(function(ret, err) {
  817. if (ret) {
  818. var result = ret.result;
  819. if (result.update == true && result.closed == false) {
  820. var str = '新版本号:' + result.version + ';更新提示语:' + result.updateTip;
  821. api.confirm({
  822. title: '有新的版本,是否下载并安装',
  823. msg: str,
  824. buttons: ['确定', '取消']
  825. }, function(ret, err) {
  826. var index = ret.buttonIndex;
  827. if (api.systemType == "android") {
  828. api.download({
  829. url: result.source,
  830. report: true
  831. }, function(ret, err) {
  832. if (ret && 0 == ret.state) {
  833. api.toast({
  834. msg: "正在下载" + ret.percent + "%",
  835. duration: 2000
  836. })
  837. }
  838. })
  839. }
  840. })
  841. } else {
  842. api.toast({
  843. msg: "已经是最新版本"
  844. })
  845. }
  846. } else {
  847. alert(JSON.stringify(err));
  848. }
  849. })
  850. }
  851. })(window);
  852. // var siteurl = 'http://www2.qzaiwang.com/';
  853. var siteurl = 'https://www.qzaiwang.com/';
  854. // var rooturl = 'http://www2.qzaiwang.com/api/index.php';
  855. var rooturl = 'https://www.qzaiwang.com/api/index.php';
  856. var version = '1.01';