foo_table-rails 0.5.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/lib/foo_table-rails/version.rb +1 -1
  4. data/vendor/assets/javascripts/footable.core.js +353 -159
  5. data/vendor/assets/javascripts/footable.core.min.js +14 -0
  6. data/vendor/assets/javascripts/footable.filter.js +145 -92
  7. data/vendor/assets/javascripts/footable.filter.min.js +14 -0
  8. data/vendor/assets/javascripts/footable.paginate.js +90 -35
  9. data/vendor/assets/javascripts/footable.paginate.min.js +1 -0
  10. data/vendor/assets/javascripts/footable.sort.js +171 -146
  11. data/vendor/assets/javascripts/footable.sort.min.js +1 -0
  12. data/vendor/assets/stylesheets/fonts/footable.eot +0 -0
  13. data/vendor/assets/stylesheets/fonts/footable.svg +78 -0
  14. data/vendor/assets/stylesheets/fonts/footable.ttf +0 -0
  15. data/vendor/assets/stylesheets/fonts/footable.woff +0 -0
  16. data/vendor/assets/stylesheets/footable.all.css +407 -0
  17. data/vendor/assets/stylesheets/footable.all.min.css +3 -0
  18. data/vendor/assets/stylesheets/footable.core.css +147 -96
  19. data/vendor/assets/stylesheets/footable.core.min.css +1 -0
  20. data/vendor/assets/stylesheets/footable.metro.css +132 -0
  21. data/vendor/assets/stylesheets/footable.metro.min.css +1 -0
  22. data/vendor/assets/stylesheets/footable.standalone.css +106 -0
  23. data/vendor/assets/stylesheets/footable.standalone.min.css +1 -0
  24. metadata +16 -7
  25. data/vendor/assets/javascripts/footable.template.js +0 -44
  26. data/vendor/assets/stylesheets/footable.paginate.css +0 -31
  27. data/vendor/assets/stylesheets/footable.sort.css +0 -24
  28. data/vendor/assets/stylesheets/footable.theme.bootstrap-responsive.css +0 -1109
  29. data/vendor/assets/stylesheets/footable.theme.bootstrap-tab.js +0 -144
  30. data/vendor/assets/stylesheets/footable.theme.bootstrap.css +0 -6158
