Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updated tableling to 0.0.19. Version bump to 0.0.16.

  • Loading branch information...
commit f05fa9a481c176822ef6b936837b15889ea1651e 1 parent d0da4de
@AlphaHydrae authored
View
2  Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- tableling-rails (0.0.14)
+ tableling-rails (0.0.15)
rails (~> 3.2)
GEM
View
2  VERSION
@@ -1 +1 @@
-0.0.15
+0.0.16
View
2  lib/tableling-rails/version.rb
@@ -1,3 +1,3 @@
module Tableling
- VERSION = "0.0.15"
+ VERSION = "0.0.16"
end
View
51 vendor/assets/javascripts/tableling.backbone.js
@@ -3555,7 +3555,7 @@ _.extend(Marionette.Module, {
return Marionette;
})(Backbone, _, $ || window.jQuery || window.Zepto || window.ender);
/*!
- * Tableling v0.0.18
+ * Tableling v0.0.19
* Copyright (c) 2012-2013 Simon Oulevay (Alpha Hydrae) <hydrae.alpha@gmail.com>
* Distributed under MIT license
* https://github.com/AlphaHydrae/tableling
@@ -3563,7 +3563,7 @@ _.extend(Marionette.Module, {
Backbone.Tableling = Tableling = (function(Backbone, _, $){
var Tableling = {
- version : "0.0.18"
+ version : "0.0.19"
};
// Tableling
@@ -4111,6 +4111,7 @@ Backbone.Tableling = Tableling = (function(Backbone, _, $){
Tableling.Plain.PageView = Tableling.Plain.Table.prototype.pageView = Tableling.Module.extend({
template : _.template('<div class="pagination"><ul><li class="first"><a href="#">&lt;&lt;</a></li><li class="previous"><a href="#">&lt;</a></li><li class="next"><a href="#">&gt;</a></li><li class="last"><a href="#">&gt;&gt;</a></li></ul></div>'),
+ pageTemplate : _.template('<li class="page"><a href="#"><%- number %></a></li>'),
ui : {
first : '.first',
@@ -4122,12 +4123,14 @@ Backbone.Tableling = Tableling = (function(Backbone, _, $){
events : {
'click .first:not(.disabled)' : 'goToFirstPage',
'click .previous:not(.disabled)' : 'goToPreviousPage',
+ 'click .page:not(.disabled)' : 'goToPage',
'click .next:not(.disabled)' : 'goToNextPage',
'click .last:not(.disabled)' : 'goToLastPage'
},
refresh : function(data) {
- if (!data) {
+ this.$el.find('.page').remove();
+ if (!data || !data.length) {
this.ui.first.addClass('disabled');
this.ui.previous.addClass('disabled');
this.ui.next.addClass('disabled');
@@ -4136,11 +4139,39 @@ Backbone.Tableling = Tableling = (function(Backbone, _, $){
this.data = data;
this.enable(this.ui.first, this.getPage(data) > 1);
this.enable(this.ui.previous, this.getPage(data) > 1);
+ this.setupPages();
this.enable(this.ui.next, this.getPage(data) < this.numberOfPages(data));
this.enable(this.ui.last, this.getPage(data) < this.numberOfPages(data));
}
},
+ setupPages : function() {
+
+ var page = this.getPage(this.data);
+ var total = this.numberOfPages();
+
+ var first = page - 2;
+ if (total - first < 4) {
+ first = total - 4;
+ }
+
+ if (first < 1) {
+ first = 1;
+ }
+
+ var n = 5;
+ if (first + n - 1 > total) {
+ n = total - first + 1;
+ }
+
+ _.times(n, function(i) {
+ $(this.pageTemplate({ number : first + i })).insertBefore(this.ui.next);
+ }, this);
+
+ var i = page - first;
+ this.$el.find('.page').slice(i, i + 1).addClass('disabled');
+ },
+
enable : function(el, enabled) {
el.removeClass('disabled');
if (!enabled) {
@@ -4153,22 +4184,26 @@ Backbone.Tableling = Tableling = (function(Backbone, _, $){
},
goToFirstPage : function() {
- this.goToPage(1);
+ this.goToPageNumber(1);
},
goToPreviousPage : function() {
- this.goToPage(this.getPage(this.data) - 1);
+ this.goToPageNumber(this.getPage(this.data) - 1);
+ },
+
+ goToPage : function(e) {
+ this.goToPageNumber(parseInt($(e.target).text(), 10));
},
goToNextPage : function() {
- this.goToPage(this.getPage(this.data) + 1);
+ this.goToPageNumber(this.getPage(this.data) + 1);
},
goToLastPage : function() {
- this.goToPage(this.numberOfPages());
+ this.goToPageNumber(this.numberOfPages());
},
- goToPage : function(n) {
+ goToPageNumber : function(n) {
this.vent.trigger('table:update', { page : n });
},
View
51 vendor/assets/javascripts/tableling.js
@@ -1,5 +1,5 @@
/*!
- * Tableling v0.0.18
+ * Tableling v0.0.19
* Copyright (c) 2012-2013 Simon Oulevay (Alpha Hydrae) <hydrae.alpha@gmail.com>
* Distributed under MIT license
* https://github.com/AlphaHydrae/tableling
@@ -7,7 +7,7 @@
Backbone.Tableling = Tableling = (function(Backbone, _, $){
var Tableling = {
- version : "0.0.18"
+ version : "0.0.19"
};
// Tableling
@@ -555,6 +555,7 @@ Backbone.Tableling = Tableling = (function(Backbone, _, $){
Tableling.Plain.PageView = Tableling.Plain.Table.prototype.pageView = Tableling.Module.extend({
template : _.template('<div class="pagination"><ul><li class="first"><a href="#">&lt;&lt;</a></li><li class="previous"><a href="#">&lt;</a></li><li class="next"><a href="#">&gt;</a></li><li class="last"><a href="#">&gt;&gt;</a></li></ul></div>'),
+ pageTemplate : _.template('<li class="page"><a href="#"><%- number %></a></li>'),
ui : {
first : '.first',
@@ -566,12 +567,14 @@ Backbone.Tableling = Tableling = (function(Backbone, _, $){
events : {
'click .first:not(.disabled)' : 'goToFirstPage',
'click .previous:not(.disabled)' : 'goToPreviousPage',
+ 'click .page:not(.disabled)' : 'goToPage',
'click .next:not(.disabled)' : 'goToNextPage',
'click .last:not(.disabled)' : 'goToLastPage'
},
refresh : function(data) {
- if (!data) {
+ this.$el.find('.page').remove();
+ if (!data || !data.length) {
this.ui.first.addClass('disabled');
this.ui.previous.addClass('disabled');
this.ui.next.addClass('disabled');
@@ -580,11 +583,39 @@ Backbone.Tableling = Tableling = (function(Backbone, _, $){
this.data = data;
this.enable(this.ui.first, this.getPage(data) > 1);
this.enable(this.ui.previous, this.getPage(data) > 1);
+ this.setupPages();
this.enable(this.ui.next, this.getPage(data) < this.numberOfPages(data));
this.enable(this.ui.last, this.getPage(data) < this.numberOfPages(data));
}
},
+ setupPages : function() {
+
+ var page = this.getPage(this.data);
+ var total = this.numberOfPages();
+
+ var first = page - 2;
+ if (total - first < 4) {
+ first = total - 4;
+ }
+
+ if (first < 1) {
+ first = 1;
+ }
+
+ var n = 5;
+ if (first + n - 1 > total) {
+ n = total - first + 1;
+ }
+
+ _.times(n, function(i) {
+ $(this.pageTemplate({ number : first + i })).insertBefore(this.ui.next);
+ }, this);
+
+ var i = page - first;
+ this.$el.find('.page').slice(i, i + 1).addClass('disabled');
+ },
+
enable : function(el, enabled) {
el.removeClass('disabled');
if (!enabled) {
@@ -597,22 +628,26 @@ Backbone.Tableling = Tableling = (function(Backbone, _, $){
},
goToFirstPage : function() {
- this.goToPage(1);
+ this.goToPageNumber(1);
},
goToPreviousPage : function() {
- this.goToPage(this.getPage(this.data) - 1);
+ this.goToPageNumber(this.getPage(this.data) - 1);
+ },
+
+ goToPage : function(e) {
+ this.goToPageNumber(parseInt($(e.target).text(), 10));
},
goToNextPage : function() {
- this.goToPage(this.getPage(this.data) + 1);
+ this.goToPageNumber(this.getPage(this.data) + 1);
},
goToLastPage : function() {
- this.goToPage(this.numberOfPages());
+ this.goToPageNumber(this.numberOfPages());
},
- goToPage : function(n) {
+ goToPageNumber : function(n) {
this.vent.trigger('table:update', { page : n });
},
View
51 vendor/assets/javascripts/tableling.world.js
@@ -14826,7 +14826,7 @@ _.extend(Marionette.Module, {
return Marionette;
})(Backbone, _, $ || window.jQuery || window.Zepto || window.ender);
/*!
- * Tableling v0.0.18
+ * Tableling v0.0.19
* Copyright (c) 2012-2013 Simon Oulevay (Alpha Hydrae) <hydrae.alpha@gmail.com>
* Distributed under MIT license
* https://github.com/AlphaHydrae/tableling
@@ -14834,7 +14834,7 @@ _.extend(Marionette.Module, {
Backbone.Tableling = Tableling = (function(Backbone, _, $){
var Tableling = {
- version : "0.0.18"
+ version : "0.0.19"
};
// Tableling
@@ -15382,6 +15382,7 @@ Backbone.Tableling = Tableling = (function(Backbone, _, $){
Tableling.Plain.PageView = Tableling.Plain.Table.prototype.pageView = Tableling.Module.extend({
template : _.template('<div class="pagination"><ul><li class="first"><a href="#">&lt;&lt;</a></li><li class="previous"><a href="#">&lt;</a></li><li class="next"><a href="#">&gt;</a></li><li class="last"><a href="#">&gt;&gt;</a></li></ul></div>'),
+ pageTemplate : _.template('<li class="page"><a href="#"><%- number %></a></li>'),
ui : {
first : '.first',
@@ -15393,12 +15394,14 @@ Backbone.Tableling = Tableling = (function(Backbone, _, $){
events : {
'click .first:not(.disabled)' : 'goToFirstPage',
'click .previous:not(.disabled)' : 'goToPreviousPage',
+ 'click .page:not(.disabled)' : 'goToPage',
'click .next:not(.disabled)' : 'goToNextPage',
'click .last:not(.disabled)' : 'goToLastPage'
},
refresh : function(data) {
- if (!data) {
+ this.$el.find('.page').remove();
+ if (!data || !data.length) {
this.ui.first.addClass('disabled');
this.ui.previous.addClass('disabled');
this.ui.next.addClass('disabled');
@@ -15407,11 +15410,39 @@ Backbone.Tableling = Tableling = (function(Backbone, _, $){
this.data = data;
this.enable(this.ui.first, this.getPage(data) > 1);
this.enable(this.ui.previous, this.getPage(data) > 1);
+ this.setupPages();
this.enable(this.ui.next, this.getPage(data) < this.numberOfPages(data));
this.enable(this.ui.last, this.getPage(data) < this.numberOfPages(data));
}
},
+ setupPages : function() {
+
+ var page = this.getPage(this.data);
+ var total = this.numberOfPages();
+
+ var first = page - 2;
+ if (total - first < 4) {
+ first = total - 4;
+ }
+
+ if (first < 1) {
+ first = 1;
+ }
+
+ var n = 5;
+ if (first + n - 1 > total) {
+ n = total - first + 1;
+ }
+
+ _.times(n, function(i) {
+ $(this.pageTemplate({ number : first + i })).insertBefore(this.ui.next);
+ }, this);
+
+ var i = page - first;
+ this.$el.find('.page').slice(i, i + 1).addClass('disabled');
+ },
+
enable : function(el, enabled) {
el.removeClass('disabled');
if (!enabled) {
@@ -15424,22 +15455,26 @@ Backbone.Tableling = Tableling = (function(Backbone, _, $){
},
goToFirstPage : function() {
- this.goToPage(1);
+ this.goToPageNumber(1);
},
goToPreviousPage : function() {
- this.goToPage(this.getPage(this.data) - 1);
+ this.goToPageNumber(this.getPage(this.data) - 1);
+ },
+
+ goToPage : function(e) {
+ this.goToPageNumber(parseInt($(e.target).text(), 10));
},
goToNextPage : function() {
- this.goToPage(this.getPage(this.data) + 1);
+ this.goToPageNumber(this.getPage(this.data) + 1);
},
goToLastPage : function() {
- this.goToPage(this.numberOfPages());
+ this.goToPageNumber(this.numberOfPages());
},
- goToPage : function(n) {
+ goToPageNumber : function(n) {
this.vent.trigger('table:update', { page : n });
},
Please sign in to comment.
Something went wrong with that request. Please try again.