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

📄 cfx.js

📁 Hippo CMS是一个以信息为中心的开源内容管理系统。Hippo CMS目标是供中,大型企业来管理其发布在互连网
💻 JS
📖 第 1 页 / 共 2 页
字号:
}


//////////////////////////////////////////////////////////////////////////////
//	Dom
//////////////////////////////////////////////////////////////////////////////
function _dom()
{
	// Browser properties.
	this.isIE = IsIE();
	this.isNetscape = IsNetscape();
	this.isMozilla = IsMozilla();
	
	// Document form function.
	_dom.prototype.GetForm = GetForm;

	// Document element functions.
	_dom.prototype.FindElementById = FindElementById;
	_dom.prototype.FindElementByName = FindElementByName;
	_dom.prototype.FindElementSetById = FindElementSetById;
	_dom.prototype.FindElementSetByName = FindElementSetByName;
	_dom.prototype.GetElementById = GetElementById;
	_dom.prototype.GetElementByName = GetElementByName;
	_dom.prototype.GetElementTerms = GetElementTerms;

	// Document image functions.
	_dom.prototype.FindImage = FindImage;
	_dom.prototype.FindImageSet = FindImageSet;
	_dom.prototype.GetImage = GetImage;

	// Document submit functions.
	_dom.prototype.PostBack = PostBack;

	return;


	//////////////////////////////////////////////////////////////////////////////
	//	IsIE()
	//////////////////////////////////////////////////////////////////////////////
	function IsIE()
	{
		var isApp = navigator.appName.indexOf( "Microsoft" ) != -1;
		
		var isVersion = ( arguments.length ) ?
					     navigator.appVersion.substring(0, 1).valueOf() >= arguments[0]
					     : true;
		
		return isApp && isVersion;
	}


	//////////////////////////////////////////////////////////////////////////////
	//	IsMozilla()
	//////////////////////////////////////////////////////////////////////////////
	function IsMozilla()
	{
		var isApp = IsNetscape() && !document.all && document.getElementById;
		
		var isVersion = ( arguments.length ) ?
					     navigator.appVersion.substring(0, 1).valueOf() >= arguments[0]
					     : true;
					     
		return isApp && isVersion;
	}


	//////////////////////////////////////////////////////////////////////////////
	//	IsNetscape()
	//////////////////////////////////////////////////////////////////////////////
	function IsNetscape()
	{
		var isApp = navigator.appName == "Netscape";
		
		var isVersion = ( arguments.length ) ?
					     navigator.appVersion.substring(0, 1).valueOf() >= arguments[0]
					     : true;
					     
		return isApp && isVersion;
	}


	//////////////////////////////////////////////////////////////////////////////
	//	FindElementById( elementName )
	//////////////////////////////////////////////////////////////////////////////
	function FindElementById( elementName )
	{
		var theForm = GetForm( arguments[1] );
		var nElements = theForm.elements.length;
		for ( var ii = 0; ii < nElements; ++ii )
		{
			var theElement = theForm.elements[ii];
			if ( theElement.id.indexOf( elementName ) != -1 ) 
				return theElement;
		}
		
		return null;
	}


	//////////////////////////////////////////////////////////////////////////////
	//	FindElementByName( elementName )
	//////////////////////////////////////////////////////////////////////////////
	function FindElementByName( elementName )
	{
		var theForm = GetForm( arguments[1] );
		var nElements = theForm.elements.length;
		for ( var ii = 0; ii < nElements; ++ii )
		{
			var theElement = theForm.elements[ii];
			if ( theElement.name.indexOf( elementName ) != -1 )
				return theElement;
		}
		
		return null;
	}


	//////////////////////////////////////////////////////////////////////////////
	//	FindElementSetById( elementName )
	//////////////////////////////////////////////////////////////////////////////
	function FindElementSetById( elementName )
	{
		var theForm = GetForm( arguments[1] );
		var nElements = theForm.elements.length;
		var elementSet = null;

		for ( var ii = 0; ii < nElements; ++ii )
		{
			var theElement = theForm.elements[ii];
			if ( theElement.id.indexOf( elementName ) != -1 )
			{
				if ( elementSet == null ) elementSet = new Array();
				elementSet[elementSet.length] = theElement;
			}
		}
		
		return elementSet;
	}


	//////////////////////////////////////////////////////////////////////////////
	//	FindElementSetByName( elementName )
	//////////////////////////////////////////////////////////////////////////////
	function FindElementSetByName( elementName )
	{
		var theForm = GetForm( arguments[1] );
		var nElements = theForm.elements.length;
		var elementSet = null;

		for ( var ii = 0; ii < nElements; ++ii )
		{
			var theElement = theForm.elements[ii];
			if ( theElement.name.indexOf( elementName ) != -1 )
			{
				if ( elementSet == null ) elementSet = new Array();
				elementSet[elementSet.length] = theElement;
			}
		}
		
		return elementSet;
	}


	//////////////////////////////////////////////////////////////////////////////
	//	GetElementById( elementId )
	//////////////////////////////////////////////////////////////////////////////
	function GetElementById( elementId )
	{
		return document.getElementById( elementId );
	}


	//////////////////////////////////////////////////////////////////////////////
	//	GetElementByName( elementName )
	//////////////////////////////////////////////////////////////////////////////
	function GetElementByName( elementName )
	{
		var theForm = GetForm( arguments[1] );
		if ( Cfx.Js.IsDefined( theForm.elements[elementName] ) )
			return theForm.elements[elementName];

		return null;
	}


	//////////////////////////////////////////////////////////////////////////////
	//	GetElementTerms
	//	
	//	Usage:
	//		GetElementTerms( argElement )
	//		GetElementTerms( argElement, splitChar )
	//////////////////////////////////////////////////////////////////////////////
	function GetElementTerms( argElement, splitChar )
	{
		var elementId = null;
		var elementTerms = null;

		// Assume default split character is underscore;
		if ( !Cfx.Js.IsDefined( splitChar ) )
			splitChar = "_";

		if ( Cfx.Js.IsObject( argElement ) )
			elementId = argElement.id;
		else if ( Cfx.Js.IsString( argElement ) )
			elementId = argElement;
		else
			throw new Error( "invalid element parameter" );

		// Perform string split if split character is not underscore.
		if ( splitChar != "_" )
			return thisElement.id.split( splitChar );
			
		// Split the element id with underscore as split character.
		while ( elementId != "" )
		{
			var results = elementId.match( /(_?[a-zA-Z\d]+_?)(\d+_?)?/ );
			if ( results != null )
			{
				var term = results[0];
				var termLen = term.length;
				if ( term.charAt( termLen - 1 ) == "_" )
					term = term.slice( 0, -1 );

				if ( elementTerms == null )
					elementTerms = new Array();

				elementTerms[elementTerms.length] = term;
				elementId = elementId.substr( termLen );
			}
		}

		return elementTerms;
	}


	//////////////////////////////////////////////////////////////////////////////
	//	FindImage( imageName )
	//////////////////////////////////////////////////////////////////////////////
	function FindImage( imageName )
	{
		var nImages = document.images.length;
		for( var ii = 0; ii < nImages; ++ii )
		{
			var theImage = document.images[ii];
			if ( theImage.id.indexOf( imageName ) != -1 )
				return theImage;
		}
		
		return null;
	}


	//////////////////////////////////////////////////////////////////////////////
	//	FindImageSet( imageName )
	//////////////////////////////////////////////////////////////////////////////
	function FindImageSet( imageName )
	{
		var nImages = document.images.length;
		var images = document.images;
		var imageSet = null;

		for ( var ii = 0; ii < nImages; ++ii )
		{
			if ( ( images[ii].id != null ) && ( images[ii].id.indexOf( imageName ) != -1 ) )
			{
				if ( imageSet == null ) imageSet = new Array();
					imageSet[imageSet.length] = images[ii];
			}
		}

		return imageSet;
	}


	//////////////////////////////////////////////////////////////////////////////
	//	GetImage( imageId )
	//////////////////////////////////////////////////////////////////////////////
	function GetImage( imageId )
	{
		var nImages = document.images.length;
		for( var ii = 0; ii < nImages; ++ii )
		{
			if ( Cfx.Js.IsDefined( document.images[imageId] ) )
				return document.images[imageId];
		}
		
		return null;
	}


	//////////////////////////////////////////////////////////////////////////////
	//	GetForm( argForm )
	//////////////////////////////////////////////////////////////////////////////
	function GetForm( argForm )
	{
		var theForm = null;

		if ( !Cfx.Js.IsDefined( argForm ) || Cfx.Js.IsNull( argForm ) )
			theForm = document.forms[0];
		else if ( Cfx.Js.IsObject( argForm ) )
		{
			if ( argForm.className == "FORM" )
				theForm = argForm;
		}
		else if ( Cfx.Js.IsNumeric( argForm ) )
			theForm = document.forms[argForm];
		else if ( Cfs.Js.IsString( argForm ) )
		{
			for ( var ii = 0; ii < documents.forms.length; ++ii )
			{
				if ( documents.forms[ii].id == objForm )
				{
					theForm = documents.forms[ii];
					break;
				}
			}
		}

		// Assign class name if we have a form.
		if ( theForm != null )
			 theForm.className = "FORM";

		// Return result.
		return theForm;
	}


	//////////////////////////////////////////////////////////////////////////////
	//	PostBack
	//	
	//	Usage:
	//		PostBack()
	//		PostBack( formIndex )
	//		PostBack( formIndex, eventTarget )
	//		PostBack( formIndex, eventTarget, eventArgument )
	//		PostBack( eventTarget )
	//		PostBack( eventTarget, eventArgument )
	//	
	//////////////////////////////////////////////////////////////////////////////
	function PostBack()
	{
		var theForm = null;
		var eventTarget = null;
		var eventArgument = null;

		for ( var ii = 0; ii < arguments.length; ++ii )
		{
			if ( Cfx.Js.IsNumeric( arguments[ii] ) )
				theForm = Cfx.Dom.GetForm( arguments[0] );
			else if ( Cfx.Js.IsString( arguments[ii] ) )
			{
				if ( eventTarget == null )
					eventTarget = arguments[ii];
				else if ( eventArgument == null )
					eventArgument = arguments[ii];
				else
					throw new Error( "Invalid arguments" );
			}
			else
				throw new Error( "Invalid argument type" );
		}

		if ( theForm == null )
			theForm = Cfx.Dom.GetForm();

		if ( eventTarget == null )
			eventTarget = "";

		if ( eventArgument == null )
			eventArgument = "";

		if ( Cfx.Js.IsDefined( theForm.__EVENTTARGET ) )
			theForm.__EVENTARGET.value = eventTarget.split("$").join(":");

		if ( Cfx.Js.IsDefined( theForm.__EVENTARGUMENT ) )
			theForm.__EVENTARGUMENT.value = eventArgument;

		// Submit the form.
		theForm.submit();
	}
}		

