User:Grrrreat/prototyping/pokingsite

From XPUB & Lens-Based wiki

this: | Poking-Site

Jasper van Loenen & Bartholomäus Traubeck

javascript which executes the php functions and inputs them into the body dynamically.

function reposition(){
	var counter = jQuery(".counter");
	var pokebutton = jQuery("#pokebuttonsubmit");
		var position = pokebutton.offset();
		jQuery(".counter").css({'position':'absolute','left':position.left + pokebutton.outerWidth() - 10});
}

}
function countDown(number){
	$('#btnText').html(number);	   	
	if(number>0){
		var t=setTimeout("countDown("+(number-1)+")",1000);
	}else{
		$('#btnText').html('Poke Me');
		$('.pokebutton').removeClass('disabledButton');
		$('.buttonshadow').css('background-image', 'url(../img/buttonshadow.png)');
		pokerEnabled = true;
		reposition();
	}

}
img1 = new Image();
img1.src = "../img/buttonshadow-smaller.png";
    
var pokerEnabled = true;
jQuery(document).ready(function() {
	reposition();
	
	jQuery(window).resize(function() {
  reposition();
});
	
	$(".what").bind("click", function(){
		$('#description').fadeIn(200, function(){ });
		var aboutTimeout=setTimeout("hideAbout()",30000);
	});

	$("#close").bind("click", function(){
		hideAbout();
		clearTimeout(aboutTimeout);
	});
			  
	$.get("count.php", function(data){
		$('#totalnumber').html(data); 
	}, "json");
  
	$('#pokebuttonsubmit').click(function(event) {
		event.preventDefault();
		if(pokerEnabled){
			$.get("poke.php");
			$.get("count.php", function(data){
			     $('#totalnumber').html(data);
			}, "json");
			$('.pokebutton').addClass('disabledButton');
			countDown(9);
			$('.buttonshadow').css('background-image', 'url(../img/buttonshadow-smaller.png)');
			reposition();
		}
		pokerEnabled = false;
	});
	

	   

});


poke.php to add 1 to the actual count of pokes.

<?
	$mysql_user = "";
	$mysql_pass = "";
	$mysql_host = "localhost";
	$mysql_dbn = "";
	
	global $my_local_connection;
	$my_local_connection = mysql_connect($mysql_host, $mysql_user, $mysql_pass) or die("Unable to connect to database");
	mysql_select_db($mysql_dbn, $my_local_connection) or die( "Unable to select database");

	mysql_query("UPDATE pokes SET amount=amount+1");

	mysql_close();
	
	sleep(1);
?>


count.php to count the stored pokes and output them as a number

<?
	$mysql_user = "";
	$mysql_pass = "";
	$mysql_host = "localhost";
	$mysql_dbn = "";
	
	global $my_local_connection;
	$my_local_connection = mysql_connect($mysql_host, $mysql_user, $mysql_pass) or die("Unable to connect to database");
	mysql_select_db($mysql_dbn, $my_local_connection) or die( "Unable to select database");
	
	$sql = mysql_query("SELECT amount FROM pokes LIMIT 1");
	$row = mysql_fetch_assoc($sql);
	echo $row['amount'];
	
	mysql_close();
?>