Closed (outdated)
Project:
Views (for Drupal 7)
Version:
6.x-2.x-dev
Component:
Miscellaneous
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
25 Aug 2009 at 03:47 UTC
Updated:
21 Dec 2022 at 16:50 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
dawehnerHere is a initial patch. I'm not sure whether this is fine and good to use for the themers :)
Comment #2
dafederHadn't realized l() gives active classes automatically, duh! It almost works, but the urls are coming in already formatted with a "/" at the beginning, so l() doesn't format them correctly. Here is a corrected patch... This is pretty hacky - I think it provides important functionality but perhaps there's a more graceful way to accomplish this "higher up" in the views code?
Comment #3
dafederI actually ended up putting a template in my theme to avoid hacking the module. Here is the template for anyone interested.
Comment #4
dafederOh, another thing... this doesn't work on the default argument. So, if you are using the typical glossary attachment, it defaults to "A". If you go to /yourview, it won't produce an active class for the "A" link, you have to go to /yourview/a to get that.
Comment #5
merlinofchaos commentedI don't really like using l() in a template. Can we just have the preprocess do the active check and throw that in a classes variable instead?
Comment #6
dafederI'm still not really comfortable working in the whole preprocess system. That sounds right but I'm not sure how it would work exactly. A preprocess function in the theme? Or are you asking about a potential patch to the module?
Comment #7
Christopher Herberte commentedSubscribe.
Meanwhile, i've used jQuery for a temporary fix. Works only with AJAX disabled (reads url) Maybe this helps.
Views default glossary:
or custom glossary attachment, I styled mine like primary tabs.
Comment #8
meecect commented+subscribe
I would like to see an easy way to do this for a block item's active trail. The 'a' tag appears to get the active class, but the 'li' tag in a block doesn't get the active-trail class so it's hard to style bullet items for the currently active page.
In the meantime, I used a slightly modified version of the jquery code from #7.
I'd really like to do this the drupal way, but at the same time, it's hard not to notice that doing it with jquery is short, understandable and fast. The drupal way apparently involves the interaction of several modules, a tangled webs of template files, template preprocess functions, the stacked nature of Drupal API's and on and on.
It's things like this that really make me question my investment in Drupal, which seems sometimes to be a towering mess of modules, functions, overrides, templates and hundreds of SQL queries to generate a single page.
Comment #9
dboulet commentedHere's my stab at it, using a preprocess function and modifying the template.
Comment #10
crashtest_ commenteddboulet - your patch was pretty much right on for formatted summary view, however it also needs to apply to the unformatted summary view, or the default glossary view doesn't seem to work (at least for me).
I added to your patch to enable this to work with unformatted.
Comment #11
merlinofchaos commentedGreat work! Committed to all branches.
Comment #12
dboulet commentedGreat! Thanks for the help CrashTest_.
Comment #13
dafederThanks!
Comment #14
nauthiz693 commentedThe patch listed in comment 10 worked great for me, but it didn't handle the situation of a default. So for my view, I wanted the first item to have the 'active' class in the default case. I did this by implementing a preprocess function in my theme:
I think you may also need to have your own template file overriding the default views one (views-view-summary.tpl.php) for drupal to find and call your function. In my case, I overwrote it for a specific view (so I added the file views-view-summary--VIEWNAME.tpl.php) because I also wanted the active class on the containing list element not the link.
Comment #15
MichaelP commentedI experienced problems with differences between the url comparison on a Catalan site with aliases like "Alòs d'Isil".
This follow on patch runs the urls to be compared through rawurldecode (perhaps there is a better way?).
Comment #16
dawehnerI would like to have documented why here rawurldecode is used....
Comment #17
MichaelP commentedReplaces patch at #15 using drupal_urlencode and only on incoming path. Comment added.
This resolves my case as in:
Comment #18
MichaelP commentedComment #19
dawehnerSorry but why?
You only describe what you are doing, which is already covered nice by the function name
Comment #20
MichaelP commented@dereine:
I made the patch at #558602-17: Class for active links in summary view attachments because:
I have summary lists of taxonomy term arguments. I noticed that the "active link" functionality was only being set when the "active link" was a single word with no space etc.
Upon investigation, I saw that the comparison to find the active link:
was trying to compare, for example:
"/map/mercat/producte/Al%C3%B2s%20d%27Isil" == "/map/mercat/producte/Alòs d'Isil"
(substituting the comparison with an actual example obtained from an xdebug session).
On the one side, the value has already been passed through drupal_urlencode in the url() call, so I perform a drupal_urlencode on the other side in order to compare like with like.
Does that make any sense at all?!!
Comment #21
MichaelP commentedComment #22
merlinofchaos commenteddereine means that the why should be in the comments in the code.
Whenever the reason for something is unclear or ambiguous, that is an opportunity to apply good code comments. =)
Comment #23
MichaelP commentedThis replaces patch at #558602-17: Class for active links in summary view attachments, hopefully with better code comments.
Patience of all concerned much appreciated.
Comment #24
MichaelP commentedThis replaces patch at #558602-17: Class for active links in summary view attachments, hopefully with better code comments.
Patience of all concerned much appreciated.
Comment #25
dboulet commentedLink to patch above doesn't work for some reason.
http://drupal.org/files/issues/views-Drupal-6--2_558602_drupal_urlencode...
Comment #26
owahab commentedNone of these patches fix the issue I currently have: with one or more exposed filters, the active class doesn't get attached to the summary attachment because if I have exposed the body field filter, URLs will look like /map/mercat/producte/Al%C3%B2s%20d%27Isil?body= while the patch #10 (currently in Views 2.10) and the latest one in #25 will both ignore the filter hence this fix won't work.
I will try to add a patch as soon as I get it fixed.
Comment #27
merlinofchaos commentedI'm not sure how filters tie in to an active class?
Comment #28
owahab commentedWell Earl, the method currently used to evaluate the status of a link being active or inactive depends on comparing the $_GET['q'] to the link's URL and ignores the other parameters in $_GET.
Without exposed filters:
$vars['rows'][$id]->url = '/example/myview/A'
$_GET['q'] = '/example/myview/A'
Result: the link has the class active.
With exposed filters (body field in this example):
$vars['rows'][$id]->url = '/example/myview/A'
$_GET['q'] = '/example/myview/A?body=ape'
Result: the link doesn't have the class active though it should.
Comment #29
merlinofchaos commented$_GET['q'] = '/example/myview/A?body=ape'$_GET['q'] should never include query parameters.
Comment #30
owahab commentedSorry, a typo.
With exposed filters (body field in this example):
$vars['rows'][$id]->url = '/example/myview/A?body=ape'
$_GET['q'] = '/example/myview/A'
Comment #31
merlinofchaos commentedOk, so we need to add a parse_url() in there. Got it.
Comment #32
ducdebreme commentedI am sorry, it doesn't work with multilingual websites.
Here is the reason:
==> the de is missing and thus the link is not getting highlighted
Proposed solution: use the url() function instead of concatenating the url fragments. It takes the language into account.
Use this ...
instead of this
Comment #33
dawehnerSo
Comment #34
ducdebreme commentedPlease see my comment #32 -> http://drupal.org/node/558602#comment-2863094
Comment #35
esmerel commentedNo work done for more than 3 months
Comment #36
willhowlett commentedSubscribe
Comment #37
webnicola commentedSubscribe
No work width Drupal 6.20 Views 6.x-2.12
Ok sorry, see comment #32!
Comment #38
dgastudio commentedany update on this?
Comment #39
gawas.sachin commentedHow Do I apply class "active" to default argument of attachment. ?
Comment #40
stolzenhain commentedsubscribe
If just a quick frontend fix is needed, the active link class could also be set with a simple jquery command, that compares the href attribute to the actual URL.Oh I see, someone already proposed that on #7
Comment #41
Carl Johan commentedReviving :)
Created a proper patch based on #32 which fixes this for me (multilingual site)
Comment #42
nickbumgarner commentedJust an FYI for anybody looking for this on the 7.x branch. I found a working patch here. https://www.drupal.org/node/2159967
Comment #43
izmeez commentedPatch in comment #41 applies without difficulty to latest views-6.x-2.26
Comment #44
chris matthews commentedThe Drupal 6 branch is no longer supported, please check with the D6LTS project if you need further support. For more information as to why this issue was closed, please see issue #3030347: Plan to clean process issue queue
Comment #45
dasSouvik93 commentedHow will I achieve the same if the glossary view is in AJAX enabled? I am using Drupal 9.