Browse files

Added disabled class. Fixes #7

Thanks to Zikes (Jason Hutchinson), of which this is based on.
  • Loading branch information...
1 parent 1c246a8 commit 6a367459002b0ae3ea2583870d53f5eead6e5c24 @beneverard committed Apr 11, 2012
Showing with 40 additions and 5 deletions.
  1. +15 −0 css/jqpagination.css
  2. +24 −4 js/jquery.jqpagination.js
  3. +1 −1 js/jquery.jqpagination.min.js
View
15 css/jqpagination.css
@@ -45,6 +45,21 @@
}
+.pagination a.disabled, .pagination a.disabled:hover, .pagination a.disabled:focus, .pagination a.disabled:active {
+
+ background: #F3F3F3; /* Old browsers */
+ background: -moz-linear-gradient(top, #F3F3F3 0%, #D3D3D3 100%); /* FF3.6+ */
+ background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#F3F3F3), color-stop(100%,#D3D3D3)); /* Chrome,Safari4+ */
+ background: -webkit-linear-gradient(top, #F3F3F3 0%,#D3D3D3 100%); /* Chrome10+,Safari5.1+ */
+ background: -o-linear-gradient(top, #F3F3F3 0%,#D3D3D3 100%); /* Opera 11.10+ */
+ background: -ms-linear-gradient(top, #F3F3F3 0%,#D3D3D3 100%); /* IE10+ */
+ background: linear-gradient(top, #F3F3F3 0%,#D3D3D3 100%); /* W3C */
+ filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#F3F3F3', endColorstr='#D3D3D3',GradientType=0 ); /* IE6-9 */
+
+ color: #A8A8A8;
+
+}
+
.pagination a:first-child {
border-radius: 2px 0 0 2px;
-moz-border-radius: 2px 0 0 2px;
View
28 js/jquery.jqpagination.js
@@ -44,7 +44,7 @@
base.options = $.extend({}, $.jqPagination.defaultOptions, options);
- // if the user hasn't provided a max page number in the options try and find
+ // if the user hasn't provided a max page number in the options try and find
// the data attribute for it, if that cannot be found, use one as a max page number
if (base.options.max_page === null) {
@@ -113,10 +113,19 @@
base.$el.find('a').live('click', function (event) {
- // for mac + windows (read: other), maintain the cmd + ctrl click for new tab
+ var $self = $(this);
+
+ // we don't want to do anything if we've clicked a disabled link
+ // return false so we stop normal link action btu also drop out of this event
+
+ if ($self.hasClass('disabled')) {
+ return false;
+ }
+
+ // for maintainac + windows (read: other), maintain the cmd + ctrl click for new tab
if (!event.metaKey && !event.ctrlKey) {
event.preventDefault();
- base.setPage($(this).data('action'));
+ base.setPage($self.data('action'));
}
});
@@ -268,7 +277,18 @@
base.$el.find('a.last').attr('href', link_string.replace('{page_number}', max_page));
}
-
+
+ // set disable class on appropriate links
+ base.$el.find('a').removeClass('disabled');
+
+ if (current_page === max_page) {
+ base.$el.find('.next, .last').addClass('disabled');
+ }
+
+ if (current_page === 1) {
+ base.$el.find('.previous, .first').addClass('disabled');
+ }
+
};
base.option = function (key, value) {
View
2 js/jquery.jqpagination.min.js
@@ -18,4 +18,4 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
- */(function(a){"use strict";a.jqPagination=function(b,c){var d=this;d.$el=a(b);d.el=b;d.$input=d.$el.find("input");d.$el.data("jqPagination",d);d.init=function(){d.options=a.extend({},a.jqPagination.defaultOptions,c);d.options.max_page===null&&(d.$input.data("max-page")!==undefined?d.options.max_page=d.$input.data("max-page"):d.options.max_page=1);d.$input.data("current-page")!==undefined&&d.isNumber(d.$input.data("current-page"))&&(d.options.current_page=d.$input.data("current-page"));d.$input.removeAttr("readonly");d.updateInput();d.$input.live("focus mouseup",function(b){if(b.type==="focusin"){var c=a(this);c.val(c.data("current-page")).select()}if(b.type==="mouseup")return!1});d.$input.live("blur keydown",function(b){var c=a(this),e=parseInt(d.options.current_page,10);if(b.keyCode===27){c.val(e);c.blur()}b.keyCode===13&&c.blur();b.type==="focusout"&&d.setPage(c.val())});d.$el.find("a").live("click",function(b){if(!b.metaKey&&!b.ctrlKey){b.preventDefault();d.setPage(a(this).data("action"))}})};d.setPage=function(a){if(a===undefined)return d.options.current_page;var b=parseInt(d.options.current_page,10),c=parseInt(d.options.max_page,10);if(isNaN(parseInt(a,10)))switch(a){case"first":a=1;break;case"prev":case"previous":a=b-1;break;case"next":a=b+1;break;case"last":a=c}a=parseInt(a,10);if(isNaN(a)||a<1||a>c||a===b){d.setInputValue(b);return!1}d.options.current_page=a;d.$input.data("current-page",a);d.updateInput()};d.setMaxPage=function(a){if(a===undefined)return d.options.max_page;if(!d.isNumber(a)){console.error("jqPagination: max_page is not a number");return!1}if(a<d.options.current_page){console.error("jqPagination: max_page lower than current_page");return!1}d.options.max_page=a;d.$input.data("max-page",a);d.updateInput()};d.updateInput=function(){var a=parseInt(d.options.current_page,10);d.setInputValue(a);d.setLinks(a);d.options.paged(a)};d.setInputValue=function(a){var b=d.options.page_string,c=d.options.max_page;b=b.replace("{current_page}",a).replace("{max_page}",c);d.$input.val(b)};d.isNumber=function(a){return!isNaN(parseFloat(a))&&isFinite(a)};d.setLinks=function(a){var b=d.options.link_string,c=parseInt(d.options.current_page,10),e=parseInt(d.options.max_page,10);if(b!==""){var f=c-1;f<1&&(f=1);var g=c+1;g>e&&(g=e);d.$el.find("a.first").attr("href",b.replace("{page_number}","1"));d.$el.find("a.prev, a.previous").attr("href",b.replace("{page_number}",f));d.$el.find("a.next").attr("href",b.replace("{page_number}",g));d.$el.find("a.last").attr("href",b.replace("{page_number}",e))}};d.option=function(a,b){switch(a.toLowerCase()){case"current_page":return d.setPage(b);case"max_page":return d.setMaxPage(b)}console.error("jqPagination: cannot get / set option "+a);return!1};d.init()};a.jqPagination.defaultOptions={current_page:1,link_string:"",max_page:null,page_string:"Page {current_page} of {max_page}",paged:function(){}};a.fn.jqPagination=function(){var b=this,c=Array.prototype.slice.call(arguments);if(c[0]==="option"){b.length>1&&(b=b.eq(0));var d=a(b).data("jqPagination");return d.option(c[1],c[2])}b.each(function(){new a.jqPagination(b,c[0])})}})(jQuery);
+ */(function(a){"use strict";a.jqPagination=function(b,c){var d=this;d.$el=a(b);d.el=b;d.$input=d.$el.find("input");d.$el.data("jqPagination",d);d.init=function(){d.options=a.extend({},a.jqPagination.defaultOptions,c);d.options.max_page===null&&(d.$input.data("max-page")!==undefined?d.options.max_page=d.$input.data("max-page"):d.options.max_page=1);d.$input.data("current-page")!==undefined&&d.isNumber(d.$input.data("current-page"))&&(d.options.current_page=d.$input.data("current-page"));d.$input.removeAttr("readonly");d.updateInput();d.$input.live("focus mouseup",function(b){if(b.type==="focusin"){var c=a(this);c.val(c.data("current-page")).select()}if(b.type==="mouseup")return!1});d.$input.live("blur keydown",function(b){var c=a(this),e=parseInt(d.options.current_page,10);if(b.keyCode===27){c.val(e);c.blur()}b.keyCode===13&&c.blur();b.type==="focusout"&&d.setPage(c.val())});d.$el.find("a").live("click",function(b){var c=a(this);if(c.hasClass("disabled"))return!1;if(!b.metaKey&&!b.ctrlKey){b.preventDefault();d.setPage(c.data("action"))}})};d.setPage=function(a){if(a===undefined)return d.options.current_page;var b=parseInt(d.options.current_page,10),c=parseInt(d.options.max_page,10);if(isNaN(parseInt(a,10)))switch(a){case"first":a=1;break;case"prev":case"previous":a=b-1;break;case"next":a=b+1;break;case"last":a=c}a=parseInt(a,10);if(isNaN(a)||a<1||a>c||a===b){d.setInputValue(b);return!1}d.options.current_page=a;d.$input.data("current-page",a);d.updateInput()};d.setMaxPage=function(a){if(a===undefined)return d.options.max_page;if(!d.isNumber(a)){console.error("jqPagination: max_page is not a number");return!1}if(a<d.options.current_page){console.error("jqPagination: max_page lower than current_page");return!1}d.options.max_page=a;d.$input.data("max-page",a);d.updateInput()};d.updateInput=function(){var a=parseInt(d.options.current_page,10);d.setInputValue(a);d.setLinks(a);d.options.paged(a)};d.setInputValue=function(a){var b=d.options.page_string,c=d.options.max_page;b=b.replace("{current_page}",a).replace("{max_page}",c);d.$input.val(b)};d.isNumber=function(a){return!isNaN(parseFloat(a))&&isFinite(a)};d.setLinks=function(a){var b=d.options.link_string,c=parseInt(d.options.current_page,10),e=parseInt(d.options.max_page,10);if(b!==""){var f=c-1;f<1&&(f=1);var g=c+1;g>e&&(g=e);d.$el.find("a.first").attr("href",b.replace("{page_number}","1"));d.$el.find("a.prev, a.previous").attr("href",b.replace("{page_number}",f));d.$el.find("a.next").attr("href",b.replace("{page_number}",g));d.$el.find("a.last").attr("href",b.replace("{page_number}",e))}d.$el.find("a").removeClass("disabled");c===e&&d.$el.find(".next, .last").addClass("disabled");c===1&&d.$el.find(".previous, .first").addClass("disabled")};d.option=function(a,b){switch(a.toLowerCase()){case"current_page":return d.setPage(b);case"max_page":return d.setMaxPage(b)}console.error("jqPagination: cannot get / set option "+a);return!1};d.init()};a.jqPagination.defaultOptions={current_page:1,link_string:"",max_page:null,page_string:"Page {current_page} of {max_page}",paged:function(){}};a.fn.jqPagination=function(){var b=this,c=Array.prototype.slice.call(arguments);if(c[0]==="option"){b.length>1&&(b=b.eq(0));var d=a(b).data("jqPagination");return d.option(c[1],c[2])}b.each(function(){new a.jqPagination(this,c[0])})}})(jQuery);

0 comments on commit 6a36745

Please sign in to comment.