Skip to content
Snippets Groups Projects
Commit 0f29e8a1 authored by Daniel Herzog's avatar Daniel Herzog
Browse files

Build release 1.0.1

parent 3395e9e0
No related branches found
No related tags found
No related merge requests found
## 1.1.0 (2016-06-25)
## 1.0.1 (2016-12-07)
Bugs:
- Fix a bug related to `initialPage` option and `_setPage` function.
- Fix a bug related to total pages count (using `.floor()` instead of `.ceil()` was a terrible mistake).
## 1.0.0 (2016-06-25)
 
General:
 
Loading
Loading
Loading
Loading
@@ -39,15 +39,13 @@
 
<script>
// Add some examples to the page
for(var i = 0; i < 40; ++i)
for(var i = 0; i < 36; ++i)
$('#myTable > tbody').append('<tr><td>' + i + '</td><td>' + i.toString(16) + '</td></tr>');
 
// Paginate it
$('#myTable').paginate({
limit: 10,
onSelect: function(obj, page) {
console.log('Page ' + page + ' selected!' );
}
initialPage: 2
});
</script>
 
Loading
Loading
Loading
Loading
@@ -115,7 +115,7 @@
},
 
_setPage: function(index) {
if(!index) index = this.options.initialPage;
if(index == undefined) index = this.options.initialPage;
 
// Hide all elements, and then show the current page.
this._rows().hide().slice(index * this.options.limit, (index + 1) * this.options.limit).show();
Loading
Loading
@@ -136,7 +136,7 @@
return this.obj.find(this.options.childrenSelector);
},
_totalPages: function() {
return Math.floor(this._totalRows() / this.options.limit);
return Math.ceil(this._totalRows() / this.options.limit);
}
};
};
Loading
Loading
!function(t){"use strict"
var i=function(){return{obj:null,options:null,nav:null,build:function(t,i){return this.obj=t,this.options=i,this._createNavigation(),this._setPage(),this.options.onCreate&&this.options.onCreate(t),this.obj},_createNavigation:function(){this._createNavigationWrapper(),this._createNavigationButtons(),this._appendNavigation(),this._addNavigationCallbacks()},_createNavigationWrapper:function(){this.nav=t("<div>",{"class":this.options.navigationClass})},_createNavigationButtons:function(){this.options.first&&this._createNavigationButton(this.options.firstText,{"data-first":!0}),this.options.previous&&this._createNavigationButton(this.options.previousText,{"data-direction":-1,"data-previous":!0})
for(var t=0;t<this._totalPages();++t)this._createNavigationButton(this.options.pageToText(t),{"data-page":t})
this.options.next&&this._createNavigationButton(this.options.nextText,{"data-direction":1,"data-next":!0}),this.options.last&&this._createNavigationButton(this.options.lastText,{"data-last":!0})},_createNavigationButton:function(i,a){this.nav.append(t("<a>",t.extend(a,{href:"#",text:i})))},_appendNavigation:function(){this.options.navigationWrapper?this.options.navigationWrapper.append(this.nav):this.obj.after(this.nav)},_addNavigationCallbacks:function(){var i=this
i.nav.find("a").click(function(a){var n=1*t(this).data("direction")
if(void 0!==t(this).data("first"))i._setPage(0)
else if(void 0!==t(this).data("page"))i._setPage(1*t(this).data("page"))
else if(void 0!==t(this).data("previous")||void 0!==t(this).data("next")){var e=i._currentPage()+n
e>=0&&e<=i._totalPages()-1&&i._setPage(e)}else void 0!==t(this).data("last")&&i._setPage(i._totalPages()-1)
return i.options.onSelect&&i.options.onSelect(i.obj,i._currentPage()),a.preventDefault(),!1})},_setPage:function(t){t||(t=this.options.initialPage),this._rows().hide().slice(t*this.options.limit,(t+1)*this.options.limit).show(),this.nav.find("a").removeAttr("data-selected").siblings("a[data-page="+t+"]").attr("data-selected",!0)},_currentPage:function(){return this.nav.find("a[data-selected=true]").data("page")},_totalRows:function(){return this._rows().length},_rows:function(){return this.obj.find(this.options.childrenSelector)},_totalPages:function(){return Math.floor(this._totalRows()/this.options.limit)}}}
t.fn.paginate=function(a){switch(a){default:return i().build(this,t.extend({},t.fn.paginate.defaults,a))}},t.fn.paginate.defaults={limit:20,initialPage:0,previous:!0,previousText:"<",next:!0,nextText:">",first:!0,firstText:"<<",last:!0,lastText:">>",optional:!0,onCreate:null,onSelect:null,childrenSelector:"tbody > tr",navigationWrapper:null,navigationClass:"page-navigation",pageToText:function(t){return(t+1).toString()}}}(jQuery)
(function($){"use strict";var Paginator=function(){return{obj:null,options:null,nav:null,build:function(obj,opts){this.obj=obj;this.options=opts;if(!this.options.optional||this._totalRows()>this.options.limit){this._createNavigation();this._setPage()}if(this.options.onCreate)this.options.onCreate(obj);return this.obj},_createNavigation:function(){this._createNavigationWrapper();this._createNavigationButtons();this._appendNavigation();this._addNavigationCallbacks()},_createNavigationWrapper:function(){this.nav=$("<div>",{class:this.options.navigationClass})},_createNavigationButtons:function(){if(this.options.first){this._createNavigationButton(this.options.firstText,{"data-first":true})}if(this.options.previous){this._createNavigationButton(this.options.previousText,{"data-direction":-1,"data-previous":true})}for(var i=0;i<this._totalPages();++i){this._createNavigationButton(this.options.pageToText(i),{"data-page":i})}if(this.options.next){this._createNavigationButton(this.options.nextText,{"data-direction":1,"data-next":true})}if(this.options.last){this._createNavigationButton(this.options.lastText,{"data-last":true})}},_createNavigationButton:function(text,options){this.nav.append($("<a>",$.extend(options,{href:"#",text:text})))},_appendNavigation:function(){if(this.options.navigationWrapper)this.options.navigationWrapper.append(this.nav);else this.obj.after(this.nav)},_addNavigationCallbacks:function(){var paginator=this;paginator.nav.find("a").click(function(e){var direction=$(this).data("direction")*1;if($(this).data("first")!==undefined){paginator._setPage(0)}else if($(this).data("page")!==undefined){paginator._setPage($(this).data("page")*1)}else if($(this).data("previous")!==undefined||$(this).data("next")!==undefined){var page=paginator._currentPage()+direction;if(page>=0&&page<=paginator._totalPages()-1){paginator._setPage(page)}}else if($(this).data("last")!==undefined){paginator._setPage(paginator._totalPages()-1)}if(paginator.options.onSelect)paginator.options.onSelect(paginator.obj,paginator._currentPage());e.preventDefault();return false})},_setPage:function(index){if(index==undefined)index=this.options.initialPage;this._rows().hide().slice(index*this.options.limit,(index+1)*this.options.limit).show();this.nav.find("a").removeAttr("data-selected").siblings("a[data-page="+index+"]").attr("data-selected",true)},_currentPage:function(){return this.nav.find("a[data-selected=true]").data("page")},_totalRows:function(){return this._rows().length},_rows:function(){return this.obj.find(this.options.childrenSelector)},_totalPages:function(){return Math.ceil(this._totalRows()/this.options.limit)}}};$.fn.paginate=function(options){switch(options){default:return Paginator().build(this,$.extend({},$.fn.paginate.defaults,options))}};$.fn.paginate.defaults={limit:20,initialPage:0,previous:true,previousText:"<",next:true,nextText:">",first:true,firstText:"<<",last:true,lastText:">>",optional:true,onCreate:null,onSelect:null,childrenSelector:"tbody > tr",navigationWrapper:null,navigationClass:"page-navigation",pageToText:function(i){return(i+1).toString()}}})(jQuery);
{
"name": "jquery-paginate",
"version": "1.0.0",
"version": "1.0.1",
"description": "jQuery pagination plugin for tables",
"main": "jquery-paginate.min.js",
"scripts": {
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment