/** * 淇℃伅鎻愰啋锛屼笉渚濊禆浠讳綍涔变竷鍏碂妗嗘灦鍙婂叾浠栨枃浠讹紝瀵煎叆 msg.js 锛宮sg.info('鍝堝搱鍝?) 涓€鍙ヤ唬鐮佷娇鐢紒 * 浣滆€咃細绠¢浄楦 * 涓汉缃戠珯锛歸ww.guanleiming.com * 涓汉寰俊: xnx3com * 鍏徃锛氭綅鍧婇浄楦d簯缃戠粶绉戞妧鏈夐檺鍏徃 * 鍏徃瀹樼綉锛歸ww.leimingyun.com */ var msg = { /* * 褰撳墠msg鐨勭増鏈 */ version:1.6, /* * 閿欒鐨勫浘 */ errorIcon:'', /* * 褰撳墠寮瑰嚭绐楀彛鏄剧ず鐨刬d銆傛瘡娆″脊鍑虹獥鍙i兘浼氱敓鎴愪竴涓殢鏈篿d */ currentWindowsId:0, /* * 寮瑰嚭灞傜殑div id鐩稿叧 */ id:{ /* * 寮瑰嚭灞 div id 鐨勯殢鏈哄懡鍚嶆暟缁勩€傝繖閲屽瓨鐨勬槸绮剧‘鍒版绉掔殑鏃堕棿鎴炽€ 姣斿鍛藉悕鏃朵細閲囩敤 wangmarket_loading + 姝ゅid鏃堕棿鎴 鐨勬柟寮 */ idArray : new Array(), /* * 浠庢暟缁勪腑澧炲姞涓€涓€硷紝杩欎釜鍊煎鍔犲埌鏁扮粍鏈€鍚庯紝骞跺皢澧炲姞鐨勫€艰繑鍥 */ create:function(){ //鍒涘缓涓€涓殢鏈篿d var thisId = new Date().getTime()+''; //灏嗛殢鏈篿d鍔犲叆寮圭獥id搴忓垪 msg.id.idArray[msg.id.idArray.length] = thisId; return thisId; }, /* * 浠庢暟缁勪腑鍒犻櫎鍊笺€傚苟灏嗗垹闄ょ殑鍊艰繑鍥炪€ * id 瑕佸垹闄ょ殑value銆傚鏋滀笉浼犲叆锛岄偅榛樿鍒犻櫎鏈€鍚庝竴涓 */ delete:function(id = ''){ var thisId = ''; if(id == ''){ //鍙栧嚭鏁扮粍鏈€鍚庝竴涓€ thisId = msg.id.idArray[msg.id.idArray.length-1]; //鍒犻櫎鏁扮粍鏈€鍚庝竴涓€ msg.id.idArray.pop(); }else{ thisId = id; //鍒犻櫎鎸囧畾鐨刬d for(var i = 0; i'); 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鍙充笅瑙掔殑鍑犱釜鎸夐挳鐨勬牱寮忥紝浼氱洿鎺ュ姞鍒 '+(i>0? '  ':'');
			}
			
			attribute.text = '
'+attribute.text+'
'+buttonsHtml+'
'; } //璧嬩簣榛樿灞炴€ if(attribute.close == null){ attribute.close = false; } if(attribute.width == null){ attribute.width = '17rem'; } return msg.popups(attribute); }, //闇€瑕佺‘璁ょ殑寮瑰嚭鎻愮ず锛屾浛浠s鍘熸湰鐨刟lert寮圭獥 alert:function(text){ return msg.confirm({ text:text, buttons:{ 纭畾:function(){} } }); }, /** * 寮瑰嚭 input 杈撳叆妗 * text 鎻愮ず鏂囧瓧,蹇呭~ * okFunc 鐐瑰嚮浜嗙‘瀹氭寜閽墽琛岀殑鏂规硶銆?蹇呭~锛 杩欓噷浼犲叆 function(value){ //杩欓噷鎷垮埌鐨剉alue 灏辨槸鐢ㄦ埛鑷繁杈撳叆鐨 } * defaultValue 杈撳叆妗嗕腑鐨勯粯璁ゅ€硷紝闈炲繀濉紝濡傛灉涓嶄紶姝ゅ弬鏁帮紝閭h緭鍏ユ涓粯璁ゅ氨鏄病鏈変换浣曞€ * isTextarea 鏄惁鏄痶extarea杈撳叆妗嗭紝榛樿鏄痜alse锛屼笉鏄紝鍙槸鍗曠函鐨刬nput杈撳叆妗嗐€傝繖涓弬鏁伴粯璁や笉鐢ㄤ紶鍏ャ€ */ input:function(text, okFunc, defaultValue, isTextarea=false){ if(typeof(okFunc) == 'undefined' || okFunc == null){ msg.failure('璇蜂紶鍏ョ偣鍑荤‘瀹氭寜閽鎵ц鐨勬柟娉?); return; } if(typeof(defaultValue) == 'undefined' || defaultValue == null){ defaultValue = ''; } //榛樿鏄痠nput var inputHTML = ''; if(isTextarea){ //textarea杈撳叆妗 inputHTML = ''; } var enterButtonId = 'msg_input_enterButtonId_'+new Date().getTime(); //纭鎸夐挳鐨刬d var text = ''+ '
'+ '
'+text+'
'+ '
'+inputHTML+'
'+ '
'+ '
'; var thisId = msg.popups({ text:text, width:'20rem' }); var enter = document.getElementById(enterButtonId); enter.onclick = function(){ var msg_input_value = document.getElementById('msg_input_id').value; msg.close(); okFunc(msg_input_value); } return thisId; }, /** * 寮瑰嚭 textarea 杈撳叆妗 * text 鎻愮ず鏂囧瓧,蹇呭~ * okFunc 鐐瑰嚮浜嗙‘瀹氭寜閽墽琛岀殑鏂规硶銆?蹇呭~锛 杩欓噷浼犲叆 function(value){ //杩欓噷鎷垮埌鐨剉alue 灏辨槸鐢ㄦ埛鑷繁杈撳叆鐨 } * defaultValue 杈撳叆妗嗕腑鐨勯粯璁ゅ€硷紝闈炲繀濉紝濡傛灉涓嶄紶姝ゅ弬鏁帮紝閭h緭鍏ユ涓粯璁ゅ氨鏄病鏈変换浣曞€ */ textarea:function(text, okFunc, defaultValue){ return msg.input(text, okFunc, defaultValue, true); } }