js: add collapsed and expanded hooks