moving undelegateEvents function into $el conditional