⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 w3base.js

📁 某网络游戏前台JS程序
💻 JS
字号:
<!--

// 载入 loadUrl 页面内容到 targetObj 物件
function loadPage ( loadUrl, targetObj ) {
	if ( typeof ( targetObj ) == 'string') {
		targetObj = document.getElementById ( targetObj );
	}
	loader.get ( loadUrl, targetObj );
}

// Ajax 读取页面
function objLoader () {
	this.get = function ( loadUrl, targetObj, queryString, callbackFunc ) {
		this.load ( 'GET', loadUrl, targetObj, queryString, callbackFunc );
	}

	this.post = function ( loadUrl, targetObj, queryString, callbackFunc ) {
		this.load ( 'POST', loadUrl, targetObj, queryString, callbackFunc );
	}

	this.load = function ( method, loadUrl, targetObj, queryString, callbackFunc ) {



		if(typeof(hideddrivetip) == 'function'){//清除tip提示
			hideddrivetip();
		}

		if(!process.processing){
			process.start();
		}
		var obj;
		if ( typeof ( targetObj ) == 'string' ) {
			obj = document.getElementById ( targetObj );
		}
		else {
			obj = targetObj;
		}

		if ( callbackFunc == null )	{
			callbackFunc = ajaxCallback;
		}

		if ( queryString == null ) queryString = '';

		var clsAjax = new Ajax ( loadUrl, queryString, callbackFunc, targetObj );

		if ( method.toLowerCase () == 'post' ) {
			clsAjax.post ();
		}
		else {
			clsAjax.get ();
		}
	}
}
var loader = new objLoader ();

// 获取服务器返回的信息
function ajaxCallback ( ret, obj )
{
	if(process.processing){
		process.finish();
	}
	var errorMsg = getError(ret);
	if(errorMsg) {
		showHTML(errorMsg);
	}
	else if( ret != '' ) {
		showHTML(ret, obj);
	}

}
// 获取错误信息
function getError(string) {
	var errorFlag = '<ERROR>';
	if ( string.substring(0, errorFlag.length) == errorFlag ) {
		return string.substring ( errorFlag.length, string.length );
	}
	else {
		return false;
	}
}

function setInnerHTML(el, htmlCode) {
    var ua = navigator.userAgent.toLowerCase();
    if (ua.indexOf('msie') >= 0 && ua.indexOf('opera') < 0) {
        htmlCode = '<div style="display:none">for IE</div>' + htmlCode;
        htmlCode = htmlCode.replace(/<script([^>]*)>/gi,
                                    '<script$1 defer>');
        el.innerHTML = htmlCode;
        el.removeChild(el.firstChild);
    } else {
        var el_next = el.nextSibling;
        var el_parent = el.parentNode;
        el_parent.removeChild(el);
        el.innerHTML = htmlCode;
        if (el_next) {
            el_parent.insertBefore(el, el_next)
        } else {
            el_parent.appendChild(el);
        }
    }
}


// 在指定对象显示信息function showHTML(msg, objName) {
	var obj;
	if (typeof(objName) == 'string') {
		obj = document.getElementById(objName);
	}
	else {
		obj = objName;
	}

	if (obj) {
		//setInnerHTML(obj,msg);
		obj.innerHTML = msg;
		try	{
			obj.scrollTop = 0;
		}
		catch (e) {
		}
	}
	else {
		showDialogBox(msg, objName);
	}
	// 解析 Script
	var re = /<script[^>]*>([^\x00]+)<\/script>/

	while ( strScript = msg.match ( re ) )
	{
		var strEval = strScript[1].replace ( /<!--/, '' );
		eval ( strEval );
		msg = msg.replace ( re, '' );
	}
}

// 对话框操作类
function clsDialog(dialogName) {
	this.dialogIndex = 0;
	this.dialogName = dialogName;
	if ( this.dialogName == null ) this.dialogName = 'dialog';

	this.open = function (loadUrl) {
		//mask.show ();
		loader.get(loadUrl, this.dialogName + (++this.dialogIndex));
	}

	// 载入至当前浮动对话框
	this.load = function (loadUrl) {
		var dialogName = this.dialogName + this.dialogIndex;
		//if ( !document.getElementById(dialogName)) {
		//	mask.show ();
		//}
		loader.get(loadUrl, dialogName);
	}

	// 提交表单至浮动对话框
	this.post = function ( loadUrl, form, procMsg )
	{
		if ( typeof ( form ) == 'string' )
		{
			form = document.getElementById ( form );
		}
		loader.post ( loadUrl, this.dialogName + this.dialogIndex, form );
	}

	// 关闭浮动对话框	this.close = function ()
	{
		var obj = document.getElementById( this.dialogName + ( this.dialogIndex ));

		if (!obj) {//防止error页面开空dialog
			this.dialogIndex--;
		}

		removeDialogBox ( this.dialogName + ( this.dialogIndex-- ) );
	}
}
var dialog = new clsDialog ( 'dialog' );

//
var gzIndex = 999;

// 显示提示窗口
function showDialogBox(msg, objId) {
	var objClass = 'dialog_box';
	mask.show ();
	if ( objId == null )
	{
		objId = objClass + mask.maskIndex;
	}
	var msgBox = document.getElementById ( objId );
	if ( msgBox )
	{
		msgBox.parentNode.removeChild ( msgBox );
		//mask.hide ();
	}

	msgBox=document.createElement ( 'div' );
	msgBox.id = objId;
	msgBox.className = objClass;
	var objBody = document.getElementsByTagName('body').item(0);
	objBody.appendChild ( msgBox );
	msgBox.style.zIndex = gzIndex ++;

	msgBox.innerHTML = msg;
	centerDiv ( msgBox );
}



