diff --git a/.gitignore b/.gitignore index caa32e6..3e20c5d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ .idea/ -*.iml \ No newline at end of file +*.iml +bower_components +node_modules \ No newline at end of file diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..61cd5ea --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,52 @@ +module.exports = function (grunt) { + // Project configuration. + grunt.initConfig({ + // Task configuration. + pkg: grunt.file.readJSON('package.json'), + + // License banner text + banner: '/*\n' + + ' * <%= pkg.nativeName %> v<%= pkg.version %>\n' + + ' * <%= pkg.homepage %>\n' + + ' *\n' + + ' * Copyright 2014-<%= grunt.template.today("yyyy") %> <%= pkg.author %>\n' + + ' * Released under <%= pkg.license %> license\n' + + ' * <%= pkg.licenseUrl %>\n' + + ' */\n', + uglify: { + main: { + options: { + banner: '<%= banner %>', + sourceMap: false, + mangle: true, + compress: true, + beautify: false + }, + files: { + 'jquery.twbsPagination.min.js':'jquery.twbsPagination.js' + } + } + }, + // Run predefined tasks whenever watched file changed or deleted + watch: { + js: { + options: { + atBegin: true + }, + files: ['jquery.twbsPagination.js'], + tasks: [ + 'build' + ] + } + } + }); + + // These plugins provide necessary tasks. + require('load-grunt-tasks')(grunt); + + // Default task. + grunt.registerTask('default', ['watch:js']); + // + //// Custom tasks + grunt.registerTask('build', ['uglify:main']); +}; diff --git a/LICENSE b/LICENSE index 5fb2033..1b3a07d 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright 2014 © Eugene Simakin +Copyright 2014-2015 © Eugene Simakin Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/README.md b/README.md index a71036c..25bd958 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -## jQuery pagination plugin (bootstrap powered) ## +# [jQuery pagination plugin (bootstrap powered)](http://esimakin.github.io/twbs-pagination/) ### Basic usage ### @@ -18,4 +18,9 @@ $('#pagination-demo').twbsPagination({ }); ``` +## Contributing +For development use grunt build to make minified file. +To use grunt install packages by using: npm install + +## Demo and Docs For more information see [docs on github pages](http://esimakin.github.io/twbs-pagination/) \ No newline at end of file diff --git a/bower.json b/bower.json index d4ae04c..e30328b 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "twbs-pagination", - "version": "1.2.5", + "version": "1.3", "homepage": "https://github.com/esimakin/twbs-pagination", "authors": [ "Eugene Simakin " @@ -24,7 +24,6 @@ "**/.*", "node_modules", "bower_components", - "test", "tests" ] } diff --git a/jquery.twbsPagination.js b/jquery.twbsPagination.js index f96332a..4bdd0ee 100644 --- a/jquery.twbsPagination.js +++ b/jquery.twbsPagination.js @@ -6,7 +6,6 @@ * Released under Apache 2.0 license * http://apache.org/licenses/LICENSE-2.0.html */ -; (function ($, window, document, undefined) { 'use strict'; @@ -38,14 +37,14 @@ } if (this.options.onPageClick instanceof Function) { - this.$element.first().bind('page', this.options.onPageClick); + this.$element.first().on('page', this.options.onPageClick); } if (this.options.href) { - var m, regexp = this.options.href.replace(/[-\/\\^$*+?.|[\]]/g, '\\$&'); + var match, 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); + if ((match = new RegExp(regexp, 'i').exec(window.location.href)) != null) { + this.options.startPage = parseInt(match[1], 10); } } @@ -81,7 +80,8 @@ destroy: function () { this.$element.empty(); this.$element.removeData('twbs-pagination'); - this.$element.unbind('page'); + this.$element.off('page'); + return this; }, @@ -94,6 +94,7 @@ this.setupEvents(); this.$element.trigger('page', page); + return this; }, @@ -126,39 +127,40 @@ }, buildItem: function (type, page) { - var itemContainer = $('
  • '), - itemContent = $(''), + var $itemContainer = $('
  • '), + $itemContent = $(''), itemText = null; switch (type) { case 'page': itemText = page; - itemContainer.addClass(this.options.pageClass); + $itemContainer.addClass(this.options.pageClass); break; case 'first': itemText = this.options.first; - itemContainer.addClass(this.options.firstClass); + $itemContainer.addClass(this.options.firstClass); break; case 'prev': itemText = this.options.prev; - itemContainer.addClass(this.options.prevClass); + $itemContainer.addClass(this.options.prevClass); break; case 'next': itemText = this.options.next; - itemContainer.addClass(this.options.nextClass); + $itemContainer.addClass(this.options.nextClass); break; case 'last': itemText = this.options.last; - itemContainer.addClass(this.options.lastClass); + $itemContainer.addClass(this.options.lastClass); break; default: break; } - itemContainer.data('page', page); - itemContainer.data('page-type', type); - itemContainer.append(itemContent.attr('href', this.makeHref(page)).html(itemText)); - return itemContainer; + $itemContainer.data('page', page); + $itemContainer.data('page-type', type); + $itemContainer.append($itemContent.attr('href', this.makeHref(page)).html(itemText)); + + return $itemContainer; }, getPages: function (currentPage) { @@ -188,7 +190,7 @@ }, render: function (pages) { - var that = this; + var _this = this; this.$listContainer.children().remove(); this.$listContainer.append(this.buildListItems(pages)); @@ -199,21 +201,21 @@ switch (pageType) { case 'page': if ($this.data('page') === pages.currentPage) { - $this.addClass(that.options.activeClass); + $this.addClass(_this.options.activeClass); } break; case 'first': - $this.toggleClass(that.options.disabledClass, pages.currentPage === 1); + $this.toggleClass(_this.options.disabledClass, pages.currentPage === 1); break; case 'last': - $this.toggleClass(that.options.disabledClass, pages.currentPage === that.options.totalPages); + $this.toggleClass(_this.options.disabledClass, pages.currentPage === _this.options.totalPages); break; case 'prev': - $this.toggleClass(that.options.disabledClass, !that.options.loop && pages.currentPage === 1); + $this.toggleClass(_this.options.disabledClass, !_this.options.loop && pages.currentPage === 1); break; case 'next': - $this.toggleClass(that.options.disabledClass, - !that.options.loop && pages.currentPage === that.options.totalPages); + $this.toggleClass(_this.options.disabledClass, + !_this.options.loop && pages.currentPage === _this.options.totalPages); break; default: break; @@ -223,20 +225,18 @@ }, setupEvents: function () { - var base = this; + var _this = this; this.$listContainer.find('li').each(function () { var $this = $(this); $this.off(); - if ($this.hasClass(base.options.disabledClass) || $this.hasClass(base.options.activeClass)) { - $this.click(function (evt) { - evt.preventDefault(); - }); + if ($this.hasClass(_this.options.disabledClass) || $this.hasClass(_this.options.activeClass)) { + $this.on('click', false); return; } $this.click(function (evt) { // Prevent click event if href is not set. - !base.options.href && evt.preventDefault(); - base.show(parseInt($this.data('page'), 10)); + !_this.options.href && evt.preventDefault(); + _this.show(parseInt($this.data('page'))); }); }); }, @@ -293,4 +293,4 @@ return this; }; -})(jQuery, window, document); +})(window.jQuery, window, document); diff --git a/jquery.twbsPagination.min.js b/jquery.twbsPagination.min.js index d5e434e..d2a5022 100644 --- a/jquery.twbsPagination.min.js +++ b/jquery.twbsPagination.min.js @@ -1,9 +1,9 @@ /* - * jQuery pagination plugin v1.2.6 - * http://esimakin.github.io/twbs-pagination/ + * jQuery Bootstrap Pagination v1.2.6 + * https://github.com/esimakin/twbs-pagination * - * Copyright 2014, Eugene Simakin + * Copyright 2014-2015 Eugene Simakin * Released under Apache 2.0 license * http://apache.org/licenses/LICENSE-2.0.html */ -(function(e,d,a,f){var b=e.fn.twbsPagination;var c=function(j,h){this.$element=e(j);this.options=e.extend({},e.fn.twbsPagination.defaults,h);if(this.options.startPage<1||this.options.startPage>this.options.totalPages){throw new Error("Start page option is incorrect")}this.options.totalPages=parseInt(this.options.totalPages);if(isNaN(this.options.totalPages)){throw new Error("Total pages option is not correct!")}this.options.visiblePages=parseInt(this.options.visiblePages);if(isNaN(this.options.visiblePages)){throw new Error("Visible pages option is not correct!")}if(this.options.totalPages")}this.$listContainer.addClass(this.options.paginationClass);if(i!=="UL"){this.$element.append(this.$listContainer)}this.render(this.getPages(this.options.startPage));this.setupEvents();if(this.options.initiateStartPageClick){this.$element.trigger("page",this.options.startPage)}return this};c.prototype={constructor:c,destroy:function(){this.$element.empty();this.$element.removeData("twbs-pagination");this.$element.unbind("page");return this},show:function(g){if(g<1||g>this.options.totalPages){throw new Error("Page is incorrect.")}this.render(this.getPages(g));this.setupEvents();this.$element.trigger("page",g);return this},buildListItems:function(g){var j=e();if(this.options.first){j=j.add(this.buildItem("first",1))}if(this.options.prev){var l=g.currentPage>1?g.currentPage-1:this.options.loop?this.options.totalPages:1;j=j.add(this.buildItem("prev",l))}for(var h=0;h"),k=e(""),g=null;switch(i){case"page":g=j;h.addClass(this.options.pageClass);break;case"first":g=this.options.first;h.addClass(this.options.firstClass);break;case"prev":g=this.options.prev;h.addClass(this.options.prevClass);break;case"next":g=this.options.next;h.addClass(this.options.nextClass);break;case"last":g=this.options.last;h.addClass(this.options.lastClass);break;default:break}h.data("page",j);h.data("page-type",i);h.append(k.attr("href",this.makeHref(j)).html(g));return h},getPages:function(j){var g=[];var k=Math.floor(this.options.visiblePages/2);var l=j-k+1-this.options.visiblePages%2;var h=j+k;if(l<=0){l=1;h=this.options.visiblePages}if(h>this.options.totalPages){l=this.options.totalPages-this.options.visiblePages+1;h=this.options.totalPages}var i=l;while(i<=h){g.push(i);i++}return{currentPage:j,numeric:g}},render:function(g){var h=this;this.$listContainer.children().remove();this.$listContainer.append(this.buildListItems(g));this.$listContainer.children().each(function(){var j=e(this),i=j.data("page-type");switch(i){case"page":if(j.data("page")===g.currentPage){j.addClass(h.options.activeClass)}break;case"first":j.toggleClass(h.options.disabledClass,g.currentPage===1);break;case"last":j.toggleClass(h.options.disabledClass,g.currentPage===h.options.totalPages);break;case"prev":j.toggleClass(h.options.disabledClass,!h.options.loop&&g.currentPage===1);break;case"next":j.toggleClass(h.options.disabledClass,!h.options.loop&&g.currentPage===h.options.totalPages);break;default:break}})},setupEvents:function(){var g=this;this.$listContainer.find("li").each(function(){var h=e(this);h.off();if(h.hasClass(g.options.disabledClass)||h.hasClass(g.options.activeClass)){h.click(function(i){i.preventDefault()});return}h.click(function(i){!g.options.href&&i.preventDefault();g.show(parseInt(h.data("page"),10))})})},makeHref:function(g){return this.options.href?this.options.href.replace(this.options.hrefVariable,g):"#"}};e.fn.twbsPagination=function(i){var h=Array.prototype.slice.call(arguments,1);var k;var l=e(this);var j=l.data("twbs-pagination");var g=typeof i==="object"&&i;if(!j){l.data("twbs-pagination",(j=new c(this,g)))}if(typeof i==="string"){k=j[i].apply(j,h)}return(k===f)?l:k};e.fn.twbsPagination.defaults={totalPages:0,startPage:1,visiblePages:5,initiateStartPageClick:true,href:false,hrefVariable:"{{number}}",first:"First",prev:"Previous",next:"Next",last:"Last",loop:false,onPageClick:null,paginationClass:"pagination",nextClass:"next",prevClass:"prev",lastClass:"last",firstClass:"first",pageClass:"page",activeClass:"active",disabledClass:"disabled"};e.fn.twbsPagination.Constructor=c;e.fn.twbsPagination.noConflict=function(){e.fn.twbsPagination=b;return this}})(jQuery,window,document); \ No newline at end of file +!function(a,b,c,d){"use strict";var e=a.fn.twbsPagination,f=function(c,d){if(this.$element=a(c),this.options=a.extend({},a.fn.twbsPagination.defaults,d),this.options.startPage<1||this.options.startPage>this.options.totalPages)throw new Error("Start page option is incorrect");if(this.options.totalPages=parseInt(this.options.totalPages),isNaN(this.options.totalPages))throw new Error("Total pages option is not correct!");if(this.options.visiblePages=parseInt(this.options.visiblePages),isNaN(this.options.visiblePages))throw new Error("Visible pages option is not correct!");if(this.options.totalPages"),this.$listContainer.addClass(this.options.paginationClass),"UL"!==g&&this.$element.append(this.$listContainer),this.render(this.getPages(this.options.startPage)),this.setupEvents(),this.options.initiateStartPageClick&&this.$element.trigger("page",this.options.startPage),this};f.prototype={constructor:f,destroy:function(){return this.$element.empty(),this.$element.removeData("twbs-pagination"),this.$element.off("page"),this},show:function(a){if(1>a||a>this.options.totalPages)throw new Error("Page is incorrect.");return this.render(this.getPages(a)),this.setupEvents(),this.$element.trigger("page",a),this},buildListItems:function(b){var c=a();if(this.options.first&&(c=c.add(this.buildItem("first",1))),this.options.prev){var d=b.currentPage>1?b.currentPage-1:this.options.loop?this.options.totalPages:1;c=c.add(this.buildItem("prev",d))}for(var e=0;e"),e=a(""),f=null;switch(b){case"page":f=c,d.addClass(this.options.pageClass);break;case"first":f=this.options.first,d.addClass(this.options.firstClass);break;case"prev":f=this.options.prev,d.addClass(this.options.prevClass);break;case"next":f=this.options.next,d.addClass(this.options.nextClass);break;case"last":f=this.options.last,d.addClass(this.options.lastClass)}return d.data("page",c),d.data("page-type",b),d.append(e.attr("href",this.makeHref(c)).html(f)),d},getPages:function(a){var b=[],c=Math.floor(this.options.visiblePages/2),d=a-c+1-this.options.visiblePages%2,e=a+c;0>=d&&(d=1,e=this.options.visiblePages),e>this.options.totalPages&&(d=this.options.totalPages-this.options.visiblePages+1,e=this.options.totalPages);for(var f=d;e>=f;)b.push(f),f++;return{currentPage:a,numeric:b}},render:function(b){var c=this;this.$listContainer.children().remove(),this.$listContainer.append(this.buildListItems(b)),this.$listContainer.children().each(function(){var d=a(this),e=d.data("page-type");switch(e){case"page":d.data("page")===b.currentPage&&d.addClass(c.options.activeClass);break;case"first":d.toggleClass(c.options.disabledClass,1===b.currentPage);break;case"last":d.toggleClass(c.options.disabledClass,b.currentPage===c.options.totalPages);break;case"prev":d.toggleClass(c.options.disabledClass,!c.options.loop&&1===b.currentPage);break;case"next":d.toggleClass(c.options.disabledClass,!c.options.loop&&b.currentPage===c.options.totalPages)}})},setupEvents:function(){var b=this;this.$listContainer.find("li").each(function(){var c=a(this);return c.off(),c.hasClass(b.options.disabledClass)||c.hasClass(b.options.activeClass)?void c.on("click",!1):void c.click(function(a){!b.options.href&&a.preventDefault(),b.show(parseInt(c.data("page")))})})},makeHref:function(a){return this.options.href?this.options.href.replace(this.options.hrefVariable,a):"#"}},a.fn.twbsPagination=function(b){var c,e=Array.prototype.slice.call(arguments,1),g=a(this),h=g.data("twbs-pagination"),i="object"==typeof b&&b;return h||g.data("twbs-pagination",h=new f(this,i)),"string"==typeof b&&(c=h[b].apply(h,e)),c===d?g:c},a.fn.twbsPagination.defaults={totalPages:0,startPage:1,visiblePages:5,initiateStartPageClick:!0,href:!1,hrefVariable:"{{number}}",first:"First",prev:"Previous",next:"Next",last:"Last",loop:!1,onPageClick:null,paginationClass:"pagination",nextClass:"next",prevClass:"prev",lastClass:"last",firstClass:"first",pageClass:"page",activeClass:"active",disabledClass:"disabled"},a.fn.twbsPagination.Constructor=f,a.fn.twbsPagination.noConflict=function(){return a.fn.twbsPagination=e,this}}(window.jQuery,window,document); \ No newline at end of file diff --git a/package.json b/package.json index 89118ff..0ca6fa2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,7 @@ { "name": "twbs-pagination", - "version": "1.2.6", + "nativeName": "jQuery Bootstrap Pagination", + "version": "1.3", "homepage": "https://github.com/esimakin/twbs-pagination", "author": "Eugene Simakin ", "description": "jQuery simple pagination plugin for bootstrap-style webpages", @@ -8,16 +9,19 @@ "dependencies": { "jquery": ">=1.7.0" }, + "devDependencies": { + "grunt": "^0.4.5", + "grunt-cli": "~0.1.13", + "grunt-contrib-watch": "~0.6.1", + "grunt-contrib-uglify": "^0.9.2", + "load-grunt-tasks": "^3.1.0" + }, "keywords": [ "pagination", "jQuery", "jQuery-plugin", "bootstrap" ], - "volo": { - "dependencies": { - "jquery": "jquery/jquery/>=1.7.0" - } - }, - "license": "Apache 2.0" + "license": "Apache 2.0", + "licenseUrl": "http://apache.org/licenses/LICENSE-2.0.html" } diff --git a/twbs-pagination.jquery.json b/twbs-pagination.jquery.json index 969f30b..23f832a 100644 --- a/twbs-pagination.jquery.json +++ b/twbs-pagination.jquery.json @@ -1,7 +1,7 @@ { "name": "twbs-pagination", - "version": "1.2.6", - "title": "Twbs Pagination", + "version": "1.3", + "title": "jQuery Bootstrap Pagination", "author": { "name": "Eugene Simakin", "email": "mail@esimakin.com", @@ -14,7 +14,7 @@ } ], "dependencies": { - "jquery": "> 1.10.2" + "jquery": "> 1.7" }, "description": "Twbs Pagination is a jQuery plugin that provides pagination for your web site or application. Check out the demo!", "keywords": [