Closed (fixed)
Project:
CKEditor Accordion
Version:
2.0.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
30 Apr 2020 at 15:36 UTC
Updated:
11 Feb 2023 at 18:54 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
zeip commentedWe had the same need. I implemented this via a small change to the Javascript code. Attached is a patch; not sure if this should be somehow optional instead of default behavior?
Comment #3
robbm commentedThanks ZeiP, that's great. Not quite working in my use case, as my tabText contains punctuation such as single quotes and question marks (and although the latter gets encoded, they still break the functionality). Will have a think about an alternative regular expression (unless you beat me to it...)
Comment #4
robbm commentedMinor change to ZeiP's patch to strip all non-alphanumeric characters (rather than just spaces) when creating IDs for named anchors.
Comment #5
stefan.butura commentedMinor change on the patches above to make it so that anchors to accordions on the same page work.
Comment #6
bernardm28 commentedComment #7
jsutta commented+1 RTBC. Thank you so much for adding this functionality!
Comment #8
tzt20 commentedThe patch in #5 works perfectly! Thank you all for this!
Comment #9
sbrenner02 commentedThis works exactly as described which is great. I have a slightly more complicated situation / ask that i'm trying to work out on my site.
We have accordions living within CK Editor Bootstrap tabs on some pages of our site. So a page may have a few tabs and different accordions within each.
If the accordion is placed within the first tab it opens as expected when linked to with this patch. If the accordion is located inside of a tab that is not on the page as it loads, the tab is not switched to but the accordion is open if that tab is navigated to.
Any suggestion on how to approach this situation and be able to link to accordions within any tab?
Thanks in advance!
Comment #10
skarbimir commentedDoes anyone have a patch for ckeditor accordion-2.0.1.? There is no ckeditor-accordion.js file in the new version. There is an accordion.frontend.js file.
Comment #11
j-vee commentedWith the move to native JS, the existing patch is out of date. I've pushed out a new dev release that adds a configuration option to /admin/config/content/ckeditor-accordion to enable this functionality. Can you check it out @Skarbimir and let me know if it works for you?
https://www.drupal.org/project/ckeditor_accordion/releases/2.x-dev
Comment #12
j-vee commentedComment #13
j-vee commentedComment #14
skarbimir commentedUnfortunately, nothing has changed for me in /admin/config/content/ckeditor-accordion. There is no new option. (Drupal 9.5.1. But it's very good idea to enable this functionality in config.
Comment #15
j-vee commentedWell for some reason my latest changes in 2.0.x don't appear as a new dev release. But I got the module tested out with that specific commit and there's now a release 2.0.2 to add this functionality into the config. It'll be disabled by default so existing accordions don't get it.
Let me know how it's working out for you!
Comment #16
skarbimir commentedIt works for me in with both ckeditor 4 and 5 versions. One more question. How to change the ID format to #home_product instead of #HomeProducts as it is now. That is, changing the letters to lowercase and the space to the underline symbol.
Comment #17
j-vee commentedYou'll need to patch out js/accordion.frontend.js file line 159 for that, something like the following would work
let tabHash = tabText.replace(/[^A-Za-z0-9 ]/g, "").replace(' ', '-').toLowerCase();I'll leave this version as it is so that sites that already have been using the patch will have their functionality work the same as it did.
Thanks for your help testing this out!
And @sbrenner02, you'd need to write some custom JS for a solution in this case. Something to check if an accordion row with current hash exists, open the tab that the accordion row resides inside. You can probably fire off an .click() event on the tab link / button to do so.
Comment #18
j-vee commentedComment #19
skarbimir commentedI noticed that in version 2.0.2 the function "Keep accordion rows open when opening another one" does not work. When an accordion opens, the previous one does not close, whether this option is checked or not.
To get the format "#home-product" not as default "#HomeProducts"
"let tabHash = tabText.replace(/[^A-Za-z0-9 ]/g, "").replace(' ', '-').toLowerCase();"
To get the format "#home_product" not as default "#HomeProducts"
"let tabHash = tabText.replace(/[^A-Za-z0-9 ]/g, "").replace(' ', '_').toLowerCase();"
Working. Thanks for the help.
Comment #20
skarbimir commentedI found one more error in the abow script for changing link:
When script is changing a two-letter title, correctly adds a '_' character between words. But if there is a 3-word title, it gives '%20' in place of the second space. So for example '#home_and%20garden' and it should be '#home_and_garden'
Comment #21
j-vee commentedTry replacing .replace with .replaceAll, that should do it.
And clear your cache once you've changed your settings if the changes to settings don't apply straight away.
Comment #22
skarbimir commentedThanks. #21 Works perfectly