Use .isClosed instead of hasClass('closed')

This ties 'closedness' to the presence of the class 'closed' in only one place so it is easier to change later.