var domanUrl = "//" + window.location.host; var base_path = "//rst.iamberry.com"; //var base_path = domanUrl+"/tooth"; //ajax loading $(window).ajaxStart(function(){ $(".covers").show(); }); $(window).ajaxStop(function(){ $(".covers").hide(); }); mui.each(document.querySelectorAll('#footer-bar-tab .mui-tab-item'), function(index, el) { el.addEventListener('tap', function() { switch(index) { case 0: mui.openWindow({ url: 'index.html' }); break; case 1: mui.openWindow({ url: 'pro-list.html' }); break; case 2: mui.openWindow({ url: 'shopping-cart.html' }); break; case 3: mui.openWindow({ url: 'my-center.html' }); break; default: break; } }, false); }); function time_before(t){ var minute=1000*60; var hour=minute*60; var day=hour*24; var halfamonth=day*15; var month=day*30; var now=new Date().getTime(); var diffValue=now-new Date().setTime(t); var monthC=diffValue/month; var weekC=diffValue/(7*day); var dayC=diffValue/day; var hourC=diffValue/hour; var minC=diffValue/minute; if(monthC>=1){ result=""+parseInt(monthC)+"月前"; }else if(weekC>=1){ result=""+parseInt(weekC)+"周前"; }else if(dayC>=1){ result=""+parseInt(dayC)+"天前"; }else if(hourC>=1){ result=""+parseInt(hourC)+"小时前"; }else if(minC>=2){ result=""+parseInt(minC)+"分钟前"; }else{ result="刚刚"; } return result; }; //封装document.getElementById function dc(objectid) { if(document.getElementById && document.getElementById(objectid)) { return document.getElementById(objectid);// w3c dom } else if (document.all && document.all(objectid)) { return document.all(objectid);// msie 4 dom } else if (document.layers && document.layers[objectid]) { return document.layers[objectid];// nn 4 dom.. note: this won't find nested layers } else { return false; } }; //生成随机字符,n长度 function generateMixed(n) { 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']; var res = ""; for(var i = 0; i < n ; i ++) { var id = Math.ceil(Math.random()*35); res += chars[id]; } return res; } function getParam(paramName) { paramValue = "", isFound = !1; if(this.location.search.indexOf("?") == 0 && this.location.search.indexOf("=") > 1) { arrSource = unescape(this.location.search).substring(1, this.location.search.length).split("&"), i = 0; while(i < arrSource.length && !isFound) { arrSource[i].indexOf("=") > 0 && arrSource[i].split("=")[0].toLowerCase() == paramName.toLowerCase() && (paramValue = arrSource[i].split("=")[1], isFound = !0), i++ } } return paramValue == "" && (paramValue = null), paramValue }; function getQueryString(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); var r = window.location.search.substr(1).match(reg); if (r != null) return unescape(r[2]); return null; } // 对Date的扩展,将 Date 转化为指定格式的String // 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符, // 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字) // 例子: // (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423 // (new Date()).Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18 Date.prototype.format = function(fmt) { //author: meizz var o = { "M+" : this.getMonth()+1, //月份 "d+" : this.getDate(), //日 "h+" : this.getHours(), //小时 "m+" : this.getMinutes(), //分 "s+" : this.getSeconds(), //秒 "q+" : Math.floor((this.getMonth()+3)/3), //季度 "S" : this.getMilliseconds() //毫秒 }; if(/(y+)/.test(fmt)) fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)); for(var k in o) if(new RegExp("("+ k +")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length))); return fmt; } //计算月份差 function getMonthNumber(date1,date2){ //默认格式为"2010-01-01",根据自己需要改格式和方法 var d1=date1.replaceAll("-",''),d2=date2.replaceAll("-",''); var year1 = d1.substring(0,4); var year2 = d2.substring(0,4); var month1 = d1.substring(6,4); var month2 = d2.substring(6,4); var len=parseInt((year2-year1)*12+(month2-month1)); return len; } //替换所有要替换的文字 String.prototype.replaceAll = function (str1,str2){ var str = this; var result = str.replace(eval("/"+str1+"/gi"),str2); return result; } /** ** 加法函数,用来得到精确的加法结果 ** 说明:javascript的加法结果会有误差,在两个浮点数相加的时候会比较明显。这个函数返回较为精确的加法结果。 ** 调用:accAdd(arg1,arg2) ** 返回值:arg1加上arg2的精确结果 **/ function accAdd(arg1, arg2) { var r1, r2, m, c; try { r1 = arg1.toString().split(".")[1].length; } catch (e) { r1 = 0; } try { r2 = arg2.toString().split(".")[1].length; } catch (e) { r2 = 0; } c = Math.abs(r1 - r2); m = Math.pow(10, Math.max(r1, r2)); if (c > 0) { var cm = Math.pow(10, c); if (r1 > r2) { arg1 = Number(arg1.toString().replace(".", "")); arg2 = Number(arg2.toString().replace(".", "")) * cm; } else { arg1 = Number(arg1.toString().replace(".", "")) * cm; arg2 = Number(arg2.toString().replace(".", "")); } } else { arg1 = Number(arg1.toString().replace(".", "")); arg2 = Number(arg2.toString().replace(".", "")); } return (arg1 + arg2) / m; } //给Number类型增加一个add方法,调用起来更加方便。 Number.prototype.add = function (arg) { return accAdd(arg, this); }; /** ** 减法函数,用来得到精确的减法结果 ** 说明:javascript的减法结果会有误差,在两个浮点数相减的时候会比较明显。这个函数返回较为精确的减法结果。 ** 调用:accSub(arg1,arg2) ** 返回值:arg1加上arg2的精确结果 **/ function accSub(arg1, arg2) { var r1, r2, m, n; try { r1 = arg1.toString().split(".")[1].length; } catch (e) { r1 = 0; } try { r2 = arg2.toString().split(".")[1].length; } catch (e) { r2 = 0; } m = Math.pow(10, Math.max(r1, r2)); //last modify by deeka //动态控制精度长度 n = (r1 >= r2) ? r1 : r2; return ((arg1 * m - arg2 * m) / m).toFixed(n); } // 给Number类型增加一个mul方法,调用起来更加方便。 Number.prototype.sub = function (arg) { return accSub(arg, this); }; /** ** 除法函数,用来得到精确的除法结果 ** 说明:javascript的除法结果会有误差,在两个浮点数相除的时候会比较明显。这个函数返回较为精确的除法结果。 ** 调用:accDiv(arg1,arg2) ** 返回值:arg1除以arg2的精确结果 **/ function accDiv(arg1, arg2) { var t1 = 0, t2 = 0, r1, r2; try { t1 = arg1.toString().split(".")[1].length; } catch (e) { } try { t2 = arg2.toString().split(".")[1].length; } catch (e) { } with (Math) { r1 = Number((arg1 + "").replace(".", "")); r2 = Number((arg2 + "").replace(".", "")); return (r1 / r2) * pow(10, t2 - t1); } } //给Number类型增加一个div方法,调用起来更加方便。 Number.prototype.div = function (arg) { return accDiv(this, arg); }; /** ** 乘法函数,用来得到精确的乘法结果 ** 说明:javascript的乘法结果会有误差,在两个浮点数相乘的时候会比较明显。这个函数返回较为精确的乘法结果。 ** 调用:accMul(arg1,arg2) ** 返回值:arg1乘以 arg2的精确结果 **/ function accMul(arg1, arg2) { var m = 0, s1 = arg1.toString(), s2 = arg2.toString(); try { m += s1.split(".")[1].length; } catch (e) { } try { m += s2.split(".")[1].length; } catch (e) { } return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m); } // 给Number类型增加一个mul方法,调用起来更加方便。 Number.prototype.mul = function (arg) { return accMul(arg, this); }; function formatDate(now) { now = new Date(now); var year=now.getFullYear(); var month=now.getMonth()+1; if(month<10){ month="0"+month; } var date=now.getDate(); return year+"年"+month+"月"+date+"日"; } function formatTime(msd) { var time = parseFloat(msd) /1000; if (null!= time &&""!= time) { if (time >60&& time <60*60) { time = parseInt(time /60.0) +"分"; // time = parseInt(time /60.0) +"分钟"+ parseInt((parseFloat(time /60.0) - // parseInt(time /60.0)) *60) +"秒"; }else if (time >=60*60&& time <60*60*24) { // time = parseInt(time /3600.0) +"小时"+ parseInt((parseFloat(time /3600.0) - // parseInt(time /3600.0)) *60) +"分钟"+ // parseInt((parseFloat((parseFloat(time /3600.0) - parseInt(time /3600.0)) *60) - // parseInt((parseFloat(time /3600.0) - parseInt(time /3600.0)) *60)) *60) +"秒"; time = parseInt(time /3600.0) +"时"+ parseInt((parseFloat(time /3600.0) - parseInt(time /3600.0)) *60) +"分"; }else { time = parseInt(time) +"分"; } }else{ time = "0分"; } return time; } function formatMinutes(msd) { // 参数msd (秒) var time = parseFloat(msd); if (null!= time && ""!= time) { if (time >0&& time <60*60) { time = parseInt(time /60.0) +"分"; }else{ time = parseInt(time /3600.0) +"时"+ parseInt((parseFloat(time /3600.0) - parseInt(time /3600.0)) *60) +"分"; } }else{ time = "0分"; } return time; } function formatDay(now) { now = new Date(now); var month=now.getMonth()+1; if(month<10){ month="0"+month; } var date=now.getDate(); if(date<10){ date="0"+date; } return month+"-"+date; } function formatDateFull(now) { now = new Date(now); var year=now.getFullYear(); var month=now.getMonth()+1; if(month<10){ month="0"+month; } var date=now.getDate(); if(date<10){ date="0"+date; } return year+"-"+month+"-"+date; } function formatDateMinute(now) { now = new Date(now); var year=now.getFullYear(); var month=now.getMonth()+1; if(month<10){ month="0"+month; } var date=now.getDate(); if(date<10){ date="0"+date; } var hour=now.getHours(); if(hour<10){ hour="0"+hour; } var Minute=now.getMinutes(); if(Minute<10){ Minute="0"+Minute; } return year+"-"+month+"-"+date+" "+hour+":"+Minute; } function int_for_time(obj){ return obj+":00"; } //替换指定传入参数的值,paramName为参数,replaceWith为新值 function replaceParamVal(paramName,replaceWith) { var oUrl = this.location.href.toString(); var re=eval('/('+ paramName+'=)([^&]*)/gi'); var nUrl = oUrl.replace(re,paramName+'='+replaceWith); window.history.pushState({},0,nUrl); } function isEmptyObject(e) { var t; for (t in e) return !1; return !0 } function gotoTop() { mui('.my-scroll-wrapper').scroll().scrollTo(0,0,500);//500毫秒滚动到顶 //$(".mui-scroll").css({"transform":"translate3d(0px, 0px, 0px) translateZ(0px)","transition-duration":"100ms"}); }; function gotoBottom(){ mui('.my-scroll-wrapper').scroll().scrollToBottom();//500毫秒滚动到底部 } $(document).on('tap', '.go_pro_list', function() { var positions=''; if(typeof($(this).attr("pos"))!="undefined"){ positions=$(this).attr("pos"); location.href="pro-list.html?pos="+positions; }else{ location.href="pro-list.html"; } }); $(document).on('tap', '.icon-shouye', function() { location.href="index.html"; }); //回到顶部 function gotoTop(acceleration, stime) { acceleration = acceleration || 0.1; stime = stime || 10; var x1 = 0, y1 = 0, x2 = 0, y2 = 0, x3 = 0, y3 = 0; if (document.documentElement) { x1 = document.documentElement.scrollLeft || 0; y1 = document.documentElement.scrollTop || 0; } if (document.body) { x2 = document.body.scrollLeft || 0; y2 = document.body.scrollTop || 0; } var x3 = window.scrollX || 0; var y3 = window.scrollY || 0; var x = Math.max(x1, Math.max(x2, x3)); var y = Math.max(y1, Math.max(y2, y3)); var speeding = 1 + acceleration; window.scrollTo(Math.floor(x / speeding), Math.floor(y / speeding)); if (x > 0 || y > 0) { var run = "gotoTop(" + acceleration + ", " + stime + ")"; window.setTimeout(run, stime); } }