@@ -0,0 +1,14 @@
1
+ /*!
2
+ * FooTable - Awesome Responsive Tables
3
+ * Version : 0.5
4
+ * http://themergency.com/footable
5
+ *
6
+ * Requires jQuery - http://jquery.com/
7
+ *
8
+ * Copyright 2012 Steven Usher & Brad Vincent
9
+ * Released under the MIT license
10
+ * You are free to use FooTable in commercial projects as long as this copyright header is left intact.
11
+ *
12
+ * Date: 22 Apr 2013
13
+ */
14
+ (function(e,t,undefined){function a(){var e=this;e.id=null,e.busy=!1,e.start=function(t,a){e.busy||(e.stop(),e.id=setTimeout(function(){t(),e.id=null,e.busy=!1},a),e.busy=!0)},e.stop=function(){null!==e.id&&(clearTimeout(e.id),e.id=null,e.busy=!1)}}function i(i,o,n){var r=this;r.id=n,r.table=i,r.options=o,r.breakpoints=[],r.breakpointNames="",r.columns={};var l=r.options,d=l.classes,s=l.events,u=l.triggers,f=0;return r.timers={resize:new a,register:function(e){return r.timers[e]=new a,r.timers[e]}},t.footable.plugins.init(r),r.init=function(){var a=e(t),i=e(r.table);if(i.hasClass(d.loaded))return r.raise(s.alreadyInitialized),undefined;r.raise(s.initializing),i.addClass(d.loading),i.find(l.columnDataSelector).each(function(){var e=r.getColumnData(this);r.columns[e.index]=e});for(var o in l.breakpoints)r.breakpoints.push({name:o,width:l.breakpoints[o]}),r.breakpointNames+=o+" ";r.breakpoints.sort(function(e,t){return e.width-t.width}),i.bind(u.initialize,function(){i.removeData("footable_info"),i.data("breakpoint",""),i.trigger(u.resize),i.removeClass(d.loading),i.addClass(d.loaded).addClass(d.main),r.raise(s.initialized)}).bind(u.redraw,function(){r.redraw()}).bind(u.resize,function(){r.resize()}).bind(u.expandFirstRow,function(){i.find(l.toggleSelector).first().not("."+d.detailShow).trigger(u.toggleRow)}),i.trigger(u.initialize),a.bind("resize.footable",function(){r.timers.resize.stop(),r.timers.resize.start(function(){r.raise(u.resize)},l.delay)})},r.addRowToggle=function(){if(l.addRowToggle){var t=e(r.table),a=!1;t.find("span."+d.toggle).remove();for(var i in r.columns){var o=r.columns[i];if(o.toggle){a=!0;var n="> tbody > tr:not(."+d.detail+") > td:nth-child("+(parseInt(o.index,10)+1)+")";return t.find(n).not("."+d.detailCell).prepend(e("<span />").addClass(d.toggle)),undefined}}a||t.find("> tbody > tr:not(."+d.detail+") > td:first-child").not("."+d.detailCell).prepend(e("<span />").addClass(d.toggle))}},r.setColumnClasses=function(){$table=e(r.table);for(var t in r.columns){var a=r.columns[t];if(null!==a.className){var i="",o=!0;e.each(a.matches,function(e,t){o||(i+=", "),i+="> tbody > tr:not(."+d.detail+") > td:nth-child("+(parseInt(t,10)+1)+")",o=!1}),$table.find(i).not("."+d.detailCell).addClass(a.className)}}},r.bindToggleSelectors=function(){var t=e(r.table);r.hasAnyBreakpointColumn()&&(t.find(l.toggleSelector).unbind(u.toggleRow).bind(u.toggleRow,function(){var t=e(this).is("tr")?e(this):e(this).parents("tr:first");r.toggleDetail(t.get(0))}),t.find(l.toggleSelector).unbind("click.footable").bind("click.footable",function(a){t.is(".breakpoint")&&e(a.target).is("td,.footable-toggle")&&e(this).trigger(u.toggleRow)}))},r.parse=function(e,t){var a=l.parsers[t.type]||l.parsers.alpha;return a(e)},r.getColumnData=function(t){var a=e(t),i=a.data("hide"),o=a.index();i=i||"",i=i.split(",");var n={index:o,hide:{},type:a.data("type")||"alpha",name:a.data("name")||e.trim(a.text()),ignore:a.data("ignore")||!1,toggle:a.data("toggle")||!1,className:a.data("class")||null,matches:[],names:{},group:a.data("group")||null,groupName:null};if(null!==n.group){var d=e(r.table).find('> thead > tr.footable-group-row > th[data-group="'+n.group+'"], > thead > tr.footable-group-row > td[data-group="'+n.group+'"]').first();n.groupName=r.parse(d,{type:"alpha"})}var u=parseInt(a.prev().attr("colspan")||0,10);f+=u>1?u-1:0;var h=parseInt(a.attr("colspan")||0,10),p=n.index+f;if(h>1){var g=a.data("names");g=g||"",g=g.split(",");for(var c=0;h>c;c++)n.matches.push(c+p),g.length>c&&(n.names[c+p]=g[c])}else n.matches.push(p);n.hide["default"]="all"===a.data("hide")||e.inArray("default",i)>=0;var b=!1;for(var m in l.breakpoints)n.hide[m]="all"===a.data("hide")||e.inArray(m,i)>=0,b=b||n.hide[m];n.hasBreakpoint=b;var v=r.raise(s.columnData,{column:{data:n,th:t}});return v.column.data},r.getViewportWidth=function(){return window.innerWidth||(document.body?document.body.offsetWidth:0)},r.getViewportHeight=function(){return window.innerHeight||(document.body?document.body.offsetHeight:0)},r.calculateWidthAndHeight=function(e,t){return jQuery.isFunction(l.calculateWidthAndHeightOverride)?l.calculateWidthAndHeightOverride(e,t):(t.viewportWidth<t.width&&(t.width=t.viewportWidth),t.viewportHeight<t.height&&(t.height=t.viewportHeight),t)},r.hasBreakpointColumn=function(e){for(var t in r.columns)if(r.columns[t].hide[e]){if(r.columns[t].ignore)continue;return!0}return!1},r.hasAnyBreakpointColumn=function(){for(var e in r.columns)if(r.columns[e].hasBreakpoint)return!0;return!1},r.resize=function(){var t=e(r.table);if(t.is(":visible")&&r.hasAnyBreakpointColumn()){var a={width:t.width(),height:t.height(),viewportWidth:r.getViewportWidth(),viewportHeight:r.getViewportHeight(),orientation:null};a.orientation=a.viewportWidth>a.viewportHeight?"landscape":"portrait",a=r.calculateWidthAndHeight(t,a);var i=t.data("footable_info");if(t.data("footable_info",a),r.raise(s.resizing,{old:i,info:a}),!i||i&&i.width&&i.width!==a.width||i&&i.height&&i.height!==a.height){for(var o,n=null,l=0;r.breakpoints.length>l;l++)if(o=r.breakpoints[l],o&&o.width&&a.width<=o.width){n=o;break}var d=null===n?"default":n.name,f=r.hasBreakpointColumn(d),h=t.data("breakpoint");t.data("breakpoint",d).removeClass("default breakpoint").removeClass(r.breakpointNames).addClass(d+(f?" breakpoint":"")),d!==h&&(t.trigger(u.redraw),r.raise(s.breakpoint,{breakpoint:d,info:a}))}r.raise(s.resized,{old:i,info:a})}},r.redraw=function(){r.addRowToggle(),r.bindToggleSelectors(),r.setColumnClasses();var t=e(r.table),a=t.data("breakpoint"),i=r.hasBreakpointColumn(a);t.find("> tbody > tr:not(."+d.detail+")").data("detail_created",!1).end().find("> thead > tr:last-child > th").each(function(){var i=r.columns[e(this).index()],o="",n=!0;e.each(i.matches,function(e,t){n||(o+=", ");var a=t+1;o+="> tbody > tr:not(."+d.detail+") > td:nth-child("+a+")",o+=", > tfoot > tr:not(."+d.detail+") > td:nth-child("+a+")",o+=", > colgroup > col:nth-child("+a+")",n=!1}),o+=', > thead > tr[data-group-row="true"] > th[data-group="'+i.group+'"]';var l=t.find(o).add(this);if(i.hide[a]===!1?l.show():l.hide(),1===t.find("> thead > tr.footable-group-row").length){var s=t.find('> thead > tr:last-child > th[data-group="'+i.group+'"]:visible, > thead > tr:last-child > th[data-group="'+i.group+'"]:visible'),u=t.find('> thead > tr.footable-group-row > th[data-group="'+i.group+'"], > thead > tr.footable-group-row > td[data-group="'+i.group+'"]'),f=0;e.each(s,function(){f+=parseInt(e(this).attr("colspan")||1,10)}),f>0?u.attr("colspan",f).show():u.hide()}}).end().find("> tbody > tr."+d.detailShow).each(function(){r.createOrUpdateDetailRow(this)}),t.find("> tbody > tr."+d.detailShow+":visible").each(function(){var t=e(this).next();t.hasClass(d.detail)&&(i?t.show():t.hide())}),t.find("> thead > tr > th.footable-last-column, > tbody > tr > td.footable-last-column").removeClass("footable-last-column"),t.find("> thead > tr > th.footable-first-column, > tbody > tr > td.footable-first-column").removeClass("footable-first-column"),t.find("> thead > tr, > tbody > tr").find("> th:visible:last, > td:visible:last").addClass("footable-last-column").end().find("> th:visible:first, > td:visible:first").addClass("footable-first-column"),r.raise(s.redrawn)},r.toggleDetail=function(t){var a=t.jquery?t:e(t),i=a.next();a.hasClass(d.detailShow)?(a.removeClass(d.detailShow),i.hasClass(d.detail)&&i.hide(),r.raise(s.rowCollapsed,{row:a[0]})):(r.createOrUpdateDetailRow(a[0]),a.addClass(d.detailShow),a.next().show(),r.raise(s.rowExpanded,{row:a[0]}))},r.removeRow=function(t){var a=t.jquery?t:e(t);a.hasClass(d.detail)&&(a=a.prev());var i=a.next();a.data("detail_created")===!0&&i.remove(),a.remove(),r.raise(s.rowRemoved)},r.appendRow=function(t){var a=t.jquery?t:e(t);e(r.table).find("tbody").append(a),r.redraw()},r.getColumnFromTdIndex=function(t){var a=null;for(var i in r.columns)if(e.inArray(t,r.columns[i].matches)>=0){a=r.columns[i];break}return a},r.createOrUpdateDetailRow=function(t){var a,i=e(t),o=i.next(),n=[];if(i.data("detail_created")===!0)return!0;if(i.is(":hidden"))return!1;if(r.raise(s.rowDetailUpdating,{row:i,detail:o}),i.find("> td:hidden").each(function(){var t=e(this).index(),a=r.getColumnFromTdIndex(t),i=a.name;return a.ignore===!0?!0:(t in a.names&&(i=a.names[t]),n.push({name:i,value:r.parse(this,a),display:e.trim(e(this).html()),group:a.group,groupName:a.groupName}),!0)}),0===n.length)return!1;var u=i.find("> td:visible").length,f=o.hasClass(d.detail);return f||(o=e('<tr class="'+d.detail+'"><td class="'+d.detailCell+'"><div class="'+d.detailInner+'"></div></td></tr>'),i.after(o)),o.find("> td:first").attr("colspan",u),a=o.find("."+d.detailInner).empty(),l.createDetail(a,n,l.createGroupedDetail,l.detailSeparator,d),i.data("detail_created",!0),r.raise(s.rowDetailUpdated,{row:i,detail:o}),!f},r.raise=function(t,a){r.options.debug===!0&&e.isFunction(r.options.log)&&r.options.log(t,"event"),a=a||{};var i={ft:r};e.extend(!0,i,a);var o=e.Event(t,i);return o.ft||e.extend(!0,o,i),e(r.table).trigger(o),o},r.init(),r}t.footable={options:{delay:100,breakpoints:{phone:480,tablet:1024},parsers:{alpha:function(t){return e(t).data("value")||e.trim(e(t).text())},numeric:function(t){var a=e(t).data("value")||e(t).text().replace(/[^0-9.\-]/g,"");return a=parseFloat(a),isNaN(a)&&(a=0),a}},addRowToggle:!0,calculateWidthAndHeightOverride:null,toggleSelector:" > tbody > tr:not(.footable-row-detail)",columnDataSelector:"> thead > tr:last-child > th, > thead > tr:last-child > td",detailSeparator:":",createGroupedDetail:function(e){for(var t={_none:{name:null,data:[]}},a=0;e.length>a;a++){var i=e[a].group;null!==i?(i in t||(t[i]={name:e[a].groupName||e[a].group,data:[]}),t[i].data.push(e[a])):t._none.data.push(e[a])}return t},createDetail:function(e,t,a,i,o){var n=a(t);for(var r in n)if(0!==n[r].data.length){"_none"!==r&&e.append('<div class="'+o.detailInnerGroup+'">'+n[r].name+"</div>");for(var l=0;n[r].data.length>l;l++){var d=n[r].data[l].name?i:"";e.append('<div class="'+o.detailInnerRow+'"><div class="'+o.detailInnerName+'">'+n[r].data[l].name+d+'</div><div class="'+o.detailInnerValue+'">'+n[r].data[l].display+"</div></div>")}}},classes:{main:"footable",loading:"footable-loading",loaded:"footable-loaded",toggle:"footable-toggle",detail:"footable-row-detail",detailCell:"footable-row-detail-cell",detailInner:"footable-row-detail-inner",detailInnerRow:"footable-row-detail-row",detailInnerGroup:"footable-row-detail-group",detailInnerName:"footable-row-detail-name",detailInnerValue:"footable-row-detail-value",detailShow:"footable-detail-show"},triggers:{initialize:"footable_initialize",resize:"footable_resize",redraw:"footable_redraw",toggleRow:"footable_toggle_row",expandFirstRow:"footable_expand_first_row"},events:{alreadyInitialized:"footable_already_initialized",initializing:"footable_initializing",initialized:"footable_initialized",resizing:"footable_resizing",resized:"footable_resized",redrawn:"footable_redrawn",breakpoint:"footable_breakpoint",columnData:"footable_column_data",rowDetailUpdating:"footable_row_detail_updating",rowDetailUpdated:"footable_row_detail_updated",rowCollapsed:"footable_row_collapsed",rowExpanded:"footable_row_expanded",rowRemoved:"footable_row_removed"},debug:!1,log:null},version:{major:0,minor:5,toString:function(){return t.footable.version.major+"."+t.footable.version.minor},parse:function(e){return version=/(\d+)\.?(\d+)?\.?(\d+)?/.exec(e),{major:parseInt(version[1],10)||0,minor:parseInt(version[2],10)||0,patch:parseInt(version[3],10)||0}}},plugins:{_validate:function(a){return"string"!=typeof a.name?(t.footable.options.debug===!0&&console.error('Validation failed, plugin does not implement a string property called "name".',a),!1):e.isFunction(a.init)?(t.footable.options.debug===!0&&console.log('Validation succeeded for plugin "'+a.name+'".',a),!0):(t.footable.options.debug===!0&&console.error('Validation failed, plugin "'+a.name+'" does not implement a function called "init".',a),!1)},registered:[],register:function(a,i){t.footable.plugins._validate(a)&&(t.footable.plugins.registered.push(a),i!==undefined&&"object"==typeof i&&e.extend(!0,t.footable.options,i),t.footable.options.debug===!0&&console.log('Plugin "'+a.name+'" has been registered with the Foobox.',a))},init:function(e){for(var a=0;t.footable.plugins.registered.length>a;a++)try{t.footable.plugins.registered[a].init(e)}catch(i){t.footable.options.debug===!0&&console.error(i)}}}};var o=0;e.fn.footable=function(a){a=a||{};var n=e.extend(!0,{},t.footable.options,a);return this.each(function(){o++;var t=new i(this,n,o);e(this).data("footable",t)})}})(jQuery,window);
@@ -1,104 +1,157 @@
1
1
  (function ($, w, undefined) {
2
- if (w.footable == undefined || w.footable == null)
3
- throw new Error('Please check and make sure footable.js is included in the page and is loaded prior to this script.');
2
+ if (w.footable === undefined || w.footable === null)
3
+ throw new Error('Please check and make sure footable.js is included in the page and is loaded prior to this script.');
4
4
 
5
- var jQversion = w.footable.version.parse($.fn.jquery);
6
- if (jQversion.major == 1 && jQversion.minor < 8) { // For older versions of jQuery, anything below 1.8
7
- $.expr[':'].ftcontains = function (a, i, m) {
8
- return $(a).html().toUpperCase().indexOf(m[3].toUpperCase()) >= 0;
5
+ var jQversion = w.footable.version.parse($.fn.jquery);
6
+ if (jQversion.major === 1 && jQversion.minor < 8) { // For older versions of jQuery, anything below 1.8
7
+ $.expr[':'].ftcontains = function (a, i, m) {
8
+ return $(a).text().toUpperCase().indexOf(m[3].toUpperCase()) >= 0;
9
+ };
10
+ } else { // For jQuery 1.8 and above
11
+ $.expr[':'].ftcontains = $.expr.createPseudo(function (arg) {
12
+ return function (elem) {
13
+ var text = $(elem).find('td').text();
14
+ var data = $(elem).find('td[data-value]').each(function () {
15
+ text += $(this).data('value');
16
+ });
17
+ return text.toUpperCase().indexOf(arg.toUpperCase()) >= 0;
18
+ };
19
+ });
20
+ }
21
+
22
+ var defaults = {
23
+ filter: {
24
+ enabled: true,
25
+ input: '.footable-filter',
26
+ timeout: 300,
27
+ minimum: 2,
28
+ disableEnter: false,
29
+ filterFunction: function(index) {
30
+ var $t = $(this),
31
+ $table = $t.parents('table:first'),
32
+ filter = $table.data('current-filter').toUpperCase(),
33
+ text = $t.find('td').text(),
34
+ data = $t.find('td[data-value]').each(function () {
35
+ text += $(this).data('value');
36
+ });
37
+ return text.toUpperCase().indexOf(filter) >= 0;
38
+ }
39
+ }
9
40
  };
10
- } else { // For jQuery 1.8 and above
11
- $.expr[':'].ftcontains = $.expr.createPseudo(function (arg) {
12
- return function (elem) {
13
- return $(elem).html().toUpperCase().indexOf(arg.toUpperCase()) >= 0;
14
- };
15
- });
16
- }
17
41
 
18
- var defaults = {
19
- filter: {
20
- enabled: true,
21
- input: '.footable-filter',
22
- timeout: 300,
23
- minimum: 2,
24
- disableEnter: false
25
- }
26
- };
42
+ function Filter() {
43
+ var p = this;
44
+ p.name = 'Footable Filter';
45
+ p.init = function (ft) {
46
+ p.footable = ft;
47
+ if (ft.options.filter.enabled === true) {
48
+ ft.timers.register('filter');
49
+ $(ft.table).bind({
50
+ 'footable_initialized': function (e) {
51
+ var $table = $(ft.table);
52
+ var data = {
53
+ 'input': $table.data('filter') || ft.options.filter.input,
54
+ 'timeout': $table.data('filter-timeout') || ft.options.filter.timeout,
55
+ 'minimum': $table.data('filter-minimum') || ft.options.filter.minimum,
56
+ 'disableEnter': $table.data('filter-disable-enter') || ft.options.filter.disableEnter
57
+ };
58
+ if (data.disableEnter) {
59
+ $(data.input).keypress(function (event) {
60
+ if (window.event)
61
+ return (window.event.keyCode !== 13);
62
+ else
63
+ return (event.which !== 13);
64
+ });
65
+ }
66
+ $table.bind('footable_clear_filter', function () {
67
+ $(data.input).val('');
68
+ p.clearFilter();
69
+ });
70
+ $table.bind('footable_filter', function (event, args) {
71
+ p.filter(args.filter);
72
+ });
73
+ $(data.input).keyup(function (eve) {
74
+ ft.timers.filter.stop();
75
+ if (eve.which === 27) {
76
+ $(data.input).val('');
77
+ }
78
+ ft.timers.filter.start(function () {
79
+ var val = $(data.input).val() || '';
80
+ p.filter(val);
81
+ }, data.timeout);
82
+ });
83
+ },
84
+ 'footable_redrawn': function (e) {
85
+ var $table = $(ft.table),
86
+ filter = $table.data('filter-string');
87
+ if (filter) {
88
+ p.filter(filter);
89
+ }
90
+ }
91
+ })
92
+ //save the filter object onto the table so we can access it later
93
+ .data('footable-filter', p);
94
+ }
95
+ };
27
96
 
28
- function Filter() {
29
- var p = this;
30
- p.name = 'Footable Filter';
31
- p.init = function (ft) {
32
- if (ft.options.filter.enabled == true) {
33
- ft.timers.register('filter');
34
- $(ft.table).bind({
35
- 'footable_initialized': function (e) {
36
- var $table = $(e.ft.table);
37
- var data = {
38
- 'input': $table.data('filter') || e.ft.options.filter.input,
39
- 'timeout': $table.data('filter-timeout') || e.ft.options.filter.timeout,
40
- 'minimum': $table.data('filter-minimum') || e.ft.options.filter.minimum,
41
- 'disableEnter': $table.data('filter-disable-enter') || e.ft.options.filter.disableEnter
42
- };
43
- if (data.disableEnter) {
44
- $(data.input).keypress(function (event) {
45
- if (window.event)
46
- return (window.event.keyCode != 13);
47
- else
48
- return (event.which != 13);
49
- });
97
+ p.filter = function (filterString) {
98
+ var ft = p.footable,
99
+ $table = $(ft.table),
100
+ minimum = $table.data('filter-minimum') || ft.options.filter.minimum,
101
+ clear = !filterString;
102
+
103
+ if (filterString && filterString.length < minimum) {
104
+ return; //if we do not have the minimum chars then do nothing
50
105
  }
51
- $table.bind('footable_clear_filter', function () {
52
- $(data.input).val('');
53
- p.clearFilter(e.ft);
54
- });
55
- $(data.input).keyup(function (eve) {
56
- e.ft.timers.filter.stop();
57
- if (eve.which == 27) { $(data.input).val(''); }
58
- e.ft.timers.filter.start(function () {
59
- e.ft.raise('footable_filtering');
60
- var val = $(data.input).val() || '';
61
- if (val.length < data.minimum) {
62
- p.clearFilter(e.ft);
63
- } else {
64
- var filters = val.split(' ');
65
- $table.find('> tbody > tr').hide().addClass('footable-filtered');
66
- var rows = $table.find('> tbody > tr:not(.footable-row-detail)');
67
- $.each(filters, function (i, f) {
68
- if (f && f.length)
69
- rows = rows.filter('*:ftcontains("' + f + '")');
70
- });
71
- rows.each(function () {
72
- p.showRow(this, e.ft);
106
+
107
+ //raise a pre-filter event so that we can cancel the filtering if needed
108
+ var event = ft.raise('footable_filtering', { filter: filterString, clear: clear });
109
+ if (event && event.result === false) return;
110
+
111
+ if (clear) {
112
+ p.clearFilter();
113
+ } else {
114
+ var filters = filterString.split(' ');
115
+
116
+ $table.find('> tbody > tr').hide().addClass('footable-filtered');
117
+ var rows = $table.find('> tbody > tr:not(.footable-row-detail)');
118
+ $.each(filters, function (i, f) {
119
+ if (f && f.length) {
120
+ $table.data('current-filter', f);
121
+ rows = rows.filter(ft.options.filter.filterFunction);
122
+ }
123
+ });
124
+ rows.each(function () {
125
+ p.showRow(this, ft);
73
126
  $(this).removeClass('footable-filtered');
74
- });
75
- e.ft.raise('footable_filtered', { filter : val });
76
- }
77
- }, data.timeout);
78
- });
79
- }
80
- });
81
- }
82
- };
127
+ });
128
+ $table.data('filter-string', filterString);
129
+ ft.raise('footable_filtered', { filter: filterString, clear: false });
130
+ }
131
+ };
83
132
 
84
- p.clearFilter = function (ft) {
85
- $(ft.table).find('> tbody > tr:not(.footable-row-detail)').removeClass('footable-filtered').each(function () {
86
- p.showRow(this, ft);
87
- });
88
- ft.raise('footable_filtered', { cleared : true });
89
- };
133
+ p.clearFilter = function () {
134
+ var ft = p.footable,
135
+ $table = $(ft.table);
90
136
 
91
- p.showRow = function (row, ft) {
92
- var $row = $(row), $next = $row.next(), $table = $(ft.table);
93
- if ($row.is(':visible')) return; //already visible - do nothing
94
- if ($table.hasClass('breakpoint') && $row.hasClass('footable-detail-show') && $next.hasClass('footable-row-detail')) {
95
- $row.add($next).show();
96
- ft.createOrUpdateDetailRow(row);
97
- }
98
- else $row.show();
99
- };
100
- };
137
+ $table.find('> tbody > tr:not(.footable-row-detail)').removeClass('footable-filtered').each(function () {
138
+ p.showRow(this, ft);
139
+ });
140
+ $table.removeData('filter-string');
141
+ ft.raise('footable_filtered', { clear: true });
142
+ };
143
+
144
+ p.showRow = function (row, ft) {
145
+ var $row = $(row), $next = $row.next(), $table = $(ft.table);
146
+ if ($row.is(':visible')) return; //already visible - do nothing
147
+ if ($table.hasClass('breakpoint') && $row.hasClass('footable-detail-show') && $next.hasClass('footable-row-detail')) {
148
+ $row.add($next).show();
149
+ ft.createOrUpdateDetailRow(row);
150
+ }
151
+ else $row.show();
152
+ };
153
+ }
101
154
 
102
- w.footable.plugins.register(new Filter(), defaults);
155
+ w.footable.plugins.register(new Filter(), defaults);
103
156
 
104
157
  })(jQuery, window);
@@ -0,0 +1,14 @@
1
+ /*!
2
+ * FooTable - Awesome Responsive Tables
3
+ * Version : 0.5
4
+ * http://themergency.com/footable
5
+ *
6
+ * Requires jQuery - http://jquery.com/
7
+ *
8
+ * Copyright 2012 Steven Usher & Brad Vincent
9
+ * Released under the MIT license
10
+ * You are free to use FooTable in commercial projects as long as this copyright header is left intact.
11
+ *
12
+ * Date: 22 Apr 2013
13
+ */
14
+ (function(e,t,undefined){function a(){var e=this;e.id=null,e.busy=!1,e.start=function(t,a){e.busy||(e.stop(),e.id=setTimeout(function(){t(),e.id=null,e.busy=!1},a),e.busy=!0)},e.stop=function(){null!==e.id&&(clearTimeout(e.id),e.id=null,e.busy=!1)}}function i(i,o,n){var r=this;r.id=n,r.table=i,r.options=o,r.breakpoints=[],r.breakpointNames="",r.columns={};var l=r.options,d=l.classes,s=l.events,u=l.triggers,f=0;return r.timers={resize:new a,register:function(e){return r.timers[e]=new a,r.timers[e]}},t.footable.plugins.init(r),r.init=function(){var a=e(t),i=e(r.table);if(i.hasClass(d.loaded))return r.raise(s.alreadyInitialized),undefined;r.raise(s.initializing),i.addClass(d.loading),i.find(l.columnDataSelector).each(function(){var e=r.getColumnData(this);r.columns[e.index]=e});for(var o in l.breakpoints)r.breakpoints.push({name:o,width:l.breakpoints[o]}),r.breakpointNames+=o+" ";r.breakpoints.sort(function(e,t){return e.width-t.width}),i.bind(u.initialize,function(){i.removeData("footable_info"),i.data("breakpoint",""),i.trigger(u.resize),i.removeClass(d.loading),i.addClass(d.loaded).addClass(d.main),r.raise(s.initialized)}).bind(u.redraw,function(){r.redraw()}).bind(u.resize,function(){r.resize()}).bind(u.expandFirstRow,function(){i.find(l.toggleSelector).first().not("."+d.detailShow).trigger(u.toggleRow)}),i.trigger(u.initialize),a.bind("resize.footable",function(){r.timers.resize.stop(),r.timers.resize.start(function(){r.raise(u.resize)},l.delay)})},r.addRowToggle=function(){if(l.addRowToggle){var t=e(r.table),a=!1;t.find("span."+d.toggle).remove();for(var i in r.columns){var o=r.columns[i];if(o.toggle){a=!0;var n="> tbody > tr:not(."+d.detail+") > td:nth-child("+(parseInt(o.index,10)+1)+")";return t.find(n).not("."+d.detailCell).prepend(e("<span />").addClass(d.toggle)),undefined}}a||t.find("> tbody > tr:not(."+d.detail+") > td:first-child").not("."+d.detailCell).prepend(e("<span />").addClass(d.toggle))}},r.setColumnClasses=function(){$table=e(r.table);for(var t in r.columns){var a=r.columns[t];if(null!==a.className){var i="",o=!0;e.each(a.matches,function(e,t){o||(i+=", "),i+="> tbody > tr:not(."+d.detail+") > td:nth-child("+(parseInt(t,10)+1)+")",o=!1}),$table.find(i).not("."+d.detailCell).addClass(a.className)}}},r.bindToggleSelectors=function(){var t=e(r.table);r.hasAnyBreakpointColumn()&&(t.find(l.toggleSelector).unbind(u.toggleRow).bind(u.toggleRow,function(){var t=e(this).is("tr")?e(this):e(this).parents("tr:first");r.toggleDetail(t.get(0))}),t.find(l.toggleSelector).unbind("click.footable").bind("click.footable",function(a){t.is(".breakpoint")&&e(a.target).is("td,.footable-toggle")&&e(this).trigger(u.toggleRow)}))},r.parse=function(e,t){var a=l.parsers[t.type]||l.parsers.alpha;return a(e)},r.getColumnData=function(t){var a=e(t),i=a.data("hide"),o=a.index();i=i||"",i=i.split(",");var n={index:o,hide:{},type:a.data("type")||"alpha",name:a.data("name")||e.trim(a.text()),ignore:a.data("ignore")||!1,toggle:a.data("toggle")||!1,className:a.data("class")||null,matches:[],names:{},group:a.data("group")||null,groupName:null};if(null!==n.group){var d=e(r.table).find('> thead > tr.footable-group-row > th[data-group="'+n.group+'"], > thead > tr.footable-group-row > td[data-group="'+n.group+'"]').first();n.groupName=r.parse(d,{type:"alpha"})}var u=parseInt(a.prev().attr("colspan")||0,10);f+=u>1?u-1:0;var h=parseInt(a.attr("colspan")||0,10),p=n.index+f;if(h>1){var g=a.data("names");g=g||"",g=g.split(",");for(var c=0;h>c;c++)n.matches.push(c+p),g.length>c&&(n.names[c+p]=g[c])}else n.matches.push(p);n.hide["default"]="all"===a.data("hide")||e.inArray("default",i)>=0;var b=!1;for(var m in l.breakpoints)n.hide[m]="all"===a.data("hide")||e.inArray(m,i)>=0,b=b||n.hide[m];n.hasBreakpoint=b;var v=r.raise(s.columnData,{column:{data:n,th:t}});return v.column.data},r.getViewportWidth=function(){return window.innerWidth||(document.body?document.body.offsetWidth:0)},r.getViewportHeight=function(){return window.innerHeight||(document.body?document.body.offsetHeight:0)},r.calculateWidthAndHeight=function(e,t){return jQuery.isFunction(l.calculateWidthAndHeightOverride)?l.calculateWidthAndHeightOverride(e,t):(t.viewportWidth<t.width&&(t.width=t.viewportWidth),t.viewportHeight<t.height&&(t.height=t.viewportHeight),t)},r.hasBreakpointColumn=function(e){for(var t in r.columns)if(r.columns[t].hide[e]){if(r.columns[t].ignore)continue;return!0}return!1},r.hasAnyBreakpointColumn=function(){for(var e in r.columns)if(r.columns[e].hasBreakpoint)return!0;return!1},r.resize=function(){var t=e(r.table);if(t.is(":visible")&&r.hasAnyBreakpointColumn()){var a={width:t.width(),height:t.height(),viewportWidth:r.getViewportWidth(),viewportHeight:r.getViewportHeight(),orientation:null};a.orientation=a.viewportWidth>a.viewportHeight?"landscape":"portrait",a=r.calculateWidthAndHeight(t,a);var i=t.data("footable_info");if(t.data("footable_info",a),r.raise(s.resizing,{old:i,info:a}),!i||i&&i.width&&i.width!==a.width||i&&i.height&&i.height!==a.height){for(var o,n=null,l=0;r.breakpoints.length>l;l++)if(o=r.breakpoints[l],o&&o.width&&a.width<=o.width){n=o;break}var d=null===n?"default":n.name,f=r.hasBreakpointColumn(d),h=t.data("breakpoint");t.data("breakpoint",d).removeClass("default breakpoint").removeClass(r.breakpointNames).addClass(d+(f?" breakpoint":"")),d!==h&&(t.trigger(u.redraw),r.raise(s.breakpoint,{breakpoint:d,info:a}))}r.raise(s.resized,{old:i,info:a})}},r.redraw=function(){r.addRowToggle(),r.bindToggleSelectors(),r.setColumnClasses();var t=e(r.table),a=t.data("breakpoint"),i=r.hasBreakpointColumn(a);t.find("> tbody > tr:not(."+d.detail+")").data("detail_created",!1).end().find("> thead > tr:last-child > th").each(function(){var i=r.columns[e(this).index()],o="",n=!0;e.each(i.matches,function(e,t){n||(o+=", ");var a=t+1;o+="> tbody > tr:not(."+d.detail+") > td:nth-child("+a+")",o+=", > tfoot > tr:not(."+d.detail+") > td:nth-child("+a+")",o+=", > colgroup > col:nth-child("+a+")",n=!1}),o+=', > thead > tr[data-group-row="true"] > th[data-group="'+i.group+'"]';var l=t.find(o).add(this);if(i.hide[a]===!1?l.show():l.hide(),1===t.find("> thead > tr.footable-group-row").length){var s=t.find('> thead > tr:last-child > th[data-group="'+i.group+'"]:visible, > thead > tr:last-child > th[data-group="'+i.group+'"]:visible'),u=t.find('> thead > tr.footable-group-row > th[data-group="'+i.group+'"], > thead > tr.footable-group-row > td[data-group="'+i.group+'"]'),f=0;e.each(s,function(){f+=parseInt(e(this).attr("colspan")||1,10)}),f>0?u.attr("colspan",f).show():u.hide()}}).end().find("> tbody > tr."+d.detailShow).each(function(){r.createOrUpdateDetailRow(this)}),t.find("> tbody > tr."+d.detailShow+":visible").each(function(){var t=e(this).next();t.hasClass(d.detail)&&(i?t.show():t.hide())}),t.find("> thead > tr > th.footable-last-column, > tbody > tr > td.footable-last-column").removeClass("footable-last-column"),t.find("> thead > tr > th.footable-first-column, > tbody > tr > td.footable-first-column").removeClass("footable-first-column"),t.find("> thead > tr, > tbody > tr").find("> th:visible:last, > td:visible:last").addClass("footable-last-column").end().find("> th:visible:first, > td:visible:first").addClass("footable-first-column"),r.raise(s.redrawn)},r.toggleDetail=function(t){var a=t.jquery?t:e(t),i=a.next();a.hasClass(d.detailShow)?(a.removeClass(d.detailShow),i.hasClass(d.detail)&&i.hide(),r.raise(s.rowCollapsed,{row:a[0]})):(r.createOrUpdateDetailRow(a[0]),a.addClass(d.detailShow),a.next().show(),r.raise(s.rowExpanded,{row:a[0]}))},r.removeRow=function(t){var a=t.jquery?t:e(t);a.hasClass(d.detail)&&(a=a.prev());var i=a.next();a.data("detail_created")===!0&&i.remove(),a.remove(),r.raise(s.rowRemoved)},r.appendRow=function(t){var a=t.jquery?t:e(t);e(r.table).find("tbody").append(a),r.redraw()},r.getColumnFromTdIndex=function(t){var a=null;for(var i in r.columns)if(e.inArray(t,r.columns[i].matches)>=0){a=r.columns[i];break}return a},r.createOrUpdateDetailRow=function(t){var a,i=e(t),o=i.next(),n=[];if(i.data("detail_created")===!0)return!0;if(i.is(":hidden"))return!1;if(r.raise(s.rowDetailUpdating,{row:i,detail:o}),i.find("> td:hidden").each(function(){var t=e(this).index(),a=r.getColumnFromTdIndex(t),i=a.name;return a.ignore===!0?!0:(t in a.names&&(i=a.names[t]),n.push({name:i,value:r.parse(this,a),display:e.trim(e(this).html()),group:a.group,groupName:a.groupName}),!0)}),0===n.length)return!1;var u=i.find("> td:visible").length,f=o.hasClass(d.detail);return f||(o=e('<tr class="'+d.detail+'"><td class="'+d.detailCell+'"><div class="'+d.detailInner+'"></div></td></tr>'),i.after(o)),o.find("> td:first").attr("colspan",u),a=o.find("."+d.detailInner).empty(),l.createDetail(a,n,l.createGroupedDetail,l.detailSeparator,d),i.data("detail_created",!0),r.raise(s.rowDetailUpdated,{row:i,detail:o}),!f},r.raise=function(t,a){r.options.debug===!0&&e.isFunction(r.options.log)&&r.options.log(t,"event"),a=a||{};var i={ft:r};e.extend(!0,i,a);var o=e.Event(t,i);return o.ft||e.extend(!0,o,i),e(r.table).trigger(o),o},r.init(),r}t.footable={options:{delay:100,breakpoints:{phone:480,tablet:1024},parsers:{alpha:function(t){return e(t).data("value")||e.trim(e(t).text())},numeric:function(t){var a=e(t).data("value")||e(t).text().replace(/[^0-9.\-]/g,"");return a=parseFloat(a),isNaN(a)&&(a=0),a}},addRowToggle:!0,calculateWidthAndHeightOverride:null,toggleSelector:" > tbody > tr:not(.footable-row-detail)",columnDataSelector:"> thead > tr:last-child > th, > thead > tr:last-child > td",detailSeparator:":",createGroupedDetail:function(e){for(var t={_none:{name:null,data:[]}},a=0;e.length>a;a++){var i=e[a].group;null!==i?(i in t||(t[i]={name:e[a].groupName||e[a].group,data:[]}),t[i].data.push(e[a])):t._none.data.push(e[a])}return t},createDetail:function(e,t,a,i,o){var n=a(t);for(var r in n)if(0!==n[r].data.length){"_none"!==r&&e.append('<div class="'+o.detailInnerGroup+'">'+n[r].name+"</div>");for(var l=0;n[r].data.length>l;l++){var d=n[r].data[l].name?i:"";e.append('<div class="'+o.detailInnerRow+'"><div class="'+o.detailInnerName+'">'+n[r].data[l].name+d+'</div><div class="'+o.detailInnerValue+'">'+n[r].data[l].display+"</div></div>")}}},classes:{main:"footable",loading:"footable-loading",loaded:"footable-loaded",toggle:"footable-toggle",detail:"footable-row-detail",detailCell:"footable-row-detail-cell",detailInner:"footable-row-detail-inner",detailInnerRow:"footable-row-detail-row",detailInnerGroup:"footable-row-detail-group",detailInnerName:"footable-row-detail-name",detailInnerValue:"footable-row-detail-value",detailShow:"footable-detail-show"},triggers:{initialize:"footable_initialize",resize:"footable_resize",redraw:"footable_redraw",toggleRow:"footable_toggle_row",expandFirstRow:"footable_expand_first_row"},events:{alreadyInitialized:"footable_already_initialized",initializing:"footable_initializing",initialized:"footable_initialized",resizing:"footable_resizing",resized:"footable_resized",redrawn:"footable_redrawn",breakpoint:"footable_breakpoint",columnData:"footable_column_data",rowDetailUpdating:"footable_row_detail_updating",rowDetailUpdated:"footable_row_detail_updated",rowCollapsed:"footable_row_collapsed",rowExpanded:"footable_row_expanded",rowRemoved:"footable_row_removed"},debug:!1,log:null},version:{major:0,minor:5,toString:function(){return t.footable.version.major+"."+t.footable.version.minor},parse:function(e){return version=/(\d+)\.?(\d+)?\.?(\d+)?/.exec(e),{major:parseInt(version[1],10)||0,minor:parseInt(version[2],10)||0,patch:parseInt(version[3],10)||0}}},plugins:{_validate:function(a){return"string"!=typeof a.name?(t.footable.options.debug===!0&&console.error('Validation failed, plugin does not implement a string property called "name".',a),!1):e.isFunction(a.init)?(t.footable.options.debug===!0&&console.log('Validation succeeded for plugin "'+a.name+'".',a),!0):(t.footable.options.debug===!0&&console.error('Validation failed, plugin "'+a.name+'" does not implement a function called "init".',a),!1)},registered:[],register:function(a,i){t.footable.plugins._validate(a)&&(t.footable.plugins.registered.push(a),i!==undefined&&"object"==typeof i&&e.extend(!0,t.footable.options,i),t.footable.options.debug===!0&&console.log('Plugin "'+a.name+'" has been registered with the Foobox.',a))},init:function(e){for(var a=0;t.footable.plugins.registered.length>a;a++)try{t.footable.plugins.registered[a].init(e)}catch(i){t.footable.options.debug===!0&&console.error(i)}}}};var o=0;e.fn.footable=function(a){a=a||{};var n=e.extend(!0,{},t.footable.options,a);return this.each(function(){o++;var t=new i(this,n,o);e(this).data("footable",t)})}})(jQuery,window);
@@ -1,51 +1,57 @@
1
1
  (function ($, w, undefined) {
2
- if (w.footable == undefined || w.footable == null)
2
+ if (w.footable === undefined || w.footable === null)
3
3
  throw new Error('Please check and make sure footable.js is included in the page and is loaded prior to this script.');
4
4
 
5
5
  var defaults = {
6
6
  paginate: true,
7
7
  pageSize: 10,
8
- pageNavigation: '.footable-nav'
8
+ pageNavigation: '.pagination',
9
+ firstText: '&laquo;',
10
+ previousText: '&lsaquo;',
11
+ nextText: '&rsaquo;',
12
+ lastText: '&raquo;'
9
13
  };
10
14
 
11
15
  function pageInfo(ft) {
12
16
  var $table = $(ft.table), $tbody = $table.find('> tbody');
13
17
  this.pageNavigation = $table.data('page-navigation') || ft.options.pageNavigation;
14
18
  this.pageSize = $table.data('page-size') || ft.options.pageSize;
19
+ this.firstText = $table.data('page-first-text') || ft.options.firstText;
20
+ this.previousText = $table.data('page-previous-text') || ft.options.previousText;
21
+ this.nextText = $table.data('page-next-text') || ft.options.nextText;
22
+ this.lastText = $table.data('page-last-text') || ft.options.lastText;
15
23
  this.currentPage = 0;
16
24
  this.pages = [];
17
- };
25
+ this.control = false;
26
+ }
18
27
 
19
28
  function Paginate() {
20
29
  var p = this;
21
30
  p.name = 'Footable Paginate';
22
31
 
23
32
  p.init = function (ft) {
24
- if (ft.options.paginate == true) {
25
- var $table = $(ft.table), $tbody = $table.find('> tbody');
33
+ if (ft.options.paginate === true) {
26
34
  $(ft.table).bind({
27
- 'footable_initialized': function (e) {
28
- e.ft.pageInfo = new pageInfo(e.ft);
29
- var $table = $(e.ft.table), $tbody = $table.find('> tbody');
30
- p.createPages(e.ft, $tbody);
31
- p.createNavigation(e.ft, $tbody);
32
- p.fillPage(e.ft, $tbody, 0);
33
- },
34
- 'footable_sorted': function (e) {
35
- var $tbody = $(e.ft.table).find('> tbody');
36
- p.createPages(e.ft, $tbody);
37
- p.fillPage(e.ft, $tbody, e.ft.pageInfo.currentPage);
35
+ 'footable_initialized': function () {
36
+ ft.pageInfo = new pageInfo(ft);
37
+ ft.raise('footable_setup_paging');
38
38
  },
39
- 'footable_filtered': function (e) {
40
- var $tbody = $(e.ft.table).find('> tbody');
41
- p.createPages(e.ft, $tbody);
42
- p.createNavigation(e.ft, $tbody);
43
- p.fillPage(e.ft, $tbody, e.ft.pageInfo.currentPage);
39
+ 'footable_row_removed footable_redrawn footable_sorted footable_filtered footable_setup_paging': function () {
40
+ if (ft.pageInfo) {
41
+ p.setupPaging(ft);
42
+ }
44
43
  }
45
44
  });
46
45
  }
47
46
  };
48
47
 
48
+ p.setupPaging = function(ft) {
49
+ var $tbody = $(ft.table).find('> tbody');
50
+ p.createPages(ft, $tbody);
51
+ p.createNavigation(ft, $tbody);
52
+ p.fillPage(ft, $tbody, ft.pageInfo.currentPage);
53
+ };
54
+
49
55
  p.createPages = function (ft, tbody) {
50
56
  var pages = 1;
51
57
  var info = ft.pageInfo;
@@ -68,43 +74,92 @@
68
74
  if (lastPage.length > 0) info.pages.push(lastPage);
69
75
  if (info.currentPage >= info.pages.length) info.currentPage = info.pages.length - 1;
70
76
  if (info.currentPage < 0) info.currentPage = 0;
77
+ if (info.pages.length === 1) {
78
+ //we only have a single page
79
+ $(ft.table).addClass('no-paging');
80
+ } else {
81
+ $(ft.table).removeClass('no-paging');
82
+ }
71
83
  };
72
84
 
73
85
  p.createNavigation = function (ft, tbody) {
74
- var $nav = $(ft.pageInfo.pageNavigation);
75
- if ($nav.length == 0) return;
86
+ var $nav = $(ft.table).find(ft.pageInfo.pageNavigation);
87
+ //if we cannot find the navigation control within the table, then try find it outside
88
+ if ($nav.length === 0) {
89
+ $nav = $(ft.pageInfo.pageNavigation);
90
+ //if the navigation control is inside another table, then get out
91
+ if ($nav.parents('table:first') !== $(ft.table)) return;
92
+ //if we found more than one navigation control, write error to console
93
+ if ($nav.length > 1 && ft.options.debug === true) console.error('More than one pagination control was found!');
94
+ }
95
+ //if we still cannot find the control, then don't do anything
96
+ if ($nav.length === 0) return;
97
+ //if the nav is not a UL, then find or create a UL
98
+ if (!$nav.is('ul')) {
99
+ if ($nav.find('ul:first').length === 0) { $nav.append('<ul />'); }
100
+ $nav = $nav.find('ul');
101
+ }
76
102
  $nav.find('li').remove();
77
103
  var info = ft.pageInfo;
104
+ info.control = $nav;
78
105
  if (info.pages.length > 0) {
79
-
80
- $nav.append('<li class="footable-page-arrow"><a data-page="prev" href="#prev">&laquo;</a></li>');
106
+ $nav.append('<li class="footable-page-arrow"><a data-page="first" href="#first">'+ft.pageInfo.firstText+'</a>');
107
+ $nav.append('<li class="footable-page-arrow"><a data-page="prev" href="#prev">'+ft.pageInfo.previousText+'</a></li>');
81
108
  $.each(info.pages, function (i, page) {
82
109
  if (page.length > 0) {
83
110
  $nav.append('<li class="footable-page"><a data-page="' + i + '" href="#">' + (i + 1) + '</a></li>');
84
111
  }
85
112
  });
86
- $nav.append('<li class="footable-page-arrow"><a data-page="next" href="#next">&raquo;</a></li>');
113
+ $nav.append('<li class="footable-page-arrow"><a data-page="next" href="#next">'+ft.pageInfo.nextText+'</a></li>');
114
+ $nav.append('<li class="footable-page-arrow"><a data-page="last" href="#last">'+ft.pageInfo.lastText+'</a></li>');
87
115
  }
88
116
  $nav.find('a').click(function (e) {
89
117
  e.preventDefault();
90
118
  var page = $(this).data('page');
91
119
  var newPage = info.currentPage;
92
- if (page == 'prev') {
120
+ if (page === 'first') {
121
+ newPage = 0;
122
+ } else if (page === 'prev') {
93
123
  if (newPage > 0) newPage--;
94
- } else if (page == 'next') {
124
+ } else if (page === 'next') {
95
125
  if (newPage < info.pages.length - 1) newPage++;
126
+ } else if (page === 'last') {
127
+ newPage = info.pages.length - 1;
96
128
  } else {
97
129
  newPage = page;
98
130
  }
99
- if (info.currentPage != newPage) {
100
- p.fillPage(ft, tbody, newPage);
101
- }
102
- $nav.find('li').removeClass('footable-page-current');
103
- $nav.find('li.footable-page > a[data-page=' + info.currentPage + ']').parent().addClass('footable-page-current');
131
+ p.paginate(ft, newPage);
104
132
  });
105
- $nav.find('li.footable-page > a[data-page=' + info.currentPage + ']').parent().addClass('footable-page-current');
133
+ p.setPagingClasses($nav, info.currentPage, info.pages.length);
134
+ };
135
+
136
+ p.paginate = function (ft, newPage) {
137
+ var info = ft.pageInfo;
138
+ if (info.currentPage !== newPage) {
139
+ var $tbody = $(ft.table).find('> tbody');
140
+
141
+ //raise a pre-pagin event so that we can cancel the paging if needed
142
+ var event = ft.raise('footable_paging', { page: newPage, size: info.pageSize });
143
+ if (event && event.result === false) return;
144
+
145
+ p.fillPage(ft, $tbody, newPage);
146
+ info.control.find('li').removeClass('active disabled');
147
+ p.setPagingClasses(info.control, info.currentPage, info.pages.length);
148
+ }
106
149
  };
107
150
 
151
+ p.setPagingClasses = function(nav, currentPage, pageCount) {
152
+ nav.find('li.footable-page > a[data-page=' + currentPage + ']').parent().addClass('active');
153
+ if (currentPage >= pageCount - 1) {
154
+ nav.find('li.footable-page-arrow > a[data-page="next"]').parent().addClass('disabled');
155
+ nav.find('li.footable-page-arrow > a[data-page="last"]').parent().addClass('disabled');
156
+ }
157
+ if (currentPage < 1) {
158
+ nav.find('li.footable-page-arrow > a[data-page="first"]').parent().addClass('disabled');
159
+ nav.find('li.footable-page-arrow > a[data-page="prev"]').parent().addClass('disabled');
160
+ }
161
+ };
162
+
108
163
  p.fillPage = function (ft, tbody, pageNumber) {
109
164
  ft.pageInfo.currentPage = pageNumber;
110
165
  tbody.find('> tr').hide();
@@ -121,7 +176,7 @@
121
176
  }
122
177
  else $row.show();
123
178
  };
124
- };
179
+ }
125
180
 
126
181
  w.footable.plugins.register(new Paginate(), defaults);
127
182
 
@@ -0,0 +1 @@
1
+ (function(e,t,undefined){function a(t){var a=e(t.table);a.find("> tbody"),this.pageNavigation=a.data("page-navigation")||t.options.pageNavigation,this.pageSize=a.data("page-size")||t.options.pageSize,this.firstText=a.data("page-first-text")||t.options.firstText,this.previousText=a.data("page-previous-text")||t.options.previousText,this.nextText=a.data("page-next-text")||t.options.nextText,this.lastText=a.data("page-last-text")||t.options.lastText,this.currentPage=0,this.pages=[],this.control=!1}function i(){var t=this;t.name="Footable Paginate",t.init=function(i){i.options.paginate===!0&&e(i.table).bind({footable_initialized:function(){i.pageInfo=new a(i),i.raise("footable_setup_paging")},"footable_row_removed footable_redrawn footable_sorted footable_filtered footable_setup_paging":function(){i.pageInfo&&t.setupPaging(i)}})},t.setupPaging=function(a){var i=e(a.table).find("> tbody");t.createPages(a,i),t.createNavigation(a,i),t.fillPage(a,i,a.pageInfo.currentPage)},t.createPages=function(t,a){var i=1,o=t.pageInfo,n=i*o.pageSize,r=[],l=[];o.pages=[];var d=a.find("> tr:not(.footable-filtered,.footable-row-detail)");d.each(function(e,t){r.push(t),e===n-1?(o.pages.push(r),i++,n=i*o.pageSize,r=[]):e>=d.length-d.length%o.pageSize&&l.push(t)}),l.length>0&&o.pages.push(l),o.currentPage>=o.pages.length&&(o.currentPage=o.pages.length-1),0>o.currentPage&&(o.currentPage=0),1===o.pages.length?e(t.table).addClass("no-paging"):e(t.table).removeClass("no-paging")},t.createNavigation=function(a){var i=e(a.table).find(a.pageInfo.pageNavigation);if(0===i.length){if(i=e(a.pageInfo.pageNavigation),i.parents("table:first")!==e(a.table))return;i.length>1&&a.options.debug===!0&&console.error("More than one pagination control was found!")}if(0!==i.length){i.is("ul")||(0===i.find("ul:first").length&&i.append("<ul />"),i=i.find("ul")),i.find("li").remove();var o=a.pageInfo;o.control=i,o.pages.length>0&&(i.append('<li class="footable-page-arrow"><a data-page="first" href="#first">'+a.pageInfo.firstText+"</a>"),i.append('<li class="footable-page-arrow"><a data-page="prev" href="#prev">'+a.pageInfo.previousText+"</a></li>"),e.each(o.pages,function(e,t){t.length>0&&i.append('<li class="footable-page"><a data-page="'+e+'" href="#">'+(e+1)+"</a></li>")}),i.append('<li class="footable-page-arrow"><a data-page="next" href="#next">'+a.pageInfo.nextText+"</a></li>"),i.append('<li class="footable-page-arrow"><a data-page="last" href="#last">'+a.pageInfo.lastText+"</a></li>")),i.find("a").click(function(i){i.preventDefault();var n=e(this).data("page"),r=o.currentPage;"first"===n?r=0:"prev"===n?r>0&&r--:"next"===n?o.pages.length-1>r&&r++:r="last"===n?o.pages.length-1:n,t.paginate(a,r)}),t.setPagingClasses(i,o.currentPage,o.pages.length)}},t.paginate=function(a,i){var o=a.pageInfo;if(o.currentPage!==i){var n=e(a.table).find("> tbody"),r=a.raise("footable_paging",{page:i,size:o.pageSize});if(r&&r.result===!1)return;t.fillPage(a,n,i),o.control.find("li").removeClass("active disabled"),t.setPagingClasses(o.control,o.currentPage,o.pages.length)}},t.setPagingClasses=function(e,t,a){e.find("li.footable-page > a[data-page="+t+"]").parent().addClass("active"),t>=a-1&&(e.find('li.footable-page-arrow > a[data-page="next"]').parent().addClass("disabled"),e.find('li.footable-page-arrow > a[data-page="last"]').parent().addClass("disabled")),1>t&&(e.find('li.footable-page-arrow > a[data-page="first"]').parent().addClass("disabled"),e.find('li.footable-page-arrow > a[data-page="prev"]').parent().addClass("disabled"))},t.fillPage=function(a,i,o){a.pageInfo.currentPage=o,i.find("> tr").hide(),e(a.pageInfo.pages[o]).each(function(){t.showRow(this,a)})},t.showRow=function(t,a){var i=e(t),o=i.next(),n=e(a.table);n.hasClass("breakpoint")&&i.hasClass("footable-detail-show")&&o.hasClass("footable-row-detail")?(i.add(o).show(),a.createOrUpdateDetailRow(t)):i.show()}}if(t.footable===undefined||null===t.footable)throw Error("Please check and make sure footable.js is included in the page and is loaded prior to this script.");var o={paginate:!0,pageSize:10,pageNavigation:".pagination",firstText:"&laquo;",previousText:"&lsaquo;",nextText:"&rsaquo;",lastText:"&raquo;"};t.footable.plugins.register(new i,o)})(jQuery,window);