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.
The code provides a js only solution to tab and accordion history, i.e. whichever quicktabs tab or accordion clicked will be remembered via cookie so when you refresh or navigate to other pages, the correct tab and accordion will be 'loaded' (virtually clicked).
Drupal.behaviors.quicktabsHistory = {
attach: function(context, settings) {
// enable accordion memory
$('.quick-accordion', context).each(function() {
var id = $(this).attr('id');
var accordion = $.cookie(id);
if (accordion != '') {
$(this).find('h3 a[href="' + accordion + '"]').click();
}
$(this).find('h3 a').click(function() {
$.cookie(id, $(this).attr('href'));
});
});
// enable tab memory
$('.quicktabs-wrapper', context).each(function() {
var id = $(this).attr('id');
var tab = $.cookie(id);
if (tab != '') {
$(this).find('ul.quicktabs-tabs a#' + tab).click();
}
$(this).find('ul.quicktabs-tabs a').click(function() {
$.cookie(id, $(this).attr('id'));
});
});
}
};
If you do not have script.js or an empty one, wrap the above code with
(function ($) {
// the code above
})(jQuery);
Inspiration from similar D6 thread #354199: Remember last clicked tab
Comment | File | Size | Author |
---|---|---|---|
#50 | qt_ui_tabs-history.patch | 1.59 KB | Yannick Perret |
#35 | quicktabs-tab-history-1454486-35.patch | 2.28 KB | RdeBoer |
#30 | quicktabs-tab-history-1454486-30.patch | 3.43 KB | WorldFallz |
#25 | interdiff-1454486-24-25.txt | 1.11 KB | Elijah Lynn |
#25 | quicktabs-tab-history-1454486-25.patch | 3.71 KB | Elijah Lynn |
Comments
Comment #1
ckngComment #2
kmare CreditAttribution: kmare commentedHello,
this may sound silly, but where exactly should I put this script?
Thank you in advance
Comment #3
ckngOf course I would hope this will get into the module. Otherwise, just include it in your theme.
Comment #4
PadenLee CreditAttribution: PadenLee commented#2 + Bump
Comment #5
ckngTo include as part of your theme
- add a script.js file inside your theme folder, if not already have one
- include the script.js into your theme .info file, if not already have one
- add the code into existing script.js or the new script .js you just created
- clear theme cache, or visit admin/appearance
Comment #6
CinemaSaville CreditAttribution: CinemaSaville commentedI followed your steps, but it's not working.
Comment #7
jdflorez CreditAttribution: jdflorez commentedWorked for me. Added it in my theme.
Thanks!
Comment #8
gynekolog CreditAttribution: gynekolog commentedHi, i have the script.js in my theme, i see that drupal is loading script (in source code) but it doesn't work at all. If I reload page, quicktabs is still at default position. I was trayed dev and also stable version.
Comment #9
ckng@CinemaSaville, @gynekolog
Make sure there are no other javascript error. That's the only thing I could think of which prevent it from working or you've alter the quicktab output.
Comment #10
gynekolog CreditAttribution: gynekolog commented@ckng
I'm getting this error ->
Comment #11
ckng@gynekolog
I've added additional note on the first post, you are missing the jquery wrapper
Comment #12
gynekolog CreditAttribution: gynekolog commentedIt works now, thank you!
Comment #13
gynekolog CreditAttribution: gynekolog commentedNext problem.. history is working only if click on main items in menu and not for child ->
edit: excuse my english and my error in word "history" on picture.
Comment #14
mathieso CreditAttribution: mathieso commentedThnx, ckng. You da man!
One problem. I was getting a JS error that $.cookie was not defined. Added the cookie jQuery plugin from:
https://github.com/carhartl/jquery-cookie/blob/master/jquery.cookie.js
Now it works.
Thnx again,
Kieran
Comment #15
Sinan Erdem CreditAttribution: Sinan Erdem commentedI tested the code in the issue with the plugin mentioned on comment #14 and it works half the time for me. Sometimes it remembers the correct tab, sometimes it doesnt. Please see it working here: www.profnews.nl (TOP 5 ACUTELE ARTIKELEN block on the right sidebar)
Comment #16
Sinan Erdem CreditAttribution: Sinan Erdem commentedI had to first remove cookie after clicking a tab to make it work consistently. Also I added the parameter "path" to make sure the cookie works in all the pages of the website.
Here is the revised JS code that is working for me (I only tested for tabs, not accordions):
Comment #17
mmtt CreditAttribution: mmtt commentedI've tried both codes, script.js is loading with theme.info file. Have copied jquery.cookie.js in libraries directory but it does,nt work.
I got this error:
Comment #18
ckng@mmtt, add the jquery.cookie.js to your theme info file, before the script.js, clear theme cache
Comment #19
No Sssweat CreditAttribution: No Sssweat commentednvm I figured it out.
Comment #20
No Sssweat CreditAttribution: No Sssweat commentedJust wanted to point out that this Java Script does NOT work if you select the "Load all tabs on page view" option. http://s21.postimg.org/aj5yvej79/quicktabs.jpg
Comment #21
ultimateboy CreditAttribution: ultimateboy commentedNo patch. Setting back to active.
Comment #21.0
ultimateboy CreditAttribution: ultimateboy commentedadded jquery wrapper for those without one
Comment #22
Elijah LynnComment #23
Elijah LynnPrefixing title with D7 as to improve clarity as to which issue is for D6 vs D7.
Doing the same for #354199: Remember last clicked tab.
Comment #24
Elijah LynnAttached is a patch that builds off of the above snippets but is heavily modified.
I also snuck in some coding standards improvements in case this patch gets in. This patch leaves out the accordian code because I just couldn't test it and I figure we could maybe get this in and then get the accordian stuff in with a follow up patch.
Per #20, this new patch appears to work with either the Ajax/non Ajax option. I also refactored it to use a unique cookie name in case there are multiple quicktabs groups on a page although I did not test that part.
Comment #25
Elijah LynnHere is an improved patch which sets the cookie to be site-wide and not just the current page. There is not expiration option set because by default it is a session cookie and I think it should stay that way.
Comment #26
markbannister CreditAttribution: markbannister commentedUsed patch #25 on 7.x-3.6 and it seems to work.
Comment #27
Elijah LynnBased on #26 I am going to mark RTBC then.
Comment #28
Elijah LynnArgh, actually it was just tested by the community, not reviewed. Changing back to needs review.
Comment #29
Anonymous (not verified) CreditAttribution: Anonymous commented#25 worked for me as well.
However, as a side note (which may or may not be related):
I use the tinynav.js module to change the quicktbabs tabs to a dropdown menu when the browser window is a smaller size. After implementing this patch, the dropdown items no longer work.
The dropdown items are basically linking to the tabs direct link.
Edit:Direct links do not seem to work either.
Comment #30
WorldFallz CreditAttribution: WorldFallz commentedNo longer applies. Updated patch attached. Patch works as advertised, fixes coding standards, and, more importantly, enables quicktabs to work as as users expect (i get this complaint on every quicktab I deploy if I forget to add this patch, lol).
Comment #31
markbannister CreditAttribution: markbannister commentedThis still does not work on https sites. I switched to https recently and this stopped working.
Tried latest patch #30
Comment #32
WorldFallz CreditAttribution: WorldFallz commentedWhere in this thread does it say it doesn't work with https? I reread it and couldn't find any reference to https. And looking through the code, it's not obvious to me why it would matter or even know if the site is http/https.
Comment #33
markbannister CreditAttribution: markbannister commentedWorldFallz:
Well there you go. I can't find any reference to it either and I could have sworn I read that some time ago..... OK... cleared the cache a few more times and the latest patch (#30) is now working both on my dev and live sites.
So I either overwrote the patch at some point....
I should change my user name to CryingWolf.
Comment #34
WorldFallz CreditAttribution: WorldFallz commentedlol, no worries-- it happens to all of us. I just didn't want this patch diverted if it wasn't an actual issue.
Comment #35
RdeBoerSome time has passed since the patch of #25, redone as #30. Thanks everyone for getting it this far!
On my Drupal 7.38 install I found that the code works when
1) user is logged in as admin and
2) there is only one set of Quicktabs on the page.
I have 3 sets of Quicktabs on the same page and I also wanted these to work for anonymous users.
Making it work for multiple sets on the page needed only
$this.find
inserted in the patch of #30, inside the quicktabsCookieClickHandler():becomes
I traced down the reason why it wasn't working for anonymous users to the fact that
/misc/jquery.cookie.js
only gets included when the system library known under machine name ‘jquery.cookie’ is loaded. This happens when the admin has the Toolbar enabled. But when jquery.cookie.js is NOT loaded, the call$.cookie(...)
will result in a JS error, visible in your browser console.To make the code work for anonymous users (for whom Toolbar is not enabled) I explicitly included this library in the first line of
function quicktabs_load_multiple()
inquicktabs.module
I tested this patch locally as well as on a secure (HTTPS) live site. It seems to work.
Suggest you clear your browser cookies before you start experimenting with the new patch.
The patch was created agains the current OFFICIAL version 7.x-3.6, not the dev branch.
Enjoy!
Rik
Comment #36
Tommy_001 CreditAttribution: Tommy_001 commented# 16 works fine for me, except that I would like the default tab to open when the user opens another node.
Back to same node = remember and activate the selected tab.
Back to another node (with the same tabs) = use the default tab.
Any suggestions on how the code snippet could be adapted to do this?
I haven't got very far in my own attempts so far...
EDITED: it turns out that the code actually already does this... sorry about the noise.
Comment #37
WorldFallz CreditAttribution: WorldFallz commentedKeep coming back to this issue, lol. Patch in 35# still applies and does work on pages with multiple quicktabs as advertised, and takes care of having the library loaded in all cases. Would be really nice to get this in.
Comment #38
Hydra CreditAttribution: Hydra at erdfisch commentedCan confirm that #35 is still applying and working like expected, thx!
Comment #39
adrianavaz CreditAttribution: adrianavaz commentedHi.
I have an online site and client just asked for this. I heard patches shouldn't be applied to production sites and I'm afraid I could break it.
Is there any other way I can solve this? Should I wait for a new release of the module with this feature?
Thank you.
Comment #40
joelpittet@adrianavaz patches that you've tested are ok to apply to production sites if they fix a problem or adds a needed feature. If this solves the problem you should test it out locally and if it works, push it to production. Keep track somewhere that the patch was applied. I do so by including the patch in the directory it is applied.
Comment #41
NWOM CreditAttribution: NWOM commented#35 worked great. Thank you!
Comment #42
Gold+1 on the RTBC. The patch at #35 is working as advertised for me too.
Comment #43
GoldUpdate...
This works okay with the Renderer set to "quicktabs". It's not working with the "ui_tabs" or "accordion" renderers.
Comment #44
markdcPatch #35 works well, but it ignores direct links. A query string in the URL for a specific tab should be respected and should replace the cookied history page with the requested page.
Comment #45
delacosta456 CreditAttribution: delacosta456 commentedhi many thanks for this.
however i was expecting this patch to also remember the tab on wich we were before refreshing the page..
On refresh page reload with tab set as default ..
May somebody can help extend this patch to that functionality which may be a king of enable/disable option in quicktabs settings
thanks
Comment #46
jmuzz CreditAttribution: jmuzz commentedAs stated in #24 accordion was removed from the patch to try to make something focused that could hopefully be committed sooner than a patch which adds multiple features. I have created the separate issue for that.
Comment #47
delacosta456 CreditAttribution: delacosta456 commentedHi ok i am back. after multiple .
After applying the patch ..and flushing twice it work as expected .. i mean on page refresh... BUT BEHAVE STRANGLY WITH CACHING METHODS/MUDULE. Example below
Am i missing somthing? is it related to caching methods ? or patch still needs more reviews?
Many thanks
Comment #48
Yannick PerretHi. We are using ui_tabs, so I tried to adapt #35 patch for that. Here is the corresponding patch, to apply to qt_ui_tabs.js (note: I guess the quicktabs.module's patch (adding cookie lib) should be present whatever).
At first tests it works for me (quicktabs including views, with ajax enabled).
Maybe as for accordions this may go into a separated issue?
Note: as functions are roughtly the same for quicktabs and ui_tabs (only classes name change) it should maybe be factorized.
Any feedback welcome.
Comment #50
Yannick PerretBad patch format. New one inserted (ways to replace an attachment?).
Note: not sure but all this may interact with feature that let select active tab ('qt-TAB_NAME=NUMBER'), no?
Comment #51
Yannick PerretComment #52
deepakkm CreditAttribution: deepakkm commentedThis worked for me , thanks for a perfect solution.
Comment #53
sarathkmAdding similar issue in drupal 8
Comment #54
butterwise CreditAttribution: butterwise commentedJust when I thought I was done with Drupal 7... #35 worked for me, version 7.x-3.8. Now back to migrating that site to D9 :)