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

click event subscription occuring multiple times

Expand Messages
  • bp_fcc
    Hi guys. I m hoping I can get some help with an event issue I m experiencing. Here is what is going on. I m using the YUI connection-manager to make ajax
    Message 1 of 5 , Apr 2, 2009
    • 0 Attachment
      Hi guys. I'm hoping I can get some help with an event issue I'm experiencing.

      Here is what is going on. I'm using the YUI connection-manager to make ajax requests. I created my own class to handle this.

      ajax(elementid)
      --------------------
      + getPage() - uses conn-man to make an ajax request
      - responseSuccess() - callback success fn
      - responseFailure() - callback failure fn
      - loadCustomEvent() - loads the YUI event object, creates onPageLoad custom event
      --------------------
      + onPageLoad:YUICustomEvent
      - elementid:string
      - isCustomEventLoaded:boolean
      - callback:jsobject

      What happens is the responseSuccess() fn fires the onPageLoad objects fire fn to announce that the ajax function successfully loaded. I then have a js function that is subscribed to the onPageLoad custom event. This function adds a listener to two anchor elements's click events to create pagination links.

      The problem is that when I click the "content_taglist_Nextlink" anchor (paginate next), and then click the "content_taglist_Previous" anchor (paginate previous), the the previous click event is executed twice, adding one for each time this specific user interaction occurs. This does not happen when next is clicked multiple times, or n-times then previous, or previous then next n-times. It only occurs when on the first instance of the ajax request, next is clicked, then previous is clicked.

      content_taglist = new ajax("content_taglist") ;

      function addOnclickListeners() {
      var Event = YAHOO.util.Event
      Event.addListener("content_taglist_Previouslink", "click", content_taglist.previous, {emptyobject:"empty"}, content_taglist) ;
      Event.addListener("content_taglist_Nextlink", "click", content_taglist.next, {emptyobject:"empty"}, content_taglist) ;
      }
      content_taglist.onPageLoad.subscribe(addOnclickListeners) ;

      Does anyone have anyideas?
    • Adam Moore
      ... Well, addOnclickListeners must be being called multiple times -- you need to track down why that is. -Adam
      Message 2 of 5 , Apr 2, 2009
      • 0 Attachment
        On Thu, Apr 02, 2009 at 05:23:48PM -0000, bp_fcc wrote:
        > Hi guys. I'm hoping I can get some help with an event issue I'm experiencing.
        >
        > Here is what is going on. I'm using the YUI connection-manager to make ajax requests. I created my own class to handle this.
        >
        > ajax(elementid)
        > --------------------
        > + getPage() - uses conn-man to make an ajax request
        > - responseSuccess() - callback success fn
        > - responseFailure() - callback failure fn
        > - loadCustomEvent() - loads the YUI event object, creates onPageLoad custom event
        > --------------------
        > + onPageLoad:YUICustomEvent
        > - elementid:string
        > - isCustomEventLoaded:boolean
        > - callback:jsobject
        >
        > What happens is the responseSuccess() fn fires the onPageLoad objects fire fn to announce that the ajax function successfully loaded. I then have a js function that is subscribed to the onPageLoad custom event. This function adds a listener to two anchor elements's click events to create pagination links.
        >
        > The problem is that when I click the "content_taglist_Nextlink" anchor (paginate next), and then click the "content_taglist_Previous" anchor (paginate previous), the the previous click event is executed twice, adding one for each time this specific user interaction occurs. This does not happen when next is clicked multiple times, or n-times then previous, or previous then next n-times. It only occurs when on the first instance of the ajax request, next is clicked, then previous is clicked.
        >
        > content_taglist = new ajax("content_taglist") ;
        >
        > function addOnclickListeners() {
        > var Event = YAHOO.util.Event
        > Event.addListener("content_taglist_Previouslink", "click", content_taglist.previous, {emptyobject:"empty"}, content_taglist) ;
        > Event.addListener("content_taglist_Nextlink", "click", content_taglist.next, {emptyobject:"empty"}, content_taglist) ;
        > }
        > content_taglist.onPageLoad.subscribe(addOnclickListeners) ;
        >
        > Does anyone have anyideas?

        Well, addOnclickListeners must be being called multiple times -- you
        need to track down why that is.

        -Adam
      • bp_fcc
        ... Well, I verified that this isn t the case. addOnclickListeners isn t being called twice, yet it seems the previous() is being applied to the PreviousLink
        Message 3 of 5 , Apr 3, 2009
        • 0 Attachment
          --- In ydn-javascript@yahoogroups.com, Adam Moore <adamoore@...> wrote:
          >
          > On Thu, Apr 02, 2009 at 05:23:48PM -0000, bp_fcc wrote:
          > > Hi guys. I'm hoping I can get some help with an event issue I'm experiencing.
          > >
          > > Here is what is going on. I'm using the YUI connection-manager to make ajax requests. I created my own class to handle this.
          > >
          > > ajax(elementid)
          > > --------------------
          > > + getPage() - uses conn-man to make an ajax request
          > > - responseSuccess() - callback success fn
          > > - responseFailure() - callback failure fn
          > > - loadCustomEvent() - loads the YUI event object, creates onPageLoad custom event
          > > --------------------
          > > + onPageLoad:YUICustomEvent
          > > - elementid:string
          > > - isCustomEventLoaded:boolean
          > > - callback:jsobject
          > >
          > > What happens is the responseSuccess() fn fires the onPageLoad objects fire fn to announce that the ajax function successfully loaded. I then have a js function that is subscribed to the onPageLoad custom event. This function adds a listener to two anchor elements's click events to create pagination links.
          > >
          > > The problem is that when I click the "content_taglist_Nextlink" anchor (paginate next), and then click the "content_taglist_Previous" anchor (paginate previous), the the previous click event is executed twice, adding one for each time this specific user interaction occurs. This does not happen when next is clicked multiple times, or n-times then previous, or previous then next n-times. It only occurs when on the first instance of the ajax request, next is clicked, then previous is clicked.
          > >
          > > content_taglist = new ajax("content_taglist") ;
          > >
          > > function addOnclickListeners() {
          > > var Event = YAHOO.util.Event
          > > Event.addListener("content_taglist_Previouslink", "click", content_taglist.previous, {emptyobject:"empty"}, content_taglist) ;
          > > Event.addListener("content_taglist_Nextlink", "click", content_taglist.next, {emptyobject:"empty"}, content_taglist) ;
          > > }
          > > content_taglist.onPageLoad.subscribe(addOnclickListeners) ;
          > >
          > > Does anyone have anyideas?
          >
          > Well, addOnclickListeners must be being called multiple times -- you
          > need to track down why that is.
          >
          > -Adam
          >

          Well, I verified that this isn't the case. addOnclickListeners isn't being called twice, yet it seems the previous() is being applied to the PreviousLink twice. The wierd thing is this occurs only when one clicks next from the first page then previous from there, and never occurs any other way. And it only happens to the previous link, not the next link.
        • Adam Moore
          ... I never found case where two listeners were added when addListener was called once on a single element. Is the behavior the same in all browsers? There
          Message 4 of 5 , Apr 3, 2009
          • 0 Attachment
            On Fri, Apr 03, 2009 at 06:49:22PM -0000, bp_fcc wrote:
            > --- In ydn-javascript@yahoogroups.com, Adam Moore <adamoore@...> wrote:
            > >
            > > On Thu, Apr 02, 2009 at 05:23:48PM -0000, bp_fcc wrote:
            > > > Hi guys. I'm hoping I can get some help with an event issue I'm experiencing.
            > > >
            > > > Here is what is going on. I'm using the YUI connection-manager to make ajax requests. I created my own class to handle this.
            > > >
            > > > ajax(elementid)
            > > > --------------------
            > > > + getPage() - uses conn-man to make an ajax request
            > > > - responseSuccess() - callback success fn
            > > > - responseFailure() - callback failure fn
            > > > - loadCustomEvent() - loads the YUI event object, creates onPageLoad custom event
            > > > --------------------
            > > > + onPageLoad:YUICustomEvent
            > > > - elementid:string
            > > > - isCustomEventLoaded:boolean
            > > > - callback:jsobject
            > > >
            > > > What happens is the responseSuccess() fn fires the onPageLoad objects fire fn to announce that the ajax function successfully loaded. I then have a js function that is subscribed to the onPageLoad custom event. This function adds a listener to two anchor elements's click events to create pagination links.
            > > >
            > > > The problem is that when I click the "content_taglist_Nextlink" anchor (paginate next), and then click the "content_taglist_Previous" anchor (paginate previous), the the previous click event is executed twice, adding one for each time this specific user interaction occurs. This does not happen when next is clicked multiple times, or n-times then previous, or previous then next n-times. It only occurs when on the first instance of the ajax request, next is clicked, then previous is clicked.
            > > >
            > > > content_taglist = new ajax("content_taglist") ;
            > > >
            > > > function addOnclickListeners() {
            > > > var Event = YAHOO.util.Event
            > > > Event.addListener("content_taglist_Previouslink", "click", content_taglist.previous, {emptyobject:"empty"}, content_taglist) ;
            > > > Event.addListener("content_taglist_Nextlink", "click", content_taglist.next, {emptyobject:"empty"}, content_taglist) ;
            > > > }
            > > > content_taglist.onPageLoad.subscribe(addOnclickListeners) ;
            > > >
            > > > Does anyone have anyideas?
            > >
            > > Well, addOnclickListeners must be being called multiple times -- you
            > > need to track down why that is.
            > >
            > > -Adam
            > >
            >

            > Well, I verified that this isn't the case. addOnclickListeners isn't
            > being called twice, yet it seems the previous() is being applied to
            > the PreviousLink twice. The wierd thing is this occurs only when one
            > clicks next from the first page then previous from there, and never
            > occurs any other way. And it only happens to the previous link, not
            > the next link.

            I never found case where two listeners were added when addListener
            was called once on a single element. Is the behavior the same
            in all browsers? There isn't much more I can add without a link to
            the application.

            -Adam
          • bp_fcc
            ... oh sweet, I figured it out. The links I am adding the listeners to are constructed as part of each ajax call. The previous link doesn t display/exist on
            Message 5 of 5 , Apr 3, 2009
            • 0 Attachment
              --- In ydn-javascript@yahoogroups.com, Adam Moore <adamoore@...> wrote:
              >
              > On Thu, Apr 02, 2009 at 05:23:48PM -0000, bp_fcc wrote:
              > > Hi guys. I'm hoping I can get some help with an event issue I'm experiencing.
              > >
              > > Here is what is going on. I'm using the YUI connection-manager to make ajax requests. I created my own class to handle this.
              > >
              > > ajax(elementid)
              > > --------------------
              > > + getPage() - uses conn-man to make an ajax request
              > > - responseSuccess() - callback success fn
              > > - responseFailure() - callback failure fn
              > > - loadCustomEvent() - loads the YUI event object, creates onPageLoad custom event
              > > --------------------
              > > + onPageLoad:YUICustomEvent
              > > - elementid:string
              > > - isCustomEventLoaded:boolean
              > > - callback:jsobject
              > >
              > > What happens is the responseSuccess() fn fires the onPageLoad objects fire fn to announce that the ajax function successfully loaded. I then have a js function that is subscribed to the onPageLoad custom event. This function adds a listener to two anchor elements's click events to create pagination links.
              > >
              > > The problem is that when I click the "content_taglist_Nextlink" anchor (paginate next), and then click the "content_taglist_Previous" anchor (paginate previous), the the previous click event is executed twice, adding one for each time this specific user interaction occurs. This does not happen when next is clicked multiple times, or n-times then previous, or previous then next n-times. It only occurs when on the first instance of the ajax request, next is clicked, then previous is clicked.
              > >
              > > content_taglist = new ajax("content_taglist") ;
              > >
              > > function addOnclickListeners() {
              > > var Event = YAHOO.util.Event
              > > Event.addListener("content_taglist_Previouslink", "click", content_taglist.previous, {emptyobject:"empty"}, content_taglist) ;
              > > Event.addListener("content_taglist_Nextlink", "click", content_taglist.next, {emptyobject:"empty"}, content_taglist) ;
              > > }
              > > content_taglist.onPageLoad.subscribe(addOnclickListeners) ;
              > >
              > > Does anyone have anyideas?
              >
              > Well, addOnclickListeners must be being called multiple times -- you
              > need to track down why that is.
              >
              > -Adam
              >
              oh sweet, I figured it out. The links I am adding the listeners to are constructed as part of each ajax call. The previous link doesn't display/exist on that first page (because its the first page) so each time the next button was clicked from the first page, the origional listener was still applied plus the new one, plus each new one after that. All I had to do was test for the existence of the element before adding the listener.
            Your message has been successfully submitted and would be delivered to recipients shortly.