Update gallery.js

Fix to stop js errors when logging in to admin.
Add length check as per https://github.com/rchavik/gallery/pull/2#issuecomment-26611049
Merge branch 'pr/2' into 2.1