JQuery Pagination Plugin - Can't Click "next" On First Page
Solution 1:
It is a bit much to dump the entire plugin code into your question and expect someone to search through it and try to find all of the modifications you have made. I am certainly not prepared to do it.
However, I want to point out a few problems with your approach:
First, you should not be modifying the plugin source directly. In my original answer to you, I made sure to leave the plugin code intact and explicitly overwrote the $.PaginationCalculator.prototype.getInterval
implementation outside of the plugin code. Anyone picking-up your code is not going to know that this plugin code has been modified and will be very confused when the behavior does not comply with the documentation.
Secondly, you should not be hard-coding 7
s all over the place. This plugin code was intentionally designed to support different configurations. By hard-coding in 7
, you have ensured that this code will break for anyone who initializes the plugin with a num_display_entries
that is not 7
.
Thirdly (and similar to the second point), you should not be modifying the default options within the plugin code. The plugin design allows you to pass, for example, your own values for prev_text
and next_text
at initialization.
Although I would not attempt to debug your modifications, I did take a look at original plugin source to see if your new requirement could be met. I believe I was able to meet your requirement by changing just a single line of code. I simply changed the default link text that is set in the $.PaginationRenderers.defaultRenderer.prototype.createLink
method. Again, in order to preserve the plugin source, I would recommend explicitly overwriting the method you want to modify. I have copied the method and have added a comment regarding the line of code I have changed:
$.PaginationRenderers.defaultRenderer.prototype.createLink = function(page_id, current_page, appendopts) {
var lnk, np = this.pc.numPages();
page_id = page_id<0?0:(page_id<np?page_id:np-1); // Normalize page id to sane value
appendopts = $.extend({
//text: page_id+1,
// Note: This is the only line of code I have changed from the original.
// It ensures that the link text is only ever within a range of 1 - num_display_entries
text: (page_id % this.opts.num_display_entries) + 1,
classes: ""
}, appendopts||{});
if(page_id == current_page){
lnk = $("<span class='current'>" + appendopts.text + "</span>");
}
else
{
lnk = $("<a>" + appendopts.text + "</a>")
.attr('href', this.opts.link_to.replace(/__id__/,page_id));
}
if(appendopts.classes){ lnk.addClass(appendopts.classes); }
if(appendopts.rel){ lnk.attr('rel', appendopts.rel); }
lnk.data('page_id', page_id);
return lnk;
};
I have created a JS Fiddle demo for reference.
Post a Comment for "JQuery Pagination Plugin - Can't Click "next" On First Page"