Skip to content

Commit

Permalink
[ux][fix] Chose a different ToC order. Also, wrote cleaner, working s…
Browse files Browse the repository at this point in the history
…ort code.
  • Loading branch information
jfhbrook committed Oct 4, 2011
1 parent 0afe02c commit 6c11fd5
Showing 1 changed file with 28 additions and 17 deletions.
45 changes: 28 additions & 17 deletions lib/helpers.js
Expand Up @@ -87,41 +87,52 @@ helpers.filesToTree = function(files){
// Function to use with sorting the ToC.
//
helpers.tocSort = function (a, b) {
// For future reference, here is the list from the top-level.
/*[
'cryptography',
'advanced',
'intermediate',
'errors',
'file-system',
'javascript-conventions',
'child-processes',
'command-line',
'REPL',
'getting-started',
'HTTP' ]
*/

// These items should be listed *first*.
var first = [
'getting-started',
'intermediate',
'advanced',
'javascript-conventions'
];

// These items should be listed *last*.
var last = [
'intermediate',
'advanced',
'cryptography'
];

//a > b: --> 1

// Handles the case where a and/or b is in the "first" list.
if ( -~first.indexOf(a) || -~first.indexOf(b) ) {
return -~first.indexOf(a) ? (
-~first.indexOf(b)
? first.indexOf(a) - first.indexOf(b)
: -1
) : 1
};

// Handles the case where a and/or b is in the "last" list.

return ( -~first.indexOf(a) && -~first.indexOf(b) )
? (first.indexOf(a) - first.indexOf(b))
: ( -~first.indexOf(a) ? -1 : 1);

}

if ( -~last.indexOf(a) || -~last.indexOf(b) ) {
return -~last.indexOf(a) ? (
-~last.indexOf(b)
? last.indexOf(a) - last.indexOf(b)
: 1
) : -1
return (-~last.indexOf(a) && -~last.indexOf(b))
? (last.indexOf(a) - last.indexOf(b))
: ( -~last.indexOf(a) ? 1 : -1);
}

// Handles "default" case.
return a > b ? 1 : (a < b ? -1 : 0);

};

helpers.treeToHTML = function(values, parent) {
Expand Down

0 comments on commit 6c11fd5

Please sign in to comment.