mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-11-15 23:54:22 +00:00
Core parser updates
Added $node to parser "is" parameter, add image parser to core, moved ipAddress to external file & add MAC address parser to renamed parser-network.js file
This commit is contained in:
parent
db8878ac83
commit
195f4fca77
@ -23,7 +23,7 @@ $(function(){
|
||||
$.tablesorter.addParser({
|
||||
// set a unique id
|
||||
id: 'data',
|
||||
is: function(s) {
|
||||
is: function(s, table, cell, $cell) {
|
||||
// return false so this parser is not auto detected
|
||||
return false;
|
||||
},
|
||||
|
@ -17,18 +17,18 @@
|
||||
<link rel="stylesheet" href="../css/theme.blue.css">
|
||||
<script src="../js/jquery.tablesorter.js"></script>
|
||||
|
||||
<script src="../js/parsers/parser-ipv6.js"></script>
|
||||
<script src="../js/parsers/parser-network.js"></script>
|
||||
|
||||
<script id="js">$(function() {
|
||||
|
||||
$('table').tablesorter({
|
||||
theme: 'blue',
|
||||
widthFixed: true,
|
||||
widgets: ['zebra'],
|
||||
sortList: [[2, 0]],
|
||||
headers: {
|
||||
2: {
|
||||
sorter: 'ipv6Address'
|
||||
}
|
||||
1: { sorter: 'MAC' },
|
||||
3: { sorter: 'ipv6Address' }
|
||||
}
|
||||
});
|
||||
|
||||
@ -48,7 +48,7 @@
|
||||
<em>NOTE!</em>
|
||||
<ul>
|
||||
<li>This parser can be applied to the original plugin.</li>
|
||||
<li>The default "ipAdress" parser (IPv4) is included with the original tablesorter.</li>
|
||||
<li>The default "ipAdress" parser (IPv4) is included with the original tablesorter; it was moved to the <code>parser-network.js</code> file in <span class="version">v2.18.0</span>.</li>
|
||||
<li>A parser for IPv6 was added in <span class="version">v2.12</span> and named "ipv6Address":
|
||||
<ul>
|
||||
<li>Unlike some other custom parsers, this one will auto-detect & check for a valid IPv6 address since the same address can be represented in many different ways. Some examples are shown in the demo table below.</li>
|
||||
@ -60,9 +60,9 @@
|
||||
<pre class="prettyprint lang-javascript">$(function(){
|
||||
$('table').tablesorter({
|
||||
headers: {
|
||||
2: {
|
||||
sorter: 'ipv6Address'
|
||||
}
|
||||
1: { sorter: 'MAC' },
|
||||
// 2: { sorter: 'ipAddress' }, this parser is auto-detected
|
||||
3: { sorter: 'ipv6Address' }
|
||||
}
|
||||
});
|
||||
});</pre>
|
||||
@ -77,21 +77,22 @@
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<td>Name</td>
|
||||
<td>IPv4</td>
|
||||
<td>IPv6</td>
|
||||
<th>Name</th>
|
||||
<th>MAC</th>
|
||||
<th>IPv4</th>
|
||||
<th>IPv6</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr><td>Fred</td><td>1.2.3.4</td><td>f0f0::1</td></tr>
|
||||
<tr><td>Ginger</td><td>1.1.1.1</td><td>f0::1</td></tr>
|
||||
<tr><td>Mike</td><td>2.222.33.44</td><td>1:2:3:4:5::7:8</td></tr>
|
||||
<tr><td>George</td><td>255.255.255.255</td><td>::2:3:4</td></tr>
|
||||
<tr><td>Harry</td><td>251.2.33.4</td><td>f0f0:f::1</td></tr>
|
||||
<tr><td>Frank</td><td>251.002.31.4</td><td>::</td></tr>
|
||||
<tr><td>Kristy</td><td>2.221.003.4</td><td>0:0:0:0:0:0:0:0</td></tr>
|
||||
<tr><td>Lily</td><td>251.02.32.4</td><td>f0f0::f:1</td></tr>
|
||||
<tr><td>Maria</td><td>1.2.3.44</td><td>1:2:3:4:5:6:1.2.3.4</td></tr>
|
||||
<tr><td>Fred</td><td>12:06:D2:8E:56:BF</td><td>1.2.3.4</td><td>f0f0::1</td></tr>
|
||||
<tr><td>Ginger</td><td>546F.5903.3C9B</td><td>1.1.1.1</td><td>f0::1</td></tr>
|
||||
<tr><td>Mike</td><td>3c-cf-44-cd-6e-d6</td><td>2.222.33.44</td><td>1:2:3:4:5::7:8</td></tr>
|
||||
<tr><td>George</td><td>ff-68-3d-e8-b4-0d</td><td>255.255.255.255</td><td>::2:3:4</td></tr>
|
||||
<tr><td>Harry</td><td>f566.6dfd.2df2</td><td>251.2.33.4</td><td>f0f0:f::1</td></tr>
|
||||
<tr><td>Frank</td><td>12:69:13:D8:FA:61</td><td>251.002.31.4</td><td>::</td></tr>
|
||||
<tr><td>Kristy</td><td>A031.5FED.43BC</td><td>2.221.003.4</td><td>0:0:0:0:0:0:0:0</td></tr>
|
||||
<tr><td>Lily</td><td>82-2D-FF-FA-CD-6C</td><td>251.02.32.4</td><td>f0f0::f:1</td></tr>
|
||||
<tr><td>Maria</td><td>125c395f08f2</td><td>1.2.3.44</td><td>1:2:3:4:5:6:1.2.3.4</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@ -104,7 +105,7 @@
|
||||
<script src="../js/jquery.tablesorter.js"></script>
|
||||
|
||||
<!-- load ipv6 parser -->
|
||||
<script src="../js/parsers/parser-ipv6.js"></script>
|
||||
<script src="../js/parsers/parser-network.js"></script>
|
||||
<script>
|
||||
$(function() {
|
||||
|
||||
@ -113,9 +114,9 @@ $(function() {
|
||||
widgets: ['zebra'],
|
||||
sortList: [[1, 0]],
|
||||
headers: {
|
||||
1: {
|
||||
sorter: 'ipv6Address'
|
||||
}
|
||||
1: { sorter: 'MAC' },
|
||||
// 2: { sorter: 'ipAddress' }, this parser is auto-detected
|
||||
3: { sorter: 'ipv6Address' }
|
||||
}
|
||||
});
|
||||
|
||||
@ -128,7 +129,7 @@ $(function() {
|
||||
<script>
|
||||
$(function(){
|
||||
// add parsed values to columns [0,1]
|
||||
addParsedValues($('table'), [1,2]);
|
||||
addParsedValues($('table'), [1,2,3]);
|
||||
});
|
||||
</script>
|
||||
|
||||
|
@ -22,7 +22,7 @@
|
||||
$.tablesorter.addParser({
|
||||
// set a unique id
|
||||
id: 'grades',
|
||||
is: function(s, table, cell) {
|
||||
is: function(s, table, cell, $cell) {
|
||||
// return false so this parser is not auto detected
|
||||
return false;
|
||||
},
|
||||
@ -65,7 +65,7 @@ $(function() {
|
||||
<li>The <code>is</code> block will allow the parser to be used for autodetecting the parser
|
||||
<ul>
|
||||
<li>Most custom parsers are made for a specific set of data/column, so the <code>is</code> block usually just returns false telling the plugin that the parser doesn't match any columns.</li>
|
||||
<li>If so desired, the function provides three parameters: <code>s</code> contains the text from the cell, <code>table</code> is the table DOM element and <code>cell</code> is the current cell DOM element.</li>
|
||||
<li>If so desired, the function provides four parameters: <code>s</code> contains the text from the cell, <code>table</code> is the table DOM element, <code>cell</code> is the current cell DOM element and <code>$cell</code> is the current cell as a jQuery object (added <span class="version">v2.18.0</span>).</li>
|
||||
<li>This function must <code>return true</code> before the plugin will use the custom parser's format block to process the column content.</li>
|
||||
<li>In version 2.7.4, the <code>is</code> block became optional because most parsers just return false.</li>
|
||||
</ul>
|
||||
@ -99,10 +99,11 @@ $(function() {
|
||||
<pre class="prettyprint lang-javascript">$.tablesorter.addParser({
|
||||
// use a unique id
|
||||
id: 'myparser',
|
||||
is: function(s, table, cell) {
|
||||
is: function(s, table, cell, $cell) {
|
||||
// s is the text from the cell
|
||||
// table is the current table (as a DOM element; not jQuery object)
|
||||
// cell is the current table cell (DOM element)
|
||||
// $cell is the current table cell (jQuery object; added v2.18.0)
|
||||
// return false if you don't want this parser to be auto detected
|
||||
return false;
|
||||
},
|
||||
|
@ -390,7 +390,7 @@
|
||||
|
||||
<h4>Parsers / Extracting Content</h4>
|
||||
<ul>
|
||||
<li><a href="example-parsers.html">Parser, writing your own</a> (<a href="#function-addparser"><code>addParser</code></a>; <span class="updated version">v2.15.0</span>)</li>
|
||||
<li><a href="example-parsers.html">Parser, writing your own</a> (<a href="#function-addparser"><code>addParser</code></a>; <span class="updated version">v2.15.0</span>; <span class="version updated">v2.18.0</span>)</li>
|
||||
<li><a href="example-parsers-advanced.html">Parser, writing your own, advanced use</a> (v2.1; <span class="updated version">v2.15.0</span>)</li>
|
||||
<li><a href="example-option-text-extraction.html">Dealing with markup inside cells</a> (<a href="#textextraction"><code>textExtraction</code></a> function)</li>
|
||||
<li><a href="example-options-headers-parser.html">Skip the parsing of column content</a> (<span class="version">v2.17.1</span>)</li>
|
||||
@ -528,9 +528,9 @@
|
||||
<li><a href="example-parsers-file-type.html">File type parser</a> (<span class="version">v2.13</span>).</li>
|
||||
<li><a href="example-parsers-ignore-articles.html">Ignore leading articles parser</a> (Ignore "A", "An" and "The" in titles) (<span class="version">v2.8</span>).</li>
|
||||
<li><a href="example-widget-grouping.html">Input/select parsers</a> (used by Grouping rows widget) (<span class="version">v2.8</span>; <span class="version updated">v2.17.5</span>).</li>
|
||||
<li><a href="example-parsers-ip-address.html">IPv6 address parser</a> (<span class="version">v2.12</span>).</li>
|
||||
<li><a href="example-parsers-feet-inch-fraction.html">Feet-inch-fraction parser</a> (<span class="version">v2.8</span>).</li>
|
||||
<li><a href="example-parsers-metric.html">Metric parser</a> (<span class="version">v2.8</span>).</li>
|
||||
<li><a href="example-parsers-ip-address.html">Network (IPv4, IPv6 and MAC address parser</a> (<span class="version">v2.12</span>; <span class="version updated">v2.18.0</span>).</li>
|
||||
<li><a href="example-parsers-roman.html">Roman Numeral parser</a> (<span class="version">v2.17.3</span>).</li>
|
||||
<li><a href="example-option-textsorter-semver.html">Semantic Versioning (Semver) sorting</a> (<span class="version">v2.14.3</span>).</li>
|
||||
</ul>
|
||||
@ -934,6 +934,7 @@
|
||||
'.first-name' : { sorter: 'text' },
|
||||
'.disabled' : { sorter: false }
|
||||
}</pre>
|
||||
<span class="label label-warning">Warning</span> What <em>won't work</em> is if you try to target the header using a filtering selector that uses an index, e.g. <code>"th:eq()"</code>, <code>":gt()"</code>, <code>":lt()"</code>, <code>":first"</code>, <code>":last"</code>, <code>":even"</code> or <code>":odd"</code>, <code>":first-child"</code>, <code>":last-child"</code>, <code>":nth-child()"</code>, <code>":nth-last-child()"</code>, etc.
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
@ -973,6 +974,28 @@
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
<tr id="imgattr">
|
||||
<td><a href="#" class="permalink">imgAttr</a></td>
|
||||
<td>String</td>
|
||||
<td>"alt"</td>
|
||||
<td>
|
||||
Used by the image parser to grab the image attribute content (<span class="version">v2.17.5</span>; moved to tablesorter core in <span class="version updated">v2.18.0</span>; see <a href="#parsers"><code>config.parsers</code></a>).
|
||||
<div class="collapsible"><br>
|
||||
Change this setting to grab a different image attribute to be used for sorting:
|
||||
<pre class="prettyprint lang-js">$(function(){
|
||||
$('table').tablesorter({
|
||||
// parse image title (value to be used while sorting & filtering)
|
||||
imgAttr : 'title',
|
||||
headers : {
|
||||
0 : { sorter: 'image' } // this parser is auto-detected, but will only work on the first image
|
||||
}
|
||||
});
|
||||
});</pre>
|
||||
</div>
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
<tr id="initialized">
|
||||
<td><a href="#" class="permalink">initialized</a></td>
|
||||
<td>Function</td>
|
||||
@ -1404,6 +1427,8 @@ From the example function above, you'll end up with something similar to this HT
|
||||
return $(node).find('strong').text();
|
||||
}
|
||||
}</pre>
|
||||
<span class="label label-warning">Warning</span> What <em>won't work</em> is if you try to target the header using a filtering selector that uses an index, e.g. <code>"th:eq()"</code>, <code>":gt()"</code>, <code>":lt()"</code>, <code>":first"</code>, <code>":last"</code>, <code>":even"</code> or <code>":odd"</code>, <code>":first-child"</code>, <code>":last-child"</code>, <code>":nth-child()"</code>, <code>":nth-last-child()"</code>, etc.<br>
|
||||
<br>
|
||||
As of version 2.16.0,
|
||||
<ul>
|
||||
<li>The default text extraction method has been renamed and updated to get data from a data-attribute (set by the <a href="#textattribute"><code>textAttribute</code></a> option).</li>
|
||||
@ -1482,7 +1507,7 @@ $(function(){
|
||||
return a - b;
|
||||
}
|
||||
});
|
||||
});</pre>The direction parameter (boolean) is merely for informational purposes as the plugin automatically switches `a` and `b` depending on the sort direction ( i.e. there's no need to worry about reverse sorting, it's taken care of by the plugin ).
|
||||
});</pre>The direction parameter (boolean) is merely for informational purposes as the plugin automatically switches <code>a</code> and <code>b</code> depending on the sort direction ( i.e. there's no need to worry about reverse sorting, it's taken care of by the plugin ).
|
||||
</div>
|
||||
</td>
|
||||
<td></td>
|
||||
@ -1530,7 +1555,7 @@ $(function(){
|
||||
3 : Array.AlphanumericSort // alphanumeric sort from sugar (http://sugarjs.com/arrays#sorting)
|
||||
}
|
||||
});
|
||||
});</pre>The direction parameter (boolean) is merely for informational purposes as the plugin automatically switches `a` and `b` depending on the sort direction ( i.e. there's no need to worry about reverse sorting, it's taken care of by the plugin ).
|
||||
});</pre>The direction parameter (boolean) is merely for informational purposes as the plugin automatically switches <code>a</code> and <code>b</code> depending on the sort direction ( i.e. there's no need to worry about reverse sorting, it's taken care of by the plugin ).
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
@ -1760,28 +1785,6 @@ $(function(){
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
<tr id="imgattr">
|
||||
<td><a href="#" class="permalink">imgAttr</a></td>
|
||||
<td>String</td>
|
||||
<td>"alt"</td>
|
||||
<td>
|
||||
Used by the image parser to grab the image attribute content (<span class="version">v2.17.5</span>).
|
||||
<div class="collapsible"><br>
|
||||
Change this setting to grab a different image attribute to be used for sorting:
|
||||
<pre class="prettyprint lang-js">$(function(){
|
||||
$('table').tablesorter({
|
||||
// parse image title (value to be used while sorting & filtering)
|
||||
imgAttr : 'title',
|
||||
headers : {
|
||||
0 : { sorter: 'image' }
|
||||
}
|
||||
});
|
||||
});</pre>
|
||||
</div>
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
</tbody>
|
||||
|
||||
<!-- non-sorting tbody -->
|
||||
@ -2197,6 +2200,8 @@ $(function(){
|
||||
});
|
||||
}
|
||||
}</pre>
|
||||
<span class="label label-warning">Warning</span> What <em>won't work</em> is if you try to target the header using a filtering selector that uses an index, e.g. <code>"th:eq()"</code>, <code>":gt()"</code>, <code>":lt()"</code>, <code>":first"</code>, <code>":last"</code>, <code>":even"</code> or <code>":odd"</code>, <code>":first-child"</code>, <code>":last-child"</code>, <code>":nth-child()"</code>, <code>":nth-last-child()"</code>, etc.<br>
|
||||
<br>
|
||||
A new file has been included named "jquery.tablesorter.widgets-filter-formatter.js". It includes code to add jQuery UI and HTML5 controls via the <a href="#widget-filter-formatter"><code>filter_formatter</code></a> option.<br>
|
||||
<br>
|
||||
Most of the formatter functions have an option named <code>valueToHeader</code> which, when <code>true</code> adds a span to the header cell above the filter row and updates it with the current control's value (see <a href="example-widget-filter-formatter-2.html">example 2</a>). If the option exists and is set to <code>false</code>, then the current value is added to the control's handle and css can be used to create a popup to show the current value (see <a href="example-widget-filter-formatter-1.html">example 1</a>).<br>
|
||||
@ -2259,6 +2264,8 @@ $(function(){
|
||||
...
|
||||
}
|
||||
}</pre>
|
||||
<span class="label label-warning">Warning</span> What <em>won't work</em> is if you try to target the header using a filtering selector that uses an index, e.g. <code>"th:eq()"</code>, <code>":gt()"</code>, <code>":lt()"</code>, <code>":first"</code>, <code>":last"</code>, <code>":even"</code> or <code>":odd"</code>, <code>":first-child"</code>, <code>":last-child"</code>, <code>":nth-child()"</code>, <code>":nth-last-child()"</code>, etc.<br>
|
||||
<br>
|
||||
Use the <a href="#widget-filter-functions"><code>"filter_functions"</code></a> option in three different ways:
|
||||
<br>
|
||||
<ul>
|
||||
@ -2617,6 +2624,8 @@ $('table').trigger('search', false);</pre></div>
|
||||
<pre class="prettyprint lang-js">filter_selectSource : {
|
||||
".model-number" : [ "abc", "def", "ghi", "xyz" ]
|
||||
}</pre>
|
||||
<span class="label label-warning">Warning</span> What <em>won't work</em> is if you try to target the header using a filtering selector that uses an index, e.g. <code>"th:eq()"</code>, <code>":gt()"</code>, <code>":lt()"</code>, <code>":first"</code>, <code>":last"</code>, <code>":even"</code> or <code>":odd"</code>, <code>":first-child"</code>, <code>":last-child"</code>, <code>":nth-child()"</code>, <code>":nth-last-child()"</code>, etc.<br>
|
||||
<br>
|
||||
A column will have a filter select dropdown when a "filter-select" class name is added to the header cell, or if the <a href="#widget-filter-functions"><code>filter_functions</code></a> column value is set to <code>true</code><br>
|
||||
<br>
|
||||
This option allows using an alternate source, or customizing options of the filter select dropdown. This option can be set as follows:
|
||||
@ -3364,7 +3373,7 @@ $.extend($.tablesorter.themes.jui, {
|
||||
<br>
|
||||
<span class="label label-info">Note</span> The pager widget equivalent option is within the <code>widgetOptions</code> and accessed via <code>widgetOptions.pager_ajaxObject</code><br>
|
||||
<br>
|
||||
The <code>ajaxObject</code> is completely customizable, except for the `url` setting which is processed using the pager's `ajaxUrl` and `customAjaxUrl` options.<br>
|
||||
The <code>ajaxObject</code> is completely customizable, except for the <code>url</code> setting which is processed using the pager's <code>ajaxUrl</code> and <code>customAjaxUrl</code> options.<br>
|
||||
<br>
|
||||
Your server does not need to return a JSON format, if you want to return pure HTML, set the dataType to <code>"html"</code> and modify the <code>ajaxProcessing</code> function to instead work with HTML; then return a jQuery object or apply the HTML to the table yourself.<br>
|
||||
<br>
|
||||
@ -5073,7 +5082,8 @@ $('.tablesorter')[0].config.cache[0].normalized[0];
|
||||
<tr><th><code>sorter: "text"</code></th><td>Sort alpha-numerically.</td></tr>
|
||||
<tr><th><code>sorter: "digit"</code></th><td>Sort numerically.</td></tr>
|
||||
<tr><th><code>sorter: "currency"</code></th><td>Sort by currency value (supports "£$€¤¥¢").</td></tr>
|
||||
<tr><th><code>sorter: "ipAddress"</code></th><td>Sort by IP Address.</td></tr>
|
||||
<tr><th><code>sorter: "image"</code></th><td>Sort by image alt value (see <a href="#imgattr"><code>imgAttr</code></a> option).</td></tr>
|
||||
<tr><th><code>sorter: "ipAddress"</code></th><td>Sort by IP Address; <span class="label label-warning">Warning</span> This parser was moved to the <code>parser-network.js</code> file in <span class="version updated">v2.18.0</span>.</td></tr>
|
||||
<tr><th><code>sorter: "url"</code></th><td>Sort by url.</td></tr>
|
||||
<tr><th><code>sorter: "isoDate"</code></th><td>Sort by ISO date (YYYY-MM-DD or YYYY/MM/DD; these formats can be followed by a time).</td></tr>
|
||||
<tr><th><code>sorter: "percent"</code></th><td>Sort by percent.</td></tr>
|
||||
@ -5767,7 +5777,7 @@ $.tablesorter.isDigit( "(2,345.67)" );</pre>
|
||||
<li><code>table</code> - table DOM element (or jQuery object) of table (or tables).</li>
|
||||
<li><code>message</code> - a plain string, or string of an HTML row.</li>
|
||||
</ul>
|
||||
This function will add a table row to the thead, with a class name from either the pager plugin <code>cssErrorRow</code> option setting, or the pager widget <code>pager_css.errorRow</code> option (the default class name is `"tablesorter-errorRow"`; and styled within each theme css file).<br>
|
||||
This function will add a table row to the thead, with a class name from either the pager plugin <code>cssErrorRow</code> option setting, or the pager widget <code>pager_css.errorRow</code> option (the default class name is <code>"tablesorter-errorRow"</code>; and styled within each theme css file).<br>
|
||||
<br>
|
||||
When passing this function a message, there are three possibilities:
|
||||
<ol>
|
||||
|
@ -187,7 +187,7 @@
|
||||
}
|
||||
|
||||
function detectParserForColumn(table, rows, rowIndex, cellIndex) {
|
||||
var cur,
|
||||
var cur, $node,
|
||||
i = ts.parsers.length,
|
||||
node = false,
|
||||
nodeValue = '',
|
||||
@ -197,6 +197,7 @@
|
||||
if (rows[rowIndex]) {
|
||||
node = rows[rowIndex].cells[cellIndex];
|
||||
nodeValue = getElementText(table, node, cellIndex);
|
||||
$node = $(node);
|
||||
if (table.config.debug) {
|
||||
log('Checking if value was empty on row ' + rowIndex + ', column: ' + cellIndex + ': "' + nodeValue + '"');
|
||||
}
|
||||
@ -207,7 +208,7 @@
|
||||
while (--i >= 0) {
|
||||
cur = ts.parsers[i];
|
||||
// ignore the default text parser because it will always be true
|
||||
if (cur && cur.id !== 'text' && cur.is && cur.is(nodeValue, table, node)) {
|
||||
if (cur && cur.id !== 'text' && cur.is && cur.is(nodeValue, table, node, $node)) {
|
||||
return cur;
|
||||
}
|
||||
}
|
||||
@ -1743,23 +1744,6 @@
|
||||
type: "numeric"
|
||||
});
|
||||
|
||||
ts.addParser({
|
||||
id: "ipAddress",
|
||||
is: function(s) {
|
||||
return (/^\d{1,3}[\.]\d{1,3}[\.]\d{1,3}[\.]\d{1,3}$/).test(s);
|
||||
},
|
||||
format: function(s, table) {
|
||||
var i, a = s ? s.split(".") : '',
|
||||
r = "",
|
||||
l = a.length;
|
||||
for (i = 0; i < l; i++) {
|
||||
r += ("00" + a[i]).slice(-3);
|
||||
}
|
||||
return s ? ts.formatFloat(r, table) : s;
|
||||
},
|
||||
type: "numeric"
|
||||
});
|
||||
|
||||
ts.addParser({
|
||||
id: "url",
|
||||
is: function(s) {
|
||||
@ -1794,6 +1778,19 @@
|
||||
type: "numeric"
|
||||
});
|
||||
|
||||
// added image parser to core v2.17.9
|
||||
ts.addParser({
|
||||
id: "image",
|
||||
is: function(s, table, node, $node){
|
||||
return $node.find('img').length > 0;
|
||||
},
|
||||
format: function(s, table, cell) {
|
||||
return $(cell).find('img').attr(table.config.imgAttr || 'alt') || s;
|
||||
},
|
||||
parsed : true, // filter widget flag
|
||||
type: "text"
|
||||
});
|
||||
|
||||
ts.addParser({
|
||||
id: "usLongDate",
|
||||
is: function(s) {
|
||||
@ -1891,9 +1888,9 @@
|
||||
b = c.$tbodies,
|
||||
rmv = (wo.zebra || [ "even", "odd" ]).join(' ');
|
||||
for (k = 0; k < b.length; k++ ){
|
||||
$tb = $.tablesorter.processTbody(table, b.eq(k), true); // remove tbody
|
||||
$tb = ts.processTbody(table, b.eq(k), true); // remove tbody
|
||||
$tb.children().removeClass(rmv);
|
||||
$.tablesorter.processTbody(table, $tb, false); // restore tbody
|
||||
ts.processTbody(table, $tb, false); // restore tbody
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -1,15 +1,16 @@
|
||||
/*! IPv6 Address parser (WIP)
|
||||
* IPv6 Address (ffff:0000:0000:0000:0000:0000:0000:0000)
|
||||
* needs to support short versions like "::8" or "1:2::7:8"
|
||||
* and "::00:192.168.10.184" (embedded IPv4 address)
|
||||
* see http://www.intermapper.com/support/tools/IPV6-Validator.aspx
|
||||
*/
|
||||
/*! Network parsers - IPv4, IPv6 and MAC Addresses */
|
||||
/*global jQuery: false */
|
||||
;(function($){
|
||||
"use strict";
|
||||
|
||||
var ts = $.tablesorter;
|
||||
|
||||
/*! IPv6 Address parser (WIP)
|
||||
* IPv6 Address (ffff:0000:0000:0000:0000:0000:0000:0000)
|
||||
* needs to support short versions like "::8" or "1:2::7:8"
|
||||
* and "::00:192.168.10.184" (embedded IPv4 address)
|
||||
* see http://www.intermapper.com/support/tools/IPV6-Validator.aspx
|
||||
*/
|
||||
$.extend( ts.regex, {}, {
|
||||
ipv4Validate : /((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})/,
|
||||
ipv4Extract : /([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/,
|
||||
@ -20,14 +21,14 @@
|
||||
});
|
||||
|
||||
ts.addParser({
|
||||
id: "ipv6Address",
|
||||
id: 'ipv6Address',
|
||||
is: function(s) {
|
||||
return ts.regex.ipv6Validate.test(s);
|
||||
},
|
||||
format: function(address, table) {
|
||||
// code modified from http://forrst.com/posts/JS_Expand_Abbreviated_IPv6_Addresses-1OR
|
||||
var i, t, sides, groups, groupsPresent,
|
||||
hex = table ? (typeof table === "boolean" ? table : table && table.config.ipv6HexFormat || false) : false,
|
||||
hex = table ? (typeof table === 'boolean' ? table : table && table.config.ipv6HexFormat || false) : false,
|
||||
fullAddress = '',
|
||||
expandedAddress = '',
|
||||
validGroupCount = 8,
|
||||
@ -44,23 +45,23 @@
|
||||
address = address.replace( ts.regex.ipv4Extract, t );
|
||||
}
|
||||
|
||||
if (address.indexOf("::") == -1) {
|
||||
if (address.indexOf('::') == -1) {
|
||||
// All eight groups are present
|
||||
fullAddress = address;
|
||||
} else {
|
||||
// Consecutive groups of zeroes have been collapsed with "::".
|
||||
sides = address.split("::");
|
||||
// Consecutive groups of zeroes have been collapsed with '::'.
|
||||
sides = address.split('::');
|
||||
groupsPresent = 0;
|
||||
for (i = 0; i < sides.length; i++) {
|
||||
groupsPresent += sides[i].split(":").length;
|
||||
groupsPresent += sides[i].split(':').length;
|
||||
}
|
||||
fullAddress += sides[0] + ":";
|
||||
fullAddress += sides[0] + ':';
|
||||
for (i = 0; i < validGroupCount - groupsPresent; i++) {
|
||||
fullAddress += "0000:";
|
||||
fullAddress += '0000:';
|
||||
}
|
||||
fullAddress += sides[1];
|
||||
}
|
||||
groups = fullAddress.split(":");
|
||||
groups = fullAddress.split(':');
|
||||
for (i = 0; i < validGroupCount; i++) {
|
||||
// it's fastest & easiest for tablesorter to sort decimal values (vs hex)
|
||||
groups[i] = hex ? ('0000' + groups[i]).slice(-4) :
|
||||
@ -70,7 +71,43 @@
|
||||
return hex ? expandedAddress : expandedAddress.replace(/:/g, '');
|
||||
},
|
||||
// uses natural sort hex compare
|
||||
type: "numeric"
|
||||
type: 'numeric'
|
||||
});
|
||||
|
||||
// ipv4 address
|
||||
// moved here from jquery.tablesorter.js (core file)
|
||||
ts.addParser({
|
||||
id: 'ipAddress',
|
||||
is: function(s) {
|
||||
return (/^\d{1,3}[\.]\d{1,3}[\.]\d{1,3}[\.]\d{1,3}$/).test(s);
|
||||
},
|
||||
format: function(s, table) {
|
||||
var i, a = s ? s.split('.') : '',
|
||||
r = '',
|
||||
l = a.length;
|
||||
for (i = 0; i < l; i++) {
|
||||
r += ('000' + a[i]).slice(-3);
|
||||
}
|
||||
return s ? ts.formatFloat(r, table) : s;
|
||||
},
|
||||
type: 'numeric'
|
||||
});
|
||||
|
||||
ts.addParser({
|
||||
id: 'MAC',
|
||||
is: function(s) {
|
||||
return ts.regex.ipv6Validate.test(s);
|
||||
},
|
||||
format: function(s) {
|
||||
var t = '',
|
||||
val = s.replace(/[:.-]/g, '').match(/\w{2}/g);
|
||||
$.each(val, function(i, v){
|
||||
t += ( '000' + parseInt(v, 16) ).slice(-3);
|
||||
});
|
||||
return t;
|
||||
},
|
||||
// uses natural sort hex compare
|
||||
type: 'numeric'
|
||||
});
|
||||
|
||||
})(jQuery);
|
Loading…
Reference in New Issue
Block a user