Add new issue and PR templates
[dygraphs.git] / gallery / interaction.js
index 05b0c80..a903737 100644 (file)
@@ -1,3 +1,6 @@
+/*global Gallery,Dygraph,data */
+/*global NoisyData,downV3,moveV3,upV3,clickV3,dblClickV3,scrollV3,restorePositioning,downV4,moveV4,upV4,dblClickV4,captureCanvas */
+
 Gallery.register(
   'interaction',
   {
@@ -46,13 +49,12 @@ Gallery.register(
 
     },
     run: function() {
-      // TODO(konigsberg): Add cleanup to remove callbacks.
-      Dygraph.addEvent(document, "mousewheel", function() { lastClickedGraph = null; });
-      Dygraph.addEvent(document, "click", function() { lastClickedGraph = null; });
-      var g = new Dygraph(document.getElementById("div_g"),
+      var lastClickedGraph;
+      document.addEventListener("mousewheel", function() { lastClickedGraph = null; });
+      document.addEventListener("click", function() { lastClickedGraph = null; });
+      new Dygraph(document.getElementById("div_g"),
            NoisyData, { errorBars : true });
-      var s = document.getElementById("g2_console");
-      var g2 = new Dygraph(document.getElementById("div_g2"),
+      new Dygraph(document.getElementById("div_g2"),
            NoisyData,
            {
              errorBars : true,
@@ -70,7 +72,7 @@ Gallery.register(
       document.getElementById("restore3").onclick = function() {
         restorePositioning(g3);
       };
-      var g4 = new Dygraph(document.getElementById("div_g4"),
+      new Dygraph(document.getElementById("div_g4"),
            NoisyData, {
              errorBars : true,
              drawPoints : true,
@@ -82,5 +84,9 @@ Gallery.register(
              },
              underlayCallback : captureCanvas
           });
+    },
+    clean: function() {
+      document.removeEventListener('mousewheel');
+      document.removeEventListener('click');
     }
   });