Improved JS logic for conditional logic and tabs to prevent unwanted tab selection when a new DOM element is added (repeater / flexible content)

Signed-off-by: Elliot Condon <e@elliotcondon.com>