main.js.bak 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. var domanUrl = "http://" + window.location.host;
  2. var base_path = "http://w.iamberry.com/iamberry";
  3. //var base_path = "/iamberry";
  4. //ajax loading
  5. $(window).ajaxStart(function(){
  6. $(".covers").show();
  7. });
  8. $(window).ajaxStop(function(){
  9. $(".covers").hide();
  10. });
  11. mui.each(document.querySelectorAll('#footer-bar-tab .mui-tab-item'), function(index, el) {
  12. el.addEventListener('tap', function() {
  13. switch(index) {
  14. case 0:
  15. mui.openWindow({
  16. url: 'index.html'
  17. });
  18. break;
  19. case 1:
  20. mui.openWindow({
  21. url: 'pro-list.html'
  22. });
  23. break;
  24. case 2:
  25. mui.openWindow({
  26. url: 'shopping-cart.html'
  27. });
  28. break;
  29. case 3:
  30. mui.openWindow({
  31. url: 'my-center.html'
  32. });
  33. break;
  34. default:
  35. break;
  36. }
  37. }, false);
  38. });
  39. function time_before(t){
  40. var minute=1000*60;
  41. var hour=minute*60;
  42. var day=hour*24;
  43. var halfamonth=day*15;
  44. var month=day*30;
  45. var now=new Date().getTime();
  46. var diffValue=now-new Date().setTime(t);
  47. var monthC=diffValue/month;
  48. var weekC=diffValue/(7*day);
  49. var dayC=diffValue/day;
  50. var hourC=diffValue/hour;
  51. var minC=diffValue/minute;
  52. if(monthC>=1){
  53. result=""+parseInt(monthC)+"月前";
  54. }else if(weekC>=1){
  55. result=""+parseInt(weekC)+"周前";
  56. }else if(dayC>=1){
  57. result=""+parseInt(dayC)+"天前";
  58. }else if(hourC>=1){
  59. result=""+parseInt(hourC)+"小时前";
  60. }else if(minC>=2){
  61. result=""+parseInt(minC)+"分钟前";
  62. }else{
  63. result="刚刚";
  64. }
  65. return result;
  66. };
  67. //封装document.getElementById
  68. function dc(objectid) {
  69. if(document.getElementById && document.getElementById(objectid)) {
  70. return document.getElementById(objectid);// w3c dom
  71. } else if (document.all && document.all(objectid)) {
  72. return document.all(objectid);// msie 4 dom
  73. } else if (document.layers && document.layers[objectid]) {
  74. return document.layers[objectid];// nn 4 dom.. note: this won't find nested layers
  75. } else {
  76. return false;
  77. }
  78. };
  79. //生成随机字符,n长度
  80. function generateMixed(n) {
  81. var chars = ['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
  82. var res = "";
  83. for(var i = 0; i < n ; i ++) {
  84. var id = Math.ceil(Math.random()*35);
  85. res += chars[id];
  86. }
  87. return res;
  88. }
  89. function getParam(paramName) {
  90. paramValue = "", isFound = !1;
  91. if(this.location.search.indexOf("?") == 0 && this.location.search.indexOf("=") > 1) {
  92. arrSource = unescape(this.location.search).substring(1, this.location.search.length).split("&"), i = 0;
  93. while(i < arrSource.length && !isFound) {
  94. arrSource[i].indexOf("=") > 0 && arrSource[i].split("=")[0].toLowerCase() == paramName.toLowerCase() && (paramValue = arrSource[i].split("=")[1], isFound = !0), i++
  95. }
  96. }
  97. return paramValue == "" && (paramValue = null), paramValue
  98. };
  99. function getQueryString(name) {
  100. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  101. var r = window.location.search.substr(1).match(reg);
  102. if (r != null) return unescape(r[2]); return null;
  103. }
  104. // 对Date的扩展,将 Date 转化为指定格式的String
  105. // 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符,
  106. // 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
  107. // 例子:
  108. // (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
  109. // (new Date()).Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18
  110. Date.prototype.format = function(fmt)
  111. { //author: meizz
  112. var o = {
  113. "M+" : this.getMonth()+1, //月份
  114. "d+" : this.getDate(), //日
  115. "h+" : this.getHours(), //小时
  116. "m+" : this.getMinutes(), //分
  117. "s+" : this.getSeconds(), //秒
  118. "q+" : Math.floor((this.getMonth()+3)/3), //季度
  119. "S" : this.getMilliseconds() //毫秒
  120. };
  121. if(/(y+)/.test(fmt))
  122. fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
  123. for(var k in o)
  124. if(new RegExp("("+ k +")").test(fmt))
  125. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
  126. return fmt;
  127. }
  128. //计算月份差
  129. function getMonthNumber(date1,date2){
  130. //默认格式为"2010-01-01",根据自己需要改格式和方法
  131. var d1=date1.replaceAll("-",''),d2=date2.replaceAll("-",'');
  132. var year1 = d1.substring(0,4);
  133. var year2 = d2.substring(0,4);
  134. var month1 = d1.substring(6,4);
  135. var month2 = d2.substring(6,4);
  136. var len=parseInt((year2-year1)*12+(month2-month1));
  137. return len;
  138. }
  139. //替换所有要替换的文字
  140. String.prototype.replaceAll = function (str1,str2){
  141. var str = this;
  142. var result = str.replace(eval("/"+str1+"/gi"),str2);
  143. return result;
  144. }
  145. /**
  146. ** 加法函数,用来得到精确的加法结果
  147. ** 说明:javascript的加法结果会有误差,在两个浮点数相加的时候会比较明显。这个函数返回较为精确的加法结果。
  148. ** 调用:accAdd(arg1,arg2)
  149. ** 返回值:arg1加上arg2的精确结果
  150. **/
  151. function accAdd(arg1, arg2) {
  152. var r1, r2, m, c;
  153. try {
  154. r1 = arg1.toString().split(".")[1].length;
  155. }
  156. catch (e) {
  157. r1 = 0;
  158. }
  159. try {
  160. r2 = arg2.toString().split(".")[1].length;
  161. }
  162. catch (e) {
  163. r2 = 0;
  164. }
  165. c = Math.abs(r1 - r2);
  166. m = Math.pow(10, Math.max(r1, r2));
  167. if (c > 0) {
  168. var cm = Math.pow(10, c);
  169. if (r1 > r2) {
  170. arg1 = Number(arg1.toString().replace(".", ""));
  171. arg2 = Number(arg2.toString().replace(".", "")) * cm;
  172. } else {
  173. arg1 = Number(arg1.toString().replace(".", "")) * cm;
  174. arg2 = Number(arg2.toString().replace(".", ""));
  175. }
  176. } else {
  177. arg1 = Number(arg1.toString().replace(".", ""));
  178. arg2 = Number(arg2.toString().replace(".", ""));
  179. }
  180. return (arg1 + arg2) / m;
  181. }
  182. //给Number类型增加一个add方法,调用起来更加方便。
  183. Number.prototype.add = function (arg) {
  184. return accAdd(arg, this);
  185. };
  186. /**
  187. ** 除法函数,用来得到精确的除法结果
  188. ** 说明:javascript的除法结果会有误差,在两个浮点数相除的时候会比较明显。这个函数返回较为精确的除法结果。
  189. ** 调用:accDiv(arg1,arg2)
  190. ** 返回值:arg1除以arg2的精确结果
  191. **/
  192. function accDiv(arg1, arg2) {
  193. var t1 = 0, t2 = 0, r1, r2;
  194. try {
  195. t1 = arg1.toString().split(".")[1].length;
  196. }
  197. catch (e) {
  198. }
  199. try {
  200. t2 = arg2.toString().split(".")[1].length;
  201. }
  202. catch (e) {
  203. }
  204. with (Math) {
  205. r1 = Number((arg1 + "").replace(".", ""));
  206. r2 = Number((arg2 + "").replace(".", ""));
  207. return (r1 / r2) * pow(10, t2 - t1);
  208. }
  209. }
  210. //给Number类型增加一个div方法,调用起来更加方便。
  211. Number.prototype.div = function (arg) {
  212. return accDiv(this, arg);
  213. };
  214. /**
  215. ** 乘法函数,用来得到精确的乘法结果
  216. ** 说明:javascript的乘法结果会有误差,在两个浮点数相乘的时候会比较明显。这个函数返回较为精确的乘法结果。
  217. ** 调用:accMul(arg1,arg2)
  218. ** 返回值:arg1乘以 arg2的精确结果
  219. **/
  220. function accMul(arg1, arg2) {
  221. var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
  222. try {
  223. m += s1.split(".")[1].length;
  224. }
  225. catch (e) {
  226. }
  227. try {
  228. m += s2.split(".")[1].length;
  229. }
  230. catch (e) {
  231. }
  232. return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m);
  233. }
  234. // 给Number类型增加一个mul方法,调用起来更加方便。
  235. Number.prototype.mul = function (arg) {
  236. return accMul(arg, this);
  237. };
  238. function formatDate(now) {
  239. now = new Date(now);
  240. var year=now.getFullYear();
  241. var month=now.getMonth()+1;
  242. if(month<10){
  243. month="0"+month;
  244. }
  245. var date=now.getDate();
  246. return year+"年"+month+"月"+date+"日";
  247. }
  248. function formatTime(msd) {
  249. var time = parseFloat(msd) /1000;
  250. if (null!= time &&""!= time) {
  251. if (time >60&& time <60*60) {
  252. time = parseInt(time /60.0) +"分";
  253. // time = parseInt(time /60.0) +"分钟"+ parseInt((parseFloat(time /60.0) -
  254. // parseInt(time /60.0)) *60) +"秒";
  255. }else if (time >=60*60&& time <60*60*24) {
  256. // time = parseInt(time /3600.0) +"小时"+ parseInt((parseFloat(time /3600.0) -
  257. // parseInt(time /3600.0)) *60) +"分钟"+
  258. // parseInt((parseFloat((parseFloat(time /3600.0) - parseInt(time /3600.0)) *60) -
  259. // parseInt((parseFloat(time /3600.0) - parseInt(time /3600.0)) *60)) *60) +"秒";
  260. time = parseInt(time /3600.0) +"时"+ parseInt((parseFloat(time /3600.0) -
  261. parseInt(time /3600.0)) *60) +"分";
  262. }else {
  263. time = parseInt(time) +"分";
  264. }
  265. }else{
  266. time = "0分";
  267. }
  268. return time;
  269. }
  270. function formatMinutes(msd) {
  271. // 参数msd (秒)
  272. var time = parseFloat(msd);
  273. if (null!= time && ""!= time) {
  274. if (time >0&& time <60*60) {
  275. time = parseInt(time /60.0) +"分";
  276. }else{
  277. time = parseInt(time /3600.0) +"时"+ parseInt((parseFloat(time /3600.0) -
  278. parseInt(time /3600.0)) *60) +"分";
  279. }
  280. }else{
  281. time = "0分";
  282. }
  283. return time;
  284. }
  285. function formatDay(now) {
  286. now = new Date(now);
  287. var month=now.getMonth()+1;
  288. if(month<10){
  289. month="0"+month;
  290. }
  291. var date=now.getDate();
  292. if(date<10){
  293. date="0"+date;
  294. }
  295. return month+"-"+date;
  296. }
  297. function formatDateFull(now) {
  298. now = new Date(now);
  299. var year=now.getFullYear();
  300. var month=now.getMonth()+1;
  301. if(month<10){
  302. month="0"+month;
  303. }
  304. var date=now.getDate();
  305. if(date<10){
  306. date="0"+date;
  307. }
  308. return year+"-"+month+"-"+date;
  309. }
  310. function formatDateMinute(now) {
  311. now = new Date(now);
  312. var year=now.getFullYear();
  313. var month=now.getMonth()+1;
  314. if(month<10){
  315. month="0"+month;
  316. }
  317. var date=now.getDate();
  318. if(date<10){
  319. date="0"+date;
  320. }
  321. var hour=now.getHours();
  322. if(hour<10){
  323. hour="0"+hour;
  324. }
  325. var Minute=now.getMinutes();
  326. if(Minute<10){
  327. Minute="0"+Minute;
  328. }
  329. return year+"-"+month+"-"+date+" "+hour+":"+Minute;
  330. }
  331. function int_for_time(obj){
  332. return obj+":00";
  333. }
  334. //替换指定传入参数的值,paramName为参数,replaceWith为新值
  335. function replaceParamVal(paramName,replaceWith) {
  336. var oUrl = this.location.href.toString();
  337. var re=eval('/('+ paramName+'=)([^&]*)/gi');
  338. var nUrl = oUrl.replace(re,paramName+'='+replaceWith);
  339. window.history.pushState({},0,nUrl);
  340. }
  341. function isEmptyObject(e) {
  342. var t;
  343. for (t in e)
  344. return !1;
  345. return !0
  346. }
  347. function gotoTop() {
  348. mui('.my-scroll-wrapper').scroll().scrollTo(0,0,500);//500毫秒滚动到顶
  349. //$(".mui-scroll").css({"transform":"translate3d(0px, 0px, 0px) translateZ(0px)","transition-duration":"100ms"});
  350. };
  351. function gotoBottom(){
  352. mui('.my-scroll-wrapper').scroll().scrollToBottom();//500毫秒滚动到底部
  353. }
  354. $(document).on('tap', '.go_pro_list', function() {
  355. var positions='';
  356. if(typeof($(this).attr("pos"))!="undefined"){
  357. positions=$(this).attr("pos");
  358. location.href="pro-list.html?pos="+positions;
  359. }else{
  360. location.href="pro-list.html";
  361. }
  362. });
  363. $(document).on('tap', '.icon-shouye', function() {
  364. location.href="index.html";
  365. });
  366. //回到顶部
  367. function gotoTop(acceleration, stime) {
  368. acceleration = acceleration || 0.1;
  369. stime = stime || 10;
  370. var x1 = 0,
  371. y1 = 0,
  372. x2 = 0,
  373. y2 = 0,
  374. x3 = 0,
  375. y3 = 0;
  376. if (document.documentElement) {
  377. x1 = document.documentElement.scrollLeft || 0;
  378. y1 = document.documentElement.scrollTop || 0;
  379. }
  380. if (document.body) {
  381. x2 = document.body.scrollLeft || 0;
  382. y2 = document.body.scrollTop || 0;
  383. }
  384. var x3 = window.scrollX || 0;
  385. var y3 = window.scrollY || 0;
  386. var x = Math.max(x1, Math.max(x2, x3));
  387. var y = Math.max(y1, Math.max(y2, y3));
  388. var speeding = 1 + acceleration;
  389. window.scrollTo(Math.floor(x / speeding), Math.floor(y / speeding));
  390. if (x > 0 || y > 0) {
  391. var run = "gotoTop(" + acceleration + ", " + stime + ")";
  392. window.setTimeout(run, stime);
  393. }
  394. }