Return to Snippet

Revision: 23758
at February 12, 2010 09:38 by ReeceMarsland


Updated Code
Drupal.behaviors.template = function(){ 
	
	/**
	  * Set namespace
	  */
	var sitename = {
		/**
		  * Initialise functions within the sitename namespace
		  */
		init : function() {
			sitename.searchReplace();
			sitename.function2();
			sitename.function3.fInit();
			sitename.function4();
		},
		
		/**
		  *  Puts title text in the field on the search box
		  */	
		searchReplace : function() {

			var searchBox = $("#edit-search-theme-form-1");
			var searchBoxDefault = "Enter keywords";
			searchBox.attr("value", searchBoxDefault);
				
			searchBox.focus(function(){  
			  if(jQuery.trim($(this).attr("value")) == searchBoxDefault) $(this).attr("value", "");  
			});  
			
			searchBox.blur(function(){  
			  if(jQuery.trim($(this).attr("value")) == "") $(this).attr("value", searchBoxDefault);  
			})
		},
		
		/**
		  *  function 2 
		  */
		function2 : function() {
			//code here
	 	},
		
		/**
		  *  function 3
		  */
		function3 : {
			fInit : function() {
				//initialise function 3
				sitename.function3.helperfunction1();
				sitename.function3.helperfunction2();
			},
			
			helperfunction1 : function() {
				//code here
			},
			
			helperfunction2 : function() {
				//code here
			}
	 	},
		
		/**
		  *  function 4 
		  */
		function4 : function() {
			//code here
	 	}
	} //end of sitename
	
	/**
	  *  Initialise sitename
	  */
	sitename.init();

}

Revision: 23757
at February 12, 2010 09:36 by ReeceMarsland


Initial Code
Drupal.behaviors.template = function(){ 
	
	/**
	  * Set sitename 
	  */
	var sitename = {
		/**
		  * Initialise functions within the sitename namespace
		  */
		init : function() {
			sitename.searchReplace();
			sitename.function2();
			sitename.function3.fInit();
			sitename.function4();
		},
		
		/**
		  *  Puts title text in the field on the search box
		  */	
		searchReplace : function() {

			var searchBox = $("#edit-search-theme-form-1");
			var searchBoxDefault = "Enter keywords";
			searchBox.attr("value", searchBoxDefault);
				
			searchBox.focus(function(){  
			  if(jQuery.trim($(this).attr("value")) == searchBoxDefault) $(this).attr("value", "");  
			});  
			
			searchBox.blur(function(){  
			  if(jQuery.trim($(this).attr("value")) == "") $(this).attr("value", searchBoxDefault);  
			})
		},
		
		/**
		  *  function 2 
		  */
		function2 : function() {
			//code here
	 	},
		
		/**
		  *  function 3
		  */
		function3 : {
			fInit : function() {
				//initialise function 3
				sitename.function3.helperfunction1();
				sitename.function3.helperfunction2();
			},
			
			helperfunction1 : function() {
				//code here
			},
			
			helperfunction2 : function() {
				//code here
			}
	 	},
		
		/**
		  *  function 4 
		  */
		function4 : function() {
			//code here
	 	}
	} //end of sitename
	
	/**
	  *  Initialise sitename
	  */
	sitename.init();

}

Initial URL

                                

Initial Description

                                

Initial Title
Drupal JS Namespacing Blueprint with Search Text Replace

Initial Tags
jquery, drupal

Initial Language
jQuery