// Underscore.js 1.4.2
// http://underscorejs.org
// (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc.
// Underscore may be freely distributed under the MIT license.
(function(){var e=this,t=e._,n={},r=Array.prototype,i=Object.prototype,s=Function.prototype,o=r.push,u=r.slice,a=r.concat,f=r.unshift,l=i.toString,c=i.hasOwnProperty,h=r.forEach,p=r.map,d=r.reduce,v=r.reduceRight,m=r.filter,g=r.every,y=r.some,b=r.indexOf,w=r.lastIndexOf,E=Array.isArray,S=Object.keys,x=s.bind,T=function(e){if(e instanceof T)return e;if(!(this instanceof T))return new T(e);this._wrapped=e};typeof exports!="undefined"?(typeof module!="undefined"&&module.exports&&(exports=module.exports=T),exports._=T):e._=T,T.VERSION="1.4.2";var N=T.each=T.forEach=function(e,t,r){if(e==null)return;if(h&&e.forEach===h)e.forEach(t,r);else if(e.length===+e.length){for(var i=0,s=e.length;i<s;i++)if(t.call(r,e[i],i,e)===n)return}else for(var o in e)if(T.has(e,o)&&t.call(r,e[o],o,e)===n)return};T.map=T.collect=function(e,t,n){var r=[];return e==null?r:p&&e.map===p?e.map(t,n):(N(e,function(e,i,s){r[r.length]=t.call(n,e,i,s)}),r)},T.reduce=T.foldl=T.inject=function(e,t,n,r){var i=arguments.length>2;e==null&&(e=[]);if(d&&e.reduce===d)return r&&(t=T.bind(t,r)),i?e.reduce(t,n):e.reduce(t);N(e,function(e,s,o){i?n=t.call(r,n,e,s,o):(n=e,i=!0)});if(!i)throw new TypeError("Reduce of empty array with no initial value");return n},T.reduceRight=T.foldr=function(e,t,n,r){var i=arguments.length>2;e==null&&(e=[]);if(v&&e.reduceRight===v)return r&&(t=T.bind(t,r)),arguments.length>2?e.reduceRight(t,n):e.reduceRight(t);var s=e.length;if(s!==+s){var o=T.keys(e);s=o.length}N(e,function(u,a,f){a=o?o[--s]:--s,i?n=t.call(r,n,e[a],a,f):(n=e[a],i=!0)});if(!i)throw new TypeError("Reduce of empty array with no initial value");return n},T.find=T.detect=function(e,t,n){var r;return C(e,function(e,i,s){if(t.call(n,e,i,s))return r=e,!0}),r},T.filter=T.select=function(e,t,n){var r=[];return e==null?r:m&&e.filter===m?e.filter(t,n):(N(e,function(e,i,s){t.call(n,e,i,s)&&(r[r.length]=e)}),r)},T.reject=function(e,t,n){var r=[];return e==null?r:(N(e,function(e,i,s){t.call(n,e,i,s)||(r[r.length]=e)}),r)},T.every=T.all=function(e,t,r){t||(t=T.identity);var i=!0;return e==null?i:g&&e.every===g?e.every(t,r):(N(e,function(e,s,o){if(!(i=i&&t.call(r,e,s,o)))return n}),!!i)};var C=T.some=T.any=function(e,t,r){t||(t=T.identity);var i=!1;return e==null?i:y&&e.some===y?e.some(t,r):(N(e,function(e,s,o){if(i||(i=t.call(r,e,s,o)))return n}),!!i)};T.contains=T.include=function(e,t){var n=!1;return e==null?n:b&&e.indexOf===b?e.indexOf(t)!=-1:(n=C(e,function(e){return e===t}),n)},T.invoke=function(e,t){var n=u.call(arguments,2);return T.map(e,function(e){return(T.isFunction(t)?t:e[t]).apply(e,n)})},T.pluck=function(e,t){return T.map(e,function(e){return e[t]})},T.where=function(e,t){return T.isEmpty(t)?[]:T.filter(e,function(e){for(var n in t)if(t[n]!==e[n])return!1;return!0})},T.max=function(e,t,n){if(!t&&T.isArray(e)&&e[0]===+e[0]&&e.length<65535)return Math.max.apply(Math,e);if(!t&&T.isEmpty(e))return-Infinity;var r={computed:-Infinity};return N(e,function(e,i,s){var o=t?t.call(n,e,i,s):e;o>=r.computed&&(r={value:e,computed:o})}),r.value},T.min=function(e,t,n){if(!t&&T.isArray(e)&&e[0]===+e[0]&&e.length<65535)return Math.min.apply(Math,e);if(!t&&T.isEmpty(e))return Infinity;var r={computed:Infinity};return N(e,function(e,i,s){var o=t?t.call(n,e,i,s):e;o<r.computed&&(r={value:e,computed:o})}),r.value},T.shuffle=function(e){var t,n=0,r=[];return N(e,function(e){t=T.random(n++),r[n-1]=r[t],r[t]=e}),r};var k=function(e){return T.isFunction(e)?e:function(t){return t[e]}};T.sortBy=function(e,t,n){var r=k(t);return T.pluck(T.map(e,function(e,t,i){return{value:e,index:t,criteria:r.call(n,e,t,i)}}).sort(function(e,t){var n=e.criteria,r=t.criteria;if(n!==r){if(n>r||n===void 0)return 1;if(n<r||r===void 0)return-1}return e.index<t.index?-1:1}),"value")};var L=function(e,t,n,r){var i={},s=k(t);return N(e,function(t,o){var u=s.call(n,t,o,e);r(i,u,t)}),i};T.groupBy=function(e,t,n){return L(e,t,n,function(e,t,n){(T.has(e,t)?e[t]:e[t]=[]).push(n)})},T.countBy=function(e,t,n){return L(e,t,n,function(e,t,n){T.has(e,t)||(e[t]=0),e[t]++})},T.sortedIndex=function(e,t,n,r){n=n==null?T.identity:k(n);var i=n.call(r,t),s=0,o=e.length;while(s<o){var u=s+o>>>1;n.call(r,e[u])<i?s=u+1:o=u}return s},T.toArray=function(e){return e?e.length===+e.length?u.call(e):T.values(e):[]},T.size=function(e){return e.length===+e.length?e.length:T.keys(e).length},T.first=T.head=T.take=function(e,t,n){return t!=null&&!n?u.call(e,0,t):e[0]},T.initial=function(e,t,n){return u.call(e,0,e.length-(t==null||n?1:t))},T.last=function(e,t,n){return t!=null&&!n?u.call(e,Math.max(e.length-t,0)):e[e.length-1]},T.rest=T.tail=T.drop=function(e,t,n){return u.call(e,t==null||n?1:t)},T.compact=function(e){return T.filter(e,function(e){return!!e})};var A=function(e,t,n){return N(e,function(e){T.isArray(e)?t?o.apply(n,e):A(e,t,n):n.push(e)}),n};T.flatten=function(e,t){return A(e,t,[])},T.without=function(e){return T.difference(e,u.call(arguments,1))},T.uniq=T.unique=function(e,t,n,r){var i=n?T.map(e,n,r):e,s=[],o=[];return N(i,function(n,r){if(t?!r||o[o.length-1]!==n:!T.contains(o,n))o.push(n),s.push(e[r])}),s},T.union=function(){return T.uniq(a.apply(r,arguments))},T.intersection=function(e){var t=u.call(arguments,1);return T.filter(T.uniq(e),function(e){return T.every(t,function(t){return T.indexOf(t,e)>=0})})},T.difference=function(e){var t=a.apply(r,u.call(arguments,1));return T.filter(e,function(e){return!T.contains(t,e)})},T.zip=function(){var e=u.call(arguments),t=T.max(T.pluck(e,"length")),n=new Array(t);for(var r=0;r<t;r++)n[r]=T.pluck(e,""+r);return n},T.object=function(e,t){var n={};for(var r=0,i=e.length;r<i;r++)t?n[e[r]]=t[r]:n[e[r][0]]=e[r][1];return n},T.indexOf=function(e,t,n){if(e==null)return-1;var r=0,i=e.length;if(n){if(typeof n!="number")return r=T.sortedIndex(e,t),e[r]===t?r:-1;r=n<0?Math.max(0,i+n):n}if(b&&e.indexOf===b)return e.indexOf(t,n);for(;r<i;r++)if(e[r]===t)return r;return-1},T.lastIndexOf=function(e,t,n){if(e==null)return-1;var r=n!=null;if(w&&e.lastIndexOf===w)return r?e.lastIndexOf(t,n):e.lastIndexOf(t);var i=r?n:e.length;while(i--)if(e[i]===t)return i;return-1},T.range=function(e,t,n){arguments.length<=1&&(t=e||0,e=0),n=arguments[2]||1;var r=Math.max(Math.ceil((t-e)/n),0),i=0,s=new Array(r);while(i<r)s[i++]=e,e+=n;return s};var O=function(){};T.bind=function(t,n){var r,i;if(t.bind===x&&x)return x.apply(t,u.call(arguments,1));if(!T.isFunction(t))throw new TypeError;return i=u.call(arguments,2),r=function(){if(this instanceof r){O.prototype=t.prototype;var e=new O,s=t.apply(e,i.concat(u.call(arguments)));return Object(s)===s?s:e}return t.apply(n,i.concat(u.call(arguments)))}},T.bindAll=function(e){var t=u.call(arguments,1);return t.length==0&&(t=T.functions(e)),N(t,function(t){e[t]=T.bind(e[t],e)}),e},T.memoize=function(e,t){var n={};return t||(t=T.identity),function(){var r=t.apply(this,arguments);return T.has(n,r)?n[r]:n[r]=e.apply(this,arguments)}},T.delay=function(e,t){var n=u.call(arguments,2);return setTimeout(function(){return e.apply(null,n)},t)},T.defer=function(e){return T.delay.apply(T,[e,1].concat(u.call(arguments,1)))},T.throttle=function(e,t){var n,r,i,s,o,u,a=T.debounce(function(){o=s=!1},t);return function(){n=this,r=arguments;var f=function(){i=null,o&&(u=e.apply(n,r)),a()};return i||(i=setTimeout(f,t)),s?o=!0:(s=!0,u=e.apply(n,r)),a(),u}},T.debounce=function(e,t,n){var r,i;return function(){var s=this,o=arguments,u=function(){r=null,n||(i=e.apply(s,o))},a=n&&!r;return clearTimeout(r),r=setTimeout(u,t),a&&(i=e.apply(s,o)),i}},T.once=function(e){var t=!1,n;return function(){return t?n:(t=!0,n=e.apply(this,arguments),e=null,n)}},T.wrap=function(e,t){return function(){var n=[e];return o.apply(n,arguments),t.apply(this,n)}},T.compose=function(){var e=arguments;return function(){var t=arguments;for(var n=e.length-1;n>=0;n--)t=[e[n].apply(this,t)];return t[0]}},T.after=function(e,t){return e<=0?t():function(){if(--e<1)return t.apply(this,arguments)}},T.keys=S||function(e){if(e!==Object(e))throw new TypeError("Invalid object");var t=[];for(var n in e)T.has(e,n)&&(t[t.length]=n);return t},T.values=function(e){var t=[];for(var n in e)T.has(e,n)&&t.push(e[n]);return t},T.pairs=function(e){var t=[];for(var n in e)T.has(e,n)&&t.push([n,e[n]]);return t},T.invert=function(e){var t={};for(var n in e)T.has(e,n)&&(t[e[n]]=n);return t},T.functions=T.methods=function(e){var t=[];for(var n in e)T.isFunction(e[n])&&t.push(n);return t.sort()},T.extend=function(e){return N(u.call(arguments,1),function(t){for(var n in t)e[n]=t[n]}),e},T.pick=function(e){var t={},n=a.apply(r,u.call(arguments,1));return N(n,function(n){n in e&&(t[n]=e[n])}),t},T.omit=function(e){var t={},n=a.apply(r,u.call(arguments,1));for(var i in e)T.contains(n,i)||(t[i]=e[i]);return t},T.defaults=function(e){return N(u.call(arguments,1),function(t){for(var n in t)e[n]==null&&(e[n]=t[n])}),e},T.clone=function(e){return T.isObject(e)?T.isArray(e)?e.slice():T.extend({},e):e},T.tap=function(e,t){return t(e),e};var M=function(e,t,n,r){if(e===t)return e!==0||1/e==1/t;if(e==null||t==null)return e===t;e instanceof T&&(e=e._wrapped),t instanceof T&&(t=t._wrapped);var i=l.call(e);if(i!=l.call(t))return!1;switch(i){case"[object String]":return e==String(t);case"[object Number]":return e!=+e?t!=+t:e==0?1/e==1/t:e==+t;case"[object Date]":case"[object Boolean]":return+e==+t;case"[object RegExp]":return e.source==t.source&&e.global==t.global&&e.multiline==t.multiline&&e.ignoreCase==t.ignoreCase}if(typeof e!="object"||typeof t!="object")return!1;var s=n.length;while(s--)if(n[s]==e)return r[s]==t;n.push(e),r.push(t);var o=0,u=!0;if(i=="[object Array]"){o=e.length,u=o==t.length;if(u)while(o--)if(!(u=M(e[o],t[o],n,r)))break}else{var a=e.constructor,f=t.constructor;if(a!==f&&!(T.isFunction(a)&&a instanceof a&&T.isFunction(f)&&f instanceof f))return!1;for(var c in e)if(T.has(e,c)){o++;if(!(u=T.has(t,c)&&M(e[c],t[c],n,r)))break}if(u){for(c in t)if(T.has(t,c)&&!(o--))break;u=!o}}return n.pop(),r.pop(),u};T.isEqual=function(e,t){return M(e,t,[],[])},T.isEmpty=function(e){if(e==null)return!0;if(T.isArray(e)||T.isString(e))return e.length===0;for(var t in e)if(T.has(e,t))return!1;return!0},T.isElement=function(e){return!!e&&e.nodeType===1},T.isArray=E||function(e){return l.call(e)=="[object Array]"},T.isObject=function(e){return e===Object(e)},N(["Arguments","Function","String","Number","Date","RegExp"],function(e){T["is"+e]=function(t){return l.call(t)=="[object "+e+"]"}}),T.isArguments(arguments)||(T.isArguments=function(e){return!!e&&!!T.has(e,"callee")}),typeof /./!="function"&&(T.isFunction=function(e){return typeof e=="function"}),T.isFinite=function(e){return T.isNumber(e)&&isFinite(e)},T.isNaN=function(e){return T.isNumber(e)&&e!=+e},T.isBoolean=function(e){return e===!0||e===!1||l.call(e)=="[object Boolean]"},T.isNull=function(e){return e===null},T.isUndefined=function(e){return e===void 0},T.has=function(e,t){return c.call(e,t)},T.noConflict=function(){return e._=t,this},T.identity=function(e){return e},T.times=function(e,t,n){for(var r=0;r<e;r++)t.call(n,r)},T.random=function(e,t){return t==null&&(t=e,e=0),e+(0|Math.random()*(t-e+1))};var _={escape:{"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"}};_.unescape=T.invert(_.escape);var D={escape:new RegExp("["+T.keys(_.escape).join("")+"]","g"),unescape:new RegExp("("+T.keys(_.unescape).join("|")+")","g")};T.each(["escape","unescape"],function(e){T[e]=function(t){return t==null?"":(""+t).replace(D[e],function(t){return _[e][t]})}}),T.result=function(e,t){if(e==null)return null;var n=e[t];return T.isFunction(n)?n.call(e):n},T.mixin=function(e){N(T.functions(e),function(t){var n=T[t]=e[t];T.prototype[t]=function(){var e=[this._wrapped];return o.apply(e,arguments),F.call(this,n.apply(T,e))}})};var P=0;T.uniqueId=function(e){var t=P++;return e?e+t:t},T.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var H=/(.)^/,B={"'":"'","\\":"\\","\r":"r","\n":"n"," ":"t","\u2028":"u2028","\u2029":"u2029"},j=/\\|'|\r|\n|\t|\u2028|\u2029/g;T.template=function(e,t,n){n=T.defaults({},n,T.templateSettings);var r=new RegExp([(n.escape||H).source,(n.interpolate||H).source,(n.evaluate||H).source].join("|")+"|$","g"),i=0,s="__p+='";e.replace(r,function(t,n,r,o,u){s+=e.slice(i,u).replace(j,function(e){return"\\"+B[e]}),s+=n?"'+\n((__t=("+n+"))==null?'':_.escape(__t))+\n'":r?"'+\n((__t=("+r+"))==null?'':__t)+\n'":o?"';\n"+o+"\n__p+='":"",i=u+t.length}),s+="';\n",n.variable||(s="with(obj||{}){\n"+s+"}\n"),s="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+s+"return __p;\n";try{var o=new Function(n.variable||"obj","_",s)}catch(u){throw u.source=s,u}if(t)return o(t,T);var a=function(e){return o.call(this,e,T)};return a.source="function("+(n.variable||"obj")+"){\n"+s+"}",a},T.chain=function(e){return T(e).chain()};var F=function(e){return this._chain?T(e).chain():e};T.mixin(T),N(["pop","push","reverse","shift","sort","splice","unshift"],function(e){var t=r[e];T.prototype[e]=function(){var n=this._wrapped;return t.apply(n,arguments),(e=="shift"||e=="splice")&&n.length===0&&delete n[0],F.call(this,n)}}),N(["concat","join","slice"],function(e){var t=r[e];T.prototype[e]=function(){return F.call(this,t.apply(this._wrapped,arguments))}}),T.extend(T.prototype,{chain:function(){return this._chain=!0,this},value:function(){return this._wrapped}})}).call(this);/**
* 公共配置文件
* 包含公共常量, 配置和方法
*/
;(function() {
/**
* 应用公共对象
*/
// window.App = new Object(); //移到 init.js去
if(!navigator.cookieEnabled){
alert('请确认您当前的浏览器已开启Cookie,如果您是IOS设备,请在 设置=>safari=>接受Cookie 中选择“总是”');
}
/**
* 常量定义
*/
var ua = navigator.userAgent.toUpperCase();
App.userAgent = ua;
// 当前环境是否为Android平台
App.IS_ANDROID = ua.indexOf('ANDROID') != -1;
// 当前环境是否为IOS平台
App.IS_IOS = ua.indexOf('IPHONE OS') != -1;
// 当前环境是否为本地Native环境
App.IS_NATIVE = (App.IS_ANDROID || App.IS_IOS) ? true : false;
App.IsWIN8 = (ua.indexOf('WINDOWS') != -1 && ua.indexOf('MSIE') != -1);//nokia浏览器设置为电脑版本
App.IsWP = (ua.indexOf('WINDOWS') != -1 && ua.indexOf('PHONE') != -1 );//nokia浏览器设置为手机版本
//媒体来源于iphone的填IPHONE
//stz 修正从手机的浏览器而来的情况:(也算是从浏览器而不是native而来)
/*if(!App.IS_NATIVE){
window.location.href = 'http://chexian.pingan.com';
} else {
window.location.href = 'http://www.pingan.com';
}*/
if(!$.fn.tap||ua.indexOf('OPERA') != -1){
$.fn.tap = $.fn.click;
}
if(!$.fn.swipe) $.fn.swipe = function(callback){ return this.bind('swipe', callback) }
App.Cild_direct = "/pa18shoplife/mobile/"; // 环境需要
if(App.IS_IOS && ua.indexOf('SAFARI') != -1){
App.IS_NATIVE = false;
App.IS_IOS = false;
}
if(App.IS_ANDROID && !window.android){
App.IS_NATIVE = false;
App.IS_ANDROID = false;
}
if(!App.IS_NATIVE){
var header = $('header');
if(header.size()){
header.show();
header.find('span.com_header_back').tap(function(e){
back();
});
//可以是可以:
// var header_back = header.find('span.com_header_back');
// header_back.on('touchstart',function(){
// header_back.addClass('com_header_back_grey');
// });
// header_back.on('touchend',function(){
// header_back.removeClass('com_header_back_grey');
// back();
// })
}
}
App.MediaSource = {
MOBILE_DEFAULT: 'SC03-Direct-00001', // 手机官网默认的媒体来源
SMS_Marketing : {
CHANNEL_1 : 'sc03-marketing-sms-00000001', // 多波次活动早保早优惠
CHANNEL_2 : 'sc03-marketing-sms-00000002', // 多波次活动夏日大促
CHANNEL_3 : 'sc03-marketing-sms-00000003', // 多波次活动秒杀
CHANNEL_4 : 'sc03-marketing-zbzyh-00000001' // 早保早优惠
},
ACTIVITY_DONGYIQU: 'sc03-marketing-dongyiqu-00000001', // 东一区活动媒体来源:首页广告
ACTIVITY_DONGYIQU_NEW: 'sc03-marketing-dyq-0001', // 新增东一区活动媒体来源
ACTIVITY_DONGERQU: 'sc03-marketing-deq-0002', // 东二区活动媒体来源:首页默认
ACTIVITY_DONGERQU_AD: 'sc03-marketing-deq-b2', // 东二区活动媒体来源:首页广告
ACTIVITY_XIQU: 'sc03-marketing-xq-0003', // 西区活动媒体来源:首页默认
ACTIVITY_XIQU_AD: 'sc03-marketing-xq-b3', // 西区活动媒体来源:首页广告
ACTIVITY_NANQU: 'sc03-marketing-nq-0004', // 南区活动媒体来源:首页默认
ACTIVITY_NANQU_AD: 'sc03-marketing-nq-b4', // 南区活动媒体来源:首页广告
ACTIVITY_YJXB_AD: 'sc03-yjxb-0000001',
ACTIVITY_YJXB_AD2: 'sc03-yjxb-0000002',
ACTIVITY_YJXB_ZBZYH: 'sc03-direct-zbzyh-0000001',
ACTIVITY_BEIQU: 'sc03-marketing-bq-0005', // 北区活动媒体来源
ACTIVITY_ALL: 'upa-marketing-all', // 非业务提供媒体来源不做统计只用于程序标识自用
WEIXIN : 'sc03-channel-weixin-00000001', // 微信媒体来源
SC03_MARKETING_BJS:{//报价送
SX:'SC03-MARKETING-BJS-0001', // 陕西
GS:'SC03-MARKETING-BJS-0002', // 甘肃
GZ:'SC03-MARKETING-BJS-0003', // 贵州
CQ:'SC03-MARKETING-BJS-0004', // 重庆
NX:'SC03-MARKETING-BJS-0005', // 宁夏
YN:'SC03-MARKETING-BJS-0006', // 云南
QH:'SC03-MARKETING-BJS-0007', // 青海
SC:'SC03-MARKETING-BJS-0008', // 四川
XJ:'SC03-MARKETING-BJS-0009' // 新疆
}
}
//线上环境
App.domain="u.pingan.com/upingan/upingan";
//测试环境
//App.domain="dmzstg1.pa18.com/upingan/upingan"; //webtrends 监控脚本实际域名地址,根据实际地址更换,线上环境地址:u.pingan.com/upingan
App.relactPath = ''; //http://www.pingan.com/ebusiness/auto/mobile/upingan/ 坑爹的配置让我们用这个转进去。。。
// 是否为开发环境
App.IS_DEV = false;
// 自定义undefined
App.UNDEFINED = 'UNDEFINED';
//userId的标识
//App.userId = 'mobile_sc03';
//车险的伙伴标识
//App.partnerName = 'chexian-mobile';
//app版本号
App.ANDROID_Version=0;
App.IOS_Version=0;
// 服务器地址
// App.ServerHost = '/';
// if (window.location.hostname == 'localhost') {
App.ServerHost = 'http://www.pingan.com/';
// }
// 后台地址
App.RequestHost = '/upingan/';
// 公共提示信息
App.lang = {
getFlowIdError : '获取流程号失败, 请稍后重试!',
serviceError : '系统发生错误, 请稍后重试!',
Tip:'提示:',
putInStartPlace:'请输入起点',
putInEndPlace:'请输入终点'
}
/**
* 模板文件地址定义
*/
/*
App.tplUrls = {
city : App.relactPath+'tpl/city.html',
date : App.relactPath+'tpl/date.html',
headFoot: App.relactPath+'tpl/headfoot.html',
vehicleType: App.relactPath+'tpl/vehicleType.html'
}
*/
/**
* 公共组件动态加载地址
*/
/*
App.completeUrls = {
touch : 'js/common/touch.js',
scroll : 'js/common/scroll.js',
scroll2 : 'js/common/Scroll2.js',
box : 'js/common/box.js',
Slide : 'js/common/Slide.js',
SlideList : 'js/common/SlideList.js'
}
*/
//服务器那边分页单位(几条数据分一页)
App.pageDateNum = 10;
//滑动多少像素开始加载
App.pageDistanceOfSlide = 80;
/**
* 证件类型/性别等配置
*/
/*
App.comConst = {
'01' : '居民身份证',
'02' : '护照',
'03' : '军官证',
'05' : '驾驶证',
'06' : '港澳回乡证或台胞证',
'M' : '男',
'F' : '女'
}
App.cerTypes = {
'居民身份证' : '01',
'护照' : '02',
'军官证' : '03',
'驾驶证' : '05',
'港澳回乡证或台胞证' : '06'
};
App.genderTypes = {
'男':'M',
'女' :'F'
}
*/
/*
* 保单状态
*/
/*
App.insureBitStatus = {
'0' : '可支付',
'1' : '待审核',
'2' : '已过期',
'3' : '已完成',
'4' : '待上门收费',
'5' : '审核不通过'
}
*/
/*
* 图片上传最大张数
*/
/*
App.picMaxNum = {
'1' : 3,
'2' : 3,
'3' : 2,
'4' : 5,
'6' : 5
}
*/
/*
* 接口请求返回的状态码,手机官网
*/
App.Res = {
CODE_SUCC : 0, // 正常返回
CODE_UNLOGIN : -1 // 未登陆
}
/**
* Web Service接口定义
*/
var webServiceUrls = {
// 查询平安服务门店信息
SearchLifeStoreAction: 'pa18shoplife/mobile/store/action/searchLifeStoreAction.jsp'
}
/**
* 在开发环境中需要使用的独立配置
*/
if(App.IS_DEV) {
// 进入基本信息页面
// toBaseInfo = 'CarInsureHybird/branches/html5/branches/data/insure/to-base-info.json';
// modelQueryParent = 'CarInsureHybird/branches/html5/branches/data/insure/model-query-parent.json';
// toApplyConfirm = 'CarInsureHybird/branches/html5/branches/data/insure/to-apply-confirm.json';
webServiceUrls = {
}
}
App.showHeader = function(){
if(!App.IS_NATIVE){
var header = $('header');
if(header.size()){
header.show();
header.find('span.com_header_back').tap(function(e){
back();
});
}
}
}
App.getWebServiceUrl = function(name) {
return App.ServerHost + webServiceUrls[name];
}
App.getRequestUrl = function(name) {
return App.RequestHost + webServiceUrls[name];
}
/**
* 获取jsonp的路径
* example: App.getJSONPUrl('rsupport/vehicle/brand/');
*/
App.getJSONPUrl = function(fileName){
var oldfileName = fileName;
var origin = location.origin, host = location.host;
if(!origin){ //android 不识别 location.origin
var protocol = location.protocol;
protocol = protocol=="http:"?"http://":protocol=="https:"?"https://":"file:///";
origin = protocol + (host||location.hostname);
}
console.log(host);
if(host == "www.pingan.com" || host == 'u.pingan.com') { //生产测试路径
fileName = 'http://www.pingan.com/' + fileName;
} else if(host == "stg.pa18.com" || host == "p1.pa18.com") { //旧环境测试地址
fileName = origin + fileName;
} else { //新域名测试地址 , 比如 http://dmzstg1.pa18.com/upingan/
fileName = 'http://stg.pa18.com/' + fileName;
}
// if(App.IS_ANDROID) fileName = oldfileName; //android 用当前根路径为起点。。。
return fileName;
}
})();
/**
* Native接口配置
*/
;(function(App) {
var callindex = 0, toString = Object.prototype.toString;
// 如果fn是一个函数类型, 则调用
var exec = function(fn) {
if(toString.call(fn) == '[object Function]') {
fn();
}
}
/**
* 调用一个Native方法
* @param {String} name 方法名称
*/
App.call = function(name) {
// 获取传递给Native方法的参数
var args = Array.prototype.slice.call(arguments, 1);
var callback = '', item = null;
// 遍历参数
for(var i = 0, len = args.length; i < len; i++) {
item = args[i];
if(item === undefined) {
item = '';
}
// 如果参数是一个Function类型, 则将Function存储到window对象, 并将函数名传递给Native
if(toString.call(item) == '[object Function]') {
callback = name + 'Callback' + i;
window[callback] = item;
//---stz test:
// if(name == 'showLoginPage'){
// App.alert('callback: '+callback+' \n '+window[callback]);
// }
item = callback;
}
args[i] = item;
}
if(App.IS_ANDROID) {// Android平台
try {
for(var i = 0, len = args.length; i < len; i++) {
// args[i] = '"' + args[i] + '"';
args[i] = '\'' + args[i] + '\'';
}
eval('window.android.' + name + '(' + args.join(',') + ')');
} catch(e) {
alert(e);
}
eval();
} else if(App.IS_IOS) {// IOS平台
if(args.length) {
args = '|' + args.join('|');
}
// IOS通过location.href调用Native方法, _call变量存储一个随机数确保每次调用时URL不一致
callindex++;
location.href = '#ios:' + name + args + '|' + callindex;
}
}
/**
* 显示alert提示信息
* @param {String} text
* @param {Function} callback
*/
App.alert = function(text, callback) {
if(App.IS_NATIVE) {
App.call('alert', text, callback);
} else {
alert(text);
exec(callback);
}
}
/**
* 显示confirm选择信息
* @param {String} text
* @param {Function} ok
* @param {Function} cancel
*/
App.confirm = function(text, ok, cancel) {
if(App.IS_NATIVE) {
App.call('confirm', text, ok, cancel);
} else {
if(confirm(text)) {
exec(ok);
} else {
exec(cancel);
}
}
}
/**
* 页面跳转, 如果在终端设备中则重新设置WebView的加载地址
* @param {String} url
*/
App.href = function(url) {
if(App.IS_NATIVE) {
App.call('href', url);
} else {
if(App.relactPath && (url.indexOf('http://')==-1&&url.indexOf('https://')==-1)){
//var origin = location.origin, host = location.host;
url = App.relactPath + url;
}
window.location.href = url;
}
}
/**
* 在浏览器中打开新页面
* @param {String} url
*/
App.open = function(url) {
if(App.IS_NATIVE) {
App.call('open', url);
} else {
window.open(url);
}
}
/**
* 通知Native页面加载完成
*/
App.onload = function() {
if(App.IS_NATIVE) {
App.call('onload');
} else {
App.onload.returnValue = true;
if( checkBeeCanvas() )
AheadHandle.loadingBee.hideAll();
}
}
/**
* 所有资源加载完毕(包括脚本) noteby stz 2013-3-26 只有首页有,已经有App.onload代替了
*/
// App.loadAll = function() {
// if(App.IS_NATIVE) {
// App.call('loadAll');
// } else {
// App.loadAll.returnValue = true;
// if( checkBeeCanvas() ) AheadHandle.loadingBee.hideAll();
// }
// }
/**
* 开始加载loading动画
* @param {Boolean} notCancel 是否不能取消, 默认能取消
*/
App.loadingBegin = function(notCancel) {
if(App.IS_NATIVE) {
App.call('loadingBegin', !!notCancel);
} else {
if( checkBeeCanvas() )
AheadHandle.loadingBee.show();
}
}
/**
* 加载完成, 隐藏loading动画
*/
App.loadingFinish = function() {
// console.log('---------------- loadingFinish -----------------')
if(App.IS_NATIVE) {
App.call('loadingFinish');
} else {
if( checkBeeCanvas() )
AheadHandle.loadingBee.hide();
}
}
/**
* 显示登录页面
});
*/
App.showLoginPage = function() {
if(App.IS_NATIVE) {
App.call('showLoginPage', function() {
Cookie('rumUserLogin', 'Y');
});
} else {
Cookie('rumUserLogin','Y');
App.href(getLoginRegistUrl('login'));
}
}
/**
* 改变标题
*/
App.changeTitle = function(title) {
if(App.IS_NATIVE) {
App.call('changeTitle', title);
} else {
// $('header span.com_header_text').text(title);
// console.log('Title: ' + title);
}
}
/**
* 最后一步的返回到native
* @param {String} menu 返回哪级哪级菜单:
* 首页菜单:---------------
* 车险报价: MainCarOffer 这样调App.backToPage('MainCarOffer','0')返回首页并销毁调这个接口的页面
* 车险服务: MainCarService [目前不需要]
* 行车助手: MainCarAssist [目前不需要]
* 优惠: MainFavorable
* 更多: MainMore
* 二级菜单:---------------
* 会员中心页: MemberCenter
* 车险服务: CarInsureSevice
* 行车助手: CarAssistant
* @param {String} oldMenu 从哪级菜单返回的. 如果是'1',直接返回上一级(默认),没这个参数或者'0'返回到首页,
* 总之0销毁第二级webview,1销毁第三级webview。如App.backToPage('MemberCenter','1')表示从会员中心的下一级返回到会员中心,而App.backToPage('MemberCenter','0')从会员中心返回到首页
*/
App.backToPage = function(menu, oldMenu) {
if(!oldMenu)
oldMenu = '1';
App.call('backToPage', menu, oldMenu);
// if(App.IS_NATIVE) {
// App.call('backToPage', menu, oldMenu);
// }else{
// var header = $('header');
// header.find('span.com_header_back').css('visibility', 'hidden');
// header.find('span.com_header_vline').css('visibility', 'hidden');
// }
}
/**
* 从native本地获取图片
* @param {Function} callback 获取成功后回调,如 :
* App.getPics(function(imgData){
* 回传的 imgData 是图片对象的json字符串格式 {"name":"图片名称", "size":"566.54", "src":"base64图片字符串"}
* })
*/
App.getPics = function(callback) {
if(App.IS_NATIVE) {
App.call('getPics', callback);
} else {
callback('{"name":"che1", "size":"566.54", "src":""}');
}
}
/**
* 从native本地获取APP数据共享
* @date 2013-3-4
* @param callback 获取成功后回调,如:
* App.getAppShare(function(shareData)){
* 返回数据格式为:{"source": "来源","phone": "手机号码","car_mark": "车牌号","certificate_list": [{"certificate_type": "证件类型","certificate_no": "证件号码"},{"certificate_type": "证件类型","certificate_no": "证件号码"}]}
* })
*/
/*
1:身份证
2:护照
3:军官证
5:驾驶证
6:港澳回乡证或台胞证
* */
App.getAppShare = function(callback) {
if(App.IS_NATIVE) {
if(App.IS_ANDROID) {
if( typeof (window.android.getAppShare) != 'undefined') { //新版本,有getAppShare函数
App.call('getAppShare', callback);
}else{
callback('');
}
} else {
var appVersionCallBack = function(version){
var v = version.replace(/\./g, "");
if(App.IS_IOS && v >= 202) { //新版本,有getAppShare函数
App.call('getAppShare', callback);
}else{ //旧版本,native无getAppShare函数
callback('');
}
}
App.call('getAppVersion',appVersionCallBack);
}
} else {
callback('');
//callback('{"source":"com.pingan.carinsure","car_mark":"粤BLZ768","phone":"13600000000","certificate_list":[{"certificate_no":"360727198610022415","certificate_type":"1"}]}');
}
}
/*
* 将sharedata数据从页面存储到native端
* @date 2013-3-4
* @param shareData 传递的参数
* 参数根式为:'{\"source\": \"哈哈,成功了!\",\"phone\": \"13333333333\",\"car_mark\": \"京A11111\",\"certificate_list\": [{\"certificate_type\": \"1\",\"certificate_no\": \"360121198909051122\"},{\"certificate_type\": \"2\",\"certificate_hu\": \"33333333333333\"}]}';
* */
App.updateAppShare = function(shareData) {
//App.alert(shareData);
if(App.IS_NATIVE) {
if(App.IS_ANDROID) {
if( typeof (window.android.updateAppShare) != 'undefined') {
App.call('updateAppShare', shareData);
}
} else {
App.call('updateAppShare', shareData);
}
} else {
//console.log(shareData);
}
}
/**
* android不能获取到函数的 return的值,智能用这个来回传给它。。。纠结啊.
* 只需android实现
*/
App.returnValueToNative = function(value) {
// App.alert('returnValueToNative: '+value);
if(App.IS_NATIVE) {
App.call('returnValueToNative', value);
} else {
}
}
/**
* 通知Native已修改商业险和交强险保险起期
*/
App.beginDateModified = function(bizQuote, forceQuote) {
if(App.IS_NATIVE) {
App.call('beginDateModified', bizQuote, forceQuote);
} else {
}
}
/**
* 页面统计代码
* @param {String} pageId
* @param {Function} callback
* web, wp7,wp8 版本暂不出来
*/
App.trackEvent = function(eventId, callback) {
var c = callback ? callback : "";
function trackSend(version) {
var v = version.replace(/\./g, "");
//wp暂时没有
if(App.IS_IOS && v > 201) {
App.call('trackEvent', eventId, c);
App.IOS_Version = version;
} else if(App.IS_ANDROID && v > 101) {
App.call('trackEvent', eventId, c);
App.ANDROID_Version = version;
}
}
if(App.IS_NATIVE) {
if(App.IS_IOS) {
if(App.IOS_Version)
trackSend(App.IOS_Version);
else
App.call('getAppVersion', trackSend);
} else if(App.IS_ANDROID) {
if(App.ANDROID_Version)
trackSend(App.ANDROID_Version)
else
App.call('getAppVersion', trackSend);
}
} else {
if( typeof callback == "function")
exec(callback);
console.log(eventId);
}
}
App.consoleLog = function(txt) {
if (App.IS_DEV) {
window.console.log(txt);
}
}
})(App);
/**
* 获取URL参数
* @return {String} name
*/
var getmtParam = function(name) {
var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
var r = window.location.search.substr(1).match(reg);
if(r) {
return decodeURI(r[2]);
}
return null;
}
/**
* Cookie操作
*/
var Cookie = function(key, value, options) {
if(arguments.length > 1 && (!/Object/.test(Object.prototype.toString.call(value)) || value === null || value === undefined)) {
options = options || {};
if(value === null || value === undefined) {
options.expires = -1;
}
if( typeof options.expires === 'number') {
var days = options.expires, t = options.expires = new Date();
t.setDate(t.getDate() + days);
}
value = String(value);
return (document.cookie = [encodeURIComponent(key), '=', options.raw ? value : encodeURIComponent(value), options.expires ? '; expires=' + options.expires.toUTCString() : '', options.path ? '; path=' + options.path : '', options.domain ? '; domain=' + options.domain : '', options.secure ? '; secure' : ''].join(''));
}
options = value || {};
var decode = options.raw ? function(s) {
return s;
} : decodeURIComponent;
var pairs = document.cookie.split('; ');
for(var i = 0, pair; pair = pairs[i] && pairs[i].split('='); i++) {
if(decode(pair[0]) === key)
return decode(pair[1] || '');
}
return null;
}
// 外部app修复 IS_NATIVE的标识
// IOS还得判断是否来自第三方应用程序|| Cookie('mt') || null;
var mtype = getmtParam('mt') || Cookie('mt') || null;
if(mtype != null){
Cookie('mt',1,{path:'/upingan/upingan'});
$.fn.tap = $.fn.click;
App.IS_NATIVE = false;
App.IS_ANDROID = false;
App.IS_IOS = false;
$('#innerHead').hide();
$('#innerFoot').hide();
}
//alert("mt="+mtype+"==App.IS_NATIVE="+App.IS_NATIVE+"==App.IS_IOS="+App.IS_IOS);
//下面为native的操作
// if(App.IS_ANDROID || App.IS_IOS){
// if(mtype == null){ //来自与平安应用
// App.IS_NATIVE = true;
// if(App.IS_ANDROID){
// App.IS_ANDROID = true;
// }
// if(App.IS_IOS){
// App.IS_IOS = true;
// }
// }else{ //来自与非平安应用
// Cookie('mt',1);
// $.fn.tap = $.fn.click; //微信支持tap事件会同时触发两次,转变为click事件
// App.IS_NATIVE = false;
// App.IS_IOS = false;
// $('#innerHead').hide();
// $('#innerFoot').hide();
// //App.showHeader();
// }
// }else{ //来自与浏览器,注:微信中浏览器,App.IS_ANDROID 返回为false
// if(mtype != null){
// Cookie('mt',1);
// $.fn.tap = $.fn.click; //微信支持tap事件会同时触发两次,转变为click事件
// $('#innerHead').hide();
// $('#innerFoot').hide();
// }
// //App.showHeader();
// }
// alert('App.IS_NATIVE'+App.IS_NATIVE);
// alert('App.IS_ANDROID'+App.IS_ANDROID);
// alert('App.IS_IOS'+App.IS_IOS);
//统一更改为click的触发事件
var eventType = getmtParam('event') || Cookie('eventType') || null;
if(eventType != null){
Cookie('eventType','true');
$.fn.tap = $.fn.click;
}
/**
* 提供给Native调用的接口函数. 各页面根据情况重写
*/
// 返回上一步
// 这可能是点击上一步按钮, 或在Android设备上点击返回按钮
// 你应该你页面的js文件中覆盖这个函数, 以实现不同的逻辑
window.back = function() {
//App.alert('调用 back 成功。。stz');
}
/**
* 注册/从native按钮登陆 成功时native通知我的. 不要重写
*/
window.registerSuccess = function() {
Cookie('rumUserLogin', 'Y');
if(App.IS_ANDROID) {
App.returnValueToNative(true);
}
//App.alert('cookie已记录')
}
/**
* 检查当前用户已经登录
* @return {Boolean} true: 登录; false: 未登录[默认值]
*/
window.rumUserIsLogin = function() {
// return true; //test
if(Cookie('rumUserLogin')) {//!=''
return true;
}
return false;
}
/**
* native 动态检查用户登陆状态是否超时
*/
window.reqJudgeIsLogin = function() {
$.ajax({
type : 'POST',
url : App.getWebServiceUrl('imageCount'), //App.getWebServiceUrl('imageCount'), // 'data/member/ImageCount.html'
data : {
responseProtocol : 'json'
},
dataType : 'json',
success : function(xml) {
Cookie('rumUserLogin', 'Y');
App.returnValueToNative(true);
},
error : function(xhr, errorType) {
if(xhr.status == 0) {
Cookie('rumUserLogin', null);
App.returnValueToNative(false);
}
}
});
}
/**
* 用户退出
*/
window.rumUserLogout = function() {
if(App.IS_ANDROID) {
Cookie('rumUserLogin', null);
App.returnValueToNative(false);
} else {
Cookie('rumUserLogin', null);
}
//App.alert('cookie已清除')
}// 公共函数集合
/**
* 会话保持
*/
function keepFlow() {
var flowid = getParams('flowid');
if(!flowid) {
flowid = Cookie('flowid');
}
if(!flowid) {
flowid = '';
}
if(!window.keepFlowImage) {
window.keepFlowImage = new Image();
}//'ebusiness/auto/ris/keep-flow2.do' App.getWebServiceUrl('keepFlow')
keepFlowImage.src = getUrlNoCache(App.getWebServiceUrl('keepFlow') + '?flowid=' + flowid);
if(!window.keepFlowInterval) {
window.keepFlowInterval = setInterval(function() {
keepFlow();
}, 20000);
}
}
/**
* 移除默认焦点
*/
function removeFocus() {
var div = document.createElement('div');
div.className = 'com_page_shadow';
document.body.appendChild(div);
setTimeout(function() {
div.style.display = 'none';
}, 500);
App.focusElement = div;
}
/**
* 格式化数据,把结构数组格式化为url格式传参格式
* @param {object} data
* format {name:"leo",age:23}
* @return {string} name=leo&age=123
*/
function parseData(data) {
var str = '';
if( typeof data == "object") {
for(key in data) {
if( typeof data[key] == 'object')
str += parseData(data[key]);
else if(data[key]) //stz+ 有值才加入参数
str += key + "=" + data[key] + "&";
}
}
str = str.replace(/(&$)/g, '');
return str;
}
/**
* 获取URL参数
* @return {String} name
*/
function getParams(name) {
var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
var r = window.location.search.substr(1).match(reg);
if(r) {
return decodeURI(r[2]);
}
return null;
}
/**
* 替换输入框中非 数字字符
* @param {string} v 传入的值
* @param {sting} id 被操作控件的id
*/
function replaceInputToNum(v, id) {
if(v != '' && id) {
var value = v.replace(/[^\d]/gi, '');
if(!App.IS_ANDROID) {
var j = value.length
var newV = []
if(j > 0) {
for( i = 0; i < j; i++) {
if(i % 4 == 0 && i != 0)
newV.push(' ');
newV.push(value.charAt(i))
}
value = newV.join('');
}
}
document.getElementById(id).value = value
}
}
/**
* 获取一个没有缓存的URL(通过追加时间戳参数)
* @param {String} url
* @return {String}
*/
function getUrlNoCache(url) {
if(url.indexOf('?') == -1) {
url += '?_t=';
} else {
url += '&_t=';
}
return url + new Date().getTime();
}
/**
* 自动删除字符串中符合匹配内容的字符
* @param {String} str
* @param {Array} chars
*/
function deleteChars(str, chars) {
var result = '', s = '', c = '', r = false, clen = chars.length, n = true;
if(!_.isArray(chars)) {
chars = [chars];
}
for(var i = 0, len = str.length; i < len; i++) {
s = str[i];
n = true;
for(var j = 0; j < clen; j++) {
c = chars[j];
if(_.isRegExp(c)) {
if(c.test(s)) {
n = false;
break;
}
} else if(s == c) {
n = false;
break;
}
}
if(n) {
result += s;
}
}
return result;
}
/**
* 将元素中的文字自动转换为大写形式, 并删除空白字符
*/
function autoToLocaleUpperCase(el) {
el.bind('keypress', function() {
var self = $(this), val = self.val();
if(val) {
val = val.replace(/\s/g, '');
self.val(val.toLocaleUpperCase());
}
});
}
/**
* 提示错误信息, 如果属于系统错误, 则提示系统错误信息, 否则提示自定义错误
*/
function getErrorMsg(response, errorMsgs) {
var unknown = '操作的人太多了,请稍后再试。';
if(!response) {
App.onload(); //关闭小蜜蜂
return unknown+'!';
}
if( typeof response == 'string') {
response = JSON.parse(response);
}
var resultCode = +response.resultCode;
if(resultCode === 0) {
return true;
}
if(resultCode === 555) {
App.onload(); //关闭小蜜蜂
return unknown+'。';
} else if(response.errorMsg) {
App.onload(); //关闭小蜜蜂
return response.errorMsg || unknown;
} else if(response.promptText) {
App.onload(); //关闭小蜜蜂
return response.promptText || unknown;
} else if(response.refuseMessage) {
App.onload(); //关闭小蜜蜂
return response.refuseMessage || unknown;
} else if(response.error) {
App.onload(); //关闭小蜜蜂
return response.error.value || unknown;
} else {
App.onload(); //关闭小蜜蜂
// return unknown; //stz
return errorMsgs[resultCode] || unknown;
}
}
/**
* 预处理函数
*/
function toPreparation(callback) {
}
/**
* 掩码数据处理
*/
function setMaskData(key, value) {
if(!window.maskMap) {
window.maskMap = {};
}
var maskMap = window.maskMap;
maskMap[key] = value;
}
function getMaskData(key, value) {
var maskMap = window.maskMap;
if(maskMap) {
var prev = maskMap[key];
if(!prev) {
return false;
} else if(prev != value) {
return false;
} else {
return true;
}
}
}
/**
* Cookie操作
*/
function Cookie(key, value, options) {
if(arguments.length > 1 && (!/Object/.test(Object.prototype.toString.call(value)) || value === null || value === undefined)) {
options = options || {};
if(value === null || value === undefined) {
options.expires = -1;
}
if( typeof options.expires === 'number') {
var days = options.expires, t = options.expires = new Date();
t.setDate(t.getDate() + days);
}
value = String(value);
return (document.cookie = [encodeURIComponent(key), '=', options.raw ? value : encodeURIComponent(value), options.expires ? '; expires=' + options.expires.toUTCString() : '', options.path ? '; path=' + options.path : '', options.domain ? '; domain=' + options.domain : '', options.secure ? '; secure' : ''].join(''));
}
options = value || {};
var decode = options.raw ? function(s) {
return s;
} : decodeURIComponent;
var pairs = document.cookie.split('; ');
for(var i = 0, pair; pair = pairs[i] && pairs[i].split('='); i++) {
if(decode(pair[0]) === key)
return decode(pair[1] || '');
}
return null;
}
/*
* 结构数组/对象 转化成 真数组
*/
var objectToArray = function(o) {
if(!$.isArray(o))
o = [o];
o.length = o.length;
return o;
}
/*
* 获取滚动条高度
*/
function getPageScroll() {
var yScroll;
var self = window;
if(self.pageYOffset) {
yScroll = self.pageYOffset;
//xScroll = self.pageXOffset;
} else if(document.documentElement && document.documentElement.scrollTop) {
yScroll = document.documentElement.scrollTop;
} else if(document.body) {
yScroll = document.body.scrollTop;
}
return yScroll;
}
/*
* 微信页面内部获取移动设备类型
* */
function weixinGetIsNative(){
var ua2 = navigator.userAgent.toUpperCase();
// 当前环境是否微信IOS平台
Weixin_IOS = ua2.indexOf('IPHONE OS') != -1;
return Weixin_IOS;
}
/**加法函数,用来得到精确的加法结果
* 说明:javascript的加法结果会有误差,在两个浮点数相加的时候会比较明显。这个函数返回较为精确的加法结果。
* @return arg1和调用函数的数字的和
*/
Number.prototype.add = function(arg1) {
var r1, r2, m, arg2 = this.valueOf();
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))
return (arg1 * m + arg2 * m) / m
}
Number.prototype.sub = function(arg2) {
var r1, r2, m, n, arg1 = this.valueOf();
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));
n = (r1 >= r2) ? r1 : r2;
return new Number( ((arg1 * m - arg2 * m) / m).toFixed(n) );
}
/**
* 获取cdn图片地址 stz
* @param {String} fileName 图片在本地相对于根目录的位置,如 images/themes/default/images/member/drawUpIcon.png
* @return {String} 真实地址
*/
function getCDNPicURL(fileName){
var oldfileName = fileName;
var origin = location.origin, host = location.host;
if(!origin){ //android 不识别 location.origin
var protocol = location.protocol;
protocol = protocol=="http:"?"http://":protocol=="https:"?"https://":"file:///";
origin = protocol + (host||location.hostname);
}
if(host == "www.pingan.com"||host == "u.pingan.com") {
//fileName = origin + '/app_series/shop/auto/mobile/'+App.Cild_direct + fileName; // 取消CDN
fileName = origin + App.Cild_direct + fileName;
} else if(host == "dmzstg1.pa18.com" || host == "p1.pa18.com") {
fileName = origin + App.Cild_direct + fileName;
} else {
//fileName = 'images/indexall/slide/' + fileName;
}
// if(App.IS_ANDROID) fileName = oldfileName; //android 用当前根路径为起点。。。
return fileName;
}
/**
* 公共页面加载完调用,封装 App.onload()
*/
function AppOnloadCom(){
App.loadingFinish();
App.onload();
}
// AJAX公共配置
if($) {
$.ajaxSettings.ajaxStart = App.loadingBegin;
$.ajaxSettings.beforeSend = App.loadingBegin;
$.ajaxSettings.complete = App.loadingFinish;
$.ajaxSettings.error = function(jqXHR, textStatus, errorThrown) {
App.loadingFinish();
if(!window.navigator.onLine || jqXHR.status) {
App.alert('网络连接失败, 请稍后重试!');
}
}
}
// keepFlow();
// 移除默认焦点
removeFocus();
// App.onload();
/**
* 在Android下显示数字键盘
*/
if(App.IS_ANDROID) {
$('.numberfield').attr('type', 'number');
}
/**
* 获取页面名称
*/
function getPageName(){
var str=window.location.href;
var pageName=str.substring(str.lastIndexOf("/") + 1);
return pageName||"";
}
function checkBeeCanvas(){
if( typeof (AheadHandle) != 'undefined' && AheadHandle.loadingBee && AheadHandle.loadingBee.canvas) return true;
return false;
};
function getHostWithProtocol(){
var origin = location.origin, host = location.host;
if(!origin){
var protocol = location.protocol;
protocol = protocol=="http:"?"http://":protocol=="https:"?"https://":"file:///";
origin = protocol + (host||location.hostname);
}
return origin;
}
/**
* 获取登陆、注册地址
* @param [String] 传login:表示注册地址、 register:登陆地址
*/
function getLoginRegistUrl(type){
var _host = getHostWithProtocol();
var url=null, page=getPageName();
App.consoleLog(page)
switch(type){
case 'login'://www.pingan.com _host+
//url=App.ServerHost+'customer/toLoginApp.do?type=01&target='+_host+'/ebusiness/auto/mobile/'+App.Cild_direct+page;
url=App.ServerHost+'customer/toLoginApp.do?type=02&target='+_host+App.Cild_direct+page;
//url=App.ServerHost+'customer/toLoginApp.do?type=02&target='+encodeURIComponent(_host+App.Cild_direct+page);
break;
case 'register':
url=App.ServerHost+'customer/toRegisterUserApp.do?type=02&target='+_host+App.Cild_direct+page;
break;
}
return url;
}
function getFcmmLogOut(){
var _host = location.host; //getHostWithProtocol(),
var logoutAddr = 'https://member-stg.pingan.com.cn/pinganone/pa/fcmmLogOut.do';
if(_host.indexOf('p1.pa18.com')!=-1){//stz mf 130814 p1环境的登出!
logoutAddr = 'https://test-member.pingan.com.cn/pinganone/pa/fcmmLogOut.do';
}
if(_host == 'www.pingan.com' || _host == 'u.pingan.com') {
logoutAddr = 'https://member.pingan.com.cn/pinganone/pa/fcmmLogOut.do';
}
return logoutAddr;
}
/**
* 日期格式化 mm/dd/yyyy
*/
function dateFormatOfFlag(date,flag){
if(!_.isDate(date)) {
date = new Date();
}
if(flag)
return parseInt(date.getMonth() + 1)+flag+parseInt(date.getDate())+flag+date.getFullYear();
}
/**
* 日期格式化 hh:mm:ss
*/
function dateFormathhmmss(date){
if(!_.isDate(date)) {
date = new Date();
}
var se =date.getSeconds();
if(se<10){
se = "0"+se;
}
return date.getHours()+":"+date.getMinutes()+":"+se;
}
/**
*日期格式化
*@param {String} dateFmt
* 格式: yyyy-mm-dd hh:MM:ss SS
*/
function dateFormat(date, dateFmt) {
if(!_.isDate(date)) {
date = new Date();
}
var year = date.getFullYear(),
month = date.getMonth() + 1,
month = month < 10 ? ('0'+month) : month,
d = date.getDate(),
d = d < 10 ? ('0'+d) : d,
hour = date.getHours(),
hour = hour < 10 ? ('0'+hour) : hour,
minutes = date.getMinutes(),
minutes = minutes < 10 ? ('0'+minutes) : minutes,
seconds = date.getSeconds(),
seconds = seconds < 10 ? ('0'+seconds) : seconds,
milliseconds = date.getMilliseconds();
dateFmt = dateFmt ? dateFmt : 'yyyy-MM-dd';
if (/yyyy/.test(dateFmt)) {
dateFmt = dateFmt.replace('yyyy', year);
}
if (/MM/.test(dateFmt)) {
dateFmt = dateFmt.replace('MM', month);
}
if (/dd/.test(dateFmt)) {
dateFmt = dateFmt.replace('dd',d);
}
if (/hh/.test(dateFmt)) {
dateFmt = dateFmt.replace('hh', hour);
}
if (/mm/.test(dateFmt)) {
dateFmt = dateFmt.replace('mm', minutes);
}
if (/ss/.test(dateFmt)) {
dateFmt = dateFmt.replace('ss',seconds);
}
if (/SS/.test(dateFmt)) {
dateFmt = dateFmt.replace('SS',milliseconds);
}
return dateFmt;
}
//将时间格式由2013年12月21日转变为2013-12-21
function dateFormat2(date){
var reg = /\d/;
if(!reg.test(date)){ //不含有数字,直接返回
return false;
}
if(_.isEmpty(date)) {
var date = new Date();
return date.getFullYear() + '-' + parseInt(date.getMonth() + 1) + '-' + parseInt(date.getDate());
}
var reg = /\d+/g;
var dateArr = date.match(reg);
if(dateArr.length == 2) {
return dateArr[0] + '-' + dateArr[1];
} else {
return dateArr[0] + '-' + dateArr[1] + '-' + dateArr[2];
}
}
function trim(data){
return data.replace(/(^\s*)|(\s*$)/g, "");
}
/*
* 根据实时环境来切换地址
*/
function changeUrl(fileName) {
var origin = location.origin, host = location.host;
if(!origin){ //android 不识别 location.origin
var protocol = location.protocol;
protocol = protocol=="http:"?"http://":protocol=="https:"?"https://":"file:///";
origin = protocol + (host||location.hostname);
}
console.log('实际host: ' + host);
if(host == "www.pingan.com" || host == 'u.pingan.com') {
fileName = 'http://u.pingan.com' + fileName;
}else if(host == "stg.pa18.com" || host == "p1.pa18.com") {
fileName = origin + fileName;
}else {
fileName = 'http://dmzstg1.pa18.com' + fileName;
}
console.log('实际请求地址: ' + fileName);
return fileName;
}
// 获取媒体来源
var mediaSourceKeyName = 'mediasource',// 媒体来源参数标识
weiXinSourceKeyName = 'mt',
weiXinSourceKeyVal = 'weixin',
cachedMediaSource = Cookie(mediaSourceKeyName),
tempParam = null;
if (getParams(mediaSourceKeyName)) {
tempParam = getParams(mediaSourceKeyName);
} else if (weiXinSourceKeyVal == getParams(weiXinSourceKeyName)) {
tempParam = App.MediaSource.WEIXIN;
}
if (tempParam) { // 链接后面有参数则直接存否则cachedMediaSource为空时存一次
Cookie(mediaSourceKeyName, tempParam);
cachedMediaSource = tempParam;
} else if (!cachedMediaSource){
Cookie(mediaSourceKeyName, App.MediaSource.MOBILE_DEFAULT);
cachedMediaSource = App.MediaSource.MOBILE_DEFAULT;
}
App.resource = cachedMediaSource;
/**
* 格式化json ,用于本地格式化
*
*/
window.formatJSON=function(result) {
if(( typeof result) == "string") {
var data = '';
eval('data=' + result);
return data;
} else if(__typeof__(result) == "Document") { //toString.call(result) == "[object Document]" wp不支持此方式!!!
return $.xml2json(result);
}
return result;
}
function __typeof__(objClass) {
if(objClass.nodeName=='#document'){
return 'Document'; //ie的xml对象没有 constructor!
}
if(objClass && objClass.constructor) {
var strFun = objClass.constructor.toString();
var ie_objPos = strFun.indexOf('[object ');
if(ie_objPos!=-1){ //修复ie! 都是其内部逻辑混乱惹得祸。toString没返回字面量
return strFun.slice(ie_objPos+8,-1);
}
var className = strFun.substr(0, strFun.indexOf('('));
className = className.replace('function', '');
return className.replace(/(^\s*)|(\s*$)/ig, '');
}
return typeof (objClass);
}
/**
* PackTools 核心对象定义 (js封装工具框架 实现封装、继承、设计模式、网络请求封装等)
* @author stz
*/
window.PackTools = {
/**
* 提供一个供全局引用的空函数对象
*/
fn : new Function(),
/**
* 通过原型实现类继承
* @param {Function} childClass
* @param {Function} parentClass
*/
inherit : function(childClass, parentClass) {
if(childClass.subclass && childClass.subclass.constructor == parentClass) {
return;
}
var Constructor = new Function();
Constructor.prototype = parentClass.prototype;
childClass.prototype = new Constructor();
childClass.prototype.constructor = childClass;
childClass.superclass = parentClass.prototype;
parentClass.subclass = childClass.prototype;
if(childClass.prototype.constructor == Object.prototype.constructor) {
childClass.prototype.constructor = parentClass;
}
},
/**
* 格式化年月日
*/
formatYMD : function(dataStr) {
var temp = dataStr.replace(new RegExp(" ", "g"), '').split('-'), str = '';
for(var i = 0, len = temp.length; i < len; i++) {
str += (parseInt(temp[i]) < 10 ? temp[i].replace('0', '') : temp[i]) + (i == 0 ? '年' : i == 1 ? '月' : '日');
}
return str;
}
}
/**
* 更新页面高度
*/
window.uPAResizePage = function(){
var clientHeight = document.documentElement.clientHeight;
pageHeihgt = $('body').height(),
innerFoot = $('#innerFoot'),
_footBanner = innerFoot.find('.footBanner');
if (pageHeihgt < clientHeight) {
// 底部条外边距 = 浏览器可见高度 -页面内容高度 parseInt:_footBanner原来的顶部margin要加上去,否则会自动扣除
innerFoot.css('margin-top', (clientHeight - pageHeihgt+(parseInt(_footBanner.css('margin-top')))));
}else{
innerFoot.css('margin-top',0); //(parseInt(this._footBanner.css('margin-top')))
pageHeihgt = $('body').height(); //设置0后反而太小的话
if (pageHeihgt < clientHeight) {
innerFoot.css('margin-top', (clientHeight - pageHeihgt+(parseInt(_footBanner.css('margin-top')))));
}
}
}
var gDomain="sdc.pingan.com"; // SDC Production Mode Domain
var gDcsId="dcspymm36v5rgwyi354yjpm91_6q9m ";
var gFpc="WT-FPC";
var gConvert=true;
var gWTIDJS=window.document.createElement("script");
window.document.getElementsByTagName("head")[0].appendChild(gWTIDJS);
if ((typeof(gConvert)!="undefined")&&gConvert&&(document.cookie.indexOf(gFpc+"=")==-1)&&(document.cookie.indexOf("WTLOPTOUT=")==-1)){
gWTIDJS.src="http"+(window.location.protocol.indexOf('https:')==0?'s':'')+"://"+gDomain+"/"+gDcsId+"/wtid.js";
}
setTimeout('setsdcjs()',0);
function setsdcjs(){
/*
var jDomain=App.domain;
//var jDomain="dmzstg1.pingan.com.cn/upingan";//根据实际地址更换,线上环境地址:u.pingan.com/upingan
var js_path="/js/webtrends/sdc_m.js";
var domain="http"+(window.location.protocol.indexOf('https:')==0?'s':'')+"://"+jDomain;
var SDC_js=document.createElement("script");
SDC_js.src=domain+js_path;
*/
//修改为相对路径
var js_path='',
host = window.location.host;
if (host == 'u.pingan.com' || host == 'dmzstg1.pa18.com') {
js_path = App.RequestHost +"upingan/js/webtrends/sdc_m.js";
} else {
js_path = "js/webtrends/sdc_m.js";
}
//var js_path="js/webtrends/sdc_m.js"; //本地环境
var SDC_js=document.createElement("script");
SDC_js.src=js_path;
var headElem=document.getElementsByTagName("head")[0];
headElem.appendChild(SDC_js);
}