Permalink
Browse files

docs

  • Loading branch information...
1 parent d29850a commit 9ef5a8e4cfbcb810cfccaf3e2505dffc4167c4a9 @tj tj committed Feb 13, 2013
Showing with 50 additions and 1 deletion.
  1. +50 −1 Readme.md
View
@@ -9,7 +9,56 @@
## API
-
+### sort(el, fn)
+
+ Sort element ascending with the given callback function.
+
+### sort.asc(el, fn)
+
+ Alias of `sort(el, fn)`
+
+### sort.desc(el, fn)
+
+ Sort descending, inverting the `fn()` return value.
+
+## Example
+
+```html
+<ul>
+ <li>Tobi</li>
+ <li>Jane</li>
+ <li>Abby</li>
+ <li>Loki</li>
+ <li>Simon</li>
+ <li>Manny</li>
+ <li>Luna</li>
+</ul>
+
+<button onclick='asc()'>Sort ascending</button>
+<button onclick='desc()'>Sort descending</button>
+
+<script src="build/build.js"></script>
+<script>
+ var sort = require('sort');
+ var ul = document.querySelector('ul');
+
+ function alpha(a, b){
+ a = a.textContent;
+ b = b.textContent;
+ if (a < b) return -1;
+ if (a > b) return 1;
+ return 0;
+ }
+
+ function asc() {
+ sort(ul, alpha);
+ }
+
+ function desc() {
+ sort.desc(ul, alpha);
+ }
+</script>
+```
## License

0 comments on commit 9ef5a8e

Please sign in to comment.