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

📄 converter.js

📁 关于网上汽车销售系统的详细编程项目实战实例
💻 JS
📖 第 1 页 / 共 3 页
字号:
/**
 * converter.js - common js functions.
 *
 * @author  Actuate Corporation
 * @version 1.0
 */

///////////////////////////////////////////////////////////////////////////////
// Globals
///////////////////////////////////////////////////////////////////////////////
var ns4 = (document.layers)? true:false

var g_widthCheck;
var g_heightCheck;
var g_browserVersion;
var g_tagBalloon = "$$$Balloon";
var g_platform = navigator.platform;

if ( ns4 )
{
	g_browserVersion = parseFloat(window.navigator.appVersion);
	g_widthCheck	= window.innerWidth;
	g_heightCheck	= window.innerHeight;
	window.onResize = resizeFix;
}

function setupConverter()
{
	// Netscape Resize Fix

	if ( document.layers )
	{
		g_widthCheck	= window.innerWidth;
		g_heightCheck	= window.innerHeight;
		window.onResize = resizeFix;
	}

	g_platform = navigator.platform;
}

function setPageNo(page)
{
	parent.g_bToolbarPageNumberSet = false;

	// Need to set the page number this early because the user could
	// click on the hyperlinks really fast before the report.js onload
	// method is called.

	if ( parent.g_currentPageNumber )
	{
		parent.g_currentPageNumber = page;
	}

	// Need to store the location cookie this early because the user could
	// click on the hyperlinks really fast before the report.js onload
	// method is called.
	if ( parent.updateLocationStoreCookie )
	{
		parent.updateLocationStoreCookie();
	}

	if (parent.frames.toolbarframe && parent.g_bToolBarFrameLoaded && parent.frames.toolbarframe.setPageNumber)
	{
		var retVal = parent.frames.toolbarframe.setPageNumber(page);
		if (retVal)
		{
			parent.g_bToolbarPageNumberSet = true;
		}
	}
}

///////////////////////////////////////////////////////////////////////////////


function NumToHex(iNum) // ACCEPTS UPTO 64k
{
	if (iNum > 255)
	{
		iQuo = iNum / 256;
		iRem = iNum % 256;
		iQuo = iQuo - (iRem / 256);
		return NumToHex(iQuo) + NumToHex(iRem);
	}
	base = iNum / 16;
	rem = iNum % 16;
	base = base - (rem / 16);
	baseS = MakeHex(base);
	remS = MakeHex(rem);
	return baseS + '' + remS;
}

function MakeHex(x)
{
	if((x >= 0) && (x <= 9))
	return x;
	else {
	switch(x) {
	case 10: return "A";
	case 11: return "B";
	case 12: return "C";
	case 13: return "D";
	case 14: return "E";
	case 15: return "F";
		  }
	   }
}


function debugText(sText)
{
	s = "";
	for (i = 0; i < sText.length; i++)
	{
		c = sText.charCodeAt(i);
		s += "[" + NumToHex(c) + "]";
	}
	return s;
}


/**************************************************************************
 Contains javascript encode and unencode functions.
***************************************************************************/

