Removed JS error on pages without sort button (es5 and non-standard)

and cleaned code