I''ve an application with an accordion-like widget which shows only one "pane" of the accordion at a time. In one of the panes, I needed to use Element.positionedOffset() to find the location of an input field. However, if that pane is invisible, the positionedOffset() method returns [0, 0]. The solution I found to this problem was to very quickly show the element, get its position, and then hide it again. Is there a better way? --~--~---------~--~----~------------~-------~--~----~ 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 came up with my own better way to avoid flickering of the element: 1. Make the element completely transparent (element.setOpacity(0)) 2. Show it (element.show()) 3. Get its position (element.positionedOffset()) 4. Hide it (element.hide()) 5. Make it opaque again (element.setOpacity(1)) Still a little ugly, though. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
How about some #wrap magic? ... Element.Methods.positionedOffset Element.Methods.positionedOffset.wrap(function(proceed, element) { element = $(element); if (element.visible()) return proceed(element); element.setStyle({ visibility: ''hidden'' }).show(); var result = proceed(element); element.hide().setStyle({ visibility: ''visible'' }); return result; }) Element.addMethods(); ... This simply encapsulates all of the "switching" into the #positionedOffset method itself. Best, kangax On Mar 21, 12:18 pm, dashifen <dashi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I came up with my own better way to avoid flickering of the element: > > 1. Make the element completely transparent (element.setOpacity(0)) > 2. Show it (element.show()) > 3. Get its position (element.positionedOffset()) > 4. Hide it (element.hide()) > 5. Make it opaque again (element.setOpacity(1)) > > Still a little ugly, though.--~--~---------~--~----~------------~-------~--~----~ 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 like this. Thanks. = Dash On Mar 21, 1:02 pm, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> How about some #wrap magic? > > ... > Element.Methods.positionedOffset > Element.Methods.positionedOffset.wrap(function(proceed, element) { > element = $(element); > if (element.visible()) return proceed(element); > element.setStyle({ visibility: ''hidden'' }).show(); > var result = proceed(element); > element.hide().setStyle({ visibility: ''visible'' }); > return result; > > }) > > Element.addMethods(); > ... > > This simply encapsulates all of the "switching" into the > #positionedOffset method itself. > > Best, > kangax > > On Mar 21, 12:18 pm, dashifen <dashi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I came up with my own better way to avoid flickering of the element: > > > 1. Make the element completely transparent (element.setOpacity(0)) > > 2. Show it (element.show()) > > 3. Get its position (element.positionedOffset()) > > 4. Hide it (element.hide()) > > 5. Make it opaque again (element.setOpacity(1)) > > > Still a little ugly, though.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---