diff --git a/jquery.twbsPagination.js b/jquery.twbsPagination.js index 3887141..be6875f 100644 --- a/jquery.twbsPagination.js +++ b/jquery.twbsPagination.js @@ -18,52 +18,47 @@ var TwbsPagination = function (element, options) { this.$element = $(element); this.options = $.extend({}, $.fn.twbsPagination.defaults, options); - this.init(this.options); - }; - - TwbsPagination.prototype = { - constructor: TwbsPagination, + if (this.options.startPage < 1 || this.options.startPage > this.options.totalPages) { + throw new Error('Start page option is incorrect'); + } - init: function (options) { - this.options = $.extend({}, this.options, options); + if (this.options.totalPages <= 0) { + throw new Error('Total pages option cannot be less 1 (one)!'); + } - if (this.options.startPage < 1 || this.options.startPage > this.options.totalPages) { - throw new Error('Start page option is incorrect'); - } + if (this.options.totalPages < this.options.visiblePages) { + this.options.visiblePages = this.options.totalPages; + } - if (this.options.totalPages <= 0) { - throw new Error('Total pages option cannot be less 1 (one)!'); - } + if (this.options.onPageClick instanceof Function) { + this.$element.first().bind('page', this.options.onPageClick); + } - if (this.options.totalPages < this.options.visiblePages) { - this.options.visiblePages = this.options.totalPages; - } + var tagName = (typeof this.$element.prop === 'function') ? + this.$element.prop('tagName') : this.$element.attr('tagName'); - if (this.options.onPageClick instanceof Function) { - this.$element.first().bind('page', this.options.onPageClick); - } + if (tagName === 'UL') { + this.$listContainer = this.$element; + } else { + this.$listContainer = $(''); + } - var tagName = (typeof this.$element.prop === 'function') ? - this.$element.prop('tagName') : this.$element.attr('tagName'); + this.$listContainer.addClass(this.options.paginationClass); - if (tagName === 'UL') { - this.$listContainer = this.$element; - } else { - this.$listContainer = $(''); - } + if (tagName !== 'UL') { + this.$element.append(this.$listContainer); + } - this.$listContainer.addClass(this.options.paginationClass); + this.render(this.getPages(this.options.startPage)); + this.setupEvents(); - if (tagName !== 'UL') { - this.$element.append(this.$listContainer); - } + return this; + }; - this.render(this.getPages(this.options.startPage)); - this.setupEvents(); + TwbsPagination.prototype = { - return this; - }, + constructor: TwbsPagination, destroy: function () { this.$element.empty();