function showAlert(msg, objId){
	var objClass = 'dialog_box';
	mask.show ();
	if ( objId == null )
	{
		objId = objClass + mask.maskIndex;
	}
	var msgBox = document.getElementById ( objId );
	if ( msgBox )
	{
		msgBox.parentNode.removeChild ( msgBox );
		//mask.hide ();
	}

	msgBox=document.createElement ( 'div' );
	msgBox.id = objId;
	msgBox.className = objClass;

	var objBody = document.getElementsByTagName('body').item(0);
	objBody.appendChild ( msgBox );
	msgBox.style.zIndex = gzIndex ++;
	msgBox.style.width = "400px";
	msgBox.align="center";

	msgBox.innerHTML = '<table width="100%" border="0" cellspacing="8" cellpadding="4">';
	msgBox.innerHTML +='<tr>';
	msgBox.innerHTML +='<td align="center">'+msg+'<br/></td>';
	msgBox.innerHTML +='</tr>';
	msgBox.innerHTML +='<tr>';
	msgBox.innerHTML +='<td align="center">&nbsp;<input type="button" name="close_button" onclick="this.blur(); removeDialogBox();" value="关闭窗口" /></td>';
	msgBox.innerHTML +='</tr>';
	msgBox.innerHTML +='</table>';

	centerDiv ( msgBox );
}



// 移除对话框function removeDialogBox(objName) {
	if (objName == null) {
		objName = 'dialog_box' + mask.maskIndex;
	}
	mask.hide ();

	var obj = document.getElementById(objName);
	if (obj) {
		obj.parentNode.removeChild(obj);
	}
	gzIndex --;
}

// 遮罩
function clsMask () {
	this.maskId = 'mask';
	this.maskIndex = 0;
	this.lastHTMLStyle = null;

	this.show = function () {

		this.maskIndex ++;
		var maskName = this.maskId + this.maskIndex;
		var mask = document.getElementById ( maskName );
		if ( mask ) {
			mask.parentNode.removeChild ( mask );
		}
		var objBody = document.getElementsByTagName('body').item(0);
		mask = document.createElement ( 'div' );
		mask.id = maskName;
		mask.className = this.maskId;
		mask.style.width = screen.width + 'px';
		mask.style.height = screen.height + 'px';
		mask.style.zIndex = gzIndex ++;

		var maskFrame = document.createElement ( 'iframe' );
		maskFrame.id = maskName + '_frame';
		maskFrame.className = this.maskId;
		maskFrame.style.width = screen.width + 'px';
		maskFrame.style.height = screen.height + 'px';
		maskFrame.style.zIndex = gzIndex ++;

		objBody.appendChild ( maskFrame );
		objBody.appendChild ( mask );

		var objHTML = document.getElementsByTagName('html').item(0);
		if ( this.lastHTMLStyle == null ) this.lastHTMLStyle = objHTML.style.overflow;
		objHTML.style.overflow = 'hidden';
	}

	this.hide = function ()
	{
		var maskFrame = document.getElementById ( this.maskId + this.maskIndex + '_frame' );
		if ( maskFrame )
		{
			try
			{
				maskFrame.parentNode.removeChild ( maskFrame );
				gzIndex --;
			}
			catch ( e )
			{
			}
		}
		var mask = document.getElementById ( this.maskId + this.maskIndex );
		if ( mask )
		{
			var objHTML = document.getElementsByTagName('html').item(0);
			mask.parentNode.removeChild ( mask );
			this.maskIndex --;
			gzIndex --;
			if ( this.maskIndex == 0 )
			{
				objHTML.style.overflow = this.lastHTMLStyle;
			}
		}
	}
}
var mask = new clsMask ();
var objHTML = document.getElementsByTagName('html').item(0);

// 处理过程提示框
function clsProcess ( dialogName ) {
	this.processing = false;
	this.dialogName = dialogName;
	this.chkTimeOut = null;
	this.timeOutSeconds = 20;

	if ( this.dialogName == null ) this.dialogName = 'processing_box';

	// 正在处理
	this.start = function ( procMsg )
	{
		if ( !this.processing )
		{
			if ( procMsg == null ) procMsg = '正在处理中, 请稍候...';

			showDialogBox ( '<table><tr><td width="300" align="center"><br/><img src="../images/loading.gif" width="16" height="16" align="abscenter">&nbsp;' + procMsg + '<br/><br/></td></tr><table>', this.dialogName );
			//setFocus ( this.dialogName );
			this.processing = true;
			this.chkTimeOut = setTimeout ( "process.timeOut()", this.timeOutSeconds * 1000 );
		}
	}

	// 处理完成
	this.finish = function ()
	{
		if ( this.processing )
		{
			objContentBody = document.getElementById ( 'body' );
			// objContentBody.scrollTop = 0;

			removeDialogBox ( this.dialogName );
			//mask.hide ();
			this.processing = false;
			clearTimeout ( this.chkTimeOut );
		}
	}

	this.timeOut = function ()
	{
		this.finish ();
		alert ( '网络连接超时,请重试!' );
	}
}
var process = new clsProcess ();


//-->

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -