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

Re: Error in DOM.js

Expand Messages
  • kolenko_r
    Here s a sample HTML page. Please note you ll have to do the includes for the YUI libs to match your installation. If there is a better way to do this, let me
    Message 1 of 8 , Sep 5, 2006
    • 0 Attachment
      Here's a sample HTML page. Please note you'll have to do the
      includes for the YUI libs to match your installation.
      If there is a better way to do this, let me know! The gist is to
      generate an object specific context menu on the fly for all browsers.
      The onMouseOver event passes the current object and some server-side
      generated ID values to the context menu generation routine. This
      way each object's context menu can be tuned for its own purposes.
      note that this is a watered down sample, so the click event and any
      values are not used.

      Without overriding the focus and blur events you'll notice errors
      are thrown after the FIRST generation of the context menu.
      Subsequent errors are thrown once those methods are overridden.


      <html>
      <head>
      <!-- Load Yahoo UI Javascript Libraries -->
      <!-- add in the appropriate <script src.... tags here... -->
      <!-- End of Yahoo UI libraries -->

      <script language="javascript">
      function onMenuItemClick(p_sType, p_aArguments) {
      alert('clicked!');
      try{
      this.parent.hide();
      }
      catch(e){}
      }


      function loadContextMenu (obj,someImportantValue) {
      try{
      oContextMenu.destroy();
      }
      catch(e){}

      oContextMenu = new YAHOO.widget.ContextMenu("mycontextmenu", {
      trigger: obj } );
      oItem = oContextMenu.addItem(new YAHOO.widget.ContextMenuItem
      ("This Menu is for Item #"+ someImportantValue));
      oItem.clickEvent.subscribe(onMenuItemClick);
      oContextMenu.addItem(new YAHOO.widget.ContextMenuItem("item 2"));
      oContextMenu.addItem(new YAHOO.widget.ContextMenuItem("item 3"));
      oContextMenu.render("thecontextmenu");

      }
      </script>

      </head>
      <body>
      <div id="thecontextmenu"></div>


      <a id="bbb48" href="#" onmouseover="loadContextMenu(this.id,48);"
      oncontextmenu="return false;" TITLE="Test 1">Test 1</a><BR>
      <a id="bbb49" href="#" onmouseover="loadContextMenu(this.id,49);"
      oncontextmenu="return false;" TITLE="Test 2">Test 2</a>



      </body>
      </html>








      --- In ydn-javascript@yahoogroups.com, Todd Kloots <kloots@...>
      wrote:
      >
      > "kolenko_r" -
      >
      > I cannot repro the error you are seeing in IE. Can
      > you please provide a simple test case URL for us so
      > that we can determine if the problem ultimately the
      > Menu or DOM lib?
      >
      > Thanks,
      > Todd
      >
      >
    • Todd Kloots
      kolenko_r - Yeah, as I see it the problem is your approach. You are on the right track with creating the ContextMenu instances on the fly as they are
      Message 2 of 8 , Sep 6, 2006
      • 0 Attachment
        "kolenko_r" -

        Yeah, as I see it the problem is your approach. You
        are on the right track with creating the ContextMenu
        instances on the fly as they are needed. But you are
        creating and destroying the same ContextMenu instance
        over and over and over and just populating it with new
        items. That is expensive and wasteful. Why destroy a
        ContextMenu instance only to turn around a create it
        again? There is a better way:

        http://yuiblog.com/sandbox/yui/v0113/examples/menu/example04.php

        In this example, when the user mouses over an element
        that has (or is supposed to have) a context menu, I
        too create it on the fly. But the ContextMenu
        instance is then registered with an OverlayManager.
        That way the next time the user mouses over the
        "trigger" I can check if that element's ContextMenu
        has already been created. If it has, then there is no
        more work to do. The benefit is that each element has
        its own ContextMenu instance and the menu is only
        generated once.

        Make sense?

        Hope that helps.

        - Todd



        --- kolenko_r <rkolenko@...> wrote:

        > Here's a sample HTML page. Please note you'll have
        > to do the
        > includes for the YUI libs to match your
        > installation.
        > If there is a better way to do this, let me know!
        > The gist is to
        > generate an object specific context menu on the fly
        > for all browsers.
        > The onMouseOver event passes the current object and
        > some server-side
        > generated ID values to the context menu generation
        > routine. This
        > way each object's context menu can be tuned for its
        > own purposes.
        > note that this is a watered down sample, so the
        > click event and any
        > values are not used.
        >
        > Without overriding the focus and blur events you'll
        > notice errors
        > are thrown after the FIRST generation of the context
        > menu.
        > Subsequent errors are thrown once those methods are
        > overridden.
        >
        >
        > <html>
        > <head>
        > <!-- Load Yahoo UI Javascript Libraries -->
        > <!-- add in the appropriate <script src.... tags
        > here... -->
        > <!-- End of Yahoo UI libraries -->
        >
        > <script language="javascript">
        > function onMenuItemClick(p_sType, p_aArguments) {
        > alert('clicked!');
        > try{
        > this.parent.hide();
        > }
        > catch(e){}
        > }
        >
        >
        > function loadContextMenu (obj,someImportantValue) {
        > try{
        > oContextMenu.destroy();
        > }
        > catch(e){}
        >
        > oContextMenu = new
        > YAHOO.widget.ContextMenu("mycontextmenu", {
        > trigger: obj } );
        > oItem = oContextMenu.addItem(new
        > YAHOO.widget.ContextMenuItem
        > ("This Menu is for Item #"+ someImportantValue));
        > oItem.clickEvent.subscribe(onMenuItemClick);
        > oContextMenu.addItem(new
        > YAHOO.widget.ContextMenuItem("item 2"));
        > oContextMenu.addItem(new
        > YAHOO.widget.ContextMenuItem("item 3"));
        > oContextMenu.render("thecontextmenu");
        >
        > }
        > </script>
        >
        > </head>
        > <body>
        > <div id="thecontextmenu"></div>
        >
        >
        > <a id="bbb48" href="#"
        > onmouseover="loadContextMenu(this.id,48);"
        > oncontextmenu="return false;" TITLE="Test 1">Test
        > 1</a><BR>
        > <a id="bbb49" href="#"
        > onmouseover="loadContextMenu(this.id,49);"
        > oncontextmenu="return false;" TITLE="Test 2">Test
        > 2</a>
        >
        >
        >
        > </body>
        > </html>
        >
        >
        >
        >
        >
        >
        >
        >
        > --- In ydn-javascript@yahoogroups.com, Todd Kloots
        > <kloots@...>
        > wrote:
        > >
        > > "kolenko_r" -
        > >
        > > I cannot repro the error you are seeing in IE.
        > Can
        > > you please provide a simple test case URL for us
        > so
        > > that we can determine if the problem ultimately
        > the
        > > Menu or DOM lib?
        > >
        > > Thanks,
        > > Todd
        > >
        > >
        >
        >
        >
        >
        >
        >
        >
        >
        > Yahoo! Groups Links
        >
        >
        >
        >
        >
        >
        >
        >
      • kolenko_r
        Todd, Thanks for the info. I see the difference in approach. works well. however the only problem I would have in this approach is creating the list of
        Message 3 of 8 , Sep 7, 2006
        • 0 Attachment
          Todd,

          Thanks for the info. I see the difference in approach. works
          well. however the only problem I would have in this approach is
          creating the list of "YAHOO.util.Event.addListener" lines on the fly
          (just due to how the system is generating the output and not having
          the ability to manipulate the javascript dynamically).


          This is why I opted for the onmouseover event within the A tags
          themselves. Trying to keep the javascript 100% static while the
          output generated by the server (which require context menus) is 100%
          dynamic (including the ID's, "important values" etc.)







          --- In ydn-javascript@yahoogroups.com, Todd Kloots <kloots@...>
          wrote:
          >
          > "kolenko_r" -
          >
          > Yeah, as I see it the problem is your approach. You
          > are on the right track with creating the ContextMenu
          > instances on the fly as they are needed. But you are
          > creating and destroying the same ContextMenu instance
          > over and over and over and just populating it with new
          > items. That is expensive and wasteful. Why destroy a
          > ContextMenu instance only to turn around a create it
          > again? There is a better way:
          >
          > http://yuiblog.com/sandbox/yui/v0113/examples/menu/example04.php
          >
          > In this example, when the user mouses over an element
          > that has (or is supposed to have) a context menu, I
          > too create it on the fly. But the ContextMenu
          > instance is then registered with an OverlayManager.
          > That way the next time the user mouses over the
          > "trigger" I can check if that element's ContextMenu
          > has already been created. If it has, then there is no
          > more work to do. The benefit is that each element has
          > its own ContextMenu instance and the menu is only
          > generated once.
          >
          > Make sense?
          >
          > Hope that helps.
          >
          > - Todd
          >
          >
        • kolenko_r
          Todd, I rejigged your example and melded it with my approach to come up with the following: var oOverlayManager = new
          Message 4 of 8 , Sep 7, 2006
          • 0 Attachment
            Todd,

            I rejigged your example and melded it with my approach to come up
            with the following:

            <script type="text/javascript">

            var oOverlayManager = new YAHOO.widget.OverlayManager();

            function onMenuItemClick(p_sType, p_aArguments) {
            alert('clicked!');
            }



            function onLIMouseOver(id, p_nImportantValue) {

            /*
            Only create a ContextMenu instance if one doesn't
            already exist for this element
            */

            var sMenuId = "menu_" + id;

            if(!oOverlayManager.find(sMenuId)) {

            var oContextMenu = new YAHOO.widget.ContextMenu
            (sMenuId, { trigger: id } );

            oItem = oContextMenu.addItem("ContextMenu for #"+
            p_nImportantValue);

            oItem.clickEvent.subscribe(onMenuItemClick);

            oContextMenu.addItem("item 2");
            oContextMenu.addItem("item 3");

            oContextMenu.render(document.body);

            oOverlayManager.register(oContextMenu);

            }

            }

            </script>
            </head>
            <body>

            <a id="bbb48" href="#" TITLE="Test 1"
            onmouseover="onLIMouseOver('bbb48','48');">Test 1</a><BR>
            <a id="bbb49" href="#" TITLE="Test 2"
            onmouseover="onLIMouseOver('bbb49','49');">Test 2</a>

            </body>



            Using a global oOverlayManager variable which is resident for the
            life of the page allows me to use the in-tag onmouseover event (thus
            bypassing the problem I noted in my other post response).

            This works great! Thanks!



            --- In ydn-javascript@yahoogroups.com, Todd Kloots <kloots@...>
            wrote:
            >
            > "kolenko_r" -
            >
            > Yeah, as I see it the problem is your approach. You
            > are on the right track with creating the ContextMenu
            > instances on the fly as they are needed. But you are
            > creating and destroying the same ContextMenu instance
            > over and over and over and just populating it with new
            > items. That is expensive and wasteful. Why destroy a
            > ContextMenu instance only to turn around a create it
            > again? There is a better way:
            >
            > http://yuiblog.com/sandbox/yui/v0113/examples/menu/example04.php
            >
            > In this example, when the user mouses over an element
            > that has (or is supposed to have) a context menu, I
            > too create it on the fly. But the ContextMenu
            > instance is then registered with an OverlayManager.
            > That way the next time the user mouses over the
            > "trigger" I can check if that element's ContextMenu
            > has already been created. If it has, then there is no
            > more work to do. The benefit is that each element has
            > its own ContextMenu instance and the menu is only
            > generated once.
            >
            > Make sense?
            >
            > Hope that helps.
            >
            > - Todd
            >
            >
          Your message has been successfully submitted and would be delivered to recipients shortly.