This update is intended to solidify the base html code produced by the pager. The current code is not semantic in any fashion and this update will largely fix that. (examples follow) Additionally it has been altered so that it produces html that is much more easily styled. True every portion of the pager can be re-themed, but that's no excuse for not moving forward to fix obvious problems. Additionally, the average "designer" might not understand the theming functions but this reconfiguration of code will make css styling incredibly simple.
-- Current Output (page 3 of 3 for illustration purposes) --
<div class="pager">
<a href="/drupal-head/?q=node" class="pager-first active" title="Go to first page">« first</a>
<a href="/drupal-head/?q=node&page=1" class="pager-previous active" title="Go to previous page">‹ previous</a>
<span class="pager-list">
<a href="/drupal-head/?q=node" class="pager-first active" title="Go to page 1">1</a>
<a href="/drupal-head/?q=node&page=1" class="pager-previous active" title="Go to page 2">2</a>
<strong class="pager-current">3</strong>
</span>
</div>
-- Proposed Output (still page 3 of 3) --
<ul class="pager">
<li class="pager-first"><a href="/drupal-head/?q=node" title="Go to first page" class="active">« first</a></li>
<li class="pager-previous"><a href="/drupal-head/?q=node&page=1" title="Go to previous page" class="active">‹ previous</a></li>
<li class="pager-item"><a href="/drupal-head/?q=node" title="Go to page 1" class="active">1</a></li>
<li class="pager-item"><a href="/drupal-head/?q=node&page=1" title="Go to page 2" class="active">2</a></li>
<li class="pager-current">3</li>
<li class="pager-next">next ›</li>
<li class="pager-last">last »</li>
</ul>
Legibility alone goes a long way to illustrate the difference on this one, but the code will be easier to maintain, no extraneous spans, the classes have been organized onto the list items, and the entire pager displays for ease of theming again. A pager with links that appear and disappear (i.e. next/last, previous/first) is hard to anticipate at all times. A pager which displays these items even when unlinked is much easier to anticipate and design for.
Finally while not necessarily part of this issue, you'll notice active gets slapped on everything. This is just due to the way the l() function works. Even if the l() function categorized pager links properly, the active pager "link" isn't really a link, and thus would never have an active tag on it. Additionally this is done via the "pager-current" class already, so it would be redundant and unneeded in any case. The l() function might benefit from some revisiting, the suggestion was made that perhaps a way to turn the active class off would be nice. I just want to recognize that's not part of this patch, but this patch does put a bit of a spotlight on it.
Included is a change to the system.css as well, it's minor for the sake of formatting.
(if there are any problems with the patch, let me know, as this is my first time doing this)
Comment | File | Size | Author |
---|---|---|---|
#31 | pager10.patch | 11.05 KB | EclipseGc |
#25 | pager9.patch | 11.76 KB | riccardoR |
#23 | pager8.patch | 10.48 KB | EclipseGc |
#14 | pager7.patch | 11.19 KB | EclipseGc |
#12 | pager6.patch | 11.33 KB | EclipseGc |
Comments
Comment #1
Zen CreditAttribution: Zen commentedYour patch format is dodgy. Moreover, this is a dupe of an old issue http://drupal.org/node/68615 which, like every second patch on drupal.org, fell on its behind due to poor work-flow. Please re-roll, update or merge the two patches and I will happily review it.
Thanks.
-K
Comment #2
Dries CreditAttribution: Dries commentedI will review this too, if you re-roll it as per Zen's suggestions. Good stuff. :)
Comment #3
EclipseGc CreditAttribution: EclipseGc commentedOk, forgive me being kind of a newb to all of this, but I'll admit that I am.
Attached is a new patch that should be "less dodgy" me hopes. It's based off of the CVS version of drupal as of right now.
Again please forgive my lack of savvy here as I'm not entire sure what you mean by "re-roll"... did you just want a better diff? or did I do something specifically that needs to be addressed in my code?
Thank you for your patience, I hope this patch goes better for all involved.
EclipseGc
Comment #4
EclipseGc CreditAttribution: EclipseGc commentedI put up the patch, but failed to to mark the status back. I'd happily merge my patch to the other listed one, but it looks as though it's striving to do more than I am. I'm only striving to change the pager and nothing more. If I need to tackle this some other way, I'll do it, I just need someone to point me in the right direction.
EclipseGc
Comment #5
EclipseGc CreditAttribution: EclipseGc commentedafter long discussion in #drupal, I'm setting the code to needs work. Hopefully more improvements soon... :-)
Comment #6
EclipseGc CreditAttribution: EclipseGc commentedOK... this went WAY further than I ever anticipated, I was just gonna slap some list items onto the code, but after uploading it and some feedback from other community members (chx) it was brought to my attention that this would be much better implemented through theme_item_list. Chx handed me a rewrite of the theme_pager that illustrated the basic principle, and mentioned that theme_pager_list probably needed to disappear. Armed with chx's code I merged theme_pager & theme_pager_list together into a single function.
The only change to the output from this is that there's now a div surrounding the unordered list.
Thanks to chx for his helping the newbie on this!
Let me know what you all think.
EclipseGc
Comment #7
EclipseGc CreditAttribution: EclipseGc commenteddangit!
status updated: code needs review on previous patch
Comment #8
EclipseGc CreditAttribution: EclipseGc commentedupdated again for a couple minor things I missed and some coding standards chx pointed out to me. I hope I got everything this time.
Comment #9
EclipseGc CreditAttribution: EclipseGc commentedMore updates due to me being a newbie. Should install better now, spacing SHOULD be correct.
Comment #10
EclipseGc CreditAttribution: EclipseGc commentedthanks to riccardoR for educating me on diff, this one SHOULD install correctly.
Comment #11
Zen CreditAttribution: Zen commentedFYI: When an issue is marked duplicate, issue queue etiquette states that you move the patch to the original issue. I have marked the other a dupe in this case.
Patch looks fine visually. However, when you remove a theme function, you will now also have to remove the function from the theme registry (hook_theme). System theme functions are included in common.inc. Setting to needs work.
I will test this later if need be.
Comment #12
EclipseGc CreditAttribution: EclipseGc commentedZen, thanks for giving the newbie some leeway on this. I didn't understand what you were doing with tabs and such, so I just kept on moving. Again thanks.
I've done the patch for the common.inc as well and removed the pager_list from the registry there. I think I did that correctly, please let me know.
Eclipse
status set to review
Comment #13
dvessel CreditAttribution: dvessel commentedSince you moved theme_pager_list into theme_pager and changed the parameters, your going to have to double check all the calls to theme('pager') and the theme registry for it to get the parameters lined up.
I'm not so sure about having the next/prev/first/last items showing when there's nothing to link to. I talked to EclipseGc about this and understand his points, just don't agree with it.
Everything else looks good. Keep it up. :)
Comment #14
EclipseGc CreditAttribution: EclipseGc commentedMore updates to handle the merger of pager & pager_list properly.
common.inc updates should now be accurate.
Comment #15
m3avrck CreditAttribution: m3avrck commentedLooks like this patch is going in the right direction, much more semantic!
One thing I can't tell from the patch is if it fixes this usability bug I opened almost 2 years ago... http://drupal.org/node/28138
Would love to see that go in now with this rewrite.
Comment #16
EclipseGc CreditAttribution: EclipseGc commentedI can tell you that this absolutely doesn't address that particular issue.
I took kind of the opposite approach, that being that all the potential links should be displayed at all times, with the variable being the number of numbered links. I much prefer this for the sake of theming. I realize everyone has their own take on this, but my logic is simply, theming a pager is much easier when you don't have to worry about the pager changing size.
That's my reasoning for my approach.
Comment #17
dvessel CreditAttribution: dvessel commentedBut EclipseGc, the visibility of pager list [1-9] varies which kills that argument. I don't see how the pager can be any bit more difficult if it changes.
Look at everything that's turned into a horizontal list. theme_links for example. It varies widely and I've never heard of any theming issues with that.
m3avrck: I generally like your idea to clean up any link clutter but it would mean hunting around with the mouse to target the relatively narrow links. Not sure which is more important.
Comment #18
EclipseGc CreditAttribution: EclipseGc commenteddvessel:
Sure the argument could be made that the numbers vary as well, but I would point you to count the actual number of characters we're talking about here. When the numbers vary we have a variance between 2-9, so a total of 7 links over the lifetime of a page with a pager on it. With limited space this would be fairly easy to anticipate and make changes for. So we have 9 total characters possible in such a situation. These character will always be present once used. A disappearing "first/previous" or "next/last" is a bit different manner (imo). "First/Previous" is actually 15 character (including the anglequotes used) that will appear and disappear depending upon what page you're on. "First/Previous" is the biggest issue here as "Next/Last" is both smaller and will be present more often (as it starts present, and people may not navigate all the way to the end of the presented articles the pager serves). That's 15 characters, almost double the variation possible between the minimum size the pager numbers will be and the maximum size.
I point you to deviantart as a practical example of what I'm talking about. They don't use "first/last" but they do use "next/previous" and they are always present. Again I make this argument because I think it makes good design sense. I'll argue the point but I don't want it to be a deciding factor for the patch. I'm not dead set on it.
EclipseGc
Comment #19
Dries CreditAttribution: Dries commentedI skimmed the code and the proposed changes look sane to me. Haven't tested the patch though. I'll test it when it is marked RTBC.
(If we can improve the PHPdoc of this function, or document the internals better, this seems like the right time to do it. Keep that in mind when massaging the code.)
Comment #20
Zen CreditAttribution: Zen commentedI think Maverick's request is sound. We are already more or less doing this anyways, except that we do this only on the first and last pages (and for both next and previous links).
Thanks :)
-K
Comment #21
EclipseGc CreditAttribution: EclipseGc commentedWill remove $quantity from the docs. Added it when I merged the two functions and forgot to remove it.
Here's my plan of attack at the moment. I think that this question of dead links is one that will likely bikeshed this issue, and I'm unwilling to do that, so the next patch will function in the same manner the pager has ALWAYS functioned, but will have the new html code. I still firmly believe this is the WRONG answer, but I'll not argue for it at the expense of the patch. I'll try to rectify any spacing issues with the arrays.
Concerning m3avrck's request: If I'm going to do as I outlined above, then his argument makes good sense to implement.
Comments?
After that I don't know what to do. Should I rtbc it at that point?
Comment #22
riccardoR CreditAttribution: riccardoR commentedI agree that this patch is a move in the right direction concerning semantic.
As for styling: I am not a fan of displaying disabled links in the pager.
It' true that some popular sites are doing this, but so far I've seen it in small pagers (2 to 7 links).
Drupal might show up to 14 items on the first page, with 4 of them disabled: first/prev/current page and ellipsis.
I am afraid this would be confusing.
Anyway, if displayed at all, the disabled links should be styled very clearly per default to make it apparent which is which (enabled/disabled/active).
BTW, the fact that all links are tagged "active" adds even more confusion.
I think that Zen's idea to style them separately from tabs was a good improvement.
Thanks
Riccardo
Comment #23
EclipseGc CreditAttribution: EclipseGc commentedAs promised, returned back to original functionality.
$quantity deleted from phpdocs
and spacing on the arrays fixed (I think I got all of it)
If everyone's cool with this let's either rtbc it or talk about m3avrck's suggestion.
Comment #24
Zen CreditAttribution: Zen commentedIt currently displays empty list elements when first, prev, next and last are supposed to be hidden. The two array blocks for pager_next and pager_last also need to be brought into the if block above and additional checks added. Considering the extremely dodgy nature of $pager_last, you might need to use the $i counter. Please also check if the ellipses also need to be addresses for the same issue.
Thanks :)
-K
Comment #25
riccardoR CreditAttribution: riccardoR commentedRe-rolled as per Zen's review: empty list elements for hidden controls are no longer generated.
Plus:
- slight optimization: no code is executed if pager is not needed.
- small PHPdoc corrections.
I did much testing and cannot find any differences from the original functionality (including ellipsis).
Thanks
Riccardo
Comment #26
Dries CreditAttribution: Dries commentedThe code looks good except for one thing: the use of $tags[2] to set the number of pages. This looks a bit hackish to me. Any particular reason for not making it a regular paramater that defaults to 9? If we don't need this, let's remove that hack. Why would modules want to communicate how many pages to list? Isn't that a theme thing? Weird.
Comment #27
EclipseGc CreditAttribution: EclipseGc commentedThe intent was to change as little of the current logic as possible. heh, that's not exactly how it turned out, but yeah... I'll look into changing this and put up an update.
Comment #28
Zen CreditAttribution: Zen commented@Dries: If we start looking at issues with pager.inc, we will be here for the rest of the year - it is something of a mess. Can we please fix the mark-up first and then look at cleaning up the rest of pager.inc in a separate issue?
Patch still applies, albeit with an offset; setting to RTBC.
Thanks,
-K
Comment #29
Dries CreditAttribution: Dries commentedEclipse: do you still intend to work on this?
Comment #30
EclipseGc CreditAttribution: EclipseGc commentedSorry, got called off on another project, I'll get another update here today or tomorrow.
Eclipse
Comment #31
EclipseGc CreditAttribution: EclipseGc commentedOK, hopefully this is the final version of this. It includes Riccardo's changes to common.inc as well. Dries said it looked sane so I left it in there.
Additionally code was altered such that:
That should about do it, please review and comment.
Eclipse
Comment #32
Dries CreditAttribution: Dries commentedTested, reviewed and committed. Thanks folks!
Comment #33
dvessel CreditAttribution: dvessel commentedWhy the extra parameter for theme_pager? The $quantity value was originally derived from $tags:
Now the $quantity is stuck as 9.
Comment #34
dvessel CreditAttribution: dvessel commentedWhoops! excuse me. Noticed that all calls to theme_pager have a NULL set for $tags. Looks like it was there only for contrib modules.
But this should be documented form mod authors.
Comment #35
(not verified) CreditAttribution: commentedComment #36
stephit CreditAttribution: stephit commentedI actually WANT a version of pager that shows "Next/Previous" shaded out but still there when they are not "needed." Client just asked for it. It's confusing in some instances otherwise. So I'm bummed that the initial great idea here was totally snuffed out when that's what got me here in the first place. So I would like to have the option to leave in Next/Previous (even without a link) or take them out if desired. (Guess I will go back into the old patches here to find a version that takes it out for now.)
Comment #37
stephit CreditAttribution: stephit commentedFigured it out - if you want to add ghost "previous/next" links on the first and last pages then you can just add some custom code as follows (and do the same for the function for the last page). This is not too hard to do, but it would be nice to have this as an option to change as desired depending on node:
function theme_pager_first($text, $limit, $element = 0, $parameters = array()) {
global $pager_page_array;
$output = '';
// If we are anywhere but the first page
if ($pager_page_array[$element] > 0) {
$output = theme('pager_link', $text, pager_load_array(0, $element, $pager_page_array), $element, $parameters, array('class' => 'pager-first'));
}
// ADDED
else {
$output = ' « first   ‹ previous';
}
return $output;
}
Comment #38
stephit CreditAttribution: stephit commentedPS What I just added was based on the original pager.inc file.