//自执行匿名函数
(function () { /* code */ } ()); // true
!function () { /* code */ } (); // true
~function () { /* code */ } (); // -1
-function () { /* code */ } (); // NaN
+function () { /* code */ } (); // NaN
var conf = {
serverHost : ''''''''
};
var _mm = {
//网络请求功能
request : function(param){
var _this = this;
$.ajax({
type : param.method || ''''get'''',
url : param.url || '''''''',
dataType : param.type || ''''json'''',
data : param.data || '''''''',
success : function(res){
//请求成功
if(0 === res.status){
typeof param.success === ''''function'''' && param.success(res.data, res.msg);
}
//请求数据错误
else if(1 === res.status){
typeof param.error === ''''function'''' && param.error(res.message);
}
},
error : function(err){
typeof param.error === ''''function'''' && param.error(res.statusText);
}
});
},
//获取服务器地址
getServerUrl : function(path){
return conf.serverHost + path;
},
//获取 url 参数
getUrlParam : function(name){
var reg = new RegExp(''''(^|&)''''+ name + ''''=([^&]*)(&|$)'''');
var result = window.location.search.substr(1).match(reg);
return result ? decodeURIComponent(result[2]) : null;
}
};
module.exports = _mm;
//-
bds.util.domain = (function(){
var list = {
"graph.baidu.com": "https://sp0.baidu.com/-aYHfD0a2gU2pMbgoY3K",
"p.qiao.baidu.com":"https://sp0.baidu.com/5PoXdTebKgQFm2e88IuM_a",
"vse.baidu.com":"https://sp3.baidu.com/6qUDsjip0QIZ8tyhnq",
"hdpreload.baidu.com":"https://sp3.baidu.com/7LAWfjuc_wUI8t7jm9iCKT-xh_"
};
var get = function(url) {
if(location.protocol === "http") {
return url;
}
var reg = /^(http[s]?:\/\/)?([^\/]+)(.*)/,
matches = url.match(reg);
url = list.hasOwnProperty(matches[2])&&(list[matches[2]] + matches[3]) || url;
return url;
},
set = function(kdomain,vdomain) {
list[kdomain] = vdomain;
};
return {
get : get,
set : set
}
})();