Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
'Versions' example removed
  • Loading branch information
Eugene Simakin committed Mar 16, 2014
1 parent a22ad70 commit 0719d42
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 88 deletions.
27 changes: 4 additions & 23 deletions index.html
Expand Up @@ -65,12 +65,10 @@ <h3>
<a id="demo" class="anchor" href="#demo"><span
class="octicon octicon-link"></span></a>Demo</h3>

<p>
<div id="page-content" class="well"></div>
<div class="text-center">
<ul id="pagination-demo" class="pagination-sm"></ul>
</div>
</p>
<div id="page-content" class="well"></div>
<div class="text-center">
<ul id="pagination-demo" class="pagination-sm"></ul>
</div>

<p>Here is corresponding piece of code:</p>
<pre><code class="highlight"> $(<span class="s">'#pagination-demo'</span>).twbsPagination({
Expand Down Expand Up @@ -127,23 +125,6 @@ <h3>
<a id="examples" class="anchor" href="#examples"><span
class="octicon octicon-link"></span></a>Examples</h3>

<h4>Versions</h4>

<p>Choose behaviour of method <code>getPages</code>. Try to following demos:</p>

<div class="text-center">
<ul id="pagination-demo-v1_0" class="pagination-sm"></ul>
</div>

<div class="text-center">VS</div>

<div class="text-center">
<ul id="pagination-demo-v1_1" class="pagination-sm"></ul>
</div>

<p>Download <a href="https://github.com/esimakin/twbs-pagination/releases/tag/v1.0">first</a> or
<a href="https://github.com/esimakin/twbs-pagination/releases/tag/v1.1">second</a>.</p>

<h4>URL page link</h4>

<p>You can specify url using <code>href</code> option:</p>
Expand Down
74 changes: 22 additions & 52 deletions js/jquery.twbsPagination.js
Expand Up @@ -28,18 +28,6 @@
init: function (options) {
this.options = $.extend({}, this.options, options);

switch (this.options.version) {
case '1.0':
this.currentPages = this.getPages_v_1_0(this.options.startPage);
break;
case '1.1':
this.currentPages = this.getPages_v_1_1(this.options.startPage);
break;
default:
this.currentPages = this.getPages_v_1_1(this.options.startPage);
break;
}

if (this.options.startPage < 1 || this.options.startPage > this.options.totalPages) {
throw new Error('Start page option is incorrect');
}
Expand All @@ -48,10 +36,12 @@
throw new Error('Total pages option cannot be less 1 (one)!');
}

if (!$.isNumeric(this.options.visiblePages) && !this.options.visiblePages) {
if (this.options.totalPages < this.options.visiblePages) {
this.options.visiblePages = this.options.totalPages;
}

this.currentPages = this.getPages(this.options.startPage);

if (this.options.onPageClick instanceof Function) {
this.$element.bind('page', this.options.onPageClick);
}
Expand All @@ -73,29 +63,29 @@
this.$element.append(this.$listContainer);
}

this.show(this.options.startPage);
this.render(this.currentPages);
this.setupEvents();

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

return this;
},

destroy: function () {
this.$element.empty();
return this;
},

show: function (page) {
if (page < 1 || page > this.options.totalPages) {
throw new Error('Page is incorrect.');
}

switch (this.options.version) {
case '1.0':
this.render(this.getPages_v_1_0(page));
break;
case '1.1':
this.render(this.getPages_v_1_1(page));
break;
default:
this.render(this.getPages_v_1_1(page));
break;
}

this.render(this.getPages(page));
this.setupEvents();

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

buildListItems: function (pages) {
Expand Down Expand Up @@ -156,26 +146,7 @@
return itemContainer;
},

getPages_v_1_0: function (currentPage) {
var pages = [];

var startPage;
var section = parseInt(currentPage / this.options.visiblePages, 10);
if (currentPage % this.options.visiblePages === 0) {
startPage = (section - 1) * this.options.visiblePages + 1;
} else {
startPage = section * this.options.visiblePages + 1;
}

var endPage = Math.min(this.options.totalPages, (startPage + this.options.visiblePages) - 1);
for (var i = startPage; i <= endPage; i++) {
pages.push(i);
}

return {"currentPage": currentPage, "numeric": pages};
},

getPages_v_1_1: function (currentPage) {
getPages: function (currentPage) {
var pages = [];

var half = Math.floor(this.options.visiblePages / 2);
Expand Down Expand Up @@ -240,10 +211,10 @@
});
},

equals: function (oldArray, newArray) {
equals: function (arr1, arr2) {
var i = 0;
while ((i < oldArray.length) || (i < newArray.length)) {
if (oldArray[i] !== newArray[i]) {
while ((i < arr1.length) || (i < arr2.length)) {
if (arr1[i] !== arr2[i]) {
return false;
}
i++;
Expand Down Expand Up @@ -284,8 +255,7 @@
next: 'Next',
last: 'Last',
paginationClass: 'pagination',
onPageClick: null,
version: '1.1'
onPageClick: null
};

$.fn.twbsPagination.Constructor = TwbsPagination;
Expand All @@ -295,4 +265,4 @@
return this;
};

})(jQuery, window, document);
})(jQuery, window, document);
14 changes: 1 addition & 13 deletions js/main.js
Expand Up @@ -13,21 +13,9 @@ $(document).ready(function () {
}
});

$('#pagination-demo-v1_0').twbsPagination({
totalPages: 15,
version: '1.0',
startPage: 5
});

$('#pagination-demo-v1_1').twbsPagination({
totalPages: 15,
startPage: 5
});

$('#visible-pages-example').twbsPagination({
totalPages: 35,
visiblePages: 10,
version: '1.1'
visiblePages: 10
});

$('.sync-pagination').twbsPagination({
Expand Down

0 comments on commit 0719d42

Please sign in to comment.