This is a very simple jQuery-based template designed to do one very simple task: remove excess vertical space from table cells due to <p> tags.
Here we show a before-and-after of what the template code does. Because using the template itself would preclude the "before", the code has instead been embedded onto this page and bound to a button.
The first table has no superfluous paragraphs in it. When entered, the carriage return key was not touched. This is the way you want your tables to look:
| this | table |
| has | no |
| paragraphs | Nice! |
For this second table, a carriage return was hit in some of the cells. Backspace was used in an attempt to remove the inserted paragraphs, but the damage is done: the editor has wrapped those cells in paragraphs and won't undo it without some extra and conscious effort in source mode. Most wiki users don't know how to do this, and even if they did they would not take the time. This results in a lot of ugly tables. Fortunately, our bit of jQuery code can do a nice little cosmetic clean-up:
| this | one |
| has | some |
| paragraphs | Yuck! |
There are two useful ways to apply this code to your wiki.
The template is an easy way to apply this code selectively. If you want to clean up all tables on a page, just insert this call on your page:
{{ CleanTables() }}
If you know the ID of your table (let's say it's "messytable"), then supply an ID selector like this:
{{ CleanTables("table#messytable") }}
Finally, if you have a class of tables you'd like to clean up ("messyclass") then supply a class selector:
{{ CleanTables("table.messyclass") }}
This is a very small chunk of jQuery code, and is easy to embed into your own code. Feel free. I plan to transplant it into TSTable().
If you want to apply this processing to every table on every page, then just stick this code in a custom HTML area in the control panel:
<script type="text/javascript">
DekiWiki.$(document).ready(function($) {
var $tables = Deki.$('div#pageContent table');
$tables.find('td > p:first-child').css({'margin-top':'0px','padding-top':'0px'});
$tables.find('td > p:last-child').css({'margin-bottom':'0px','padding-bottom':'0px'});
});
</script>
The primary disadvantage here is that it may waste some processing time on some pages with large tables. It's a bit of a brute-force approach, but might still be reasonable for some users.
// CleanTables() by neilw, 2009
//
// Usage:
// CleanTables(table : str?)
// table = a single jQuery selector for tables you want to clean. By default, all tables on the page are selected.
// Note that only tables inside div#content are affected.
// Examples: "table#FixThisTableOnly", "table.FixAllTablesWithThisClass"
//
var tableSelect = $0 ?? $table ?? "table";
<html><tail>
<script type="text/javascript"> "
DekiWiki.$(document).ready(function($) {
var $tables = Deki.$('div#pageContent "..tableSelect.."');
$tables.find('td > p:first-child').css({'margin-top':'0px', 'padding-top':'0px'});
$tables.find('td > p:last-child').css({'margin-bottom':'0px', 'padding-bottom':'0px'});
});
" </script>
</tail></html>
| Images 0 | ||
|---|---|---|
| No images to display in the gallery. |