Skip to content

Commit 9f80881

Browse files
committed
Merge pull request #3 from HubSpot/cleanup
Cleanup
2 parents 94d1b58 + ed8b714 commit 9f80881

9 files changed

Lines changed: 30 additions & 33 deletions

File tree

Gruntfile.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ module.exports = (grunt) ->
2929
grunt.loadNpmTasks 'grunt-contrib-coffee'
3030
grunt.loadNpmTasks 'grunt-contrib-compass'
3131

32-
grunt.registerTask 'default', ['coffee', 'uglify', 'compass']
32+
grunt.registerTask 'default', ['coffee', 'uglify', 'compass']

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ Sortable is an open-source javascript and CSS library which adds sorting functio
66

77
#### Credits
88

9-
Loosely based on [Stuart Langridge](https://github.com/stuartlangridge)'s [SortTable](http://www.kryogenix.org/code/browser/sorttable/) ([History](https://github.com/HubSpot/sortable/commits/e068642453bb39eed676ed338e9bbeb372ca74c4/sorttable.js), [Original](https://github.com/HubSpot/sortable/blob/37894eb51bda9f0e438d735967f16eef0d403ef9/sorttable.js))
9+
Loosely based on [Stuart Langridge](https://github.com/stuartlangridge)'s [SortTable](http://www.kryogenix.org/code/browser/sorttable/) ([History](https://github.com/HubSpot/sortable/commits/e068642453bb39eed676ed338e9bbeb372ca74c4/sorttable.js), [Original](https://github.com/HubSpot/sortable/blob/37894eb51bda9f0e438d735967f16eef0d403ef9/sorttable.js))

coffee/sortable.coffee

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
ascending = 'ascending'
2-
descending = 'descending'
1+
SELECTOR = 'table[data-sortable]'
32

43
numberRegExp = /^-?[£$¤]?[\d,.]+%?$/
54
trimRegExp = /^\s+|\s+$/g
65

7-
touchDevice = `'ontouchstart' in document.documentElement`
6+
touchDevice = 'ontouchstart' of document.documentElement
87
clickEvent = if touchDevice then 'touchstart' else 'click'
98

109
sortable =
11-
1210
init: ->
13-
tables = document.querySelectorAll 'table[data-sortable]'
11+
tables = document.querySelectorAll SELECTOR
1412
sortable.initTable table for table in tables
1513

1614
initTable: (table) ->
@@ -35,7 +33,7 @@ sortable =
3533
sortedDirection = @getAttribute 'data-sorted-direction'
3634

3735
if sorted
38-
newSortedDirection = if sortedDirection is ascending then descending else ascending
36+
newSortedDirection = if sortedDirection is 'ascending' then 'descending' else 'ascending'
3937
else
4038
newSortedDirection = type.defaultSortDirection
4139

@@ -74,9 +72,8 @@ sortable =
7472
node.textContent.replace trimRegExp, ''
7573

7674
types:
77-
7875
numeric:
79-
defaultSortDirection: descending
76+
defaultSortDirection: 'descending'
8077
compare: (a, b) ->
8178
aa = parseFloat(a[0].replace(/[^0-9.-]/g, ''))
8279
bb = parseFloat(b[0].replace(/[^0-9.-]/g, ''))
@@ -85,12 +82,14 @@ sortable =
8582
bb - aa
8683

8784
alpha:
88-
defaultSortDirection: ascending
85+
defaultSortDirection: 'ascending'
8986
compare: (a, b) ->
9087
aa = a[0].toLowerCase()
9188
bb = b[0].toLowerCase()
9289
return 0 if aa is bb
9390
return -1 if aa < bb
9491
1
9592

96-
window.sortable = sortable
93+
setTimeout sortable.init, 0
94+
95+
window.Sortable = sortable

docs/api/1-Options.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,21 @@ Example:
1414

1515
##### `init`
1616

17-
To initialize all tables on the page, call `init`.
17+
All tables on the page will be automatically initted when the page is loaded.
18+
19+
If you add tables with javascript, call `init` after they are added to the page:
1820

1921
```coffeescript
20-
sortable.init()
22+
Sortable.init()
2123
```
2224

2325
##### `initTable`
2426

2527
To initialize an individual table, call `initTable`.
2628

2729
```coffeescript
28-
exampleTable = document.querySelector('#exampleTable[data-sortable]')
29-
sortable.initTable(exampleTable)
30+
exampleTable = document.querySelector('#exampleTable')
31+
Sortable.initTable(exampleTable)
3032
```
3133

3234
#### Sorting options
@@ -70,4 +72,3 @@ To disable sorting on a particular column, add `data-sortable="false"` to the `<
7072
<p style="-webkit-transform: translateZ(0)"></p>
7173
<script src="/sortable/js/sortable.js"></script>
7274
<link rel="stylesheet" href="/sortable/css/sortable-theme-light.css" />
73-
<script>setTimeout(function(){ sortable.init(); }, 0);</script>

docs/api/2-Themes.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ You can download a release (containing all 6 themes) [here](/sortable). Or you c
3535
<!-- Resources for the demos -->
3636
<p style="-webkit-transform: translateZ(0)"></p>
3737
<script src="/sortable/js/sortable.js"></script>
38-
<script>setTimeout(function(){ sortable.init(); }, 0);</script>
3938
<style>
4039
.hs-doc-content table {
4140
border: 0;
@@ -58,4 +57,4 @@ $('[data-theme]').each(function(){
5857
return false;
5958
});
6059
});
61-
</script>
60+
</script>

docs/intro.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ For the most common usage of sortable, you'll want to include following:
3535
```html
3636
<script src="sortable.min.js"></script>
3737
<link rel="stylesheet" href="sortable-theme-bootstrap.css" />
38-
<script>setTimeout(function(){ sortable.init(); }, 0);</script>
3938
```
4039

4140
Now any table with the attribute `data-sortable` will be made sortable. To get the styling, you'll also need to add a class name to the table to match the theme you chose:
@@ -75,4 +74,3 @@ Sortable was built by [Adam Schwartz](http://twitter.com/adamfschwartz)
7574
}
7675
</style>
7776
<link rel="stylesheet" href="/sortable/css/sortable-theme-bootstrap.css">
78-
<script>setTimeout(function(){ sortable.init(); }, 0);</script>

docs/welcome/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@
216216
<table class="showcase hero"><tr><td>
217217
<div class="showcase-inner">
218218
<h1>Sortable</h1>
219-
<h2>The simplest, most elegant way to sort a table.</h2>
219+
<h2>Drop-in script to make your tables sortable.</h2>
220220
<p>
221221
<a class="button" href="http://github.com/hubspot/sortable">★ On Github</a> &nbsp;&nbsp;
222222
<a class="button dark" href="https://github.com/HubSpot/sortable/releases">Download</a>
@@ -450,4 +450,4 @@ <h2>Help us spread the word.</h2>
450450
ga('send', 'pageview');
451451
</script>
452452
</body>
453-
</html>
453+
</html>

js/sortable.js

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/sortable.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)