Move client-side sorting into separate javascript file

so that `application.js` remains readable