Glenn wrote:
> I am new to Ajax and wondering if it is possible to create Ajax
> component like following link in Rails. I am not sure how to call
> this kinds of widgets. It shows bars which you can dynamically show
> and hide. This seems very useful to save screen space.
>
> quicken.intuit.com/personal-finance/basic-personal-budget.jhtml
>
> Could anyone point me what is the best way to write this kind of
> components or anything I need to know?
Get Firebug, open that page with Firefox, distend the context menu for one
of those bars (the right-click-mouse-button-menu), and inspect the element:
<a onclick="infoToggle(''1''); return false;"
href="#"><span title="Features &
Benefits">Features & Benefits</span></a>
Now look up infoToggle, in Firebug''s script panel:
function infoToggle(num) {
infoOffID = "info-"+num;
infoOnID = "info-on-"+num;
if (document.getElementById(infoOffID).className == "off") {
document.getElementById(infoOffID).className = "";
document.getElementById(infoOnID).className = "off";
if (num == "all") {
for (i=1; document.getElementById("info-on-"+i); i++) {
document.getElementById("info-on-"+i).className = "off";
document.getElementById("info-"+i).className = "";
}
}
}
else {
document.getElementById(infoOffID).className = "off";
document.getElementById(infoOnID).className = "";
if (num == "all") {
for (i=1; document.getElementById("info-on-"+i); i++) {
document.getElementById("info-on-"+i).className = "";
document.getElementById("info-"+i).className = "off";
}
}
}
}
I''m not sure if I agree with the style. All the variables need
''var '' before
them. And FireBug wrecked the indentation.
Note that the code uses no Ajax. It just shows and hides DIVs based on their
IDs. It switches between a visible and invisible class, "off", and
this
class probably says display:none inside. Ajax is more complex - it fetches
new data from a server, and slips it into the page. This page just uses the
common technique of sending out much more information than you see, and
"accordioning" it when you need it.
New question to the group: What is the JavaScriptGenerator way to do all
that?
--
Phlip
oreilly.com/catalog/9780596510657
"Test Driven Ajax (on Rails)"
assert_xpath, assert_javascript, & assert_ajax
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---