By intu.cz on
Hi! I would like to use the "collapsible" content effect from /admin/settings on a node page, but not necessarily in a form. What I would like to achieve is
If you click on this text
The following text will appear in a box,
perhaps with a different background, as an ex
planation for the brief version, and disappear
on another click on the text above I know the /admin/settings uses /misc/collapse.js. Can this javascript be used for something like this and how? Thanks for any help. Roman
Comments
I think my question is kinda
I think my question is kinda related to this as well:
http://drupal.org/node/60467
I used to 4.7 forms API
I just used the 4.7 forms API and used a fieldset to surround the content and generated the output with drupal_form_get. So while it is technically a form, it has no input fields and no submit button. It provides a quick way to do what you want.
Thanks nevets. Using aurka's
Thanks nevets.
Using aurka's example, if there was no content entered into the fieldset, then I presume the fieldset would not display anything in the page?
I've had a look for the Forms API, but could not see it on the Modules list for Drupal 4.7. :(
It's part of core
To find information on the form API's goto 'Drupal's APIs' in the handbook, select HEAD, then files. Scroll down (almost to the end) and you will a quick start guide and a reference for the form API's.
Forms API
Thanks for the suggestion, I looked at Forms API - the Quickstart Guide - and unfortunately my lack of e-wisdom prevents me from understanding how to use it for my purpose. What I tried to do was:
- while editing the page I tried to stick some code from the Quickstart Guide, but nothing desired happened. And there was no collapse.js loaded when I looked at the page. The code was the bit with something like "collapsible = 'true'"... I must have missed something important...
Do you know of any examples which would help more specifically with putting "something" collapsible on a normal page (or article)..?
Now I am going to try and use the trick from CSS Play, if that works I'll come back...
UPDATE: It does what I want using just css and a litttle bit of javascript.
Teasers
Does someone have an implementation for this when it comes to teasers ? When clicking the title of the node (or Read more link) the full text of the node expands using CSS/javascript (or even Ajax).
I'm thinking that the javascript is already there, but how can I make the node page load full nodes instead of just teasers, and also how to automagically set the expand link after desired teaser length and correct div's around rest of the content ?
please share
Aurka - would you mind sharing the code you ended up using? I have a similar need.
thanks!
Link provided
Hello, the code is at the provided link (CSSPlay). The code is used on intu.cz/preklady. The CSS part in my style.css is
and the actual code on the page is
But recently I installed a module called Javascript Tools, which might provide better solutions to needs such as these (I have still to try it... so it's just a feeling). Incidentally, a fellow drupaller said the CSSPlay solution doesn't work with Safari...
A simple way
If you just want to add collapsible fieldset tags to a node, just remove your filters and make sure to include the script calls in your node.
Could this code be added to
Could this code be added to node.tpl.php so all read more-links behave this way ? How ? I am just learning ...
This code doesn't work for me...
Hi !
This code doesn't work for me...
When I load the page the fieldset is collapsed as it should be but the content of my div is displayed just under it.
When I click on the legend link, the content is now displayed in the fieldset as it should be...
Can you tell me what can happen ?
Thanks a lot.
Matt
Caveats
This works nicely, but note the following (I'm testing in 4.7):
class="collapsible collapsed"<p></fieldset></p>. May not kill the script, but invalid HTML.In my theme, a variant of Pushbutton under 4.7, the following code works well, even though "Lines and paragraphs break automatically" does add extra p's around both fieldset tags:
I like to keep script tags far at the bottom if functional.
-A
slight refinement
Not sure how correct it is to include JS in the above manner. The better "Drupal way" (tested in 4.7) would be as follows:
Using the drupal_add_js() function means that these JS files won't be included twice or anything bad like that :) It also looks after all your paths so your site won't break if you move it from one location on your server to another.
Jeff
_________
http://marmaladesoul.com
Great
This solution works great for me, thanks a lot!
Is there a way to expand a box that is not directly underneath the legend tag? I have a horizontal menu with several options. I want one of those options to expand a box under the menu, not under the specific menu option.
Thanks in advance.
-Jesse
I can't get this to work
<fieldset class="collapsible ">correctly puts the content in box, but there is no javascript to collapse/expand the box itself.
<fieldset class="collapsible collapsed">collapses the box, although some of the content ("Current State:") is displayed below the horizontal line. However, there is no control or link to expand the box. what's wrong?
here is the actual html output from my code:
I added a full path name to the javascipt files
is the JS being loaded?
Sorry this reply is a bit late, but hopefully better late than never :)
The first thing I would check is whether the javascript files are actually getting loaded into your page. To do this, in your browser visit the page containing your code above, then view any errors reported by the browser; your browser should tell you if it couldn't find the .js files.
Jeff
_________
http://marmaladesoul.com
Jeff H and all thanks.
Jeff H's code worked great.
This:
TEST TITLE
test
Thanks!
Quick Question (I hope) re Collapsible Content
Hi Jeff --
I'm doing something like this but a bit more elaborate
It shows the collapsed field sets and when I click on the legend, it opens up. All is good and everything is beautiful but when I try to close it, there it won't close back up. It stays expanded.
Do you think you could give me some direction on this?
Thanks --
Missy.
This may be minor to most
This may be minor to most but keep in mind those collapsible fieldsets are made for forms. It's semantically incorrect and your pages will not validate.
Another alternative is to use jQuery directly (it should be simple) or look at this:
http://drupal.org/node/131959
Awesome!! I was looking for
Awesome!! I was looking for something similar in Drupal 6.
- HK.info @ XTX