From 8ca01eaefaeca34a8d9353061aeda08ee1bc0174 Mon Sep 17 00:00:00 2001
From: Martijn Vermaat <martijn@vermaat.name>
Date: Mon, 2 Nov 2015 20:55:09 +0100
Subject: [PATCH] Live attachment of javascript event handlers

This enables attachement of these handlers to elements that are
added to the DOM later as opposed to being in the original source
HTML.
---
 mutalyzer/website/templates/homepage.html          |  7 ++++---
 mutalyzer/website/templates/static/js/interface.js | 10 ++++++----
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/mutalyzer/website/templates/homepage.html b/mutalyzer/website/templates/homepage.html
index 264ca598..f1d2bedf 100644
--- a/mutalyzer/website/templates/homepage.html
+++ b/mutalyzer/website/templates/homepage.html
@@ -126,11 +126,12 @@ This project is sponsored by <a href = "http://www.sun.com">SUN Microsystems</a>
 </p>
 
 <script>
-    $(".clickbox").click(function(){
+    $(document).on('click', ".clickbox", function(e){
          window.location=$(this).find("a").attr("href");
-         return false;
+         e.preventDefault();
+         e.stopPropagation();
     });
-    $(".clickbox input").click(function(e){
+    $(document).on('click', ".clickbox input", function(e){
          e.stopPropagation();
     });
 </script>
diff --git a/mutalyzer/website/templates/static/js/interface.js b/mutalyzer/website/templates/static/js/interface.js
index 88897ee4..5d45e92d 100644
--- a/mutalyzer/website/templates/static/js/interface.js
+++ b/mutalyzer/website/templates/static/js/interface.js
@@ -29,14 +29,15 @@ function clearField(form, fieldName) {
 }
 
 $(document).ready(function() {
-  $('.example-input').on('click', function() {
+  $(document).on('click', '.example-input', function(event) {
     var target = document.getElementById($(this).data('for'));
 
     $(target).val($(this).text());
-    return false;
+    event.preventDefault();
+    event.stopPropagation();
   });
 
-  $('.input-select').on('change', function() {
+  $(document).on('change', '.input-select', function(event) {
     var context = document.getElementById(
           $(this).data('context')).getElementsByClassName('subform'),
         target = document.getElementById($(this).data('for')),
@@ -47,6 +48,7 @@ $(document).ready(function() {
     }
     target.style.display = '';
 
-    return false;
+    event.preventDefault();
+    event.stopPropagation();
   });
 });
-- 
GitLab