Skip to content

Commit

Permalink
Core: Debug components separately
Browse files Browse the repository at this point in the history
  • Loading branch information
Mottie committed Mar 18, 2018
1 parent 6f9edd7 commit 7b15ec9
Show file tree
Hide file tree
Showing 11 changed files with 266 additions and 208 deletions.
89 changes: 46 additions & 43 deletions addons/pager/jquery.tablesorter.pager.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@
pagerArrows( table, p );
fixHeight(table, p);
if (p.initialized && completed !== false) {
if (c.debug) {
console.log('Pager: Triggering pagerComplete');
if (ts.debug(c, 'pager')) {
console.log('Pager >> Triggering pagerComplete');
}
c.$table.triggerHandler('pagerComplete', p);
// save pager info to storage
Expand Down Expand Up @@ -429,8 +429,8 @@
ts.showError( table );

if ( exception ) {
if (c.debug) {
console.error('Pager: >> Ajax Error', xhr, settings, exception);
if (ts.debug(c, 'pager')) {
console.error('Pager >> Ajax Error', xhr, settings, exception);
}
ts.showError( table, xhr, settings, exception );
c.$tbodies.eq(0).children('tr').detach();
Expand Down Expand Up @@ -527,8 +527,8 @@
// apply widgets after table has rendered & after a delay to prevent
// multiple applyWidget blocking code from blocking this trigger
setTimeout(function() {
if (c.debug) {
console.log('Pager: Triggering pagerChange');
if (ts.debug(c, 'pager')) {
console.log('Pager >> Triggering pagerChange');
}
$table.triggerHandler( 'pagerChange', p );
ts.applyWidget( table );
Expand Down Expand Up @@ -573,8 +573,8 @@
p.oldAjaxSuccess(data);
}
};
if (c.debug) {
console.log('Pager: Ajax initialized', p.ajaxObject);
if (ts.debug(c, 'pager')) {
console.log('Pager >> Ajax initialized', p.ajaxObject);
}
$.ajax(p.ajaxObject);
}
Expand Down Expand Up @@ -618,8 +618,8 @@
if ( typeof p.customAjaxUrl === 'function' ) {
url = p.customAjaxUrl(table, url);
}
if (c.debug) {
console.log('Pager: Ajax url = ' + url);
if (ts.debug(c, 'pager')) {
console.log('Pager >> Ajax url = ' + url);
}
return url;
},
Expand All @@ -628,13 +628,14 @@
var $tb, index, count, added,
$t = $(table),
c = table.config,
debug = ts.debug(c, 'pager'),
f = c.$table.hasClass('hasFilters'),
l = rows && rows.length || 0, // rows may be undefined
e = p.size === 'all' ? p.totalRows : p.size,
s = ( p.page * e );
if ( l < 1 ) {
if (c.debug) {
console.warn('Pager: >> No rows for pager to render');
if (debug) {
console.warn('Pager >> No rows for pager to render');
}
// empty table, abort!
return;
Expand All @@ -646,8 +647,8 @@
p.cacheIndex = [];
p.isDisabled = false; // needed because sorting will change the page and re-enable the pager
if (p.initialized) {
if (c.debug) {
console.log('Pager: Triggering pagerChange');
if (debug) {
console.log('Pager >> Triggering pagerChange');
}
$t.triggerHandler( 'pagerChange', p );
}
Expand Down Expand Up @@ -676,8 +677,8 @@
}
updatePageDisplay(table, p);
if (table.isUpdating) {
if (c.debug) {
console.log('Pager: Triggering updateComplete');
if (debug) {
console.log('Pager >> Triggering updateComplete');
}
$t.triggerHandler('updateComplete', [ table, true ]);
}
Expand All @@ -700,8 +701,8 @@
renderTable(table, table.config.rowsCopy, p);
p.isDisabled = true;
ts.applyWidget( table );
if (table.config.debug) {
console.log('Pager: Disabled');
if (ts.debug(table.config, 'pager')) {
console.log('Pager >> Disabled');
}
}
// disable size selector
Expand Down Expand Up @@ -734,9 +735,10 @@
moveToPage = function(table, p, pageMoved) {
if ( p.isDisabled ) { return; }
var tmp,
c = table.config,
$t = $(table),
l = p.last;
c = table.config,
debug = ts.debug(c, 'pager'),
$t = $(table),
l = p.last;
if ( pageMoved !== false && p.initialized && ts.isEmptyObject(c.cache)) {
return updateCache(table);
}
Expand All @@ -756,8 +758,8 @@
// & ajax url option changes (dynamically add/remove/rename sort & filter parameters)
(l.optAjaxUrl || '') === (p.ajaxUrl || '') &&
l.sortList === (c.sortList || []).join(',') ) { return; }
if (c.debug) {
console.log('Pager: Changing to page ' + p.page);
if (debug) {
console.log('Pager >> Changing to page ' + p.page);
}
p.last = {
page : p.page,
Expand All @@ -774,9 +776,9 @@
p.processAjaxOnInit = true;
tmp = p.initialRows;
p.totalRows = typeof tmp.total !== 'undefined' ? tmp.total :
( c.debug ? console.error('Pager: no initial total page set!') || 0 : 0 );
( debug ? console.error('Pager >> No initial total page set!') || 0 : 0 );
p.filteredRows = typeof tmp.filtered !== 'undefined' ? tmp.filtered :
( c.debug ? console.error('Pager: no initial filtered page set!') || 0 : 0 );
( debug ? console.error('Pager >> No initial filtered page set!') || 0 : 0 );
pagerInitialized( table, p );
} else {
getAjax(table, p);
Expand All @@ -786,14 +788,14 @@
}
$.data(table, 'pagerLastPage', p.page);
if (p.initialized && pageMoved !== false) {
if (c.debug) {
console.log('Pager: Triggering pageMoved');
if (debug) {
console.log('Pager >> Triggering pageMoved');
}
$t.triggerHandler('pageMoved', p);
ts.applyWidget( table );
if (table.isUpdating) {
if (c.debug) {
console.log('Pager: Triggering updateComplete');
if (debug) {
console.log('Pager >> Triggering updateComplete');
}
$t.triggerHandler('updateComplete', [ table, true ]);
}
Expand Down Expand Up @@ -866,8 +868,8 @@
pagerInitialized = function(table, p) {
p.initialized = true;
p.initializing = false;
if (table.config.debug) {
console.log('Pager: Triggering pagerInitialized');
if (ts.debug(table.config, 'pager')) {
console.log('Pager >> Triggering pagerInitialized');
}
$(table).triggerHandler( 'pagerInitialized', p );
ts.applyWidget( table );
Expand Down Expand Up @@ -934,8 +936,8 @@
setPageSize(table, p.size, p);
moveToPage(table, p);
hideRowsSetup(table, p);
if (c.debug) {
console.log('Pager: Enabled');
if (ts.debug(c, 'pager')) {
console.log('Pager >> Enabled');
}
}
},
Expand All @@ -944,15 +946,16 @@
var t, ctrls, fxn, $el,
c = table.config,
wo = c.widgetOptions,
debug = ts.debug(c, 'pager'),
p = c.pager = $.extend( true, {}, $.tablesorterPager.defaults, settings ),
$t = c.$table,
namespace = c.namespace + 'pager',
// added in case the pager is reinitialized after being destroyed.
pager = p.$container = $(p.container).addClass('tablesorter-pager').show();
// save a copy of the original settings
p.settings = $.extend( true, {}, $.tablesorterPager.defaults, settings );
if (c.debug) {
console.log('Pager: Initializing');
if (debug) {
console.log('Pager >> Initializing');
}
p.oldAjaxSuccess = p.oldAjaxSuccess || p.ajaxObject.success;
c.appender = $this.appender;
Expand Down Expand Up @@ -1066,8 +1069,8 @@
// clicked controls
ctrls = [ p.cssFirst, p.cssPrev, p.cssNext, p.cssLast ];
fxn = [ moveToFirstPage, moveToPrevPage, moveToNextPage, moveToLastPage ];
if (c.debug && !pager.length) {
console.warn('Pager: >> Container not found');
if (debug && !pager.length) {
console.warn('Pager >> "container" not found');
}
pager.find(ctrls.join(','))
.attr('tabindex', 0)
Expand Down Expand Up @@ -1095,8 +1098,8 @@
moveToPage(table, p, true);
updatePageDisplay(table, p, false);
});
} else if (c.debug) {
console.warn('Pager: >> Goto selector not found');
} else if (debug) {
console.warn('Pager >> "goto" selector not found');
}
// page size selector
$el = pager.find(p.cssPageSize);
Expand All @@ -1113,8 +1116,8 @@
}
return false;
});
} else if (c.debug) {
console.warn('Pager: >> Size selector not found');
} else if (debug) {
console.warn('Pager >> "size" selector not found');
}

// clear initialized flag
Expand Down Expand Up @@ -1145,8 +1148,8 @@
// update page size on init
setPageSize(table, p.size, p);
moveToPage(table, p);
if (c.debug) {
console.log('Pager: Triggering pagerInitialized');
if (debug) {
console.log('Pager >> Triggering pagerInitialized');
}
c.$table.triggerHandler( 'pagerInitialized', p );
if ( !( c.widgetOptions.filter_initialized && ts.hasWidget(table, 'filter') ) ) {
Expand Down
10 changes: 7 additions & 3 deletions docs/example-option-debug.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@
<!-- Tablesorter: required -->
<link rel="stylesheet" href="../css/theme.blue.css">
<script src="../js/jquery.tablesorter.js"></script>
<script src="../js/widgets/widget-filter.js"></script>

<script id="js">$(function() {

// call the tablesorter plugin
$("table").tablesorter({
theme : 'blue',
// enable debug mode
debug: true
// enable debug mode;
// debug: true => all debugging
// debug: "filter" => filter widget debugging only
debug: "core filter", // => core and filter widget debugging
widgets: ["filter"]
});

});</script>
Expand All @@ -39,7 +43,7 @@ <h3>Flexible client-side table sorting</h3>

<div id="main">
<p class="tip">
<em>NOTE!</em> If firebug is installed the debuging information will be displayed in the firebug console.
<em>NOTE!</em> Debugging information will be displayed in the development console (Press <kbd>F12</kbd> and select the console tab).
</p>

<h1>Demo</h1>
Expand Down
19 changes: 16 additions & 3 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -928,11 +928,24 @@ <h1>Configuration</h1>
</tr>

<tr id="debug">
<td><span class="permalink">debug</span></td>
<td>Boolean</td>
<td><a href="#" class="permalink">debug</a></td>
<td>Boolean or String</td>
<td>false</td>
<td>
Boolean flag indicating if tablesorter should display debuging information useful for development.
Set this option to provide useful for development debugging information in the console <span class="version updated">v2.30.0</span>.
<div class="collapsible">
In <span class="version updated">v2.30.0</span>, set this option as a string containing either "core" and/or a specific widget name; or, a boolean value.
<p>When a boolean flag is set, <em>all</em> debugging information is shown in the console.</p>
To display debugging information specific to a widget, or widgets include the widget name:
<pre class="prettyprint lang-js">$(function() {
$("table").tablesorter({
// Show debugging info only for the filter and columnSelector widgets
// include "core" to only show the core debugging info
debug : "filter columnSelector"
});
});</pre>
The option only tests if the string contains the widget name, so <code>"corefilter"</code> would show debugging for both the core and filter widget.
</div>
</td>
<td><a href="example-option-debug.html">Example</a></td>
</tr>
Expand Down
Loading

0 comments on commit 7b15ec9

Please sign in to comment.