fix issue #4930, by only calling offset() after checking vals.length
Merge pull request #5044 from joeydi/master

Only call offset() after checking vals.length