diff --git a/src/javascripts/jquery.tocify.js b/src/javascripts/jquery.tocify.js index f464d95..45d199e 100644 --- a/src/javascripts/jquery.tocify.js +++ b/src/javascripts/jquery.tocify.js @@ -143,6 +143,9 @@ self.extendPageScroll = true; + // Getting rid of possibly existing helper divs + $("[data-unique]").remove(); + // Internal array that keeps track of all TOC items (Helps to recognize if there are duplicate TOC item strings) self.items = []; @@ -515,9 +518,12 @@ $self, // Instantiates a new variable that will be used to determine the smoothScroll animation time duration - duration; + duration, + + li = this.element.find("li"); // Event delegation that looks for any clicks on list item elements inside of the HTML element calling the plugin + this.element.off("click.tocify", "li"); this.element.on("click.tocify", "li", function(event) { if(self.options.history) { @@ -546,7 +552,9 @@ }); // Mouseenter and Mouseleave event handlers for the list item's within the HTML element calling the plugin - this.element.find("li").on({ + li.off("mouseenter.tocify"); + li.off("mouseleave.tocify"); + li.on({ // Mouseenter event handler "mouseenter.tocify": function() { @@ -576,6 +584,7 @@ if (self.options.extendPage || self.options.highlightOnScroll || self.options.scrollHistory || self.options.showAndHideOnScroll) { // Window scroll event handler + $(window).off("scroll.tocify"); $(window).on("scroll.tocify", function() { // Once all animations on the page are complete, this callback function will be called