');
this.delayClose(1500, func);
return thisId;
},
/**
* 澶辫触銆侀敊璇殑鎻愰啋
* @param text 鎻愮ず鏂囧瓧
* @param func 鍏抽棴鎻愮ず鍚庯紝瑕佹墽琛岀殑鏂规硶
*/
failure:function(text, func){
var thisId = this.show(text, this.errorIcon);
this.delayClose(2500, func);
return thisId;
},
/**
* 鎻愮ず淇℃伅
* @param text 鎻愮ず鏂囧瓧
* @param func 鍏抽棴鎻愮ず鍚庯紝瑕佹墽琛岀殑鏂规硶
*/
info:function(text, func){
var thisId = this.show(text, '');
this.delayClose(2500, func);
return thisId;
},
/**
* 寮瑰嚭璇㈤棶閫夋嫨妗嗭細纭畾銆佸彇娑
*/
confirm:function(text){
return confirm(text);
},
/**
* 鍔犺浇涓€佺瓑寰呬腑鐨勫姩鐢绘晥鏋
* @param text 鎻愮ず鏂囧瓧
*/
loading:function(text){
this.show(text, '');
},
/**
* 鍏抽棴鍚勭鎻愮ず锛屽寘鎷姞杞戒腑銆佹垚鍔熴€佸け璐ャ€佹彁绀轰俊鎭瓑锛岄兘鍙互鐢ㄦ寮哄埗鍏抽棴
* id 寮瑰嚭灞傜殑id銆傛甯镐娇鐢ㄦ棤闇€浼犲叆 銆傝繖閲屼紶鍏ョ殑鏄 msg.id.idArray 涓殑鏌愪釜鍊
*/
close:function(id = ''){
this.currentWindowsId = 0; //褰撳墠娌℃湁浠讳綍绐楀彛
//鍙栧嚭鏁扮粍鐨勫€
var thisId = msg.id.delete(id);
var loadingDiv = document.getElementById('wangmarket_popup_'+thisId);
if(loadingDiv != null){
var loadingDivParent = loadingDiv.parentNode;
if(loadingDivParent != null){
loadingDivParent.removeChild(loadingDiv);
}
}
//鍏抽棴pupups鐩稿叧
//var popupsDiv = document.getElementById('wangmarket_popups')
//if(popupsDiv != null){
// var popupsDivParent = popupsDiv.parentNode;
// if(popupsDivParent != null){
// popupsDivParent.removeChild(popupsDiv);
// }
//}
},
/**
* 寤惰繜鍑犵鍚庡叧闂脊鍑烘彁绀
* @param time 寤惰繜澶氶暱鏃堕棿锛屽崟浣嶆槸姣
* @param func 鍏抽棴鎻愮ず鍚庯紝瑕佹墽琛岀殑鏂规硶
*/
delayClose: function(time, func){
var cid = parseInt(Math.random()*100000);
this.currentWindowsId = cid;
var that = this;
setTimeout(function(){
if(that.currentWindowsId == cid){
/* 鑳藉搴旇捣鏉ワ紝鎵嶄細鍏抽棴銆傞伩鍏嶅叧闂埆鐨勫垰鏄剧ず鐨勭獥鍙 */
that.close();
}
if(func != null){
func();
}
},time);
},
/**
* 鏄剧ず鎻愮ず绐楀彛锛岀鏈夋柟娉
* text 鎻愮ず鏂囧瓧
* img 鏄剧ず鐨勫浘鐗囨垨鑰卻vg
* @return 杩斿洖寮瑰嚭灞傜殑id銆傚彲浠ヤ娇鐢 msg.close(id) 鏉ュ叧闂寚瀹氱殑寮瑰嚭灞
*/
show:function(text, img){
/** 鏄惁鏄í鍚戞樉绀 **/
var wangmarket_loading_hengxiang = false;
if(text != null && text.length > 10){
wangmarket_loading_hengxiang = true;
}
//鍒涘缓涓€涓殢鏈篿d
var thisId = msg.id.create();
/** 鏄剧ず鍓嶏紝濡傛灉杩樻湁鍏朵粬姝e湪鏄剧ず鐨勶紝灏嗗叾閮藉叧鎺 **/
//this.close();
if(document.getElementsByTagName("body") != null && document.getElementsByTagName("body").length > 0){
var div=document.createElement("div");
div.id = 'wangmarket_popup_'+thisId;
div.style = 'position: fixed;z-index: 2147483647;margin: 0 auto;text-align: center;width: 100%;';
div.innerHTML = ''
+''
+'
'
+'
'+img+'
'
+'
'+text+'
'
+'
';
+'
';
document.getElementsByTagName("body")[0].appendChild(div);
}else{
alert('鎻愮ず锛宐ody涓病鏈夊瓙鍏冪礌锛屾棤娉曟樉绀 msg.js 鐨勬彁绀?);
}
return thisId;
},
/**
* 寮瑰嚭灞傦紝寮瑰嚭绐楀彛
* @param attribute 寮瑰嚭灞傜殑鍏朵粬灞炴€с€備紶鍏ュ锛
*
* {
* text:'寮圭獥鐨勫唴瀹?, //寮瑰嚭绐楁樉绀虹殑鍐呭锛屾敮鎸乭tml
* url:'https://www.leimingyun.com/index.html' //璁剧疆寮瑰嚭绐楀彛瑕佹墦寮€鐨勭綉鍧€锛屽鏋渦rl璺焧ext鍚屾椂璁剧疆锛岄偅涔堜紭鍏堥噰鐢╱rl锛 text璁剧疆灏嗘棤鏁
* top:'30%', //寮瑰嚭灞傝窛绂婚《閮ㄧ殑璺濈锛屼笉浼犻粯璁ゆ槸30%銆 鍙互浼犲叆濡 30%銆 5rem銆 10px 绛
* left:'5%', //寮瑰嚭灞傝窛绂绘祻瑙堝櫒宸︿晶鐨勮窛绂伙紝涓嶄紶榛樿鏄?%
* height:'100px', //寮瑰嚭灞傛樉绀虹殑楂樺害銆備笉浼犻粯璁ゆ槸 auto銆 浼犲叆濡 100px 銆 10rem 绛夈€備笉鑳戒娇鐢?鐧惧垎姣斻€
* width:'90%', //寮瑰嚭灞傛樉绀虹殑瀹藉害銆備笉浼犻粯璁ゆ槸 90%銆備紶鍏ュ 100px 銆 10rem 銆 50% 绛夈€
* bottom:'1rem', //寮瑰嚭灞傝窛绂诲簳閮ㄧ殑璺濈銆備笉浼犻粯璁ゆ槸 auto 銆 height 璺 bottom 濡傛灉杩欎袱涓悓鏃惰缃簡锛岄偅涔坔eight鐢熸晥锛宐ottom鏄笉鐢熸晥鐨
* close:false //鏄惁鏄剧ず鍙充笂瑙掔殑鍏抽棴鎸夐挳锛屼笉浼犻粯璁ゆ槸true锛屾樉绀哄叧闂寜閽
* background:'#2e2d3c' //鑳屾櫙棰滆壊銆傚崄鍏繘鍒堕鑹茬紪鐮併€備笉浼犻粯璁ゆ槸 '#2e2d3c'
* opacity:92 //寮瑰嚭灞傜殑閫忔槑搴︼紝榛樿鏄?2, 鍙栧€?~100锛?鏄笉閫忔槑锛?00鏄叏閮ㄩ€忔槑
* padding:'10px' //寮瑰嚭灞傚洓鍛ㄧ暀鐨勭┖闅欙紝榛樿鏄?rem銆傚彲浼犲叆濡 10px 銆 1rem 绛
* }
*
* @return 杩斿洖寮瑰嚭灞傜殑id銆傚彲浠ヤ娇鐢 msg.close(id) 鏉ュ叧闂寚瀹氱殑寮瑰嚭灞
*/
popups:function(attribute){
var setLeftPosition = false; //鏄惁璁剧疆浜嗚窛绂诲乏渚ц窛绂
var setTopPosition = false; //鏄惁璁剧疆浜嗚窛绂婚《閮ㄨ窛绂
if(typeof(attribute) == 'undefined'){
attribute = {};
}else if(typeof(attribute) == 'string'){
//鐩存帴浼犲叆浜 string 鏍煎紡鐨勬彁绀烘枃鏈
attribute = {text:attribute};
}
if(attribute == null){
attribute = {}
}
if(attribute.left != null){
setLeftPosition = true;
}
if(attribute.top != null || attribute.bottom != null){
setTopPosition = true;
}
if(attribute.url != null){
if(attribute.text != null){
//鍙嬪ソ鎻愰啋
console.log('鍙嬪ソ鎻愰啋锛氭偍宸茬粡璁剧疆浜 attribute.url 锛屼絾鏄偍鍙堣缃簡 attribute.text 锛屾牴鎹紭鍏堢骇锛 灏嗛噰鐢 attribute.url 锛岃€ attribute.text 璁剧疆鏃犳晥銆 ');
}
attribute.text = '';
}
//濡傛灉text涓虹┖锛岄偅涔堟彁绀轰竴涓
if(attribute.text == null){
attribute.text = '鎮ㄦ湭璁剧疆text鐨勫€硷紝鎵€浠ヨ繖閲屽嚭鐜版彁閱掓枃瀛椼€傛偍鍙互杩欐牱鐢? msg.popups(\'鎴戞槸鎻愮ず鏂囧瓧\');
';
}
//鍒ゆ柇涓€涓 height 璺 bottom 鏄惁鍚屾椂璁剧疆浜嗭紝鍥犱负濡傛灉杩欎袱涓悓鏃惰缃簡锛宐ottom鏄笉鐢熸晥鐨
if(attribute.height != null && attribute.bottom != null){
console.log('msg.js -- function popups() : 鍙嬫儏鎻愮ず:鎮ㄥ悓鏃惰缃簡height銆乥ottom涓や釜灞炴€э紝姝ゆ椂height灞炴€х敓鏁堬紝bottom灞炴€у皢浼氫笉璧蜂綔鐢?);
}
//璧嬩簣榛樿灞炴€
if(attribute.close == null){
attribute.close = true;
}
if(attribute.top == null){
attribute.top = 'auto';
}
if(attribute.bottom == null || attribute.bottom.length < 1){
attribute.bottom = 'auto';
}
if(attribute.background == null){
attribute.background = '#2e2d3c';
}
if(attribute.opacity == null){
attribute.opacity = 92;
}
if(attribute.height == null){
attribute.height = 'auto';
}
if(attribute.left == null){
attribute.left = '5%';
}
if(attribute.width == null){
attribute.width = '90%';
}
if(attribute.padding == null){
attribute.padding = '1rem';
}
//鍒涘缓涓€涓殢鏈篿d
var thisId = msg.id.create();
var div=document.createElement("div");
//div.id = 'wangmarket_popups';
div.id = 'wangmarket_popup_'+thisId;
div.style = 'position: fixed; z-index: 2147483647; margin: 0px auto; text-align: center; width: 100%; ';
div.innerHTML = ''+
'
'+
'
'+
'
'+
attribute.text+
'
'+
(attribute.close? '
':'')+
'
'+
'
'+
'
';
//
if(document.getElementsByTagName("body") != null && document.getElementsByTagName("body").length > 0){
document.getElementsByTagName("body")[0].appendChild(div);
/** 璁$畻浣嶇疆锛屽墽涓樉绀 **/
//寮圭獥浣嶇疆鎺у埗鍏冪礌
//var msgPositionDom = document.getElementById('wangmarket_popups').firstChild;
var msgPositionDom = document.getElementById('wangmarket_popup_'+thisId).firstChild;
if(!setLeftPosition){
//濡傛灉娌℃湁璁剧疆left锛岄偅涔堣缃搴﹀眳涓
try {
var htmlWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; //html鍙鍖哄煙瀹藉害
var msgWidth = msgPositionDom.clientWidth||msgPositionDom.offsetWidth; //褰撳墠寮圭獥鐨勫搴
msgPositionDom.style.left = ((htmlWidth - msgWidth)/2) + 'px';
} catch (e) {
console.log(e);
}
}
if(!setTopPosition){
//濡傛灉娌℃湁璁剧疆top銆乥ottom锛岄偅涔堣缃珮搴﹀眳涓
try {
var htmlHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight; //html鍙鍖哄煙楂樺害
var msgHeight = msgPositionDom.clientHeight||msgPositionDom.offsetHeight; //褰撳墠寮圭獥鐨勯珮搴
if(msgHeight > htmlHeight){
//濡傛灉寮圭獥楂樺害姣攂ody杩橀珮锛岄偅涔堢洿鎺ュ氨鏄剧ず鍒伴《閮
msgPositionDom.style.top = '20px';
}else{
msgPositionDom.style.top = ((htmlHeight - msgHeight)/2) + 'px';
}
} catch (e) {
console.log(e);
}
}
}else{
alert('鎻愮ず锛宐ody涓病鏈夊瓙鍏冪礌锛屾棤娉曟樉绀 msg.js 鐨勬彁绀?);
return;
}
return thisId;
},
/**
* 纭寮瑰嚭鎻愮ず
* @param attribute 寮瑰嚭灞傜殑鍏朵粬灞炴€с€備紶鍏ュ锛
*
* {
* text:'寮圭獥鐨勫唴瀹?, //寮瑰嚭绐楁樉绀虹殑鍐呭锛屾敮鎸乭tml
* width:'17rem', //寮瑰嚭灞傛樉绀虹殑瀹藉害銆備笉浼犻粯璁ゆ槸 17rem銆備紶鍏ュ 100px 銆 17rem 銆 50% 绛夈€
* close:false //鏄惁鏄剧ず鍙充笂瑙掔殑鍏抽棴鎸夐挳锛屼笉浼犻粯璁ゆ槸false锛屼笉鏄剧ず鍏抽棴鎸夐挳
* background:'#2e2d3c' //鑳屾櫙棰滆壊銆傚崄鍏繘鍒堕鑹茬紪鐮併€備笉浼犻粯璁ゆ槸 '#2e2d3c'
* opacity:92, //寮瑰嚭灞傜殑閫忔槑搴︼紝榛樿鏄?2, 鍙栧€?~100锛?鏄笉閫忔槑锛?00鏄叏閮ㄩ€忔槑
* padding:'10px', //寮瑰嚭灞傚洓鍛ㄧ暀鐨勭┖闅欙紝榛樿鏄?rem銆傚彲浼犲叆濡 10px 銆 1rem 绛
* buttons:{
* '纭畾':function(){
* console.log('鐐瑰嚮浜嗙‘瀹?);
* },
* '鍙栨秷':function(){
* console.log('鐐瑰嚮浜嗗彇娑?);
* }
* },
* buttonStyle:'padding-left:0.6rem; padding-right:0.6rem; font-size: 0.9rem;' //寮瑰嚭鐨刢onfirm鍙充笅瑙掔殑鍑犱釜鎸夐挳鐨勬牱寮忥紝浼氱洿鎺ュ姞鍒