var hex = new Array(
	"%00", "%01", "%02", "%03", "%04", "%05", "%06", "%07",
	"%08", "%09", "%0a", "%0b", "%0c", "%0d", "%0e", "%0f",
	"%10", "%11", "%12", "%13", "%14", "%15", "%16", "%17",
	"%18", "%19", "%1a", "%1b", "%1c", "%1d", "%1e", "%1f",
	"%20", "%21", "%22", "%23", "%24", "%25", "%26", "%27",
	"%28", "%29", "%2a", "%2b", "%2c", "%2d", "%2e", "%2f",
	"%30", "%31", "%32", "%33", "%34", "%35", "%36", "%37",
	"%38", "%39", "%3a", "%3b", "%3c", "%3d", "%3e", "%3f",
	"%40", "%41", "%42", "%43", "%44", "%45", "%46", "%47",
	"%48", "%49", "%4a", "%4b", "%4c", "%4d", "%4e", "%4f",
	"%50", "%51", "%52", "%53", "%54", "%55", "%56", "%57",
	"%58", "%59", "%5a", "%5b", "%5c", "%5d", "%5e", "%5f",
	"%60", "%61", "%62", "%63", "%64", "%65", "%66", "%67",
	"%68", "%69", "%6a", "%6b", "%6c", "%6d", "%6e", "%6f",
	"%70", "%71", "%72", "%73", "%74", "%75", "%76", "%77",
	"%78", "%79", "%7a", "%7b", "%7c", "%7d", "%7e", "%7f",
	"%80", "%81", "%82", "%83", "%84", "%85", "%86", "%87",
	"%88", "%89", "%8a", "%8b", "%8c", "%8d", "%8e", "%8f",
	"%90", "%91", "%92", "%93", "%94", "%95", "%96", "%97",
	"%98", "%99", "%9a", "%9b", "%9c", "%9d", "%9e", "%9f",
	"%a0", "%a1", "%a2", "%a3", "%a4", "%a5", "%a6", "%a7",
	"%a8", "%a9", "%aa", "%ab", "%ac", "%ad", "%ae", "%af",
	"%b0", "%b1", "%b2", "%b3", "%b4", "%b5", "%b6", "%b7",
	"%b8", "%b9", "%ba", "%bb", "%bc", "%bd", "%be", "%bf",
	"%c0", "%c1", "%c2", "%c3", "%c4", "%c5", "%c6", "%c7",
	"%c8", "%c9", "%ca", "%cb", "%cc", "%cd", "%ce", "%cf",
	"%d0", "%d1", "%d2", "%d3", "%d4", "%d5", "%d6", "%d7",
	"%d8", "%d9", "%da", "%db", "%dc", "%dd", "%de", "%df",
	"%e0", "%e1", "%e2", "%e3", "%e4", "%e5", "%e6", "%e7",
	"%e8", "%e9", "%ea", "%eb", "%ec", "%ed", "%ee", "%ef",
	"%f0", "%f1", "%f2", "%f3", "%f4", "%f5", "%f6", "%f7",
	"%f8", "%f9", "%fa", "%fb", "%fc", "%fd", "%fe", "%ff"
);

/**
* Encode a string to the "x-www-form-urlencoded" form, enhanced
* with the UTF-8-in-URL proposal. This is what happens:
*
* <ul>
* <li><p>The ASCII characters 'a' through 'z', 'A' through 'Z',
*        and '0' through '9' remain the same.
*
* <li><p>The unreserved characters - _ . ! ~ * ' ( ) remain the same.
*
* <li><p>The space character ' ' is converted into a plus sign '+'.
*
* <li><p>All other ASCII characters are converted into the
*        3-character string "%xy", where xy is
*        the two-digit hexadecimal representation of the character
*        code
*
* <li><p>All non-ASCII characters are encoded in two steps: first
*        to a sequence of 2 or 3 bytes, using the UTF-8 algorithm;
*        secondly each of these bytes is encoded as "%xx".
* </ul>
*
* @param s The string to be encoded
* @return The encoded string
*/

function encode(s)
{
	s = new String(s);
	var sbuf = new String("");

	var len = s.length;
	for (var i = 0; i < len; i++)
	{
		var ch = s.charAt(i);
		var chCode = s.charCodeAt(i);
		if ('A' <= ch && ch <= 'Z')
		{		// 'A'..'Z'
			sbuf+=ch;
		}
		else if ('a' <= ch && ch <= 'z')	// 'a'..'z'
		{
			sbuf+=ch;
		}
		else if ('0' <= ch && ch <= '9')	// '0'..'9'
		{
			sbuf+=ch;
		}
		else if (chCode <= 0x007f)	// other ASCII
		{
			sbuf+=hex[chCode];
		}
		else if (chCode <= 0x07FF)		// non-ASCII <= 0x7FF
		{
			sbuf+=(hex[0xc0 | (chCode >> 6)]);
			sbuf+=(hex[0x80 | (chCode & 0x3F)]);
		}
		else					// 0x7FF < ch <= 0xFFFF
		{
			sbuf+=(hex[0xe0 | (chCode >> 12)]);
			sbuf+=(hex[0x80 | ((chCode >> 6) & 0x3F)]);
			sbuf+=(hex[0x80 | (chCode & 0x3F)]);
		}
	}
	return sbuf;
}

