Learn how to use jQuery at the Blog

Pedro Figueras « visit

  • Added 6 months ago
  • 262 Lines of Code shown
  • 4 Links of Interest
http://pedrofigueras.com/web
This is my Source Code and I don't want to show it here
View Source Code only (as overlay)
// That code snippet belongs to Pedro Figueras - http://pedrofigueras.com/web

$(function() {		
	$("#workDetail").hide();
	
	/* MENU */
	$(".menu li a").each(function() {
		$(this).attr("enabled","false");
		$(this).css({'background-position': 'left 0px'});		
		/*$(this).attr("href","#");*/
			
			
		$(this).click(function() {
			
			if ($(this).attr("enabled")=="false") {
				$(this).css({'background-position': 'left -50px'});		
				$(this).attr("enabled","true");
			} else {
				$(this).css({'background-position': 'left 0px'});		
				$(this).attr("enabled","false");
			}
			
			
			/* ALL WORKS */
			if ($(this).attr("rel")=="all") {
				if ($(this).attr("enabled")=="true") {				
					markAll();
				} else {
					unmarkAll()
				}
			}
			
			loadWorks();
			
			return false;
		});			
	});
	
	$(".menu li:first a").each(function() {
		$(this).attr("enabled","true");
		$(this).css({'background-position': 'left -50px'});		
	});
	
	
	
	
	/* TAGS */
	$(".tags li a").each(function() {
		$(this).attr("enabled","false");
		$(this).css({'background-position': 'left 0px'});		
		//$(this).attr("href","#");
			
		$(this).hover(
			function() {	
				if ($(this).attr("enabled")=="false") {
					$(this).css({'background-position': 'left -500px'});							
				} 	
			},
			function() {	
				if ($(this).attr("enabled")=="false") {
					$(this).css({'background-position': 'left 0'});							
				} 	
			}
		);
		
		
		
			
		$(this).click(function() {				
			
			/* ALL WORKS */
			if ($(this).attr("rel")=="all") {
				if ($(this).attr("enabled")=="false") {									
					markAllTags();
				} else {
					unmarkAllTags();					
				}
			} else {					
				if ($(this).attr("enabled")=="false") {
					unmarkRecentTag();					
					$(this).css({'background-position': 'left -500px'});		
					$(this).attr("enabled","true");
				} else {
					$(this).css({'background-position': 'left 0px'});		
					$(this).attr("enabled","false");				
				}
			}
			
			
			markAll();
						
			loadWorks();
			
			/* GA tracker */
			pageTracker._trackPageview($(this).attr("href"));
			
			return false;
		});		
	});
	
	markRecentTag();
				
	prepareWorks();
	
});




function markAll() {
	$(".menu li a").each(function() {
		if ($(this).attr("rel")!="all") {
			$(this).attr("enabled","true");
			$(this).css({'background-position': 'left -50px'});	
		}
	})	
}

function unmarkAll() {
	$(".menu li a").each(function() {
		if ($(this).attr("rel")!="all") {
			$(this).attr("enabled","false");
			$(this).css({'background-position': 'left 0px'});	
		}
	})
	
	$(".menu li:first a").each(function() {
		$(this).attr("enabled","true");
		$(this).css({'background-position': 'left -50px'});		
	});

}


function markAllTags() {
	$(".tags li a").each(function() {
		/*if ($(this).attr("rel")!="all") {*/
			$(this).attr("enabled","true");
			$(this).css({'background-position': 'left -500px'});	
		/*}*/
	})	
}


function unmarkRecentTag() {	
	$(".tags li a[rel=recent]").each(function() {
		$(this).attr("enabled","false");
		$(this).css({'background-position': 'left 0px'});		
	});
}

function markRecentTag() {	
	$(".tags li a[rel=recent]").each(function() {
		$(this).attr("enabled","true");
		$(this).css({'background-position': 'left -500px'});		
	});
}


function unmarkAllTags() {
	$(".tags li a").each(function() {
		/*if ($(this).attr("rel")!="all") {*/
			$(this).attr("enabled","false");
			$(this).css({'background-position': 'left 0px'});	
		/*}*/
	})
	
	markRecentTag();
}



function prepareWorks() {
	$(".portfolio").preload();
	
	$(".portfolio a").each(function() {
		//$(this).attr("rel",$(this).attr("href"));	
		//$(this).attr("href","#");
							
		$(this).hover(
			function() {
				$(".hover",this).animate({top: "0"},500);
			},
			function() {
				$(".hover",this).animate({top: "-65px"},500);
			}
		)
		
				
		$(this).click(function() {		
			var src=$("img",$(this)).attr("src");	
			
			/* REPLACE PICTURE */
			$("img",$(this)).remove();
			$(this).append('<img src="'+src+'&bw=1" />');			

			$("#workDetailLoader").show();
			
			/* GA tracker */
			pageTracker._trackPageview($(this).attr("href"));
			
			//$("#workDetail").load($(this).attr("rel")+" .work","x=1",function() {				
			$("#workDetail").load(BASE+"/ajax/getWork.php?id_work="+$(this).attr("rel"),null,function() {				
				// Load & show work 
				$("#workDetail").show("fast");
				$("#workDetail .pictures").jqGalScroll({height:503,width:710,ease:'easeOutCubic',speed:1000,titleOpacity:0});				

				//Hide Loader 
				$("#workDetailLoader").hide();
														
				// Close button 
				$("#workDetail .close").click(function() {									
					hideWorkDetail();	
					return false;									
				});
				
			});
					
			
			return false;
			
			
		});		
	});	

}

function hideWorkDetail() {
	/* Hide work detail */
	$("#workDetail").html();
	$("#workDetail").hide("slow");	

}



function loadWorks() {
	hideWorkDetail();
	
	var categories="";	
	var tags="";
	
	$(".menu li a").each(function() {
		if ($(this).attr("enabled")=="true") {
			categories=categories+$(this).attr("rel")+"|";			
		}		
	})
	
	$(".tags li a").each(function() {
		if ($(this).attr("enabled")=="true") {
			tags=tags+$(this).attr("rel")+"|";			
		}		
	})
	
	
	
	$(".updating").slideDown("slow");
	
	$("#resultset").load("ajax/getWorkList.php?categories="+categories+"&tags="+tags,null,function() {
		prepareWorks();
		$(".updating").slideUp("fast");	
	});
	
}