Preserve existing classes on the active li element

Instead of deleting or replacing all classes of the active element with "active", add and remove the "active" class. This way it is possible to style  some of the li elements with additional classes. In my case, this was useful when adding a separator which did not appear for all elements.