You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

tablesort

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tablesort - npm Package Compare versions

Comparing version

to
5.0.0

_config.yml

2

bower.json
{
"name": "tablesort",
"description": "A sorting component for HTML tables",
"version": "4.0.1",
"version": "5.0.0",
"license": "MIT",

@@ -6,0 +6,0 @@ "main": "tablesort.min.js",

@@ -13,3 +13,3 @@ module.exports = function(grunt) {

' * Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %>\n' +
' Licensed <%= pkg.license %>\n' +
'*/'

@@ -16,0 +16,0 @@ },

{
"name": "tablesort",
"description": "A sorting component for HTML tables",
"version": "4.1.0",
"version": "5.0.0",
"author": "tristen",
"ender": "./ender.js",
"license": "MIT",
"main": "./src/tablesort.js",
"homepage": "http://tristen.ca/tablesort/demo/",
"scripts": {
"build": "grunt",
"test": "tape test/test.client.js | tap-spec"

@@ -16,11 +17,7 @@ },

},
"licenses": [
{
"type": "MIT"
}
],
"devDependencies": {
"finalhandler": "0.2.x",
"grunt": "~0.4.5",
"grunt-contrib-uglify": "~0.5.0",
"grunt": "^1.0.1",
"grunt-cli": "^1.2.0",
"grunt-contrib-uglify": "^2.0.0",
"phantomjs": "~1.9.x",

@@ -27,0 +24,0 @@ "serve-static": "1.6.x",

tablesort
---
A small & simple sorting component for tables written in Javascript.
A small & simple sorting component for tables written in JavaScript.

@@ -21,7 +21,8 @@ [![npm version](http://img.shields.io/npm/v/tablesort.svg)](https://npmjs.org/package/tablesort) [![Build Status](https://travis-ci.org/tristen/tablesort.png?Zeqckz55oF1LjKHEqHT7)](https://travis-ci.org/tristen/tablesort)

```
**[See usage and demos for more](http://tristen.ca/tablesort/demo/)**
---
### Browser Support
Tablesort expects `classList` to be supported. For this to work on older versions of IE, use [a shim](https://github.com/Modernizr/Modernizr/wiki/HTML5-Cross-Browser-Polyfills#classlist).
| <img src="http://i.imgur.com/dJC1GUv.png" width="48px" height="48px" alt="Chrome logo"> | <img src="http://i.imgur.com/o1m5RcQ.png" width="48px" height="48px" alt="Firefox logo"> | <img src="http://i.imgur.com/8h3iz5H.png" width="48px" height="48px" alt="Internet Explorer logo"> | <img src="http://i.imgur.com/iQV4nmJ.png" width="48px" height="48px" alt="Opera logo"> | <img src="http://i.imgur.com/j3tgNKJ.png" width="48px" height="48px" alt="Safari logo"> |

@@ -31,113 +32,2 @@ |:---:|:---:|:---:|:---:|:---:|

### Sort Types
See all available sort types in the [sorts](https://github.com/tristen/tablesort/tree/gh-pages/src/sorts/)
directory. Defaults to string if no sort types are provided.
### Additional options
#### Ascending/Descending
You can pass in options as a second parameter. Currently one option is
supported: `descending: true`. By default, sort is set to ascending.
``` js
new Tablesort(document.getElementById('table-id'), {
descending: true
});
```
To override the sort order of a particular column, a `data-sort-order`
attribute can be added to its `th` element. Accepted values are `asc` for
ascending and `desc` for descending.
``` html
<th data-sort-order='desc'>Name</th>
```
#### Exclude columns or rows
For columns or rows that do not require sorting, you can add a class of
`no-sort` to a columns `th` or a `tr` element.
``` html
<th class='no-sort'>Name</th>
<tr class='no-sort'>
<td>1</td>
<td>Gonzo the Great</td>
<td>12-2-70</td>
<td>Radishes</td>
<td>$0.63</td>
</tr>
```
#### Override data that is sorted on
Sometimes text inside cells is not normalized. Using a `data-sort` attribute
you can use optional data to sort on.
``` html
<tr>
<td>1</td>
<td data-sort='1357656438'>01/08/13 @ 8:47:18am EST</td>
</tr>
<tr>
<td>2</td>
<td data-sort='1078673085'>3/7/2004 @ 9:24:45 EST</td>
</tr>
```
#### Specify the sort method for a column
By adding a `data-sort-method` attribute to a table heading you can force
Tablesort to use a specific sorting method rather than guessing it. The value
of `data-sort-method` corresponds to the name of a sort function.
``` html
<th>Number</th>
<th data-sort-method='dotsep'>Version</th>
<tr>
<td>1</td>
<td>1.08.2013</td>
</tr>
<tr>
<td>2</td>
<td>3.7.2004</td>
</tr>
```
#### Default sort on tablesort initialization
It is possible to automatically sort the table once you create a Tablesort
instance by adding `sort-default` class.
``` html
<th class='sort-default'>Name</th>
```
#### Events
Tablesort supports two custom events: `beforeSort` & `afterSort`.
``` js
var table = document.getElementById('table-id');
var sort = new Tablesort(table);
table.addEventListener('beforeSort', function() {
alert('Table is about to be sorted!');
});
table.addEventListener('afterSort', function() {
alert('Table sorted!');
});
```
#### Refresh sort on appended data
Tablesort supports sorting when new data has been added. Simply call the refresh
method.
``` js
var table = document.getElementById('table-id');
var sort = new Tablesort(table);
// Make some Ajax request to fetch new data and on success:
sort.refresh();
```
[See homepage for example](http://tristen.ca/tablesort/demo/#refresh)
### Node/Browserify

@@ -152,48 +42,5 @@

### Ender support
Add `tablesort` as an internal chain method to your [Ender](https://github.com/ender-js/Ender/)
compilation.
``` js
// ender add tablesort
$('.table').tablesort();
```
### Default CSS
Add the styling below to your CSS or roll with your own.
Add the styling from [tablesort.css](tablesort.css) file to your CSS or roll with your own.
``` css
th.sort-header::-moz-selection { background:transparent; }
th.sort-header::selection { background:transparent; }
th.sort-header {
cursor:pointer;
}
th.sort-header::-moz-selection,
th.sort-header::selection {
background:transparent;
}
table th.sort-header:after {
content:'';
float:right;
margin-top:7px;
border-width:0 4px 4px;
border-style:solid;
border-color:#404040 transparent;
visibility:hidden;
}
table th.sort-header:hover:after {
visibility:visible;
}
table th.sort-up:after,
table th.sort-down:after,
table th.sort-down:hover:after {
visibility:visible;
opacity:0.4;
}
table th.sort-up:after {
border-bottom:none;
border-width:4px 4px 0;
}
```

@@ -226,3 +73,3 @@ ### Extending Tablesort

Tablesort relies on [Grunt](http://gruntjs.com) as its build tool. Simply run
`grunt` to package code from any contributions you make to `src/tablesort.js`
`npm run build` to package code from any contributions you make to `src/tablesort.js`
before submitting pull requests.

@@ -229,0 +76,0 @@

@@ -85,3 +85,3 @@ ;(function() {

for (i = 0; i < el.tHead.rows.length; i++) {
if (el.tHead.rows[i].classList.contains("sort-row")) {
if (el.tHead.rows[i].getAttribute('data-sort-method') === 'thead') {
firstRow = el.tHead.rows[i];

@@ -104,4 +104,3 @@ break;

if (that.current && that.current !== this) {
that.current.classList.remove('sort-up');
that.current.classList.remove('sort-down');
that.current.removeAttribute('aria-sort');
}

@@ -116,8 +115,8 @@

cell = firstRow.cells[i];
if (!cell.classList.contains('no-sort')) {
cell.classList.add('sort-header');
cell.setAttribute('role','columnheader');
if (cell.getAttribute('data-sort-method') !== 'none') {
cell.tabindex = 0;
cell.addEventListener('click', onClick, false);
if (cell.classList.contains('sort-default')) {
if (cell.getAttribute('data-sort-default') !== null) {
defaultSort = cell;

@@ -141,26 +140,18 @@ }

i = that.thead ? 0 : 1,
sortDir,
sortMethod = header.getAttribute('data-sort-method'),
sortOrder = header.getAttribute('data-sort-order');
sortOrder = header.getAttribute('aria-sort');
that.table.dispatchEvent(createEvent('beforeSort'));
// If updating an existing sort `sortDir` should remain unchanged.
if (update) {
sortDir = header.classList.contains('sort-up') ? 'sort-up' : 'sort-down';
} else {
if (header.classList.contains('sort-up')) {
sortDir = 'sort-down';
} else if (header.classList.contains('sort-down')) {
sortDir = 'sort-up';
} else if (sortOrder === 'asc') {
sortDir = 'sort-down';
} else if (sortOrder === 'desc') {
sortDir = 'sort-up';
// If updating an existing sort, direction should remain unchanged.
if (!update) {
if (sortOrder === 'ascending') {
sortOrder = 'descending';
} else if (sortOrder === 'descending') {
sortOrder = 'ascending';
} else {
sortDir = that.options.descending ? 'sort-up' : 'sort-down';
sortOrder = that.options.descending ? 'ascending' : 'descending';
}
header.classList.remove(sortDir === 'sort-down' ? 'sort-up' : 'sort-down');
header.classList.add(sortDir);
header.setAttribute('aria-sort', sortOrder);
}

@@ -213,3 +204,3 @@

item = that.table.tBodies[i].rows[j];
if (item.classList.contains('no-sort')) {
if (item.getAttribute('data-sort-method') === 'none') {
// keep no-sorts in separate list to be able to insert

@@ -231,3 +222,3 @@ // them back at their original position later

// the double negatives cancel out
if (sortDir === 'sort-down') {
if (sortOrder === 'descending') {
newRows.sort(stabilize(sortFunction, true));

@@ -234,0 +225,0 @@ newRows.reverse();

/*!
* tablesort v4.0.1 (2016-07-23)
* tablesort v4.1.0 (2016-12-29)
* http://tristen.ca/tablesort/demo/
* Copyright (c) 2016 ; Licensed MIT
*/!function(){function a(b,c){if(!(this instanceof a))return new a(b,c);if(!b||"TABLE"!==b.tagName)throw new Error("Element must be a table");this.init(b,c||{})}var b=[],c=function(a){var b;return window.CustomEvent&&"function"==typeof window.CustomEvent?b=new CustomEvent(a):(b=document.createEvent("CustomEvent"),b.initCustomEvent(a,!1,!1,void 0)),b},d=function(a){return a.getAttribute("data-sort")||a.textContent||a.innerText||""},e=function(a,b){return a=a.toLowerCase(),b=b.toLowerCase(),a===b?0:b>a?1:-1},f=function(a,b){return function(c,d){var e=a(c.td,d.td);return 0===e?b?d.index-c.index:c.index-d.index:e}};a.extend=function(a,c,d){if("function"!=typeof c||"function"!=typeof d)throw new Error("Pattern and sort must be a function");b.push({name:a,pattern:c,sort:d})},a.prototype={init:function(a,b){var c,d,e,f,g=this;if(g.table=a,g.thead=!1,g.options=b,a.rows&&a.rows.length>0)if(a.tHead&&a.tHead.rows.length>0){for(e=0;e<a.tHead.rows.length;e++)if(a.tHead.rows[e].classList.contains("sort-row")){c=a.tHead.rows[e];break}c||(c=a.tHead.rows[a.tHead.rows.length-1]),g.thead=!0}else c=a.rows[0];if(c){var h=function(){g.current&&g.current!==this&&(g.current.classList.remove("sort-up"),g.current.classList.remove("sort-down")),g.current=this,g.sortTable(this)};for(e=0;e<c.cells.length;e++)f=c.cells[e],f.classList.contains("no-sort")||(f.classList.add("sort-header"),f.tabindex=0,f.addEventListener("click",h,!1),f.classList.contains("sort-default")&&(d=f));d&&(g.current=d,g.sortTable(d))}},sortTable:function(a,g){var h,i=this,j=a.cellIndex,k=e,l="",m=[],n=i.thead?0:1,o=a.getAttribute("data-sort-method"),p=a.getAttribute("data-sort-order");if(i.table.dispatchEvent(c("beforeSort")),g?h=a.classList.contains("sort-up")?"sort-up":"sort-down":(h=a.classList.contains("sort-up")?"sort-down":a.classList.contains("sort-down")?"sort-up":"asc"===p?"sort-down":"desc"===p?"sort-up":i.options.descending?"sort-up":"sort-down",a.classList.remove("sort-down"===h?"sort-up":"sort-down"),a.classList.add(h)),!(i.table.rows.length<2)){if(!o){for(;m.length<3&&n<i.table.tBodies[0].rows.length;)l=d(i.table.tBodies[0].rows[n].cells[j]),l=l.trim(),l.length>0&&m.push(l),n++;if(!m)return}for(n=0;n<b.length;n++)if(l=b[n],o){if(l.name===o){k=l.sort;break}}else if(m.every(l.pattern)){k=l.sort;break}for(i.col=j,n=0;n<i.table.tBodies.length;n++){var q,r=[],s={},t=0,u=0;if(!(i.table.tBodies[n].rows.length<2)){for(q=0;q<i.table.tBodies[n].rows.length;q++)l=i.table.tBodies[n].rows[q],l.classList.contains("no-sort")?s[t]=l:r.push({tr:l,td:d(l.cells[i.col]),index:t}),t++;for("sort-down"===h?(r.sort(f(k,!0)),r.reverse()):r.sort(f(k,!1)),q=0;t>q;q++)s[q]?(l=s[q],u++):l=r[q-u].tr,i.table.tBodies[n].appendChild(l)}}i.table.dispatchEvent(c("afterSort"))}},refresh:function(){void 0!==this.current&&this.sortTable(this.current,!0)}},"undefined"!=typeof module&&module.exports?module.exports=a:window.Tablesort=a}();
*/!function(){function a(b,c){if(!(this instanceof a))return new a(b,c);if(!b||"TABLE"!==b.tagName)throw new Error("Element must be a table");this.init(b,c||{})}var b=[],c=function(a){var b;return window.CustomEvent&&"function"==typeof window.CustomEvent?b=new CustomEvent(a):(b=document.createEvent("CustomEvent"),b.initCustomEvent(a,!1,!1,void 0)),b},d=function(a){return a.getAttribute("data-sort")||a.textContent||a.innerText||""},e=function(a,b){return a=a.toLowerCase(),b=b.toLowerCase(),a===b?0:a<b?1:-1},f=function(a,b){return function(c,d){var e=a(c.td,d.td);return 0===e?b?d.index-c.index:c.index-d.index:e}};a.extend=function(a,c,d){if("function"!=typeof c||"function"!=typeof d)throw new Error("Pattern and sort must be a function");b.push({name:a,pattern:c,sort:d})},a.prototype={init:function(a,b){var c,d,e,f,g=this;if(g.table=a,g.thead=!1,g.options=b,a.rows&&a.rows.length>0)if(a.tHead&&a.tHead.rows.length>0){for(e=0;e<a.tHead.rows.length;e++)if("thead"===a.tHead.rows[e].getAttribute("data-sort-method")){c=a.tHead.rows[e];break}c||(c=a.tHead.rows[a.tHead.rows.length-1]),g.thead=!0}else c=a.rows[0];if(c){var h=function(){g.current&&g.current!==this&&g.current.removeAttribute("aria-sort"),g.current=this,g.sortTable(this)};for(e=0;e<c.cells.length;e++)f=c.cells[e],f.setAttribute("role","columnheader"),"none"!==f.getAttribute("data-sort-method")&&(f.tabindex=0,f.addEventListener("click",h,!1),null!==f.getAttribute("data-sort-default")&&(d=f));d&&(g.current=d,g.sortTable(d))}},sortTable:function(a,g){var h=this,i=a.cellIndex,j=e,k="",l=[],m=h.thead?0:1,n=a.getAttribute("data-sort-method"),o=a.getAttribute("aria-sort");if(h.table.dispatchEvent(c("beforeSort")),g||(o="ascending"===o?"descending":"descending"===o?"ascending":h.options.descending?"ascending":"descending",a.setAttribute("aria-sort",o)),!(h.table.rows.length<2)){if(!n){for(;l.length<3&&m<h.table.tBodies[0].rows.length;)k=d(h.table.tBodies[0].rows[m].cells[i]),k=k.trim(),k.length>0&&l.push(k),m++;if(!l)return}for(m=0;m<b.length;m++)if(k=b[m],n){if(k.name===n){j=k.sort;break}}else if(l.every(k.pattern)){j=k.sort;break}for(h.col=i,m=0;m<h.table.tBodies.length;m++){var p,q=[],r={},s=0,t=0;if(!(h.table.tBodies[m].rows.length<2)){for(p=0;p<h.table.tBodies[m].rows.length;p++)k=h.table.tBodies[m].rows[p],"none"===k.getAttribute("data-sort-method")?r[s]=k:q.push({tr:k,td:d(k.cells[h.col]),index:s}),s++;for("descending"===o?(q.sort(f(j,!0)),q.reverse()):q.sort(f(j,!1)),p=0;p<s;p++)r[p]?(k=r[p],t++):k=q[p-t].tr,h.table.tBodies[m].appendChild(k)}}h.table.dispatchEvent(c("afterSort"))}},refresh:function(){void 0!==this.current&&this.sortTable(this.current,!0)}},"undefined"!=typeof module&&module.exports?module.exports=a:window.Tablesort=a}();

@@ -174,3 +174,3 @@ tape('sorts insensitive', function(t) {

tape('sort row is first', function(t) {
t.equal(tableSortRowSet.querySelector(".sort-header").innerHTML, 'Sort Row');
t.equal(tableSortRowSet.querySelector("[role=columnheader]").innerHTML, 'Sort Row');
t.end();

@@ -180,4 +180,4 @@ });

tape('sort row is last', function(t) {
t.equal(tableSortRowAuto.querySelector(".sort-header").innerHTML, 'Sort Row');
t.equal(tableSortRowAuto.querySelector("[role=columnheader]").innerHTML, 'Sort Row');
t.end();
});

@@ -0,1 +1,5 @@

'use strict';
/* global phantom */
var page = require('webpage').create();

@@ -27,2 +31,1 @@ var system = require('system');

}, 60000);
#!/usr/bin/env node
'use strict';
var path = require('path');

@@ -24,3 +26,3 @@ var url = require('url');

port: port,
pathname: '/test/',
pathname: '/test/'
});

@@ -27,0 +29,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display