Skip to content

Commit

Permalink
Merge branch 'release/1.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelthq committed Nov 4, 2015
2 parents cfaa8b3 + 5184069 commit ffaf90b
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 51 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.idea/
*.iml
*.iml
bower_components
node_modules
52 changes: 52 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -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']);
};
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2014 &copy; Eugene Simakin
Copyright 2014-2015 &copy; Eugene Simakin

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## jQuery pagination plugin (bootstrap powered) ##
# [jQuery pagination plugin (bootstrap powered)](http://esimakin.github.io/twbs-pagination/)

### Basic usage ###

Expand All @@ -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/)
3 changes: 1 addition & 2 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "twbs-pagination",
"version": "1.2.5",
"version": "1.3",
"homepage": "https://github.com/esimakin/twbs-pagination",
"authors": [
"Eugene Simakin <[email protected]>"
Expand All @@ -24,7 +24,6 @@
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
]
}
64 changes: 32 additions & 32 deletions jquery.twbsPagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* Released under Apache 2.0 license
* http://apache.org/licenses/LICENSE-2.0.html
*/
;
(function ($, window, document, undefined) {

'use strict';
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -81,7 +80,8 @@
destroy: function () {
this.$element.empty();
this.$element.removeData('twbs-pagination');
this.$element.unbind('page');
this.$element.off('page');

return this;
},

Expand All @@ -94,6 +94,7 @@
this.setupEvents();

this.$element.trigger('page', page);

return this;
},

Expand Down Expand Up @@ -126,39 +127,40 @@
},

buildItem: function (type, page) {
var itemContainer = $('<li></li>'),
itemContent = $('<a></a>'),
var $itemContainer = $('<li></li>'),
$itemContent = $('<a></a>'),
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) {
Expand Down Expand Up @@ -188,7 +190,7 @@
},

render: function (pages) {
var that = this;
var _this = this;
this.$listContainer.children().remove();
this.$listContainer.append(this.buildListItems(pages));

Expand All @@ -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;
Expand All @@ -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')));
});
});
},
Expand Down Expand Up @@ -293,4 +293,4 @@
return this;
};

})(jQuery, window, document);
})(window.jQuery, window, document);
8 changes: 4 additions & 4 deletions jquery.twbsPagination.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ffaf90b

Please sign in to comment.