Posted By

ReeceMarsland on 02/12/10


Tagged

jquery drupal namespace


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

EkTrOn


Drupal JS Namespacing Blueprint


 / Published in: jQuery
 

  1. Drupal.behaviors.themeNameSpace = function(){
  2.  
  3. /**
  4. * Set namespace
  5. */
  6. var namespace = {
  7. /**
  8. * Initialise functions within the namespace
  9. */
  10. init : function() {
  11. namespace.function1();
  12. namespace.function2();
  13. namespace.function3.fInit();
  14. namespace.function4();
  15. },
  16.  
  17. /**
  18. * function 1
  19. */
  20. function1 : function() {
  21. //code here
  22. },
  23.  
  24. /**
  25. * function 2
  26. */
  27. function2 : function() {
  28. //code here
  29. },
  30.  
  31. /**
  32. * function 3
  33. */
  34. function3 : {
  35. fInit : function() {
  36. //initialise function 3
  37. namespace.function3.helperfunction1();
  38. namespace.function3.helperfunction2();
  39. },
  40.  
  41. helperfunction1 : function() {
  42. //code here
  43. },
  44.  
  45. helperfunction2 : function() {
  46. //code here
  47. }
  48. },
  49.  
  50. /**
  51. * function 4
  52. */
  53. function4 : function() {
  54. //code here
  55. }
  56. } //end of namespace
  57.  
  58. /**
  59. * Initialise namespace
  60. */
  61. namespace.init();
  62.  
  63. }

Report this snippet  

You need to login to post a comment.