[ticket/11956] Move JS to reusable function

Move JS to reusable function that can be ran
for all content added with JavaScript such as
results of AJAX forms

PHPBB3-11956