Skip to content

Commit 700c094

Browse files
committed
Cleanup
1 parent 6b0352d commit 700c094

7 files changed

Lines changed: 31 additions & 34 deletions

File tree

Gruntfile.coffee

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module.exports = (grunt) ->
1212
tasks: ['coffee', 'uglify', 'compass']
1313

1414
uglify:
15-
vex:
15+
sortable:
1616
src: 'js/sortable.js'
1717
dest: 'js/sortable.min.js'
1818
options:
@@ -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']

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: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,9 @@ 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

41-
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:
40+
Now any table with the attribute `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:
4241

4342
```html
4443
<table class="sortable-theme-bootstrap" data-sortable>
@@ -52,8 +51,8 @@ This example uses the "bootstrap" theme. For a full list of supported themes, ch
5251

5352
To learn more about how to use sortable, visit our API pages.
5453

55-
- [Basic](http://github.hubspot.com/vex/api/basic)
56-
- [Themes](http://github.hubspot.com/vex/api/themes)
54+
- [Basic](http://github.hubspot.com/sortable/api/basic)
55+
- [Themes](http://github.hubspot.com/sortable/api/themes)
5756

5857
#### Credits
5958

@@ -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>

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)