Javascript menu modifications

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Richard Cornford

    #16
    Re: Javascript menu modifications

    Rob B wrote:[color=blue]
    > Resubmitted:
    >
    > Or...
    >
    > function initMenu(item)
    > {
    > var menus, menu, text, a, i;
    > if (item) item = new RegExp(item);
    > menus = getChildrenByEl ement(document. getElementById( "menu"));
    > for(i = 0; i < menus.length; i++)
    > {
    > menu = menus[i];
    > text = getFirstChildBy Text(menu);
    > a = document.create Element("a");
    > menu.replaceChi ld(a, text);
    > a.appendChild(t ext);
    > a.href = "#";
    > a.onclick = showMenu;
    > a.onfocus = function(){this .blur()};
    > if (item && item.test(text. nodeValue))
    > a.onclick();
    > }
    > }
    >
    > ..and in specific pages:
    >
    > if(document.cre ateElement)
    > window.onload = function()
    > {
    > initMenu('Menu Item 3');
    > }[/color]

    If you are going to post code that will error-out and fail
    uncontrollably on known user agents (due to inadequate feature
    detection), the least you should do is list the subset of browsers on
    which you know it should work, so that readers can appreciate how far
    short of being cross-browser they can expect your code to be.

    Richard.


    Comment

    • RobB

      #17
      Re: Javascript menu modifications

      Richard Cornford wrote:[color=blue]
      > Rob B wrote:[color=green]
      > > Resubmitted:
      > >
      > > Or...
      > >
      > > function initMenu(item)
      > > {
      > > var menus, menu, text, a, i;
      > > if (item) item = new RegExp(item);
      > > menus = getChildrenByEl ement(document. getElementById( "menu"));
      > > for(i = 0; i < menus.length; i++)
      > > {
      > > menu = menus[i];
      > > text = getFirstChildBy Text(menu);
      > > a = document.create Element("a");
      > > menu.replaceChi ld(a, text);
      > > a.appendChild(t ext);
      > > a.href = "#";
      > > a.onclick = showMenu;
      > > a.onfocus = function(){this .blur()};
      > > if (item && item.test(text. nodeValue))
      > > a.onclick();
      > > }
      > > }
      > >
      > > ..and in specific pages:
      > >
      > > if(document.cre ateElement)
      > > window.onload = function()
      > > {
      > > initMenu('Menu Item 3');
      > > }[/color]
      >
      > If you are going to post code that will error-out and fail
      > uncontrollably on known user agents (due to inadequate feature
      > detection), the least you should do is list the subset of browsers on
      > which you know it should work, so that readers can appreciate how far
      > short of being cross-browser they can expect your code to be.
      >
      > Richard.[/color]

      If I understand you correctly, there's a simple answer: it's not my
      ('your') code. The only thing I appended to it was a regular expression
      construction and method, invocation of an HTML event handler
      explicitly, and extraction of a text node's cdata for comparison. Are
      there any user agents that will render the original menu yet fail with
      these simple additions?

      I agree that 'if (document.creat eElement)...' is insufficient sniffing
      for an application of this sort - but I don't feel it's the
      responsibility of contributors here to rewrite third-party scripts to
      make them less prone to 'error-out and fail'. Most - OK, *some* - of
      these scripts come with caveats about their coverage, and users will
      hopefully be aware of these.

      Comment

      Working...