diff --git a/responsive-paginate.js b/responsive-paginate.js index b84d66e..552367f 100755 --- a/responsive-paginate.js +++ b/responsive-paginate.js @@ -13,12 +13,19 @@ function rPage($container) { + // maybe user can pre-define this later + this.nextprev_class = ["prev", "next"]; + this.nextprev_text = ["prev", "next", "»", "«"]; + this.dots_class = ["dots"]; + this.dots_text = ["..."]; + this.label = function() { var active_index = this.els.filter(".active").index(); var rp = this; this.els.each(function(){ - if (rp.isNextOrPrevLink($(this)) == false) + //if (rp.isNextOrPrevLink($(this)) == false) + if (!rp.isNextOrPrevLink($(this))) { $(this).addClass("page-away-" + (Math.abs(active_index - $(this).index())).toString()); } @@ -36,6 +43,23 @@ }); } + this.compareText = function(text, str) + { + if (!text) return; + + var regex = new RegExp( + "(" + + str + .join('@') + .replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, '\\$&') + .replace(/@/g, "|") + + ")", + 'gi' + ); + + return text.match(regex); + } + this.makeResponsive = function() { this.reset(); @@ -52,15 +76,27 @@ } } - this.isNextOrPrevLink = function(element) + this.isNextOrPrevLink = function(element) + { + return ( + this.compareText(element.attr("class"), this.nextprev_class) + || this.compareText(element.text(), this.nextprev_text) + ); + } + + /* + this.isNextOrPrevLink = function(element) { return ( - element.hasClass('pagination-prev') - || element.hasClass('pagination-next') - || element.text() == "»" - || element.text() == "«" + //element.hasClass('pagination-prev') + //|| element.hasClass('pagination-next') + element.is("[class*='prev']") + || element.is("[class*='next']") + || element.text().trim() == "»" + || element.text().trim() == "«" ); } + */ this.isRemovable = function(element) { @@ -73,11 +109,14 @@ { return false; } - if (element.text() == "...") + /* + if (element.text().trim() == "...") { return false; } return true; + */ + return !this.compareText(element.attr("class"), this.dots_class) && !this.compareText(element.text(), this.dots_text); } this.removeOne = function() @@ -103,11 +142,11 @@ candid_candidate.css("display", "none"); if (this.needsEtcSign(active_index, farthest_index - 1)) { - this.els.eq(farthest_index - 2).before("