How can I know if a an element is visible or hidden in RJS I''m trying to hide/show some data but it does not work Error => parse error, unexpected $undefined. #show_doctor.rjs if($("#{@element}").visible()) page.hide "hide_#{@element}" end Any ideas? @element contains the value of the html element -- Posted via http://www.ruby-forum.com/.
Rath --- wrote:> How can I know if a an element is visible or hidden in RJS > > I''m trying to hide/show some data but it does not work > Error => parse error, unexpected $undefined. > > #show_doctor.rjs > if($("#{@element}").visible()) > page.hide "hide_#{@element}" > end > > Any ideas? > > @element contains the value of the html elementThis code should work if @element contains the id of the html element, what do you have exactly in @element ? Btw since hiding an already hidden element won''t do anything you don''t even need to test if it is visible ^^ You can then rewrite it like this: page["hide_#{@element}"].hide() -- Posted via http://www.ruby-forum.com/.
On Saturday, July 22, 2006, at 7:42 PM, Julien Schmurfy wrote:>Rath --- wrote: >> How can I know if a an element is visible or hidden in RJS >> >> I''m trying to hide/show some data but it does not work >> Error => parse error, unexpected $undefined. >> >> #show_doctor.rjs >> if($("#{@element}").visible()) >> page.hide "hide_#{@element}" >> end >> >> Any ideas? >> >> @element contains the value of the html element > >This code should work if @element contains the id of the html element, >what do you have exactly in @element ? >Btw since hiding an already hidden element won''t do anything you don''t >even need to test if it is visible ^^ >You can then rewrite it like this: >page["hide_#{@element}"].hide() > >-- >Posted via http://www.ruby-forum.com/. >_______________________________________________ >Rails mailing list >Rails@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/railsI seem to recall that you can do something like: page[''element''].toggle _Kevin www.sciwerks.com -- Posted with http://DevLists.com. Sign up and save your mailbox.
Thanks Kevin Yes, there is a page[''element''].toggle function but the problem is that I need to check if an object is displayed, if not I want to display it and at the same time do more stuff... (ie hide or show more elements) I had to do a quick hack, perhaps it is not the best way to do it but for the time been I will do the following I''m sending the id with the hide_ or show_ prefix and then check if @element.starts_with?("show_") page.show "whatever" more stuff else page.hide "whatever" something else end Any ideas are welcome Cheers -- Posted via http://www.ruby-forum.com/.
On Sunday, July 23, 2006, at 1:54 PM, Rath --- wrote:>Thanks Kevin > >Yes, there is a page[''element''].toggle function but the problem is that >I need to check if an object is displayed, if not I want to display it >and at the same time do more stuff... (ie hide or show more elements) > >I had to do a quick hack, perhaps it is not the best way to do it but >for the time been I will do the following > >I''m sending the id with the hide_ or show_ prefix and then check > >if @element.starts_with?("show_") > page.show "whatever" > more stuff >else > page.hide "whatever" > something else >end > >Any ideas are welcome > >Cheers > >-- >Posted via http://www.ruby-forum.com/. >_______________________________________________ >Rails mailing list >Rails@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/railsIf it works, that''s great. The problem with RJS in this case is that the RJS template needs to be rendered in one shot before sending it to the browser. There is no way to query JS objects on the other side and have that alter the rendering. I see two ways to deal with this. One would be to use the RJS template to generate a JS script that could do the conditional processing on the client browser, and the other way would be to pack all the information you need into a proxy object that gets sent along with the request (sort of like how you have already done it). You could do something like this... page << "if $(''obj'').visible {do_something()} else {do_something_else()}" You could predefine the two functions into a JS library, or you could generate them and send them back with the RJS request. _Kevin www.sciwerks.com -- Posted with http://DevLists.com. Sign up and save your mailbox.