Closed (outdated)
Project:
Collapse Text
Version:
7.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
9 Jan 2015 at 09:56 UTC
Updated:
8 Nov 2025 at 02:52 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
pukku commentedNot really in this module. The module merely introduces a fieldset with a legend. Changing the legend on expand/collapse would involve all kinds of complications like JavaScript.
Sorry,
Ricky
Comment #2
prophet108 commentedThis would be a really valuable feature in an already useful module.
Comment #3
dydave commentedShall we give this a shot?
I guess a patch with some JS could be considered for testing?
Let's bring this back in the stack and we'll see....
Comment #4
dydave commentedAlright guys,
This is a feature that has been requested multiple times by various users, directly or indirectly.
So I took a quick look and came up with a very simple, initial version, that's very clean/short, doesn't disrupt any of Collapse Text's logic or processing and should at least fulfill this feature request to some extent :-)
By default (not sure exactly why, I didn't spend any time to look any further/deeper than that), collapse.js has its own hidden markup in fieldsets with different texts corresponding to the two states:
1 - Show, when collapsed.
2 - Hide, when expanded.
For example, when collapsed, the markup looks like this:
see the JavaScript code, in collapse.js, line 79.
By default, this markup is hidden, as the class
element-invisibleindicates (rather explicit, isn't it?).In a sense, this requested feature already exists in Drupal core, by default, but is hidden.
I took a first stab at this feature and came up with an initial version 0.1, with the attached patch against collapse_text-7.x-2.x at 85656e4. File attached as: collapse_text-different-title-for-collapse-expand-2404547-4.patch.
This patch is 100% JavaScript (so far, in such a basic version), that takes place when the page loads JS and JQuery kicks in. What the patch does is very simple and straight forward:
<span>, including<span class="fieldset-legend-prefix element-invisible">.<span class="fieldset-legend-prefix element-invisible">is moved out of the<span>added in step 1, and prepended to its parent<a class="fieldset-title" href="#">, to be adjacent to the<span>added in 1.At this point the markup looks like this:
element-invisibleis moved from the first<span>to the second, so the 'standard' title is hidden and thefieldset-legend-prefixfrom the markup described at the beginning of this comment is displayed.Now, I understand this patch perhaps doesn't completely cover the extent some would have hoped to see :-) (patience), but at least the texts
HideandShowcan be overridden with Sting Overrides (giving users the ability to set: "different titles for collapse & expand", that will only show for fieldsets created with Collapse Text).I believe, some of the further improvements to this version could be:
At least this version gets things started with this feature request and should probably fulfill the requirements of some users.
At the very least, this patch should fulfill this feature request as it is described in the issue summary :-P.
As we get more feedback, we will keep modifying, fixing and building on top of this version.
I would greatly appreciate your reviews, feedbacks, testing/reporting, suggestions, objections, concerns, questions or ideas on this issue, any help would be warmly welcome.
Please let me know if you would have any comments, feedback, questions, issues, objections, suggestions or concerns on any aspects of this comment, attached patch or this feature request in general, I would be glad to provide more information or explain in more details.
Thanks very much in advance to everyone for your feedback, testing and reporting.
Cheers!
Comment #5
dydave commentedraaaahhh coding standards.... re-roll!!
Please find attached to this comment a re-rolled patch against collapse_text-7.x-2.x at 85656e4, exactly the same as #4, minus the bad indents. File attached as: collapse_text-different-title-for-collapse-expand-2404547-5.patch.
Thanks very much in advance to everyone for your feedback, testing and reporting.
Cheers!
Comment #6
zrpnrI think you have the right idea DYdave, which is to start from the Drupal collapse.js defaults and work from there. Drupal core collapse.js adds the link in the legend to the fieldset which triggers the collapse toggle, and fires off a "collapsed" event which can be used to trigger the text swap.
Rather than using string overrides, I think it's better to extend the features collapse_text already provides, which is to allow for a default string in the Text Format Filter, and the option to override in the text area where you write your
[collapsed ... ]tag.Comment #7
zrpnrHere is a patch that adds an additional text field to the Filter options for adding a value in the text area to override.
Then, these values are added to a data attribute which is swapped using js based on the value of the the "collapsed" event.
Use: Navigate to your text format config page, such as admin/config/content/formats/filtered_html
Set a "Default title" and an optional "Toggled title"
To override, in the text area when wrapping your content with
[collapsed] ... [/collapsed]use the title= and toggled=.Example:
[collapsed title="Show More" toggled="Show Less"]Comment #8
zrpnrMarking "needs review"
Comment #9
dydave commentedSounds good @zrpnr!
Sorry for the late reply BTW....
Let's see if any interest is shown in this.... thus far very little (why am I not surprised :) haha)
More testing and reporting would be greatly appreciated.
Thanks in advance to everyone for your testing, reviews, reporting and feedback.
Cheers!
Comment #10
jacquelynfisher commentedI applied the Patch from #7 on a fresh install of 7.x-1.0, and it returned the following errors:
Warning: simplexml_load_string(): Entity: line 1: parser error : attributes construct error in _collapse_text_process_child_item() (line 534 of /srv/bindings/dc4653cfe5b849b4855c6265d59617fd/code/sites/all/modules/collapse_text/collapse_text.module).
Warning: simplexml_load_string(): in _collapse_text_process_child_item() (line 534 of /srv/bindings/dc4653cfe5b849b4855c6265d59617fd/code/sites/all/modules/collapse_text/collapse_text.module).
Warning: simplexml_load_string(): ^ in _collapse_text_process_child_item() (line 534 of /srv/bindings/dc4653cfe5b849b4855c6265d59617fd/code/sites/all/modules/collapse_text/collapse_text.module).
Warning: simplexml_load_string(): Entity: line 1: parser error : Couldn't find end of Start Tag collapse line 1 in _collapse_text_process_child_item() (line 534 of /srv/bindings/dc4653cfe5b849b4855c6265d59617fd/code/sites/all/modules/collapse_text/collapse_text.module).
Warning: simplexml_load_string(): in _collapse_text_process_child_item() (line 534 of /srv/bindings/dc4653cfe5b849b4855c6265d59617fd/code/sites/all/modules/collapse_text/collapse_text.module).
Warning: simplexml_load_string(): ^ in _collapse_text_process_child_item() (line 534 of /srv/bindings/dc4653cfe5b849b4855c6265d59617fd/code/sites/all/modules/collapse_text/collapse_text.module).
Warning: simplexml_load_string(): Entity: line 1: parser error : Extra content at the end of the document in _collapse_text_process_child_item() (line 534 of /srv/bindings/dc4653cfe5b849b4855c6265d59617fd/code/sites/all/modules/collapse_text/collapse_text.module).
Warning: simplexml_load_string(): in _collapse_text_process_child_item() (line 534 of /srv/bindings/dc4653cfe5b849b4855c6265d59617fd/code/sites/all/modules/collapse_text/collapse_text.module).
Warning: simplexml_load_string(): ^ in _collapse_text_process_child_item() (line 534 of /srv/bindings/dc4653cfe5b849b4855c6265d59617fd/code/sites/all/modules/collapse_text/collapse_text.module).
I replaced the module with a fresh install and applied the patch from #5. It works! It would be nice to customize the default Show/Hide text, but it will do for now.
Comment #11
brendanrjohn commentedManually applied patch from #5 into 7.x-2.4. Works a treat. Thank you v much.
Comment #12
brendanrjohn commentedHas anyone successfully used String Overrides to alter the text? The string searched for by collapse.js (as per here: http://cgit.drupalcode.org/drupal/tree/misc/collapse.js?h=7.x) would appear to be just the word 'Show' or 'Hide'. But String Overrides does not change the text for me with those values. Where does that default span come from?
Comment #13
dydave commentedHi @brendanrjohn,
Thank you very much for your testing and feedback, it's greatly appreciated.
If I recall properly, when I worked on the patch from #5, I tested also with String Overrides and it worked fine, which seems logical given the strings (Show/Hide) are wrapped in a
Drupal.t(see the link to collapse.js in your comment lines 13 and 32).Did you try flushing the caches after/before?
Did you try putting clearly identifiable translations/overrides?
Not sure exactly what could be going wrong, but it "should" work.
If you still can't figure this out, I'll give it a quick try when I get some time.
Hope this comment will help and that you'll be able to work things out.
Thanks again to everyone for your feedback, testing, reporting and involvement in the Drupal community.
Cheers!
Comment #14
frederickjhI am using this patch and it works well. One more thing needs added before this gets committed. A change needs to me made to the help text that appear under each text field. Currently it reads:
So, now not even how to set a different open text is mentioned. In addition to the above we need something like this:
To set a custom open text use title="Show more" or to set a custom close text use toggled="Show less" in the opening tag.
Example: [collapsed title="Show More" toggled="Show Less"]
Comment #15
dydave commentedDrupal 7 is not supported anymore, therefore this issue is unlikely to go any further.
Additionally: No activity or reply for more than 6 years.
If this issue is still valid for more recent versions of the module and Drupal core, please create a new ticket with the appropriate version.
Marking issue as Closed (outdated), for now.
Thanks everyone for your interest in the Collapse Text module and contributions! 😊