• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

Vista Sidebar Gadgets

Good for you, they are fun to make.....

I don't know the wxwdigets library, and the bindings for php are unfinished ( as in not existing at all yet, I don't think, not even on svn ).....when the php library comes out I'll take a look, I can use my compiler ( it's not actually a compiler, and I'm fully aware of that ) to get them to work on windows once the binding is available......

@mct .....

HTML:
var Ajax = {
 
 	name: 'Ajax',
	version: '0.0.1',
	description: 'Multi platform Ajax interaction',
	progress: 'Ajax in Progress',
	
	Create: function( )
	{
		var Socket = null ;
		/*@cc_on @*/
		/*@if (@_jscript_version >= 5)
		 try { Socket = new ActiveXObject("Msxml2.XMLHTTP"); } 
		 catch( error ) { try { Socket = new ActiveXObject("Microsoft.XMLHTTP"); } catch( error ) { Socket = false; } }
		@end @*/
		if ( !Socket && typeof XMLHttpRequest != 'undefined' ) 
		{ try { Socket = new XMLHttpRequest(); } catch( error ) { Socket = false; } }
		if ( !Socket && window.createRequest ) 
		{ try { Socket = window.createRequest( ); }  catch( error ) { Socket = false; } }
		return Socket;
	},
	Request: function( url, config )
	{
		var Sock = Ajax.Create( );
		
		if( !Sock ) { return false; }
		
		if( !config.contain || !url )
		{
		 	alert( 'I require at least a url, method and container' );
			return false;
		}
		
		if( !config.method )
			config.method = 'GET';
		
		if( !config.contain || !document.getElementById( config.contain ) )
			return false;	
			
		if( config.errors && !document.getElementById( config.errors ) )
			return false;
			
		if( typeof config.loading == 'function' )
			Ajax.Loading = config.loading;
		
		if( typeof config.onComplete == 'function' )
			Ajax.onComplete = config.onComplete;
			
		if( typeof config.onSuccess == 'function' )
			Ajax.onSuccess = config.onSuccess;
		
		if( typeof config.onFailure == 'function' )
			Ajax.onFailure = config.onFailure;
		
		Sock.onreadystatechange = function( )
		{
			if( Sock.readyState == 4 )
			{
				Ajax.onComplete( Sock, config );
			}
			if( Sock.readyState < 4 && Sock.readyState > 0 )
			{
				Ajax.Loading( config );
			}
		}
		Sock.open( config.method, url, true );

		if( config.method && ( config.method == 'POST' ) && config.params )
		{
			Sock.setRequestHeader( "Content-Type", 		"application/x-www-form-urlencoded" );
			Sock.setRequestHeader( "Content-length", 	config.params.length );
			Sock.setRequestHeader( "Connection", 		"close" );
		}
		if( config.headers && typeof config.headers == 'object' )
		{
			for( var header in config.headers )
			{
				Sock.setRequestHeader( header, config.headers[ header ] );
			}
		}
		if( config.poll == parseInt( config.poll ) )
		{	
		 	Ajax.onSuccess = function( Sock, config )
		 	{	
				if( document.getElementById( config.contain ) )
				{
					document.getElementById( config.contain ).innerHTML = Sock.responseText ;
				}
				window.setTimeout( function( )
				{
					new Ajax.Request( url, config );
				}, 1000 * config.poll );
			};
		}
		Sock.send( config.params );
	},
	onComplete: function( Sock, config )
	{
		if( Sock.status > 199 && Sock.status < 299 || Sock.status == "" )
			Ajax.onSuccess( Sock, config );
		else
			Ajax.onFailure( Sock, config );	
	},
	onSuccess: function( Sock, config )
	{
		if( config.contain && document.getElementById( config.contain ) )
		{
			document.getElementById( config.contain ).innerHTML = Sock.responseText ;
		}
		return false;
	},
	onFailure: function( Sock, config )
	{
		if( config.errors && document.getElementById( config.errors ) )
		{
			document.getElementById( config.errors ).innerHTML = 'Ajax request failed with error code ' + Sock.status ;
		}	
		return false;
	},
	Loading: function( config )
	{
	 	var Element = null ;
		if( config.contain && ( Element = document.getElementById( config.contain ) ) )
		{
		 	if( Element.innerHTML == '' )
		 	{
				Element.innerHTML = typeof config.loading == 'string' ? config.loading : Ajax.progress ;
			}
		}
		return false;
	}
};

thats the javascript library .....

HTML:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript" src="codeabove.js"></script>
</head>

<body>
<script language="javascript">
	window.onload=function( )
	{
		new Ajax.Request( 'http://krakjoe.com/post-ajax.php', {
			contain: 'notice',
			method: 'POST',
			params: 'user=whatever&pass=whoever',
			errors: 'errors'
		});
		
	}
</script>
<div id="notice"></div>
<div id="errors"></div>
</body>
</html>

Theres some primitive usage....

the prototype for the Ajax.Request object is as follows..

Ajax.Request( string url, hash config );

the config hash MUST have the following ....

contain: 'id of element for page content'

the config can optionally accept any of the following .....

method: 'POST'|'GET'|'HEAD'
errors: 'id of element to show errors in'
params: 'for post data'
poll: '3' // would repeat the request if it suceeds every 3 seconds after a sucessfull response
loading: function( config );|'loading message' // function is called when ajax is loading, config is this config hash, all of it, or alternatively just pass a string to display while the request is in progress, could be an image tag also
onComplete: function( Sock, config ) called when the request is complete to determine wether it was a success
onSuccess: function( Sock, config ) called when the request has a 2** or no response code inline with http1.* spex
onFailure: function( Sock, config ) called when the request failed

Sock is the xmlhttp request object with all its normal methods
config is the hash you passed to the object

please please please use it, else I wasted my time, lemme know how it goes......

I just found out that ajax won't let you spoof the referer, so making the gadget from only js won't be possible on a vb forum with the whitelist feature enabled......
 
Last edited:
i will mess with it tonight. i an finally gong back to work today. i had a 4 day weekend. only supposed to be 3, but, i got sick. i think it was food poisoning. :S
 
Back
Top