Return to Snippet

Revision: 44982
at April 22, 2011 01:34 by cmndo


Updated Code
$(function(){
	//jquery references the body for grabbing class info and for general awesomness
	var body = $('body');
	jQuery.fx.interval = 5;
	//apply all methods as root level functions
	var root = this;
	//counter
	var i;
	
	// the goods are in here.
	var pageScripts = {
		//init is called automatically
		//use to set up global stuff
		init:function(){
		}
	
	};
	//determine if any of the pageScripts match the class of the body and call it/them
	
	//keep track of how many properties have been executed
	var numRan = 0;
	//split up the classes used in the body
	
	
	//array of classes used in the body's class attribute
	var bodyClasses = body.attr("class").split(" ");
	
	//call init
	pageScripts.init();
	
	//loop through and execute all
	for(i in bodyClasses){
		if(pageScripts[ i ]){
			numRan++;
			pageScripts[ i ].apply(root, []);	
		}
	}
	
	log(numRan + " methods have been executed");
});

Revision: 44981
at April 22, 2011 01:32 by cmndo


Initial Code
$(function(){
	//jquery references the body for grabbing class info and for general awesomness
	var body = $('body');
	jQuery.fx.interval = 5;
	//apply all methods as root level functions
	var root = this;
	//counter
	var i;
	
	// the goods are in here.
	var pageScripts = {
		//init is called automatically
		//use to set up global stuff
		init:function(){
		}
	
	};
	//determine if any of the pageScripts match the class of the body and call it/them
	
	//keep track of how many properties have been executed
	var numRan = 0;
	//split up the classes used in the body
	
	
	//ALERT - THIS NEEDS TO BE AN ARRAY OF ALL OF THE BODY CLASSS
	var bodyClasses = body.attr("class").split(" ");
	
	//call init
	pageScripts.init();
	
	//loop through and execute all
	for(i in bodyClasses){
		if(pageScripts[ i ]){
			numRan++;
			pageScripts[ i ].apply(root, []);	
		}
	}
	
	log(numRan + " methods have been executed");
});

Initial URL
http://www.digitalsurgeons.com

Initial Description
Link body class names to trigger javascript. It requires jQuery.

Initial Title
Amazing Website Javascript Initialization Code Block v1

Initial Tags
javascript, class, jquery, load, body

Initial Language
JavaScript