function decode(s)
{
	s = new String(s);
	var sbuf = new String("") ;
	var l  = s.length;
	var ch = -1 ;
	var b, sumb = 0;
	for (var i = 0, more = -1 ; i < l ; i++)
	{
		switch (ch = s.charAt(i))
		{
			case '%':
				 ch = s.charAt (++i) ;
				 var hb = (isDigit (ch)
						   ? ch - '0'
							 : 10+ (toLowerCase(ch)).charCodeAt(0) - (new String('a')).charCodeAt(0)) & 0xF ;
				 ch = s.charAt (++i) ;
				 var lb = (isDigit (ch)
						   ? ch - '0'
							 : 10+(toLowerCase(ch)).charCodeAt(0) - (new String('a')).charCodeAt(0)) & 0xF ;
				 b = (String.fromCharCode((hb << 4) | lb)).charCodeAt(0) ;
				 break ;
			case '+':
				 b = ' '.charCodeAt(0) ;
				 break ;
			default:
				 b = ch.charCodeAt(0);
		}
		if ((b & 0xc0) == 0x80)		// 10xxxxxx (continuation byte)
		{
			sumb = String.fromCharCode(((sumb.charCodeAt(0) << 6) | (b & 0x3f))) ;	// Add 6 bits to sumb
			if (--more == 0)
			{
				sbuf += sumb;
			}
		}
		else if ((b & 0x80) == 0x00)		// 0xxxxxxx (yields 7 bits)
		{
			sbuf+=String.fromCharCode(b);
		}
		else if ((b & 0xe0) == 0xc0)		// 110xxxxx (yields 5 bits)
		{
			sumb = String.fromCharCode(b & 0x1f);
			more = 1;						// Expect 1 more byte
		}
		else if ((b & 0xf0) == 0xe0)		// 1110xxxx (yields 4 bits)
		{
			sumb = String.fromCharCode(b & 0x0f);
			more = 2;						// Expect 2 more bytes
		}
		else if ((b & 0xf8) == 0xf0)		// 11110xxx (yields 3 bits)
		{
			sumb = String.fromCharCode(b & 0x07);
			more = 3;						// Expect 3 more bytes
		}
		else if ((b & 0xfc) == 0xf8)		// 111110xx (yields 2 bits)
		{
			sumb = String.fromCharCode(b & 0x03);
			more = 4;						// Expect 4 more bytes
		}
		else 								// 1111110x (yields 1 bit)
		{
			sumb = String.fromCharCode(b & 0x01);
			more = 5;						// Expect 5 more bytes
		}
	}
	return sbuf;
}

//returns true or false.
function isDigit(charVal)
{
	return (charVal >= '0' && charVal <= '9');
}

function toLowerCase(charVal)
{
	var str = new String(charVal);
	str = str.toLowerCase();
	return str.charAt(0);
}




///////////////////////////////////////////////////////////////////////////////

function mouseOver( id, alias, balloonHelp, classId, className, link, linkType, linkTarget )
{
	if (!ns4) {
		if (g_browserType.name == "IE")
		{
			window.event.cancelBubble = true;
		}
	}

	if (inSearchMode() && alias)
	{
		// Escape the alias, because it could have special
		// string chars ",' in it
		if(className.substring(0, 2) == "($" )
		{
			createArea( id, encode(alias), className );
		}
		else
		{
			createArea( id, encode(alias), classId );
		}
	}
	//balloon help is not supposed to show in search mode
	else if (!inSearchMode())
	{
		if (balloonHelp)
		{
			createBalloonHelp( id, balloonHelp, link, linkType, linkTarget );
		}
	}
}


///////////////////////////////////////////////////////////////////////////////

function resizeFix()
{
	// If we are in the frameset, and the frameset is resized then reload the whole thing.
	if (eval( 'parent.g_inViewFrameset' ) && parent.g_inViewFrameset == true)	// In ViewFrameset
	{
		if ( parent.g_widthCheck  != parent.innerWidth || parent.g_heightCheck != parent.innerHeight )
		{
			parent.location.reload();
			return;
		}
	}

	// the browser version used here needs to be confirmed by Netscape (re: incident #120903)
	if ( g_browserVersion > 4.08 || g_widthCheck != window.innerWidth || g_heightCheck != window.innerHeight )
	{
		// For MacOS, we should reload the whole frameset. Reloading the frame only will cause the Netscape
		// browser to crash with a "type 2"(memory) error.

		if (g_platform.indexOf("Mac") != -1)
		{
			parent.location.reload();
		}
		else
		{
		window.stop();
		window.setTimeout( 'window.location.reload();', 1000 );
	}
}
}

///////////////////////////////////////////////////////////////////////////////


/**
 * Note: Duplicate definition; also defined in viewer.js
 */
function removeParams(sObjURL, sParam)

⌨️ 快捷键说明

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