diff --git a/js/widgets/widget-pager.js b/js/widgets/widget-pager.js index 77e2c1f4..411f84cc 100644 --- a/js/widgets/widget-pager.js +++ b/js/widgets/widget-pager.js @@ -11,9 +11,10 @@ ts.addWidget({ id: 'pager', priority: 55, // load pager after filter widget - options : { + options: { // output default: '{page}/{totalPages}' - // possible variables: {size}, {page}, {totalPages}, {filteredPages}, {startRow}, {endRow}, {filteredRows} and {totalRows} + // possible variables: {size}, {page}, {totalPages}, {filteredPages}, {startRow}, + // {endRow}, {filteredRows} and {totalRows} pager_output: '{startRow} to {endRow} of {totalRows} rows', // '{page}/{totalPages}' // apply disabled classname to the pager arrows when the rows at either extreme is visible @@ -32,14 +33,15 @@ // Number of options to include in the pager number selector pager_maxOptionSize: 20, - // Save pager page & size if the storage script is loaded (requires $.tablesorter.storage in jquery.tablesorter.widgets.js) + // Save pager page & size if the storage script is loaded (requires $.tablesorter.storage + // in jquery.tablesorter.widgets.js) pager_savePages: true, // defines custom storage key pager_storageKey: 'tablesorter-pager', - // if true, the table will remain the same height no matter how many records are displayed. The space is made up by an empty - // table row set to a height to compensate; default is false + // if true, the table will remain the same height no matter how many records are displayed. + // The space is made up by an empty table row set to a height to compensate; default is false pager_fixedHeight: false, // count child rows towards the set page size? (set true if it is a visible table row within the pager) @@ -48,7 +50,8 @@ pager_countChildRows: false, // remove rows from the table to speed up the sort of large tables. - // setting this to false, only hides the non-visible rows; needed if you plan to add/remove rows with the pager enabled. + // setting this to false, only hides the non-visible rows; needed if you plan to add/remove rows with + // the pager enabled. pager_removeRows: false, // removing rows in larger tables speeds up the sort // use this format: 'http://mydatabase.com?page={page}&size={size}&{sortList:col}&{filterList:fcol}' @@ -60,7 +63,7 @@ pager_ajaxUrl: null, // modify the url after all processing has been applied - pager_customAjaxUrl: function(table, url) { return url; }, + pager_customAjaxUrl: function( table, url ) { return url; }, // ajax error callback from $.tablesorter.showError function // pager_ajaxError: function( config, xhr, settings, exception ){ return exception; }; @@ -88,13 +91,15 @@ // ], // [ "header1", "header2", ... "headerN" ] // optional // ] - pager_ajaxProcessing: function(ajax){ return [ 0, [], null ]; }, + pager_ajaxProcessing: function( ajax ){ return [ 0, [], null ]; }, // css class names of pager arrows pager_css: { container : 'tablesorter-pager', - errorRow : 'tablesorter-errorRow', // error information row (don't include period at beginning) - disabled : 'disabled' // class added to arrows @ extremes (i.e. prev/first arrows 'disabled' on first page) + // error information row (don't include period at beginning) + errorRow : 'tablesorter-errorRow', + // class added to arrows @ extremes (i.e. prev/first arrows 'disabled' on first page) + disabled : 'disabled' }, // jQuery selectors @@ -109,27 +114,27 @@ pageSize : '.pagesize' // page size selector - select dropdown that sets the 'size' option } }, - init: function(table){ - tsp.init(table); + init: function( table ) { + tsp.init( table ); }, // only update to complete sorter initialization - format: function(table, c){ - if (!(c.pager && c.pager.initialized)){ - return tsp.initComplete(table, c); + format: function( table, c ) { + if ( !( c.pager && c.pager.initialized ) ) { + return tsp.initComplete( c ); } - tsp.moveToPage(table, c.pager, false); + tsp.moveToPage( c, c.pager, false ); }, - remove: function(table, c, wo, refreshing){ - tsp.destroyPager(table, c, refreshing); + remove: function( table, c, wo, refreshing ) { + tsp.destroyPager( c, refreshing ); } }); /* pager widget functions */ tsp = ts.pager = { - init: function(table) { + init: function( table ) { // check if tablesorter has initialized - if (table.hasInitialized && table.config.pager && table.config.pager.initialized) { return; } + if ( table.hasInitialized && table.config.pager && table.config.pager.initialized ) { return; } var t, c = table.config, wo = c.widgetOptions, @@ -150,55 +155,60 @@ // save original pager size setSize: wo.pager_size, setPage: wo.pager_startPage - }, c.pager); + }, c.pager ); // pager initializes multiple times before table has completed initialization - if (p.isInitializing) { return; } + if ( p.isInitializing ) { return; } p.isInitializing = true; - if (c.debug) { - console.log('Pager: Initializing'); + if ( c.debug ) { + console.log( 'Pager: Initializing' ); } - p.size = $.data(table, 'pagerLastSize') || wo.pager_size; + p.size = $.data( table, 'pagerLastSize' ) || wo.pager_size; // added in case the pager is reinitialized after being destroyed. - p.$container = $(s.container).addClass(wo.pager_css.container).show(); + p.$container = $( s.container ).addClass( wo.pager_css.container ).show(); // goto selector - p.$goto = p.$container.find(s.gotoPage); // goto is a reserved word #657 + p.$goto = p.$container.find( s.gotoPage ); // goto is a reserved word #657 // page size selector - p.$size = p.$container.find(s.pageSize); - p.totalRows = c.$tbodies.eq(0).children('tr').not( wo.pager_countChildRows ? '' : '.' + c.cssChildRow ).length; + p.$size = p.$container.find( s.pageSize ); + p.totalRows = c.$tbodies.eq( 0 ) + .children( 'tr' ) + .not( wo.pager_countChildRows ? '' : '.' + c.cssChildRow ) + .length; p.oldAjaxSuccess = p.oldAjaxSuccess || wo.pager_ajaxObject.success; c.appender = tsp.appender; p.initializing = true; - if (wo.pager_savePages && ts.storage) { - t = ts.storage(table, wo.pager_storageKey) || {}; // fixes #387 - p.page = ( isNaN(t.page) ? p.page : t.page ) || p.setPage || 0; - p.size = ( isNaN(t.size) ? p.size : t.size ) || p.setSize || 10; - $.data(table, 'pagerLastSize', p.size); + if ( wo.pager_savePages && ts.storage ) { + t = ts.storage( table, wo.pager_storageKey ) || {}; // fixes #387 + p.page = ( isNaN( t.page ) ? p.page : t.page ) || p.setPage || 0; + p.size = ( isNaN( t.size ) ? p.size : t.size ) || p.setSize || 10; + $.data( table, 'pagerLastSize', p.size ); } // skipped rows - p.regexRows = new RegExp('(' + (wo.filter_filteredRow || 'filtered') + '|' + c.selectorRemove.slice(1) + '|' + c.cssChildRow + ')'); + p.regexRows = new RegExp( '(' + ( wo.filter_filteredRow || 'filtered' ) + '|' + + c.selectorRemove.slice( 1 ) + '|' + c.cssChildRow + ')' ); // clear initialized flag p.initialized = false; // before initialization event - c.$table.trigger('pagerBeforeInitialized', c); + c.$table.trigger( 'pagerBeforeInitialized', c ); - tsp.enablePager(table, c, false); + tsp.enablePager( c, false ); // p must have ajaxObject - p.ajaxObject = wo.pager_ajaxObject; // $.extend({}, wo.pager_ajaxObject ); + p.ajaxObject = wo.pager_ajaxObject; p.ajaxObject.url = wo.pager_ajaxUrl; if ( typeof wo.pager_ajaxUrl === 'string' ) { // ajax pager; interact with database p.ajax = true; - // When filtering with ajax, allow only custom filtering function, disable default filtering since it will be done server side. + // When filtering with ajax, allow only custom filtering function, disable default filtering + // since it will be done server side. wo.filter_serversideFiltering = true; c.serverSideSorting = true; - tsp.moveToPage(table, p); + tsp.moveToPage( c, p ); } else { p.ajax = false; // Regular pager; all rows stored in memory @@ -207,30 +217,30 @@ }, - initComplete: function(table, c){ + initComplete: function( c ) { var p = c.pager; - tsp.bindEvents(table, c); - tsp.setPageSize(c, 0); // page size 0 is ignored - if (!p.ajax) { - tsp.hideRowsSetup(table, c); + tsp.bindEvents( c ); + tsp.setPageSize( c, 0 ); // page size 0 is ignored + if ( !p.ajax ) { + tsp.hideRowsSetup( c ); } // pager initialized p.initialized = true; p.initializing = false; p.isInitializing = false; - if (c.debug) { - console.log('Pager: Triggering pagerInitialized'); + if ( c.debug ) { + console.log( 'Pager: Triggering pagerInitialized' ); } c.$table.trigger( 'pagerInitialized', c ); // filter widget not initialized; it will update the output display & fire off the pagerComplete event - if ( !( c.widgetOptions.filter_initialized && ts.hasWidget(table, 'filter') ) ) { + if ( !( c.widgetOptions.filter_initialized && ts.hasWidget( c.table, 'filter' ) ) ) { // if ajax, then don't fire off pagerComplete - tsp.updatePageDisplay(table, c, !p.ajax); + tsp.updatePageDisplay( c, !p.ajax ); } }, - bindEvents: function(table, c){ + bindEvents: function( c ) { var ctrls, fxn, p = c.pager, wo = c.widgetOptions, @@ -239,106 +249,108 @@ c.$table .off( namespace ) - .on('filterInit filterStart '.split(' ').join(namespace + ' '), function(e, filters) { - p.currentFilters = $.isArray(filters) ? filters : c.$table.data('lastSearch'); + .on( 'filterInit filterStart '.split( ' ' ).join( namespace + ' ' ), function( e, filters ) { + p.currentFilters = $.isArray( filters ) ? filters : c.$table.data( 'lastSearch' ); // don't change page if filters are the same (pager updating, etc) - if (e.type === 'filterStart' && wo.pager_pageReset !== false && (c.lastCombinedFilter || '') !== (p.currentFilters || []).join('')) { + if ( e.type === 'filterStart' && wo.pager_pageReset !== false && + ( c.lastCombinedFilter || '' ) !== ( p.currentFilters || [] ).join( '' ) ) { p.page = wo.pager_pageReset; // fixes #456 & #565 } }) // update pager after filter widget completes - .on('filterEnd sortEnd '.split(' ').join(namespace + ' '), function() { - p.currentFilters = c.$table.data('lastSearch'); - if (p.initialized || p.initializing) { - if (c.delayInit && c.rowsCopy && c.rowsCopy.length === 0) { + .on( 'filterEnd sortEnd '.split( ' ' ).join( namespace + ' ' ), function() { + p.currentFilters = c.$table.data( 'lastSearch' ); + if ( p.initialized || p.initializing ) { + if ( c.delayInit && c.rowsCopy && c.rowsCopy.length === 0 ) { // make sure we have a copy of all table rows once the cache has been built - tsp.updateCache(table); + tsp.updateCache( c ); } - tsp.updatePageDisplay(table, c, false); - // tsp.moveToPage(table, p, false); <-- called when applyWidgets is triggered - ts.applyWidget( table ); + tsp.updatePageDisplay( c, false ); + // tsp.moveToPage( c, p, false ); <-- called when applyWidgets is triggered + ts.applyWidget( c.table ); } }) - .on('disablePager' + namespace, function(e){ + .on( 'disablePager' + namespace, function( e ) { e.stopPropagation(); - tsp.showAllRows(table, c); + tsp.showAllRows( c ); }) - .on('enablePager' + namespace, function(e){ + .on( 'enablePager' + namespace, function( e ) { e.stopPropagation(); - tsp.enablePager(table, c, true); + tsp.enablePager( c, true ); }) - .on('destroyPager' + namespace, function(e, refreshing){ + .on( 'destroyPager' + namespace, function( e, refreshing ) { e.stopPropagation(); // call removeWidget to make sure internal flags are modified. - ts.removeWidget( table, 'pager', false ); + ts.removeWidget( c.table, 'pager', false ); }) - .on('updateComplete' + namespace, function(e, table, triggered){ + .on( 'updateComplete' + namespace, function( e, table, triggered ) { e.stopPropagation(); // table can be unintentionally undefined in tablesorter v2.17.7 and earlier // don't recalculate total rows/pages if using ajax - if (!table || triggered || p.ajax) { return; } - var $rows = c.$tbodies.eq(0).children('tr').not(c.selectorRemove); - p.totalRows = $rows.length - ( wo.pager_countChildRows ? 0 : $rows.filter('.' + c.cssChildRow).length ); + if ( !table || triggered || p.ajax ) { return; } + var $rows = c.$tbodies.eq( 0 ).children( 'tr' ).not( c.selectorRemove ); + p.totalRows = $rows.length - + ( wo.pager_countChildRows ? 0 : $rows.filter( '.' + c.cssChildRow ).length ); p.totalPages = Math.ceil( p.totalRows / p.size ); - if ($rows.length && c.rowsCopy && c.rowsCopy.length === 0) { + if ( $rows.length && c.rowsCopy && c.rowsCopy.length === 0 ) { // make a copy of all table rows once the cache has been built - tsp.updateCache(table); + tsp.updateCache( c ); } if ( p.page >= p.totalPages ) { - tsp.moveToLastPage(table, p); + tsp.moveToLastPage( c, p ); } - tsp.hideRows(table, c); - tsp.changeHeight(table, c); + tsp.hideRows( c ); + tsp.changeHeight( c ); // update without triggering pagerComplete - tsp.updatePageDisplay(table, c, false); + tsp.updatePageDisplay( c, false ); // make sure widgets are applied - fixes #450 ts.applyWidget( table ); - tsp.updatePageDisplay(table, c); + tsp.updatePageDisplay( c ); }) - .on('pageSize refreshComplete '.split(' ').join(namespace + ' '), function(e, size){ + .on( 'pageSize refreshComplete '.split( ' ' ).join( namespace + ' ' ), function( e, size ) { e.stopPropagation(); - tsp.setPageSize(c, tsp.parsePageSize( c, size, 'get' )); - tsp.hideRows(table, c); - tsp.updatePageDisplay(table, c, false); + tsp.setPageSize( c, tsp.parsePageSize( c, size, 'get' ) ); + tsp.hideRows( c ); + tsp.updatePageDisplay( c, false ); }) - .on('pageSet pagerUpdate '.split(' ').join(namespace + ' '), function(e, num){ + .on( 'pageSet pagerUpdate '.split( ' ' ).join( namespace + ' ' ), function( e, num ) { e.stopPropagation(); // force pager refresh - if (e.type === 'pagerUpdate') { + if ( e.type === 'pagerUpdate' ) { num = typeof num === 'undefined' ? p.page + 1 : num; p.last.page = true; } - p.page = (parseInt(num, 10) || 1) - 1; - tsp.moveToPage(table, p, true); - tsp.updatePageDisplay(table, c, false); + p.page = ( parseInt( num, 10 ) || 1 ) - 1; + tsp.moveToPage( c, p, true ); + tsp.updatePageDisplay( c, false ); }) - .on('pageAndSize' + namespace, function(e, page, size){ + .on( 'pageAndSize' + namespace, function( e, page, size ) { e.stopPropagation(); - p.page = (parseInt(page, 10) || 1) - 1; - tsp.setPageSize(c, tsp.parsePageSize( c, size, 'get' )); - tsp.moveToPage(table, p, true); - tsp.hideRows(table, c); - tsp.updatePageDisplay(table, c, false); + p.page = ( parseInt(page, 10) || 1 ) - 1; + tsp.setPageSize( c, tsp.parsePageSize( c, size, 'get' ) ); + tsp.moveToPage( c, p, true ); + tsp.hideRows( c ); + tsp.updatePageDisplay( c, false ); }); // clicked controls ctrls = [ s.first, s.prev, s.next, s.last ]; fxn = [ 'moveToFirstPage', 'moveToPrevPage', 'moveToNextPage', 'moveToLastPage' ]; - if (c.debug && !p.$container.length) { - console.warn('Pager: >> Container not found'); + if ( c.debug && !p.$container.length ) { + console.warn( 'Pager: >> Container not found' ); } - p.$container.find(ctrls.join(',')) - .attr('tabindex', 0) - .off('click' + namespace) - .on('click' + namespace, function(e){ + p.$container.find( ctrls.join( ',' ) ) + .attr( 'tabindex', 0 ) + .off( 'click' + namespace ) + .on( 'click' + namespace, function( e ) { e.stopPropagation(); var i, - $c = $(this), + $c = $( this ), l = ctrls.length; - if ( !$c.hasClass(wo.pager_css.disabled) ) { - for (i = 0; i < l; i++) { - if ($c.is(ctrls[i])) { - tsp[fxn[i]](table, p); + if ( !$c.hasClass( wo.pager_css.disabled ) ) { + for ( i = 0; i < l; i++ ) { + if ( $c.is( ctrls[ i ] ) ) { + tsp[ fxn[ i ] ]( c, p ); break; } } @@ -347,38 +359,38 @@ if ( p.$goto.length ) { p.$goto - .off('change' + namespace) - .on('change' + namespace, function(){ - p.page = $(this).val() - 1; - tsp.moveToPage(table, p, true); - tsp.updatePageDisplay(table, c, false); + .off( 'change' + namespace ) + .on( 'change' + namespace, function() { + p.page = $( this ).val() - 1; + tsp.moveToPage( c, p, true ); + tsp.updatePageDisplay( c, false ); }); - } else if (c.debug) { - console.warn('Pager: >> Goto selector not found'); + } else if ( c.debug ) { + console.warn( 'Pager: >> Goto selector not found' ); } if ( p.$size.length ) { // setting an option as selected appears to cause issues with initial page size - p.$size.find('option').removeAttr('selected'); + p.$size.find( 'option' ).removeAttr( 'selected' ); p.$size - .off('change' + namespace) - .on('change' + namespace, function() { - if ( !$(this).hasClass(wo.pager_css.disabled) ) { - var size = $(this).val(); + .off( 'change' + namespace ) + .on( 'change' + namespace, function() { + if ( !$( this ).hasClass( wo.pager_css.disabled ) ) { + var size = $( this ).val(); p.$size.val( size ); // in case there are more than one pagers - tsp.setPageSize(c, size); - tsp.changeHeight(table, c); + tsp.setPageSize( c, size ); + tsp.changeHeight( c ); } return false; }); - } else if (c.debug) { + } else if ( c.debug ) { console.warn('Pager: >> Size selector not found'); } }, // hide arrows at extremes - pagerArrows: function(c, disable) { + pagerArrows: function( c, disable ) { var p = c.pager, dis = !!disable, first = dis || p.page === 0, @@ -387,8 +399,14 @@ wo = c.widgetOptions, s = wo.pager_selectors; if ( wo.pager_updateArrows ) { - p.$container.find(s.first + ',' + s.prev).toggleClass(wo.pager_css.disabled, first).attr('aria-disabled', first); - p.$container.find(s.next + ',' + s.last).toggleClass(wo.pager_css.disabled, last).attr('aria-disabled', last); + p.$container + .find( s.first + ',' + s.prev ) + .toggleClass( wo.pager_css.disabled, first ) + .attr( 'aria-disabled', first ); + p.$container + .find( s.next + ',' + s.last ) + .toggleClass( wo.pager_css.disabled, last ) + .attr( 'aria-disabled', last ); } }, @@ -396,33 +414,41 @@ var normalized, indx, len, wo = c.widgetOptions, p = c.pager, - hasFilters = c.$table.hasClass('hasFilters'); - if (hasFilters && !wo.pager_ajaxUrl) { - if ($.isEmptyObject(c.cache)) { + hasFilters = c.$table.hasClass( 'hasFilters' ); + if ( hasFilters && !wo.pager_ajaxUrl ) { + if ( $.isEmptyObject( c.cache ) ) { // delayInit: true so nothing is in the cache - p.filteredRows = p.totalRows = c.$tbodies.eq(0).children('tr').not( wo.pager_countChildRows ? '' : '.' + c.cssChildRow ).length; + p.filteredRows = p.totalRows = c.$tbodies.eq( 0 ) + .children( 'tr' ) + .not( wo.pager_countChildRows ? '' : '.' + c.cssChildRow ) + .length; } else { p.filteredRows = 0; - normalized = c.cache[0].normalized; + normalized = c.cache[ 0 ].normalized; len = normalized.length; - for (indx = 0; indx < len; indx++) { - p.filteredRows += p.regexRows.test(normalized[indx][c.columns].$row[0].className) ? 0 : 1; + for ( indx = 0; indx < len; indx++ ) { + p.filteredRows += p.regexRows.test( normalized[ indx ][ c.columns ].$row[ 0 ].className ) ? 0 : 1; } } - } else if (!hasFilters) { + } else if ( !hasFilters ) { p.filteredRows = p.totalRows; } }, - updatePageDisplay: function(table, c, completed) { + updatePageDisplay: function( c, completed ) { if ( c.pager.initializing ) { return; } var s, t, $out, options, indx, len, + table = c.table, wo = c.widgetOptions, p = c.pager, namespace = c.namespace + 'pager', sz = tsp.parsePageSize( c, p.size, 'get' ); // don't allow dividing by zero - if (wo.pager_countChildRows) { t.push(c.cssChildRow); } - p.$size.add(p.$goto).removeClass(wo.pager_css.disabled).removeAttr('disabled').attr('aria-disabled', 'false'); + if ( wo.pager_countChildRows ) { t.push( c.cssChildRow ); } + p.$size + .add( p.$goto ) + .removeClass( wo.pager_css.disabled ) + .removeAttr( 'disabled' ) + .attr( 'aria-disabled', 'false' ); p.totalPages = Math.ceil( p.totalRows / sz ); // needed for 'pageSize' method c.totalRows = p.totalRows; tsp.parsePageNumber( c, p ); @@ -430,62 +456,68 @@ c.filteredRows = p.filteredRows; p.filteredPages = Math.ceil( p.filteredRows / sz ) || 0; if ( tsp.getTotalPages( c, p ) >= 0 ) { - t = (p.size * p.page > p.filteredRows) && completed; - p.page = (t) ? wo.pager_pageReset || 0 : p.page; - p.startRow = (t) ? p.size * p.page + 1 : (p.filteredRows === 0 ? 0 : p.size * p.page + 1); + t = ( p.size * p.page > p.filteredRows ) && completed; + p.page = t ? wo.pager_pageReset || 0 : p.page; + p.startRow = t ? p.size * p.page + 1 : ( p.filteredRows === 0 ? 0 : p.size * p.page + 1 ); p.endRow = Math.min( p.filteredRows, p.totalRows, p.size * ( p.page + 1 ) ); - $out = p.$container.find(wo.pager_selectors.pageDisplay); + $out = p.$container.find( wo.pager_selectors.pageDisplay ); // form the output string (can now get a new output string from the server) s = ( p.ajaxData && p.ajaxData.output ? p.ajaxData.output || wo.pager_output : wo.pager_output ) // {page} = one-based index; {page+#} = zero based index +/- value - .replace(/\{page([\-+]\d+)?\}/gi, function(m, n){ - return p.totalPages ? p.page + (n ? parseInt(n, 10) : 1) : 0; + .replace( /\{page([\-+]\d+)?\}/gi, function( m, n ) { + return p.totalPages ? p.page + ( n ? parseInt( n, 10 ) : 1 ) : 0; }) // {totalPages}, {extra}, {extra:0} (array) or {extra : key} (object) - .replace(/\{\w+(\s*:\s*\w+)?\}/gi, function(m){ + .replace( /\{\w+(\s*:\s*\w+)?\}/gi, function( m ) { var len, indx, - str = m.replace(/[{}\s]/g, ''), - extra = str.split(':'), + str = m.replace( /[{}\s]/g, '' ), + extra = str.split( ':' ), data = p.ajaxData, // return zero for default page/row numbers - deflt = /(rows?|pages?)$/i.test(str) ? 0 : ''; - if (/(startRow|page)/.test(extra[0]) && extra[1] === 'input') { - len = ('' + (extra[0] === 'page' ? p.totalPages : p.totalRows)).length; - indx = extra[0] === 'page' ? p.page + 1 : p.startRow; - return ''; + deflt = /(rows?|pages?)$/i.test( str ) ? 0 : ''; + if ( /(startRow|page)/.test( extra[ 0 ] ) && extra[ 1 ] === 'input' ) { + len = ( '' + ( extra[ 0 ] === 'page' ? p.totalPages : p.totalRows ) ).length; + indx = extra[ 0 ] === 'page' ? p.page + 1 : p.startRow; + return ''; } - return extra.length > 1 && data && data[extra[0]] ? data[extra[0]][extra[1]] : p[str] || (data ? data[str] : deflt) || deflt; + return extra.length > 1 && data && data[ extra[ 0 ] ] ? + data[ extra[ 0 ] ][ extra[ 1 ] ] : + p[ str ] || ( data ? data[ str ] : deflt ) || deflt; }); if ( p.$goto.length ) { t = ''; - options = tsp.buildPageSelect(p, c); + options = tsp.buildPageSelect( c, p ); len = options.length; - for (indx = 0; indx < len; indx++) { - t += ''; + for ( indx = 0; indx < len; indx++ ) { + t += ''; } // innerHTML doesn't work in IE9 - http://support2.microsoft.com/kb/276228 - p.$goto.html(t).val( p.page + 1 ); + p.$goto.html( t ).val( p.page + 1 ); } - if ($out.length) { - $out[ ($out[0].nodeName === 'INPUT') ? 'val' : 'html' ](s); + if ( $out.length ) { + $out[ ($out[ 0 ].nodeName === 'INPUT' ) ? 'val' : 'html' ]( s ); // rebind startRow/page inputs - $out.find('.ts-startRow, .ts-page').off('change' + namespace).on('change' + namespace, function(){ - var v = $(this).val(), - pg = $(this).hasClass('ts-startRow') ? Math.floor( v / p.size ) + 1 : v; - c.$table.trigger('pageSet' + namespace, [ pg ]); - }); + $out + .find( '.ts-startRow, .ts-page' ) + .off( 'change' + namespace ) + .on( 'change' + namespace, function() { + var v = $( this ).val(), + pg = $( this ).hasClass( 'ts-startRow' ) ? Math.floor( v / p.size ) + 1 : v; + c.$table.trigger( 'pageSet' + namespace, [ pg ] ); + }); } } - tsp.pagerArrows(c); - tsp.fixHeight(table, c); - if (p.initialized && completed !== false) { - if (c.debug) { - console.log('Pager: Triggering pagerComplete'); + tsp.pagerArrows( c ); + tsp.fixHeight( c ); + if ( p.initialized && completed !== false ) { + if ( c.debug ) { + console.log( 'Pager: Triggering pagerComplete' ); } - c.$table.trigger('pagerComplete', c); + c.$table.trigger( 'pagerComplete', c ); // save pager info to storage - if (wo.pager_savePages && ts.storage) { - ts.storage(table, wo.pager_storageKey, { + if ( wo.pager_savePages && ts.storage ) { + ts.storage( table, wo.pager_storageKey, { page : p.page, size : p.size }); @@ -493,100 +525,107 @@ } }, - buildPageSelect: function(p, c) { + buildPageSelect: function( c, p ) { // Filter the options page number link array if it's larger than 'pager_maxOptionSize' // as large page set links will slow the browser on large dom inserts - var i, central_focus_size, focus_option_pages, insert_index, option_length, focus_length, + var i, centralFocusSize, focusOptionPages, insertIndex, optionLength, focusLength, wo = c.widgetOptions, pg = tsp.getTotalPages( c, p ) || 1, // make skip set size multiples of 5 - skip_set_size = Math.ceil( ( pg / wo.pager_maxOptionSize ) / 5 ) * 5, - large_collection = pg > wo.pager_maxOptionSize, - current_page = p.page + 1, - start_page = skip_set_size, - end_page = pg - skip_set_size, - option_pages = [ 1 ], + skipSetSize = Math.ceil( ( pg / wo.pager_maxOptionSize ) / 5 ) * 5, + largeCollection = pg > wo.pager_maxOptionSize, + currentPage = p.page + 1, + startPage = skipSetSize, + endPage = pg - skipSetSize, + optionPages = [ 1 ], // construct default options pages array - option_pages_start_page = (large_collection) ? skip_set_size : 1; + optionPagesStartPage = largeCollection ? skipSetSize : 1; - for ( i = option_pages_start_page; i <= pg; ) { - option_pages.push(i); - i = i + ( large_collection ? skip_set_size : 1 ); + for ( i = optionPagesStartPage; i <= pg; ) { + optionPages.push( i ); + i = i + ( largeCollection ? skipSetSize : 1 ); } - option_pages.push(pg); + optionPages.push( pg ); - if (large_collection) { - focus_option_pages = []; + if ( largeCollection ) { + focusOptionPages = []; // don't allow central focus size to be > 5 on either side of current page - central_focus_size = Math.max( Math.floor( wo.pager_maxOptionSize / skip_set_size ) - 1, 5 ); + centralFocusSize = Math.max( Math.floor( wo.pager_maxOptionSize / skipSetSize ) - 1, 5 ); - start_page = current_page - central_focus_size; - if (start_page < 1) { start_page = 1; } - end_page = current_page + central_focus_size; - if (end_page > pg) { end_page = pg; } + startPage = currentPage - centralFocusSize; + if ( startPage < 1 ) { startPage = 1; } + endPage = currentPage + centralFocusSize; + if ( endPage > pg ) { endPage = pg; } // construct an array to get a focus set around the current page - for (i = start_page; i <= end_page ; i++) { - focus_option_pages.push(i); + for ( i = startPage; i <= endPage ; i++ ) { + focusOptionPages.push( i ); } // keep unique values - option_pages = $.grep(option_pages, function(value, indx) { - return $.inArray(value, option_pages) === indx; + optionPages = $.grep( optionPages, function( value, indx ) { + return $.inArray( value, optionPages ) === indx; }); - option_length = option_pages.length; - focus_length = focus_option_pages.length; + optionLength = optionPages.length; + focusLength = focusOptionPages.length; - // make sure at all option_pages aren't replaced - if (option_length - focus_length > skip_set_size / 2 && option_length + focus_length > wo.pager_maxOptionSize ) { - insert_index = Math.floor(option_length / 2) - Math.floor(focus_length / 2); - Array.prototype.splice.apply(option_pages, [ insert_index, focus_length ]); + // make sure at all optionPages aren't replaced + if ( optionLength - focusLength > skipSetSize / 2 && optionLength + focusLength > wo.pager_maxOptionSize ) { + insertIndex = Math.floor( optionLength / 2 ) - Math.floor( focusLength / 2 ); + Array.prototype.splice.apply( optionPages, [ insertIndex, focusLength ] ); } - option_pages = option_pages.concat(focus_option_pages); + optionPages = optionPages.concat( focusOptionPages ); } // keep unique values again - option_pages = $.grep(option_pages, function(value, indx) { - return $.inArray(value, option_pages) === indx; + optionPages = $.grep( optionPages, function( value, indx ) { + return $.inArray( value, optionPages ) === indx; }) - .sort(function(a, b) { return a - b; }); + .sort( function( a, b ) { + return a - b; + }); - return option_pages; + return optionPages; }, - fixHeight: function(table, c) { + fixHeight: function( c ) { var d, h, + table = c.table, p = c.pager, wo = c.widgetOptions, - $b = c.$tbodies.eq(0); - $b.find('tr.pagerSavedHeightSpacer').remove(); - if (wo.pager_fixedHeight && !p.isDisabled) { - h = $.data(table, 'pagerSavedHeight'); - if (h) { + $b = c.$tbodies.eq( 0 ); + $b.find( 'tr.pagerSavedHeightSpacer' ).remove(); + if ( wo.pager_fixedHeight && !p.isDisabled ) { + h = $.data( table, 'pagerSavedHeight' ); + if ( h ) { d = h - $b.height(); - if ( d > 5 && $.data(table, 'pagerLastSize') === p.size && $b.children('tr:visible').length < p.size ) { - $b.append('