tableling-rails 0.0.15 → 0.0.16

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module Tableling
2
- VERSION = "0.0.15"
2
+ VERSION = "0.0.16"
3
3
  end
@@ -3555,7 +3555,7 @@ _.extend(Marionette.Module, {
3555
3555
  return Marionette;
3556
3556
  })(Backbone, _, $ || window.jQuery || window.Zepto || window.ender);
3557
3557
  /*!
3558
- * Tableling v0.0.18
3558
+ * Tableling v0.0.19
3559
3559
  * Copyright (c) 2012-2013 Simon Oulevay (Alpha Hydrae) <hydrae.alpha@gmail.com>
3560
3560
  * Distributed under MIT license
3561
3561
  * https://github.com/AlphaHydrae/tableling
@@ -3563,7 +3563,7 @@ _.extend(Marionette.Module, {
3563
3563
  Backbone.Tableling = Tableling = (function(Backbone, _, $){
3564
3564
 
3565
3565
  var Tableling = {
3566
- version : "0.0.18"
3566
+ version : "0.0.19"
3567
3567
  };
3568
3568
 
3569
3569
  // Tableling
@@ -4111,6 +4111,7 @@ Backbone.Tableling = Tableling = (function(Backbone, _, $){
4111
4111
  Tableling.Plain.PageView = Tableling.Plain.Table.prototype.pageView = Tableling.Module.extend({
4112
4112
 
4113
4113
  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>'),
4114
+ pageTemplate : _.template('<li class="page"><a href="#"><%- number %></a></li>'),
4114
4115
 
4115
4116
  ui : {
4116
4117
  first : '.first',
@@ -4122,12 +4123,14 @@ Backbone.Tableling = Tableling = (function(Backbone, _, $){
4122
4123
  events : {
4123
4124
  'click .first:not(.disabled)' : 'goToFirstPage',
4124
4125
  'click .previous:not(.disabled)' : 'goToPreviousPage',
4126
+ 'click .page:not(.disabled)' : 'goToPage',
4125
4127
  'click .next:not(.disabled)' : 'goToNextPage',
4126
4128
  'click .last:not(.disabled)' : 'goToLastPage'
4127
4129
  },
4128
4130
 
4129
4131
  refresh : function(data) {
4130
- if (!data) {
4132
+ this.$el.find('.page').remove();
4133
+ if (!data || !data.length) {
4131
4134
  this.ui.first.addClass('disabled');
4132
4135
  this.ui.previous.addClass('disabled');
4133
4136
  this.ui.next.addClass('disabled');
@@ -4136,11 +4139,39 @@ Backbone.Tableling = Tableling = (function(Backbone, _, $){
4136
4139
  this.data = data;
4137
4140
  this.enable(this.ui.first, this.getPage(data) > 1);
4138
4141
  this.enable(this.ui.previous, this.getPage(data) > 1);
4142
+ this.setupPages();
4139
4143
  this.enable(this.ui.next, this.getPage(data) < this.numberOfPages(data));
4140
4144
  this.enable(this.ui.last, this.getPage(data) < this.numberOfPages(data));
4141
4145
  }
4142
4146
  },
4143
4147
 
4148
+ setupPages : function() {
4149
+
4150
+ var page = this.getPage(this.data);
4151
+ var total = this.numberOfPages();
4152
+
4153
+ var first = page - 2;
4154
+ if (total - first < 4) {
4155
+ first = total - 4;
4156
+ }
4157
+
4158
+ if (first < 1) {
4159
+ first = 1;
4160
+ }
4161
+
4162
+ var n = 5;
4163
+ if (first + n - 1 > total) {
4164
+ n = total - first + 1;
4165
+ }
4166
+
4167
+ _.times(n, function(i) {
4168
+ $(this.pageTemplate({ number : first + i })).insertBefore(this.ui.next);
4169
+ }, this);
4170
+
4171
+ var i = page - first;
4172
+ this.$el.find('.page').slice(i, i + 1).addClass('disabled');
4173
+ },
4174
+
4144
4175
  enable : function(el, enabled) {
4145
4176
  el.removeClass('disabled');
4146
4177
  if (!enabled) {
@@ -4153,22 +4184,26 @@ Backbone.Tableling = Tableling = (function(Backbone, _, $){
4153
4184
  },
4154
4185
 
4155
4186
  goToFirstPage : function() {
4156
- this.goToPage(1);
4187
+ this.goToPageNumber(1);
4157
4188
  },
4158
4189
 
4159
4190
  goToPreviousPage : function() {
4160
- this.goToPage(this.getPage(this.data) - 1);
4191
+ this.goToPageNumber(this.getPage(this.data) - 1);
4192
+ },
4193
+
4194
+ goToPage : function(e) {
4195
+ this.goToPageNumber(parseInt($(e.target).text(), 10));
4161
4196
  },
4162
4197
 
4163
4198
  goToNextPage : function() {
4164
- this.goToPage(this.getPage(this.data) + 1);
4199
+ this.goToPageNumber(this.getPage(this.data) + 1);
4165
4200
  },
4166
4201
 
4167
4202
  goToLastPage : function() {
4168
- this.goToPage(this.numberOfPages());
4203
+ this.goToPageNumber(this.numberOfPages());
4169
4204
  },
4170
4205
 
4171
- goToPage : function(n) {
4206
+ goToPageNumber : function(n) {
4172
4207
  this.vent.trigger('table:update', { page : n });
4173
4208
  },
4174
4209
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Tableling v0.0.18
2
+ * Tableling v0.0.19
3
3
  * Copyright (c) 2012-2013 Simon Oulevay (Alpha Hydrae) <hydrae.alpha@gmail.com>
4
4
  * Distributed under MIT license
5
5
  * https://github.com/AlphaHydrae/tableling
@@ -7,7 +7,7 @@
7
7
  Backbone.Tableling = Tableling = (function(Backbone, _, $){
8
8
 
9
9
  var Tableling = {
10
- version : "0.0.18"
10
+ version : "0.0.19"
11
11
  };
12
12
 
13
13
  // Tableling
@@ -555,6 +555,7 @@ Backbone.Tableling = Tableling = (function(Backbone, _, $){
555
555
  Tableling.Plain.PageView = Tableling.Plain.Table.prototype.pageView = Tableling.Module.extend({
556
556
 
557
557
  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>'),
558
+ pageTemplate : _.template('<li class="page"><a href="#"><%- number %></a></li>'),
558
559
 
559
560
  ui : {
560
561
  first : '.first',
@@ -566,12 +567,14 @@ Backbone.Tableling = Tableling = (function(Backbone, _, $){
566
567
  events : {
567
568
  'click .first:not(.disabled)' : 'goToFirstPage',
568
569
  'click .previous:not(.disabled)' : 'goToPreviousPage',
570
+ 'click .page:not(.disabled)' : 'goToPage',
569
571
  'click .next:not(.disabled)' : 'goToNextPage',
570
572
  'click .last:not(.disabled)' : 'goToLastPage'
571
573
  },
572
574
 
573
575
  refresh : function(data) {
574
- if (!data) {
576
+ this.$el.find('.page').remove();
577
+ if (!data || !data.length) {
575
578
  this.ui.first.addClass('disabled');
576
579
  this.ui.previous.addClass('disabled');
577
580
  this.ui.next.addClass('disabled');
@@ -580,11 +583,39 @@ Backbone.Tableling = Tableling = (function(Backbone, _, $){
580
583
  this.data = data;
581
584
  this.enable(this.ui.first, this.getPage(data) > 1);
582
585
  this.enable(this.ui.previous, this.getPage(data) > 1);
586
+ this.setupPages();
583
587
  this.enable(this.ui.next, this.getPage(data) < this.numberOfPages(data));
584
588
  this.enable(this.ui.last, this.getPage(data) < this.numberOfPages(data));
585
589
  }
586
590
  },
587
591
 
592
+ setupPages : function() {
593
+
594
+ var page = this.getPage(this.data);
595
+ var total = this.numberOfPages();
596
+
597
+ var first = page - 2;
598
+ if (total - first < 4) {
599
+ first = total - 4;
600
+ }
601
+
602
+ if (first < 1) {
603
+ first = 1;
604
+ }
605
+
606
+ var n = 5;
607
+ if (first + n - 1 > total) {
608
+ n = total - first + 1;
609
+ }
610
+
611
+ _.times(n, function(i) {
612
+ $(this.pageTemplate({ number : first + i })).insertBefore(this.ui.next);
613
+ }, this);
614
+
615
+ var i = page - first;
616
+ this.$el.find('.page').slice(i, i + 1).addClass('disabled');
617
+ },
618
+
588
619
  enable : function(el, enabled) {
589
620
  el.removeClass('disabled');
590
621
  if (!enabled) {
@@ -597,22 +628,26 @@ Backbone.Tableling = Tableling = (function(Backbone, _, $){
597
628
  },
598
629
 
599
630
  goToFirstPage : function() {
600
- this.goToPage(1);
631
+ this.goToPageNumber(1);
601
632
  },
602
633
 
603
634
  goToPreviousPage : function() {
604
- this.goToPage(this.getPage(this.data) - 1);
635
+ this.goToPageNumber(this.getPage(this.data) - 1);
636
+ },
637
+
638
+ goToPage : function(e) {
639
+ this.goToPageNumber(parseInt($(e.target).text(), 10));
605
640
  },
606
641
 
607
642
  goToNextPage : function() {
608
- this.goToPage(this.getPage(this.data) + 1);
643
+ this.goToPageNumber(this.getPage(this.data) + 1);
609
644
  },
610
645
 
611
646
  goToLastPage : function() {
612
- this.goToPage(this.numberOfPages());
647
+ this.goToPageNumber(this.numberOfPages());
613
648
  },
614
649
 
615
- goToPage : function(n) {
650
+ goToPageNumber : function(n) {
616
651
  this.vent.trigger('table:update', { page : n });
617
652
  },
618
653
 
@@ -14826,7 +14826,7 @@ _.extend(Marionette.Module, {
14826
14826
  return Marionette;
14827
14827
  })(Backbone, _, $ || window.jQuery || window.Zepto || window.ender);
14828
14828
  /*!
14829
- * Tableling v0.0.18
14829
+ * Tableling v0.0.19
14830
14830
  * Copyright (c) 2012-2013 Simon Oulevay (Alpha Hydrae) <hydrae.alpha@gmail.com>
14831
14831
  * Distributed under MIT license
14832
14832
  * https://github.com/AlphaHydrae/tableling
@@ -14834,7 +14834,7 @@ _.extend(Marionette.Module, {
14834
14834
  Backbone.Tableling = Tableling = (function(Backbone, _, $){
14835
14835
 
14836
14836
  var Tableling = {
14837
- version : "0.0.18"
14837
+ version : "0.0.19"
14838
14838
  };
14839
14839
 
14840
14840
  // Tableling
@@ -15382,6 +15382,7 @@ Backbone.Tableling = Tableling = (function(Backbone, _, $){
15382
15382
  Tableling.Plain.PageView = Tableling.Plain.Table.prototype.pageView = Tableling.Module.extend({
15383
15383
 
15384
15384
  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>'),
15385
+ pageTemplate : _.template('<li class="page"><a href="#"><%- number %></a></li>'),
15385
15386
 
15386
15387
  ui : {
15387
15388
  first : '.first',
@@ -15393,12 +15394,14 @@ Backbone.Tableling = Tableling = (function(Backbone, _, $){
15393
15394
  events : {
15394
15395
  'click .first:not(.disabled)' : 'goToFirstPage',
15395
15396
  'click .previous:not(.disabled)' : 'goToPreviousPage',
15397
+ 'click .page:not(.disabled)' : 'goToPage',
15396
15398
  'click .next:not(.disabled)' : 'goToNextPage',
15397
15399
  'click .last:not(.disabled)' : 'goToLastPage'
15398
15400
  },
15399
15401
 
15400
15402
  refresh : function(data) {
15401
- if (!data) {
15403
+ this.$el.find('.page').remove();
15404
+ if (!data || !data.length) {
15402
15405
  this.ui.first.addClass('disabled');
15403
15406
  this.ui.previous.addClass('disabled');
15404
15407
  this.ui.next.addClass('disabled');
@@ -15407,11 +15410,39 @@ Backbone.Tableling = Tableling = (function(Backbone, _, $){
15407
15410
  this.data = data;
15408
15411
  this.enable(this.ui.first, this.getPage(data) > 1);
15409
15412
  this.enable(this.ui.previous, this.getPage(data) > 1);
15413
+ this.setupPages();
15410
15414
  this.enable(this.ui.next, this.getPage(data) < this.numberOfPages(data));
15411
15415
  this.enable(this.ui.last, this.getPage(data) < this.numberOfPages(data));
15412
15416
  }
15413
15417
  },
15414
15418
 
15419
+ setupPages : function() {
15420
+
15421
+ var page = this.getPage(this.data);
15422
+ var total = this.numberOfPages();
15423
+
15424
+ var first = page - 2;
15425
+ if (total - first < 4) {
15426
+ first = total - 4;
15427
+ }
15428
+
15429
+ if (first < 1) {
15430
+ first = 1;
15431
+ }
15432
+
15433
+ var n = 5;
15434
+ if (first + n - 1 > total) {
15435
+ n = total - first + 1;
15436
+ }
15437
+
15438
+ _.times(n, function(i) {
15439
+ $(this.pageTemplate({ number : first + i })).insertBefore(this.ui.next);
15440
+ }, this);
15441
+
15442
+ var i = page - first;
15443
+ this.$el.find('.page').slice(i, i + 1).addClass('disabled');
15444
+ },
15445
+
15415
15446
  enable : function(el, enabled) {
15416
15447
  el.removeClass('disabled');
15417
15448
  if (!enabled) {
@@ -15424,22 +15455,26 @@ Backbone.Tableling = Tableling = (function(Backbone, _, $){
15424
15455
  },
15425
15456
 
15426
15457
  goToFirstPage : function() {
15427
- this.goToPage(1);
15458
+ this.goToPageNumber(1);
15428
15459
  },
15429
15460
 
15430
15461
  goToPreviousPage : function() {
15431
- this.goToPage(this.getPage(this.data) - 1);
15462
+ this.goToPageNumber(this.getPage(this.data) - 1);
15463
+ },
15464
+
15465
+ goToPage : function(e) {
15466
+ this.goToPageNumber(parseInt($(e.target).text(), 10));
15432
15467
  },
15433
15468
 
15434
15469
  goToNextPage : function() {
15435
- this.goToPage(this.getPage(this.data) + 1);
15470
+ this.goToPageNumber(this.getPage(this.data) + 1);
15436
15471
  },
15437
15472
 
15438
15473
  goToLastPage : function() {
15439
- this.goToPage(this.numberOfPages());
15474
+ this.goToPageNumber(this.numberOfPages());
15440
15475
  },
15441
15476
 
15442
- goToPage : function(n) {
15477
+ goToPageNumber : function(n) {
15443
15478
  this.vent.trigger('table:update', { page : n });
15444
15479
  },
15445
15480
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tableling-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.15
4
+ version: 0.0.16
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-09 00:00:00.000000000 Z
12
+ date: 2013-03-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails