Loading ...
Sorry, an error occurred while loading the content.

Problems with YAHOO.env.listeners

Expand Messages
  • Ryan V. Bayona
    Hello, Im having problems with YAHOO.env.listeners. http://developer.yahoo.com/yui/docs/Env.js.html This site says that YAHOO.env.listeners is a: List of
    Message 1 of 1 , Jan 6, 2009
    • 0 Attachment
      Hello,
      Im having problems with YAHOO.env.listeners.

      http://developer.yahoo.com/yui/docs/Env.js.html
      This site says that YAHOO.env.listeners is a:

      "List of functions that should be executed every time a YUI module
      reports itself"

      And this is how I coded it according to my understanding :

      YAHOO.env.listeners[YAHOO.env.listeners.length] = function(){
      if (YAHOO.env.getVersion('datatable') != null){
      alert('datatable');
      //execute code here
      }
      }

      It runs fine but the alert pops up twice. I wonder why?

      The reason why I wanted to understand how YAHOO.env.listeners work is
      to load page-specific js code that will initialize the YUI controls
      (because not all pages uses the same YUI components ).

      So for example in my News page i wanted to load datatable, calendar,
      and tabview, this is how i envision it :


      //loading the datatable
      YAHOO.env.listeners[YAHOO.env.listeners.length] = function (){
      //detect YAHOO module
      if (YAHOO.env.getVersion('datatable') != null){
      //execute code here to initialize datatable
      }
      //rest of the code that detects and initializes calendar and tabview...
      }

      In this way, I can just keep on adding the functions to the
      YAHOO.env.listeners.

      Thanks!
    Your message has been successfully submitted and would be delivered to recipients shortly.