Makes pagination by JS take first and last page into account