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

Re: [ydn-javascript] Re: dynamic context menu??

Expand Messages
  • priya rupa
    Todd I suspect that ,some how the context menu is saving the state of the previous element click every time... I am calling onContextMenuInit function in the
    Message 1 of 10 , Jul 29 8:17 PM
    • 0 Attachment
      Todd

      I suspect that ,some how the context menu is saving
      the state of the previous element click every time...

      I am calling onContextMenuInit function in the
      findState,and the findState function in the jsp
      page,i.e whenever the user does a mousekey down click
      event on the element, the id of that element is being
      passed into findState.....

      Please suggest ,how to get off this problem??

      Thanks Priya


      --- Todd Kloots <kloots@...> wrote:

      > Priya -
      >
      > How are these functions "findState" and
      > "onContextMenuInit" getting called? Every time a
      > context menu is displayed? If so, realize that you
      > are calling "addItem" which keeps adding more items
      > to
      > the same context menu. My guess is that is the
      > problem.
      >
      > - Todd
      >
      > --- priya_806 <priya_806@...> wrote:
      >
      > > Here is my snippet...
      > >
      > > var oContextMenu;
      > > function findState(id){
      > > this.id=document.getElementById(id);
      > > this.st = this.id.className;
      > > onContextMenuInit();
      > > oContextMenu.render(document.body);
      > > }
      > >
      > > function onContextMenuInit(){
      > >
      > > var aImages =
      > > document.getElementsByTagName("img");
      > > oContextMenu = new YAHOO.widget.ContextMenu
      > > ("contextmenu", { trigger:aImages});
      > > var aMenuItemData =["Enable","Disable"],
      > > n=aMenuItemData.length,oMenuItem;
      > >
      > > for(var i=0;i<n;i++){
      > >
      > > oMenuItem=oContextMenu.addItem(aMenuItemData[i]);
      > > oMenuItem.element.id =
      > > aMenuItemData[i];
      > > }
      > > oContextMenu.addItem(new
      > > YAHOO.widget.ContextMenuItem
      > > ("Properties"),1);
      > > oContextMenu.addItem(new
      > > YAHOO.widget.ContextMenuItem
      > > ("Edit"),1);
      > >
      > > if(st=='Enabled') {
      > >
      > > oContextMenu.getItem(0).cfg.setProperty("checked",
      > > true);
      > >
      > >
      > oContextMenu.getItem(0).cfg.setProperty("disabled",
      > > true);
      > > } else if(st=='Disabled') {
      > >
      > > oContextMenu.getItem(1).cfg.setProperty("checked",
      > > true);
      > >
      > >
      > oContextMenu.getItem(1).cfg.setProperty("disabled",
      > > true);
      > > }
      > >
      > > }
      > >
      > > I am calling the findState function in my jsp
      > > page...
      > > hope this helps finding solution for my problem
      > >
      > > Priya
      > >
      > >
      > >
      > > --- In ydn-javascript@yahoogroups.com, Todd Kloots
      > > <kloots@...>
      > > wrote:
      > > >
      > > > Priya -
      > > >
      > > > Can you provide a snippet of your context menu
      > > code?
      > > > Otherwise it'll be difficult to help you.
      > > >
      > > > - Todd
      > > >
      > > > --- priya_806 <priya_806@...> wrote:
      > > >
      > > > > I solved my problem in displaying a dynamic
      > > menu,but
      > > > > now I am having
      > > > > a new problem..
      > > > >
      > > > > My context menu is getting appended....for
      > > example
      > > > > if I click on one
      > > > > element ,menu displays as ( enable,disable)
      > > ,again
      > > > > when I click on
      > > > > next element ,menu gets added and displaying
      > > > > (enable,disable,enable,disable)
      > > > >
      > > > > Please advice
      > > > > Thanks
      > > > > Priya
      > > > >
      > > > >
      > > > > --- In ydn-javascript@yahoogroups.com,
      > > "priya_806"
      > > > > <priya_806@>
      > > > > wrote:
      > > > > >
      > > > > > Todd
      > > > > >
      > > > > > How can I add the "beforeShowEvent" handler
      > to
      > > my
      > > > > context
      > > > > > menu...which changes the text(or show and
      > > hide)of
      > > > > relevant element
      > > > > > in the context menu on the fly,depending on
      > > the
      > > > > state of element??
      > > > > >
      > > > > > the context menu is being constructed as
      > soon
      > > as
      > > > > the window get
      > > > > > loaded by
      > > > > > YAHOO.util.Event.addListener(window,
      > > > > "load",onWindowLoad);
      > > > > >
      > > > > > its not changing on fly,once the context
      > menu
      > > gets
      > > > > loaded,its
      > > > > > remaining the same for each and every
      > > > > element.....which should
      > > > > > change depending on state!!!!
      > > > > >
      > > > > > Please advice
      > > > > >
      > > > > > Thanks in advance
      > > > > > Priya
      > > > > >
      > > > > >
      > > > > >
      > > > > > --- In ydn-javascript@yahoogroups.com, Todd
      > > Kloots
      > > > > <kloots@>
      > > > > > wrote:
      > > > > > >
      > > > > > > Priya -
      > > > > > >
      > > > > > > I would add a "beforeShowEvent" handler to
      > > your
      > > > > > > context menu that would consider the state
      > > of
      > > > > the item
      > > > > > > to which it is bound and alter the items
      > of
      > > the
      > > > > menu
      > > > > > > accordingly.
      > > > > > >
      > > > > > > You could either have one menu item that
      > you
      > > > > toggle
      > > > > > > the text of on the fly via the MenuItem's
      > > "text"
      > > > > > > configuration property. Something like:
      > > > > > >
      > > > > > > function onBeforeShow() {
      > > > > > >
      > > > > > > ...
      > > > > > >
      > > > > > > this.getItem(0).cfg.setProperty("text",
      > > > > > > "disabled");
      > > > > > >
      > > > > > > ...
      > > > > > >
      > > > > > > }
      > > > > > >
      > > > > > >
      > > > > > > OR - you could have both an "enable" and
      > > > > "disable"
      > > > > > > item in your ContextMenu instance and show
      > > or
      > > > > hide the
      > > > > > > relevant item on the fly. Something like:
      > > > > > >
      > > > > > > function onBeforeShow() {
      > > > > > >
      > > > > > > ...
      > > > > > >
      > > > > > > this.getItem(0).element.style.display =
      > > > > "none";
      > > > > > >
      > > > > > > ...
      > > > > > >
      >
      === message truncated ===


      __________________________________________________
      Do You Yahoo!?
      Tired of spam? Yahoo! Mail has the best spam protection around
      http://mail.yahoo.com
    • Todd Kloots
      Priya - If you look at your code you ll see that your onContextMenuInit is the problem. That function adds two items to the context menu and, as you said,
      Message 2 of 10 , Jul 31 10:45 AM
      • 0 Attachment
        Priya -

        If you look at your code you'll see that your
        "onContextMenuInit" is the problem. That function
        adds two items to the context menu and, as you said,
        you're calling that function "whenever the user does a
        mousekey down click." So, with every click you're
        appending new items to an existing menu.

        You need to design your code so that you create the
        context menu once and tweak the state of the items
        before it is displayed.

        I have created an example page to demonstrate:

        http://yuiblog.com/sandbox/yui/v011/examples/menu/example07.php

        - Todd

        --- priya rupa <priya_806@...> wrote:

        > Todd
        >
        > I suspect that ,some how the context menu is saving
        > the state of the previous element click every
        > time...
        >
        > I am calling onContextMenuInit function in the
        > findState,and the findState function in the jsp
        > page,i.e whenever the user does a mousekey down
        > click
        > event on the element, the id of that element is
        > being
        > passed into findState.....
        >
        > Please suggest ,how to get off this problem??
        >
        > Thanks Priya
        >
        >
        > --- Todd Kloots <kloots@...> wrote:
        >
        > > Priya -
        > >
        > > How are these functions "findState" and
        > > "onContextMenuInit" getting called? Every time a
        > > context menu is displayed? If so, realize that
        > you
        > > are calling "addItem" which keeps adding more
        > items
        > > to
        > > the same context menu. My guess is that is the
        > > problem.
        > >
        > > - Todd
        > >
        > > --- priya_806 <priya_806@...> wrote:
        > >
        > > > Here is my snippet...
        > > >
        > > > var oContextMenu;
        > > > function findState(id){
        > > > this.id=document.getElementById(id);
        > > > this.st = this.id.className;
        > > > onContextMenuInit();
        > > > oContextMenu.render(document.body);
        > > > }
        > > >
        > > > function onContextMenuInit(){
        > > >
        > > > var aImages =
        > > > document.getElementsByTagName("img");
        > > > oContextMenu = new YAHOO.widget.ContextMenu
        > > > ("contextmenu", { trigger:aImages});
        > > > var aMenuItemData =["Enable","Disable"],
        > > > n=aMenuItemData.length,oMenuItem;
        > > >
        > > > for(var i=0;i<n;i++){
        > > >
        > > >
        > oMenuItem=oContextMenu.addItem(aMenuItemData[i]);
        > > > oMenuItem.element.id =
        > > > aMenuItemData[i];
        > > > }
        > > > oContextMenu.addItem(new
        > > > YAHOO.widget.ContextMenuItem
        > > > ("Properties"),1);
        > > > oContextMenu.addItem(new
        > > > YAHOO.widget.ContextMenuItem
        > > > ("Edit"),1);
        > > >
        > > > if(st=='Enabled') {
        > > >
        > > >
        > oContextMenu.getItem(0).cfg.setProperty("checked",
        > > > true);
        > > >
        > > >
        > >
        > oContextMenu.getItem(0).cfg.setProperty("disabled",
        > > > true);
        > > > } else if(st=='Disabled') {
        > > >
        > > >
        > oContextMenu.getItem(1).cfg.setProperty("checked",
        > > > true);
        > > >
        > > >
        > >
        > oContextMenu.getItem(1).cfg.setProperty("disabled",
        > > > true);
        > > > }
        > > >
        > > > }
        > > >
        > > > I am calling the findState function in my jsp
        > > > page...
        > > > hope this helps finding solution for my problem
        > > >
        > > > Priya
        > > >
        > > >
        > > >
        > > > --- In ydn-javascript@yahoogroups.com, Todd
        > Kloots
        > > > <kloots@...>
        > > > wrote:
        > > > >
        > > > > Priya -
        > > > >
        > > > > Can you provide a snippet of your context menu
        > > > code?
        > > > > Otherwise it'll be difficult to help you.
        > > > >
        > > > > - Todd
        > > > >
        > > > > --- priya_806 <priya_806@...> wrote:
        > > > >
        > > > > > I solved my problem in displaying a dynamic
        > > > menu,but
        > > > > > now I am having
        > > > > > a new problem..
        > > > > >
        > > > > > My context menu is getting appended....for
        > > > example
        > > > > > if I click on one
        > > > > > element ,menu displays as ( enable,disable)
        > > > ,again
        > > > > > when I click on
        > > > > > next element ,menu gets added and displaying
        > > > > > (enable,disable,enable,disable)
        > > > > >
        > > > > > Please advice
        > > > > > Thanks
        > > > > > Priya
        > > > > >
        > > > > >
        > > > > > --- In ydn-javascript@yahoogroups.com,
        > > > "priya_806"
        > > > > > <priya_806@>
        > > > > > wrote:
        > > > > > >
        > > > > > > Todd
        > > > > > >
        > > > > > > How can I add the "beforeShowEvent"
        > handler
        > > to
        > > > my
        > > > > > context
        > > > > > > menu...which changes the text(or show and
        > > > hide)of
        > > > > > relevant element
        > > > > > > in the context menu on the fly,depending
        > on
        > > > the
        > > > > > state of element??
        > > > > > >
        > > > > > > the context menu is being constructed as
        > > soon
        > > > as
        > > > > > the window get
        > > > > > > loaded by
        > > > > > > YAHOO.util.Event.addListener(window,
        > > > > > "load",onWindowLoad);
        > > > > > >
        > > > > > > its not changing on fly,once the context
        > > menu
        > > > gets
        > > > > > loaded,its
        > > > > > > remaining the same for each and every
        > > > > > element.....which should
        > > > > > > change depending on state!!!!
        > > > > > >
        > > > > > > Please advice
        > > > > > >
        > > > > > > Thanks in advance
        > > > > > > Priya
        > > > > > >
        > > > > > >
        > > > > > >
        > > > > > > --- In ydn-javascript@yahoogroups.com,
        > Todd
        > > > Kloots
        > > > > > <kloots@>
        > > > > > > wrote:
        > > > > > > >
        > > > > > > > Priya -
        > > > > > > >
        > > > > > > > I would add a "beforeShowEvent" handler
        > to
        > > > your
        > > > > > > > context menu that would consider the
        > state
        > > > of
        > > > > > the item
        > > > > > > > to which it is bound and alter the items
        > > of
        > > > the
        > > > > > menu
        > > > > > > > accordingly.
        > > > > > > >
        > > > > > > > You could either have one menu item that
        >
        === message truncated ===
      • priya_806
        Thank you, Todd...I too figured out that my onContextMenuInit is the problem ,which is making menus add up every time... I appreciate ur help...Priya
        Message 3 of 10 , Jul 31 3:05 PM
        • 0 Attachment
          Thank you, Todd...I too figured out that my onContextMenuInit is the
          problem ,which is making menus add up every time...

          I appreciate ur help...Priya

          --- In ydn-javascript@yahoogroups.com, Todd Kloots <kloots@...>
          wrote:
          >
          > Priya -
          >
          > If you look at your code you'll see that your
          > "onContextMenuInit" is the problem. That function
          > adds two items to the context menu and, as you said,
          > you're calling that function "whenever the user does a
          > mousekey down click." So, with every click you're
          > appending new items to an existing menu.
          >
          > You need to design your code so that you create the
          > context menu once and tweak the state of the items
          > before it is displayed.
          >
          > I have created an example page to demonstrate:
          >
          > http://yuiblog.com/sandbox/yui/v011/examples/menu/example07.php
          >
          > - Todd
          >
          > --- priya rupa <priya_806@...> wrote:
          >
          > > Todd
          > >
          > > I suspect that ,some how the context menu is saving
          > > the state of the previous element click every
          > > time...
          > >
          > > I am calling onContextMenuInit function in the
          > > findState,and the findState function in the jsp
          > > page,i.e whenever the user does a mousekey down
          > > click
          > > event on the element, the id of that element is
          > > being
          > > passed into findState.....
          > >
          > > Please suggest ,how to get off this problem??
          > >
          > > Thanks Priya
          > >
          > >
          > > --- Todd Kloots <kloots@...> wrote:
          > >
          > > > Priya -
          > > >
          > > > How are these functions "findState" and
          > > > "onContextMenuInit" getting called? Every time a
          > > > context menu is displayed? If so, realize that
          > > you
          > > > are calling "addItem" which keeps adding more
          > > items
          > > > to
          > > > the same context menu. My guess is that is the
          > > > problem.
          > > >
          > > > - Todd
          > > >
          > > > --- priya_806 <priya_806@...> wrote:
          > > >
          > > > > Here is my snippet...
          > > > >
          > > > > var oContextMenu;
          > > > > function findState(id){
          > > > > this.id=document.getElementById(id);
          > > > > this.st = this.id.className;
          > > > > onContextMenuInit();
          > > > > oContextMenu.render(document.body);
          > > > > }
          > > > >
          > > > > function onContextMenuInit(){
          > > > >
          > > > > var aImages =
          > > > > document.getElementsByTagName("img");
          > > > > oContextMenu = new YAHOO.widget.ContextMenu
          > > > > ("contextmenu", { trigger:aImages});
          > > > > var aMenuItemData =["Enable","Disable"],
          > > > > n=aMenuItemData.length,oMenuItem;
          > > > >
          > > > > for(var i=0;i<n;i++){
          > > > >
          > > > >
          > > oMenuItem=oContextMenu.addItem(aMenuItemData[i]);
          > > > > oMenuItem.element.id =
          > > > > aMenuItemData[i];
          > > > > }
          > > > > oContextMenu.addItem(new
          > > > > YAHOO.widget.ContextMenuItem
          > > > > ("Properties"),1);
          > > > > oContextMenu.addItem(new
          > > > > YAHOO.widget.ContextMenuItem
          > > > > ("Edit"),1);
          > > > >
          > > > > if(st=='Enabled') {
          > > > >
          > > > >
          > > oContextMenu.getItem(0).cfg.setProperty("checked",
          > > > > true);
          > > > >
          > > > >
          > > >
          > > oContextMenu.getItem(0).cfg.setProperty("disabled",
          > > > > true);
          > > > > } else if(st=='Disabled') {
          > > > >
          > > > >
          > > oContextMenu.getItem(1).cfg.setProperty("checked",
          > > > > true);
          > > > >
          > > > >
          > > >
          > > oContextMenu.getItem(1).cfg.setProperty("disabled",
          > > > > true);
          > > > > }
          > > > >
          > > > > }
          > > > >
          > > > > I am calling the findState function in my jsp
          > > > > page...
          > > > > hope this helps finding solution for my problem
          > > > >
          > > > > Priya
          > > > >
          > > > >
          > > > >
          > > > > --- In ydn-javascript@yahoogroups.com, Todd
          > > Kloots
          > > > > <kloots@>
          > > > > wrote:
          > > > > >
          > > > > > Priya -
          > > > > >
          > > > > > Can you provide a snippet of your context menu
          > > > > code?
          > > > > > Otherwise it'll be difficult to help you.
          > > > > >
          > > > > > - Todd
          > > > > >
          > > > > > --- priya_806 <priya_806@> wrote:
          > > > > >
          > > > > > > I solved my problem in displaying a dynamic
          > > > > menu,but
          > > > > > > now I am having
          > > > > > > a new problem..
          > > > > > >
          > > > > > > My context menu is getting appended....for
          > > > > example
          > > > > > > if I click on one
          > > > > > > element ,menu displays as ( enable,disable)
          > > > > ,again
          > > > > > > when I click on
          > > > > > > next element ,menu gets added and displaying
          > > > > > > (enable,disable,enable,disable)
          > > > > > >
          > > > > > > Please advice
          > > > > > > Thanks
          > > > > > > Priya
          > > > > > >
          > > > > > >
          > > > > > > --- In ydn-javascript@yahoogroups.com,
          > > > > "priya_806"
          > > > > > > <priya_806@>
          > > > > > > wrote:
          > > > > > > >
          > > > > > > > Todd
          > > > > > > >
          > > > > > > > How can I add the "beforeShowEvent"
          > > handler
          > > > to
          > > > > my
          > > > > > > context
          > > > > > > > menu...which changes the text(or show and
          > > > > hide)of
          > > > > > > relevant element
          > > > > > > > in the context menu on the fly,depending
          > > on
          > > > > the
          > > > > > > state of element??
          > > > > > > >
          > > > > > > > the context menu is being constructed as
          > > > soon
          > > > > as
          > > > > > > the window get
          > > > > > > > loaded by
          > > > > > > > YAHOO.util.Event.addListener(window,
          > > > > > > "load",onWindowLoad);
          > > > > > > >
          > > > > > > > its not changing on fly,once the context
          > > > menu
          > > > > gets
          > > > > > > loaded,its
          > > > > > > > remaining the same for each and every
          > > > > > > element.....which should
          > > > > > > > change depending on state!!!!
          > > > > > > >
          > > > > > > > Please advice
          > > > > > > >
          > > > > > > > Thanks in advance
          > > > > > > > Priya
          > > > > > > >
          > > > > > > >
          > > > > > > >
          > > > > > > > --- In ydn-javascript@yahoogroups.com,
          > > Todd
          > > > > Kloots
          > > > > > > <kloots@>
          > > > > > > > wrote:
          > > > > > > > >
          > > > > > > > > Priya -
          > > > > > > > >
          > > > > > > > > I would add a "beforeShowEvent" handler
          > > to
          > > > > your
          > > > > > > > > context menu that would consider the
          > > state
          > > > > of
          > > > > > > the item
          > > > > > > > > to which it is bound and alter the items
          > > > of
          > > > > the
          > > > > > > menu
          > > > > > > > > accordingly.
          > > > > > > > >
          > > > > > > > > You could either have one menu item that
          > >
          > === message truncated ===
          >
        Your message has been successfully submitted and would be delivered to recipients shortly.