josecebe / twbs-pagination

jQuery pagination plugin (bootstrap powered)
http://josecebe.github.io/twbs-pagination/
Other
1.1k stars 401 forks source link

I find a bug when config the startPage #125

Closed AnchorRen closed 7 years ago

AnchorRen commented 8 years ago

I set the params like: href: '?keywords='+keywords+'&page={{pageNumber}}', hrefVariable: '{{pageNumber}}',

I use this plugin in a search page. when i use keywords has more than two words with blank like "snow water" to search the reault, the plugin's startPage is always locate at 1. Then i see the source code. if (this.options.href) { var m, regexp = this.options.href.replace(/[-\/\\^$*+?.|[\]]/g, '\\$&'); regexp = regexp.replace(this.options.hrefVariable, '(\\d+)'); if ((m = new RegExp(regexp, 'i').exec(window.location.href)) != null) { this.options.startPage = parseInt(m[1], 10); } } I find when the param keywords have blanks. m will not match with the page num. when there is no blanks i works well. So I think the prolem is at this code block.

I fix it as:

if (this.options.href) { var m, regexp = this.options.href.replace(/[-\/\\^$*+?.|[\]]/g, '\\$&'); regexp = regexp.replace(this.options.hrefVariable, '(\\d+)'); if ((m = new RegExp(regexp, 'i').exec(window.location.href)) != null) { this.options.startPage = parseInt(m[1], 10); }else{ var reg = new RegExp("(^|&)" + "page" + "=([^&]*)(&|$)"); var r = window.location.search.substr(1).match(reg); if (r != null){ var page = parseInt(r[2],10); this.options.startPage = page; } } }

then it works well. But it only fix my speciall config param. I wish you can fix it to common problems.

eugenesimakin commented 7 years ago

Fixed. Closed.