Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi there,
Thanks for this module. I have a request though. Would it be possible to make long code blocks automatically collapse to a smaller area? I think this would be possible with jQuery through a theme, but wouldn't it be nice to have as a feature?
I would ask to look at the PHPBB-module which has this functionality, but it seems like the demo site is not working at this moment.
Thanks in advance!
Comment | File | Size | Author |
---|---|---|---|
#31 | 516356-code-collapsing-d6-04.patch | 7.24 KB | soxofaan |
#21 | 516356_codecollapsing_03.patch | 8.33 KB | soxofaan |
#18 | 516356_codecollapsing_02.patch | 3.69 KB | soxofaan |
#18 | geshifilter.js.txt | 1.86 KB | soxofaan |
#15 | 516356_codecollapsing_01.patch | 3.41 KB | soxofaan |
Comments
Comment #1
libeco CreditAttribution: libeco commentedI have started something, I'm not very experienced with jQuery, so I don't know if there's a better way. This is still pure jQuery, not implemented into Drupal.
The jQuery:
And some css:
Comment #2
soxofaan CreditAttribution: soxofaan commentedinteresting,
I'll try it out when I have more time.
looking at the code: does it also work when there are several geshifilter snippets on the same page?
maybe you should also check out the height(val) function (http://docs.jquery.com/CSS/height),
and maybe we can avoid the CSS part and do everything in jquery?
Comment #3
libeco CreditAttribution: libeco commentedI haven't tried it on the real page yet. I'll see if I can implement it into Drupal, I haven't really thought about the behaviour of multiple GeSHi snippets. The reason I used CSS is the ability for the user to easily change the height of the box, but perhaps this could also be an admin setting?
The height function is already in the code. As I said I'm not an experienced jQuery developer, don't know if I'm using the most efficient code, but it's a start and I'm willing to learn from corrections. :-)
Comment #4
libeco CreditAttribution: libeco commentedHere's a rewrite of the previous code which will work for different GeSHi snippets, however, it still needs some work for snippets with different heights.
Comment #5
libeco CreditAttribution: libeco commentedAnd I think this is the finished code which works well with multiple GeSHi snippets:
Comment #6
soxofaan CreditAttribution: soxofaan commentedI tried your code, but it doesn't work because of the 'live' function,
apparently that's a jQuery 1.3 (http://docs.jquery.com/Events/live)
I think Drupal 6 ships only a 1.2.something version by default
Comment #7
libeco CreditAttribution: libeco commentedYou're right, Ok I've just tried this and it seems to work:
Step 1
Download jQuery Update module and enable it. Make sure you use the 6.x.2.x (currently still dev).
Step 2
Add
drupal_add_js(drupal_get_path('module', 'geshifilter') .'/geshifilter.js');
to function geshifilter_init() in geshifilter.module.Step 3
Create a new geshifilter.js file and add this code:
Step 4
Add these lines to geshifilter.css:
Maybe you need to clear your cache, but now it should work! :-)
Comment #8
soxofaan CreditAttribution: soxofaan commentedI don't think depending on jQuery Update is a good idea.
Isn't it possible to implement it with with jQuery 1.2?
Comment #9
libeco CreditAttribution: libeco commentedThe live function is available only since 1.3. This function makes it possible to create an event listener form an element before the element exists. I have no idea how to do this without this function.
I found an example of doing it the 1.2 way, but I will have to look into it to see if I can convert the code to work that way.
Why would depending on a newer, better version of jQuery not be a good idea? jQuery 1.3 is said to be much faster and it's functions like .live that make it very easy to use. Or is it just the idea of having to install a module for such little added functionality?
Thanks!
Comment #10
soxofaan CreditAttribution: soxofaan commentedI have nothing against 1.3 :)
it is indeed about having to install an extra module for a rather small feature. GeSHi filter has no dependencies outside of Drupal core and I want to keep it that way.
I've been experimenting myself a bit and came up with the following (based on http://andylangton.co.uk/articles/javascript/jquery-show-hide-multiple-e...):
it's still very rough, (shows all or nothing of a snippet, instead of partial collapsing), but I don't need the live function something alike.
Comment #11
libeco CreditAttribution: libeco commentedHere is my version without the .live function:
Step 1
Add
drupal_add_js(drupal_get_path('module', 'geshifilter') .'/geshifilter.js');
to function geshifilter_init() in geshifilter.module.Step 2
Create a new geshifilter.js file and add this code:
Step 3
Add these lines to geshifilter.css:
Maybe you need to clear your cache, but now it should work! :-)
Comment #12
soxofaan CreditAttribution: soxofaan commented#11 doesn't seem to work for me: code is not collapsed and collapse link does not change much
I'm also trying some stuff out.
I found this interesting inspiration: http://sim.plified.com/2008/09/15/sliding-content-from-a-partial-height-... (also try out the demo).
A big advantage of this approach is that the collapsing/expanding is animated, which is much more user friendly than instantaneous hiding/showing.
Comment #13
soxofaan CreditAttribution: soxofaan commentedthis seems to work well for me:
still some (styling) issues to do
Comment #14
libeco CreditAttribution: libeco commentedI wonder why #11 is not working for you, here it works perfectly.
#13 works well for me, but what I read from the book Drupal 6 JavaScript and jQuery it is better to let Drupal handle the jQuery with
Drupal.behaviors.collapseGeSHi = function() {
Or ofcourse some other name you choose.
Comment #15
soxofaan CreditAttribution: soxofaan commentedok, here is a real patch (and a screenshot).
About the behaviors: from what I understand of it, behaviors is only about attaching event handlers to objects. Here we are also adding objects on their own (the toggle link inside a div), so I think Drupal.behaviors is not needed here. (The click event handler added to the toggle link could be done with Drupal.behaviors, but it's not necessary as far as I know, and it would make the code more difficult to understand.)
still to do/figure out:
* make it an opt-in feature through the admin interface?
* make configurable inline like
[code collapsible=true]foo bar code [/code]
?* collapsing should also be optional for geshinodes and geshifields
Comment #16
libeco CreditAttribution: libeco commentedDoes this make any sense for the admin setting? Ofcourse a checkbox should be added to the admin settings for this to work.
Comment #17
libeco CreditAttribution: libeco commentedI've applied the patch with TortoiseMerge and it did not create the .js file, don't know if it's a limitation of TortoiseMerge, patch-files or this one in particular.
Comment #18
soxofaan CreditAttribution: soxofaan commentedadding new files should be no problem with patch files, so I'm afraid it's a limitation of ToroiseMerge
anyway here is an updated patch and individual js file
Comment #19
libeco CreditAttribution: libeco commentedWouldn't it be better to change 'Show more code' to 'Show all code'?
Comment #20
voipfc CreditAttribution: voipfc commentedsubscribing
Comment #21
soxofaan CreditAttribution: soxofaan commentedWorked a bit more on the patch
now collapsible code blocks are optional (off by default) and can be triggered with something like
Comment #22
voipfc CreditAttribution: voipfc commentedI am just wondering if this patch can make it into the mainline version.
I'd love not to login via SSH to patch it, on my few sites that use it.
I like it so much that I blogged about it http://devblog.brahmancreations.com/content/geshi-show-more-code.
I wonder if only the 3 of us in this thread that know about it.
Thanks
Frank
Comment #23
soxofaan CreditAttribution: soxofaan commentedIf there is more user feedback on this patch, it's certainly supposed to go in the main line.
(Some simpletest coverage of the feature would also be nice.)
Have you already tried it on a development/localhost site or something?
Comment #24
sanpi CreditAttribution: sanpi commentedGreat feature! I use successfully the second patch to minimize changes.
Comment #25
voipfc CreditAttribution: voipfc commented#21: 516356_codecollapsing_03.patch queued for re-testing.
Comment #26
voipfc CreditAttribution: voipfc commentedDoes the patch depend on which version of Geshi is used?
Does it change the Geshi libraries own files, or only those of the Drupal module?
What directory should the patch be applied from?
Comment #27
soxofaan CreditAttribution: soxofaan commentedat voipfc:
It should be applied against the CVS HEAD version (or the latest 6.x-1.x-dev nighly build tar ball) of the geshifilter module (applying it from the geshifilter directory should work).
It only changes the geshifilter drupal module files, it does not touch the geshi library.
Comment #28
voipfc CreditAttribution: voipfc commented#18: 516356_codecollapsing_02.patch queued for re-testing.
Comment #29
benlotter CreditAttribution: benlotter commentedI've just recently started using this module and I think it great. Unfortunately the version I downloaded doesn't seem to have this feature yet. I'm not a developer and I don't know how to apply the patch. Can someone attach a .zip that I can download or make a new build so I can use this?
Comment #30
voipfc CreditAttribution: voipfc commentedDoes this feature still work for both D6 and D7?
I find myself having to revert my Geshi filter to older versions in order to keep it functioning.
Was it implemented for Drupal 7?
Comment #31
soxofaan CreditAttribution: soxofaan commentedHere a reroll against 6.x-1.x
Comment #32
voipfc CreditAttribution: voipfc commentedI have applied patch #31 to 6.14 and it is working.
A search and replace is required to change existing code blocks to the
<langxxx collapsible="true">
syntax to work, ie add thecollapsible="true"
tagComment #33
voipfc CreditAttribution: voipfc commentedComment #34
yukare CreditAttribution: yukare commentedDrupal 6 is not supported anymore.
I really think that this is a good thing to have, so i will change the version to 8. I can not work on it now, but will accept a patch if someone else wants to work on it.