main.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. var domanUrl = "//" + window.location.host,
  2. path="//w.iamberry.com",
  3. base_path= path +"/wechat_rg/wechat";
  4. function errorfn(xhr) {
  5. if(xhr.readyState == 4 && xhr.status == 200) {} else {
  6. var ref = location.href.split("#")[0],
  7. src = '';
  8. if(ref.indexOf('?') != -1) {
  9. src = ref + "&date=" + new Date().getTime()
  10. } else {
  11. src = ref + "?date=" + new Date().getTime()
  12. }
  13. location.href = src;
  14. return
  15. }
  16. }
  17. function gotoTop(acceleration, stime) {
  18. acceleration = acceleration || 0.1;
  19. stime = stime || 10;
  20. var x1 = 0,
  21. y1 = 0,
  22. x2 = 0,
  23. y2 = 0,
  24. x3 = 0,
  25. y3 = 0;
  26. if(document.documentElement) {
  27. x1 = document.documentElement.scrollLeft || 0;
  28. y1 = document.documentElement.scrollTop || 0
  29. }
  30. if(document.body) {
  31. x2 = document.body.scrollLeft || 0;
  32. y2 = document.body.scrollTop || 0
  33. }
  34. var x3 = window.scrollX || 0;
  35. var y3 = window.scrollY || 0;
  36. var x = Math.max(x1, Math.max(x2, x3));
  37. var y = Math.max(y1, Math.max(y2, y3));
  38. var speeding = 1 + acceleration;
  39. window.scrollTo(Math.floor(x / speeding), Math.floor(y / speeding));
  40. if(x > 0 || y > 0) {
  41. var run = "gotoTop(" + acceleration + ", " + stime + ")";
  42. window.setTimeout(run, stime)
  43. }
  44. };
  45. function accDiv(arg1, arg2) {
  46. var t1 = 0,
  47. t2 = 0,
  48. r1, r2;
  49. try {
  50. t1 = arg1.toString().split(".")[1].length
  51. } catch(e) {}
  52. try {
  53. t2 = arg2.toString().split(".")[1].length
  54. } catch(e) {}
  55. with(Math) {
  56. r1 = Number(arg1.toString().replace(".", ""));
  57. r2 = Number(arg2.toString().replace(".", ""));
  58. return(r1 / r2) * pow(10, t2 - t1)
  59. }
  60. };
  61. Number.prototype.div = function(arg) {
  62. return accDiv(this, arg)
  63. };
  64. function accAdd(arg1, arg2) {
  65. var r1, r2, m, c;
  66. try {
  67. r1 = arg1.toString().split(".")[1].length
  68. } catch(e) {
  69. r1 = 0
  70. }
  71. try {
  72. r2 = arg2.toString().split(".")[1].length
  73. } catch(e) {
  74. r2 = 0
  75. }
  76. c = Math.abs(r1 - r2);
  77. m = Math.pow(10, Math.max(r1, r2));
  78. if(c > 0) {
  79. var cm = Math.pow(10, c);
  80. if(r1 > r2) {
  81. arg1 = Number(arg1.toString().replace(".", ""));
  82. arg2 = Number(arg2.toString().replace(".", "")) * cm
  83. } else {
  84. arg1 = Number(arg1.toString().replace(".", "")) * cm;
  85. arg2 = Number(arg2.toString().replace(".", ""))
  86. }
  87. } else {
  88. arg1 = Number(arg1.toString().replace(".", ""));
  89. arg2 = Number(arg2.toString().replace(".", ""))
  90. }
  91. return(arg1 + arg2) / m
  92. };
  93. Number.prototype.add = function(arg) {
  94. return accAdd(arg, this)
  95. };
  96. function accSub(arg1, arg2) {
  97. var r1, r2, m, n;
  98. try {
  99. r1 = arg1.toString().split(".")[1].length
  100. } catch(e) {
  101. r1 = 0
  102. }
  103. try {
  104. r2 = arg2.toString().split(".")[1].length
  105. } catch(e) {
  106. r2 = 0
  107. }
  108. m = Math.pow(10, Math.max(r1, r2));
  109. n = (r1 >= r2) ? r1 : r2;
  110. return((arg1 * m - arg2 * m) / m).toFixed(n)
  111. };
  112. Number.prototype.sub = function(arg) {
  113. return accMul(arg, this)
  114. };
  115. function accMul(arg1, arg2) {
  116. var m = 0,
  117. s1 = arg1.toString(),
  118. s2 = arg2.toString();
  119. try {
  120. m += s1.split(".")[1].length
  121. } catch(e) {}
  122. try {
  123. m += s2.split(".")[1].length
  124. } catch(e) {}
  125. return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m)
  126. };
  127. Number.prototype.mul = function(arg) {
  128. return accMul(arg, this)
  129. };
  130. function getParam(paramName) {
  131. paramValue = "", isFound = !1;
  132. if(this.location.search.indexOf("?") == 0 && this.location.search.indexOf("=") > 1) {
  133. arrSource = unescape(this.location.search).substring(1, this.location.search.length).split("&"), i = 0;
  134. while(i < arrSource.length && !isFound) {
  135. arrSource[i].indexOf("=") > 0 && arrSource[i].split("=")[0].toLowerCase() == paramName.toLowerCase() && (paramValue = arrSource[i].split("=")[1], isFound = !0), i++
  136. }
  137. }
  138. return paramValue == "" && (paramValue = null), paramValue
  139. };
  140. function dc(objectid) {
  141. if(document.getElementById && document.getElementById(objectid)) {
  142. return document.getElementById(objectid)
  143. } else if(document.all && document.all(objectid)) {
  144. return document.all(objectid)
  145. } else if(document.layers && document.layers[objectid]) {
  146. return document.layers[objectid]
  147. } else {
  148. return false
  149. }
  150. };
  151. function formatDate(now) {
  152. now = new Date(now);
  153. var year = now.getFullYear();
  154. var month = now.getMonth() + 1;
  155. var date = now.getDate();
  156. var hour = now.getHours();
  157. var minute = now.getMinutes();
  158. var second = now.getSeconds();
  159. return year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second
  160. };
  161. function springFestivalPop() {
  162. if(getCookie("WATERO_WEB_") == null) {
  163. maskspringFestival.show();
  164. $(".mui-backdrop").append('<div style="position:relative;"><img src="//s.iamberry.com/watero/images/shop/springFestival_2017.png" style="width:80%;margin:10% 10% auto 10%;"/><button type="button" id="close-springFestival" class="mui-btn my-btn-red" style="position: absolute;bottom: 5%;left: 50%;-webkit-transform: translateX(-50%)">我知道了</button></div>');
  165. mui('body').on('tap', '#close-springFestival', function(e) {
  166. setCookie();
  167. $(".mui-backdrop").hide();
  168. });
  169. }
  170. };
  171. function getCookie(name) {
  172. var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
  173. if(arr = document.cookie.match(reg))
  174. return unescape(arr[2]);
  175. else
  176. return null;
  177. };
  178. var maskspringFestival = mui.createMask(function() {
  179. return false;
  180. }); //callback为用户点击蒙版时自动执行的回调;
  181. function setCookie() {
  182. var Days = 30;
  183. var exp = new Date();
  184. exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
  185. document.cookie = "WATERO_WEB_=OK;Path=/;expires=" + exp.toGMTString();
  186. };
  187. /**
  188. * 该方法用于将Undefined转换为空值
  189. * @param val
  190. */
  191. function convertUndefinedToEmpty(val) {
  192. if (undefined == val || null == val||typeof val == undefined || typeof val == 'undefined'|| 'undefined' == val) {
  193. val = "";
  194. }
  195. return val;
  196. }
  197. /**
  198. * 该方法用于将Undefined转换为空值
  199. * @param val
  200. */
  201. function cufte(val) {
  202. return convertUndefinedToEmpty(val);
  203. }
  204. /**
  205. * 空值返回0,其他值返回原值
  206. * @param val
  207. */
  208. function cufteInt(val) {
  209. if(convertUndefinedToEmpty(val) == "")
  210. return 0;
  211. return val;
  212. }
  213. /**
  214. * 空值返回false
  215. * @param val
  216. */
  217. function isEmpty(val) {
  218. if(convertUndefinedToEmpty(val) == "")
  219. return false;
  220. return true;
  221. }