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&amp;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&amp;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&amp;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&amp;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)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Zen’s picture

Status: Needs review » Closed (duplicate)

Your 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

Dries’s picture

I will review this too, if you re-roll it as per Zen's suggestions. Good stuff. :)

EclipseGc’s picture

FileSize
5.87 KB

Ok, 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

EclipseGc’s picture

Status: Closed (duplicate) » Needs review

I 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

EclipseGc’s picture

Status: Needs review » Needs work

after long discussion in #drupal, I'm setting the code to needs work. Hopefully more improvements soon... :-)

EclipseGc’s picture

FileSize
9.2 KB

OK... 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

EclipseGc’s picture

Status: Needs work » Needs review

dangit!

status updated: code needs review on previous patch

EclipseGc’s picture

FileSize
10.38 KB

updated again for a couple minor things I missed and some coding standards chx pointed out to me. I hope I got everything this time.

EclipseGc’s picture

FileSize
10.52 KB

More updates due to me being a newbie. Should install better now, spacing SHOULD be correct.

EclipseGc’s picture

FileSize
10.42 KB

thanks to riccardoR for educating me on diff, this one SHOULD install correctly.

Zen’s picture

Status: Needs review » Needs work

FYI: 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.

EclipseGc’s picture

Status: Needs work » Needs review
FileSize
11.33 KB

Zen, 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

dvessel’s picture

Status: Needs review » Needs work

Since 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. :)

EclipseGc’s picture

Status: Needs work » Needs review
FileSize
11.19 KB

More updates to handle the merger of pager & pager_list properly.

common.inc updates should now be accurate.

m3avrck’s picture

Looks 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.

EclipseGc’s picture

I 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.

dvessel’s picture

But 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.

EclipseGc’s picture

dvessel:

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

Dries’s picture

I 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.)

Zen’s picture

Status: Needs review » Needs work
  • Not sure why $quantity is in the PHPDoc.
  • There are a few indentation issues with array declarations.
  • The whole idea of disabled links is regressive. It is IMO not usable either. -1. Also, by your reasoning, even if we have only 3 pages, we should display pages disabled links for pages 4 through 10 every time.

I 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

EclipseGc’s picture

Will 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?

riccardoR’s picture

I 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

EclipseGc’s picture

Status: Needs work » Needs review
FileSize
10.48 KB

As 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.

Zen’s picture

Status: Needs review » Needs work

It 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

riccardoR’s picture

Status: Needs work » Needs review
FileSize
11.76 KB

Re-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

Dries’s picture

The 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.

EclipseGc’s picture

The 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.

Zen’s picture

Status: Needs review » Reviewed & tested by the community

@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

Dries’s picture

Eclipse: do you still intend to work on this?

EclipseGc’s picture

Sorry, got called off on another project, I'll get another update here today or tomorrow.

Eclipse

EclipseGc’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
11.05 KB

OK, 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:

  • Pager now displays like the old pager did, next/previous will not appear if not needed
  • $quantity has been added to theme_pager with a default of 9

That should about do it, please review and comment.

Eclipse

Dries’s picture

Status: Needs review » Fixed

Tested, reviewed and committed. Thanks folks!

dvessel’s picture

Status: Fixed » Needs work

Why the extra parameter for theme_pager? The $quantity value was originally derived from $tags:

// From theme_pager calling pager_list.
$output .= theme('pager_list', $limit, $element, ($tags[2] ? $tags[2] : 9 ), '', $parameters);


theme_pager_list($limit, $element = 0, $quantity = 5, $text = '', $parameters = array())

Now the $quantity is stuck as 9.

dvessel’s picture

Status: Needs work » Fixed

Whoops! 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.

Anonymous’s picture

Status: Fixed » Closed (fixed)
stephit’s picture

I 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.)

stephit’s picture

Figured 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 &nbsp ‹ previous';
}

return $output;
}

stephit’s picture

PS What I just added was based on the original pager.inc file.