/**
* ========================加载中、提示框、获取路径参数========================
*/
var publicUtil = {
/**
* 获取路径参数1:
* @param param //参数名
* @returns {string}
*/
"getParameter" : function(param) {
var query = window.location.search,
iLen = param.length,
iStart = query.indexOf(param);
if (iStart == -1)
return "";
iStart += iLen + 1;
var iEnd = query.indexOf("&", iStart);
if (iEnd == -1)
return query.substring(iStart);
return query.substring(iStart, iEnd);
},
/**
* 获取路径参2:正则实现
* @param name //参数名
* @returns {*}
*/
"getUrlParam" :function(name){
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
var r = window.location.search.substr(1).match(reg); //匹配目标参数
if (r!=null){
return unescape(r[2]);
}
return null; //返回参数值
},
/**
* 获取路径参数3
* @param str //参数名
*/
"getQuery" : function(str) {
var n_v, v, n, attrs = str;
var data = {};
n_v = attrs.split('&');
n = null;
v = null;
for (var j in n_v) {
var i = n_v[j].indexOf('=');
if (i !== -1) {
n = n_v[j].substr(0, i);
v = n_v[j].substr(i + 1);
data[n] = v;
}
}
return data;
},
/**
* 弹出加载中
*/
"popLoader" : function(){
if (document.querySelector(".z_loader")) {
var elem = document.querySelector(".z_loader");
elem.parentNode.removeChild(elem);
}
var loaderStr='<div class="z_loader">\
<div class="z_loadercon">\
<img src="../images/loader.gif">\
<p>努力加载中...</p>\
</div>\
</div>';
document.querySelector("body").appendChild(loaderStr);
document.querySelector(".z_loader").style.display = "block";
},
/**
* 关闭加载中
*/
"closeLoader" : function(){
document.querySelector(".z_loader").style.display = "none";
},
/**
* 弹出alert信息,默认2秒后消失
* @param msg //提示信息
* @param time //提示信息显示时间
*/
"alert" : function(msg,time){
var _this = this,
elem = document.getElementById("alert_mask"),
_time = time? time*1000 : 2000;
if (elem) {
_this.removeElement(elem);
}
var alertStr='<div class="alert_mask" id="alert_mask">\
<section class="alert_section" id="alert_section">\
<div class="alert_content">\
<p>'+msg+'</p>\
</div>\
</section>\
</div>';
document.querySelector("body").appendChild(alertStr);
setTimeout(function(){
var elem = document.getElementById("alert_mask");
_this.removeElement(elem);
}, _time);
},
/**
* jQuery弹出alert信息,默认2秒后消失
* @param msg //提示信息
* @param time //提示信息显示时间
*/
"alert1" : function(msg,time){
var _time = time? time*1000 : 2000;
if (document.getElementById("alert_mask")) {
$("#alert_mask").remove();
}
var alertStr='<div class="alert_mask" id="alert_mask">\
<section class="alert_section" id="alert_section">\
<div class="alert_content">\
<p>'+msg+'</p>\
</div>\
</section>\
</div>';
$("body").append(alertStr);
setTimeout(function(){
$("#alert_mask").remove();
}, _time);
},
/**
* 移除节点
* @param elem //当前结点
*/
"removeElement" : function(elem){
var parentNode = elem.parentNode;
if(parentNode){
parentNode.removeChild(elem);
}
}
}
/**
* 重写alert函数
*/
// window.alert = function(alertMsg){};
/*
样式文件:
.alert_mask{ position: fixed; left: 0px; top: 0px; width: 100%; height: 100%; z-index:1000; -webkit-transform:translateZ(30rem); transform:translateZ(30rem);}
.alert_section{ max-width:70%;padding: .75rem 1rem; background:rgba(0,0,0,0.8); color:#fff; border-radius:4px; position:absolute; left:50%; top:50%; -webkit-transform:translate(-50%,-50%); transform:translate(-50%,-50%); overflow:hidden;}
.alert_content p{text-align:center; font-size:.7rem;}
.z_loader{position: fixed; width: 100%; height: 100%; z-index: 1000; -webkit-transform:translateZ(30rem); transform:translateZ(30rem); display:none;}
.z_loader .z_loadercon{position: absolute; top: 50%; left:50%; -webkit-transform: translate(-50%,-50%); text-align:center; background:rgba(51,51,51,0.85); padding: .5rem .75rem; border-radius: 5px;}
.z_loader .z_loadercon p{font-size:.7rem; color:#fff; margin-top:.5rem;}
*/