(function ($, w, undefined) { if (w.footable === undefined || w.footable === null) throw new Error('Please check and make sure footable.js is included in the page and is loaded prior to this script.'); var defaults = { paginate: true, pageSize: 10, pageNavigation: '.pagination', firstText: '«', previousText: '‹', nextText: '›', lastText: '»', limitNavigation: 0, limitPreviousText: '...', limitNextText: '...' }; function pageInfo(ft) { var $table = $(ft.table), data = $table.data(); this.pageNavigation = data.pageNavigation || ft.options.pageNavigation; this.pageSize = data.pageSize || ft.options.pageSize; this.firstText = data.firstText || ft.options.firstText; this.previousText = data.previousText || ft.options.previousText; this.nextText = data.nextText || ft.options.nextText; this.lastText = data.lastText || ft.options.lastText; this.limitNavigation = parseInt(data.limitNavigation || ft.options.limitNavigation || defaults.limitNavigation, 10); this.limitPreviousText = data.limitPreviousText || ft.options.limitPreviousText; this.limitNextText = data.limitNextText || ft.options.limitNextText; this.limit = this.limitNavigation > 0; this.currentPage = data.currentPage || 0; this.pages = []; this.control = false; } function Paginate() { var p = this; p.name = 'Footable Paginate'; p.init = function (ft) { if (ft.options.paginate === true) { if ($(ft.table).data('page') === false) return; p.footable = ft; $(ft.table) .unbind('.paging') .bind({ 'footable_initialized.paging footable_row_removed.paging footable_redrawn.paging footable_sorted.paging footable_filtered.paging': function () { p.setupPaging(); } }) //save the filter object onto the table so we can access it later .data('footable-paging', p); } }; p.setupPaging = function () { var ft = p.footable, $tbody = $(ft.table).find('> tbody'); ft.pageInfo = new pageInfo(ft); p.createPages(ft, $tbody); p.createNavigation(ft, $tbody); p.fillPage(ft, $tbody, ft.pageInfo.currentPage); }; p.createPages = function (ft, tbody) { var pages = 1; var info = ft.pageInfo; var pageCount = pages * info.pageSize; var page = []; var lastPage = []; info.pages = []; var rows = tbody.find('> tr:not(.footable-filtered,.footable-row-detail)'); rows.each(function (i, row) { page.push(row); if (i === pageCount - 1) { info.pages.push(page); pages++; pageCount = pages * info.pageSize; page = []; } else if (i >= rows.length - (rows.length % info.pageSize)) { lastPage.push(row); } }); if (lastPage.length > 0) info.pages.push(lastPage); if (info.currentPage >= info.pages.length) info.currentPage = info.pages.length - 1; if (info.currentPage < 0) info.currentPage = 0; if (info.pages.length === 1) { //we only have a single page $(ft.table).addClass('no-paging'); } else { $(ft.table).removeClass('no-paging'); } }; p.createNavigation = function (ft, tbody) { var $nav = $(ft.table).find(ft.pageInfo.pageNavigation); //if we cannot find the navigation control within the table, then try find it outside if ($nav.length === 0) { $nav = $(ft.pageInfo.pageNavigation); //if the navigation control is inside another table, then get out if ($nav.parents('table:first').length > 0 && $nav.parents('table:first') !== $(ft.table)) return; //if we found more than one navigation control, write error to console if ($nav.length > 1 && ft.options.debug === true) console.error('More than one pagination control was found!'); } //if we still cannot find the control, then don't do anything if ($nav.length === 0) return; //if the nav is not a UL, then find or create a UL if (!$nav.is('ul')) { if ($nav.find('ul:first').length === 0) { $nav.append('