sort = function(a, b) { var instance = this, nodeA, nodeB, typeA, typeB, textA, textB, retVal;
nodeA = instance.get_node(a); nodeB = instance.get_node(b); typeA = nodeA.original.type; typeB = nodeB.original.type; textA = nodeA.original.text.toLowerCase(); textB = nodeB.original.text.toLowerCase(); retVal = 0; // for a sort function: // if you return 1, a comes first // if you return -1, b comes first switch (typeA) { case 'folder': if (typeB === 'file') { retVal = -1; } else { retVal = textA > textB ? 1 : -1 } break; case 'file': if (typeB === 'file') { retVal = textA > textB ? 1 : -1 } else { retVal = 1; } break; } return retVal; };
textA = nodeA.original.text.toLowerCase(); textB = nodeB.original.text.toLowerCase(); textA = nodeA.text.toLowerCase(); textB = nodeB.text.toLowerCase();