Is there any possible way (I''m using prototype framework) to glean what the name of the container element to be updated (using Ajax.Updater) is? I have appended at the bottom of prototype.js a function that shows a loading dialog when any AJAX interaction takes place (I use this all the time, it''s AMAZING, feel free to use it, and if you want the rest just reply and I''ll paste all the code), but I need to cancel it for one particular element and cannot figure out a way without knowing the element name. Here''s the code: Ajax.Responders.register({ onCreate:function() { if($(''busy'') && Ajax.activeRequestCount > 0) { // show the loading dialog } } }); ..... (more code) I would love to do something like alert(Ajax.Updater.container); but that does not work, does anyone know how to do this? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
I would be interested in the full function. Terry Riegel On Jun 13, 2007, at 2:32 PM, conspireagainst wrote:> > Is there any possible way (I''m using prototype framework) to glean > what the name of the container element to be updated (using > Ajax.Updater) is? > > I have appended at the bottom of prototype.js a function that shows a > loading dialog when any AJAX interaction takes place (I use this all > the time, it''s AMAZING, feel free to use it, and if you want the rest > just reply and I''ll paste all the code), but I need to cancel it for > one particular element and cannot figure out a way without knowing the > element name. > > Here''s the code: > > Ajax.Responders.register({ > onCreate:function() { > if($(''busy'') && Ajax.activeRequestCount > 0) { > // show the loading dialog > } > } > }); > > ..... (more code) > > I would love to do something like alert(Ajax.Updater.container); but > that does not work, does anyone know how to do this? > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Ajax.Responders.register({ onCreate:function() { if($(''busy'') && Ajax.activeRequestCount > 0) { // does the busy element exist, and have we requested ajax? $(''busy'').style.paddingTop = getPageScroll()[1]+80+''px''; // set the indicator to somewhere roughtly centered top-down $(''busy'').style.display = ''block''; // and show the element } }, onComplete:function() { // when we''re finished being busy, shut it off if($(''busy'')) { // does the busy element exist? $(''busy'').style.display = ''none''; // turn the element off } } }); Note: this code requires you to have a container element on every page with the id "busy", I chose to use an animated gif 80 x 80 pixels that is a spinning loading circle. Very *important* caveat: You have to be very careful with this, because this can cause problems with some elements, like javascript tooltip rollovers that load their content via ajax, as the system will constantly switch on and off the activeRequestCount between 1, 2, and 0. I had another if statement inside the first one to cancel this action. I can paste more code if necessary. On Jun 13, 2:36 pm, Terry Riegel <trie...-9geWAZNePKniiUjhnDU40B2eb7JE58TQ@public.gmane.org> wrote:> I would be interested in the full function. > > Terry Riegel > > On Jun 13, 2007, at 2:32 PM, conspireagainst wrote: > > > > > Is there any possible way (I''m using prototype framework) to glean > > what the name of the container element to be updated (using > > Ajax.Updater) is? > > > I have appended at the bottom of prototype.js a function that shows a > > loading dialog when any AJAX interaction takes place (I use this all > > the time, it''s AMAZING, feel free to use it, and if you want the rest > > just reply and I''ll paste all the code), but I need to cancel it for > > one particular element and cannot figure out a way without knowing the > > element name. > > > Here''s the code: > > > Ajax.Responders.register({ > > onCreate:function() { > > if($(''busy'') && Ajax.activeRequestCount > 0) { > > // show the loading dialog > > } > > } > > }); > > > ..... (more code) > > > I would love to do something like alert(Ajax.Updater.container); but > > that does not work, does anyone know how to do this?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Christophe Porteneuve
2007-Jun-14 07:55 UTC
Re: Ajax.Responders, grabbing the element name?
Hey, conspireagainst a écrit :> Is there any possible way (I''m using prototype framework) to glean > what the name of the container element to be updated (using > Ajax.Updater) is?Of course there is.> I have appended at the bottom of prototype.js a function that shows aOK, don''t do that, please. You''re asking for trouble: whenever we release a new prototype.js file, you''ll have to patch it. Create your own .js file and load it after prototype.js, instead. Don''t hack the lib, that''s not in your mid- or long-term interest. As the docs state [1], Ajax.Responders callbacks are invoked with the request object (either Ajax.Request or Ajax.Updater) as the first argument. In the case of Ajax.Updater, the container it''s going to update is referenced with the updater''s container.success property. So you could do something like this (and btw, be clear: you''re not looking for names, but for id''s): Ajax.Responders.register({ _skippedIds: /^(?:id1|id2|id3...)$/, onCreate: function(req) { var container = req.container; if (!container || !this._skippedIds.test(container.success.id)) return; // Your code here. } }); ''HTH -- Christophe Porteneuve aka TDD tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---