function _html()
{
	// Naming functions.
	_html.prototype.URLEncode = URLEncode;
	_html.prototype.URLDecode = URLDecode;
	_html.prototype.getHTTPRequest = getHTTPRequest;
    
    
    function URLEncode(str) {
      if(Cfx.Js.IsDefined(encodeURIComponent)) {
	    var code = encodeURIComponent(str);
	    code = code.replace( /%20/g , "+" );
	    return code;
	  }
	  return str;
    }	
    
    function URLDecode(str) {
    	//TODO: implement
    }
    
    function getHTTPRequest() {
      var requestObject = null;
      if(Cfx.Js.IsDefined(window.ActiveXObject)) {
	    try {
		  requestObject = new ActiveXObject("Microsoft.XMLHTTP");
	    }
  	    catch(e) {
		  return null;
	    }
	  }
	  else if(Cfx.Js.IsDefined(XMLHttpRequest)) {
	    try {
		  requestObject = new XMLHttpRequest();
	    }
	    catch(e) {
	      return null;
	    }
	  }  
      return requestObject;
    }
}

function _stopwatch() 
{
	_stopwatch.prototype.start = start;
	_stopwatch.prototype.end = end;
	_stopwatch.prototype.reset = reset;
	_stopwatch.prototype.interval = interval;
	_stopwatch.prototype.isRunning = isRunning;
	this.times = new Array();
	this.running = false;
	return;
	
	function start() {
		this.running = true;
		this.times[this.times.length] = new Date().getTime();
		
	}
	
	function end() {
		this.running = false;
		this.times[this.times.length] = new Date().getTime();
		return this.times[this.times.length-1] - this.times[0];
	}
	
	function reset() {
		this.times = new Array();
	}
	
  function interval() {
  	if(!this.running) throw new Error("Stopwatch must be started before interval can be called"); 
    this.times[this.times.length] = new Date().getTime();
    return this.times[this.times.length-1] - this.times[this.times.length-2];  	
  }	
  
  function isRunning() {
  	return this.running == true;
  }
}

⌨️ 快捷键说明

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