`
huangyongxing310
  • 浏览: 495782 次
  • 性别: Icon_minigender_1
  • 来自: 广州
文章分类
社区版块
存档分类
最新评论

weuiJsLayer.js

 
阅读更多
var weuiJsAlterMap = {};


function addWeuiJsAlter(htmlString,alterId) {
	AddElement('body', htmlString);



	addWeuiJsAlterOtherDeal(alterId);
	// commonJs.commonConsole(weuiJsAlterMap, "addWeuiJsAlter weuiJsAlterMap");
}

function closeWeuiJsAlter(alterId) {
	removeElement("#" + alterId);

	closeWeuiJsAlterOtherDeal(alterId);

	//==========
	delete weuiJsAlterMap[alterId]; //true



	// commonJs.commonConsole(weuiJsAlterMap, "weuiJsAlterMap");
}

function addWeuiJsAlterOtherDeal(alterId) {
	var scrollTopValue = weuiJsAlterGetscrollTopValue(alterId);
	weuiJsAlterMap[alterId].scrollTopValue = scrollTopValue;

	window.document.body.style.overflow='hidden';
	window.document.body.style.top=-1*scrollTopValue+"px";
}


function weuiJsAlterGetscrollTopValue(alterId) {
	var scrollTopValue = window.pageYOffset;
	return scrollTopValue;
}


function closeWeuiJsAlterOtherDeal(alterId) {
	var scrollTopValue = weuiJsAlterMap[alterId].scrollTopValue;

	window.document.body.style.overflow='auto';
	window.document.body.style.position=null;
	window.document.body.style.top=null;
	window.scrollTo(0,scrollTopValue);
}


function getAlterId() {
	var alterId = 'alterId_' + new Date().getTime();


	var alterIdTemp = alterId;

	var count = 0;
	while(1){
		if(weuiJsAlterMap[alterIdTemp]){
			count = count +1;
			alterIdTemp=  alterId + "_" +  count;
		}else{
			return alterIdTemp;
		}
	}
}


//=============================================Alert
var weuiJsAlertTemplate = `
        <div id="{{alterId}}">
            <div class="weui-mask"></div>
            <div class="weui-dialog" :style="{ width:width }">
                <div class="weui-dialog__hd">
                    <div class="weui-dialog__title">{{title}}</div>
                </div>
                <div class="weui-dialog__bd">
                    {{content}}
                </div>
                <div class="weui-dialog__ft">
                    <a onclick="okClickWeuiJsAlterFun('{{alterId}}')" class="weui-dialog__btn weui-dialog__btn_primary">{{confirmButtonText}}</a>
                </div>
            </div>
        </div>
    `;


function openWeuiJsAlter(content, title, fun, confirmButtonText) {
	var temp = weuiJsAlertTemplate;
	var alterId = getAlterId();
	temp = replaceAll(temp, "{{title}}", title);
	temp = replaceAll(temp, "{{content}}", content);
	temp = replaceAll(temp, "{{alterId}}", alterId);
	temp = replaceAll(temp, "{{confirmButtonText}}", confirmButtonText);

	var obj = {
		callBackFun: fun
	};

	weuiJsAlterMap[alterId] = obj;
	// weuiJsAlterMap[alterId].callBackFun=fun;

	addWeuiJsAlter(temp,alterId);

	return alterId;
}

function okClickWeuiJsAlterFun(alterId) {
	commonJs.commonConsole(alterId, "okClickFun alterId");

	var callBackFun = weuiJsAlterMap[alterId]['callBackFun'];
	if (callBackFun) {
		callBackFun('ok');
	}

	closeWeuiJsAlter(alterId);
}



//=============================================confirm
var weuiJsConfirmTemplate = `
        <div id="{{alterId}}">
            <div class="weui-mask"></div>
            <div class="weui-dialog" :style="{ width:width }">
                <div class="weui-dialog__hd">
                    <div class="weui-dialog__title">{{title}}</div>
                </div>
                <div class="weui-dialog__bd">
                    {{content}}
                </div>
                <div class="weui-dialog__ft">
                    <a onclick="cancelClickWeuiJsAlterFun('{{alterId}}')" class="weui-dialog__btn weui-dialog__btn_default">{{cancelButtonText}}</a>
            		<a onclick="okClickWeuiJsAlterFun('{{alterId}}')" class="weui-dialog__btn weui-dialog__btn_primary">{{confirmButtonText}}</a>
                </div>
            </div>
        </div>
    `;


function openWeuiJsConfirm(content, title, fun, confirmButtonText,cancelButtonText) {
	var temp = weuiJsConfirmTemplate;
	var alterId =  getAlterId();
	temp = replaceAll(temp, "{{title}}", title);
	temp = replaceAll(temp, "{{content}}", content);
	temp = replaceAll(temp, "{{alterId}}", alterId);
	temp = replaceAll(temp, "{{confirmButtonText}}", confirmButtonText);
	temp = replaceAll(temp, "{{cancelButtonText}}", cancelButtonText);

	var obj = {
		callBackFun: fun
	};

	weuiJsAlterMap[alterId] = obj;
	// weuiJsAlterMap[alterId].callBackFun=fun;

	addWeuiJsAlter(temp,alterId);

	return alterId;
}

function cancelClickWeuiJsAlterFun(alterId) {
	commonJs.commonConsole(alterId, "okClickFun alterId");

	var callBackFun = weuiJsAlterMap[alterId]['callBackFun'];
	if (callBackFun) {
		callBackFun('no');
	}

	closeWeuiJsAlter(alterId);
}


//=============================================Loading
var weuiJsLoadingTemplate = `
        <div id="{{alterId}}">
			<div class="weui-mask"></div>
			<div class="weui-toast">
				<i class="weui-loading weui-icon_toast"></i>
				<p class="weui-toast__content">{{content}}</p>
			</div>
		</div>
    `;


function openWeuiJsLoading(content) {
	var temp = weuiJsLoadingTemplate;
	var alterId =  getAlterId();
	// temp = replaceAll(temp, "{{title}}", title);
	temp = replaceAll(temp, "{{content}}", content);
	temp = replaceAll(temp, "{{alterId}}", alterId);
	// temp = replaceAll(temp, "{{confirmButtonText}}", confirmButtonText);
	// temp = replaceAll(temp, "{{cancelButtonText}}", cancelButtonText);

	var obj = {
		// callBackFun: fun
	};

	weuiJsAlterMap[alterId] = obj;
	// weuiJsAlterMap[alterId].callBackFun=fun;

	addWeuiJsAlter(temp,alterId);

	return alterId;
}


function closeWeuiJsLoading(index) {
	closeWeuiJsAlter(index)
}


//=============================================Toast
var weuiJsToastTemplate = `
        <div id="{{alterId}}">
			<div class="weui-mask_transparent"></div>
   			<div class="weui-toast">
				<p class="weui-toast__content weui-toast__text">{{content}}</p>
			</div>
		</div>
    `;

function openWeuiJsToast(content, msTime) {
	var temp = weuiJsToastTemplate;
	var alterId = getAlterId();
	// temp = replaceAll(temp, "{{title}}", title);
	temp = replaceAll(temp, "{{content}}", content);
	temp = replaceAll(temp, "{{alterId}}", alterId);
	// temp = replaceAll(temp, "{{confirmButtonText}}", confirmButtonText);
	// temp = replaceAll(temp, "{{cancelButtonText}}", cancelButtonText);

	var obj = {
		// callBackFun: fun
	};

	weuiJsAlterMap[alterId] = obj;
	// weuiJsAlterMap[alterId].callBackFun=fun;

	addWeuiJsAlter(temp,alterId);


	window.setTimeout(function () {
		closeWeuiJsAlter(alterId)
	}, msTime);


	return alterId;

}







分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics