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

Browser History Manager

Expand Messages
  • dvidluca
    I m having a little difficulty getting to grips with the BHM utility; in the documentation it says that a module must be registered with the BHM before the BHM
    Message 1 of 2 , Feb 13, 2008
      I'm having a little difficulty getting to grips with the BHM utility;
      in the documentation it says that a module must be registered with
      the BHM before the BHM is initialized, however in the calendar-bhm
      example linked to from the BHM documentation, it appears that the
      calendar module is not registered until the calendar is interacted
      with. The following page, which is basically the same as the
      example, has an alert inserted into the register function and if you
      run the page, the alert doesn't appear until the month is changed:


      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML
      4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
      <html>
      <head>
      <title>BHM Test</title>
      <script type="text/javascript"
      src="http://yui.yahooapis.com/2.4.1/build/yahoo-dom-event/yahoo-dom-
      event.js"></script>
      <script type="text/javascript"
      src="http://yui.yahooapis.com/2.4.1/build/calendar/calendar-
      min.js"></script>
      <script type="text/javascript"
      src="http://yui.yahooapis.com/2.4.1/build/history/history-
      min.js"></script>
      <link rel="stylesheet" type="text/css"
      href="yui/build/calendar/assets/skins/sam/calendar.css">
      </head>
      <body class="yui-skin-sam">
      <iframe id="yui-history-iframe" src="yahoo.gif"></iframe>
      <input id="yui-history-field" type="hidden">
      <div id="cal"></div>
      <script type="text/javascript">
      var initPage = function() {

      var today = new Date();
      var initialState = (today.getMonth() + 1) + "_" +
      today.getFullYear();
      var calObj;

      YAHOO.util.History.register("calObj", initialState, function
      (state) {
      alert("register"); // <- here's the alert!
      calObj.cfg.setProperty("pagedate", state.replace("_", "/"));
      calObj.render();
      });

      function handleCalendarBeforeRender () {

      var calDate = calObj.cfg.getProperty("pageDate");
      var newState = (calDate.getMonth() + 1) + "_" +
      calDate.getFullYear();
      var currentState = YAHOO.util.History.getCurrentState
      ("calObj");

      if (newState !== currentState) {
      YAHOO.util.History.navigate("calObj", newState);
      }
      }

      function initCalendar (startDate) {
      calObj = new YAHOO.widget.Calendar("calObj", "cal",
      startDate);
      calObj.beforeRenderEvent.subscribe
      (handleCalendarBeforeRender, calObj, true);
      calObj.render();
      }

      YAHOO.util.History.onReady(function () {
      var currentState = YAHOO.util.History.getCurrentState
      ("calObj");
      initCalendar({ pagedate: currentState.replace("_", "/") });
      });

      YAHOO.util.History.initialize("yui-history-field", "yui-
      history-iframe");

      };

      //create calendar on page load
      YAHOO.util.Event.onDOMReady(initPage);
      </script>
      </body>
      </html>


      Sorry there's no test page up to view, I tried to put it on my
      geocities site but the page stops working as soon as it's online
      (even though it runs perfectly on my localhost apache installation on
      my PC)

      What is going on, why isn't the register alert shown before the
      calendar is rendered?
    Your message has been successfully submitted and would be delivered to recipients shortly.