From d01cb61473f6fb8a84568b240327018f68d9077d Mon Sep 17 00:00:00 2001 From: Anthony Johnson Date: Wed, 23 Sep 2015 10:55:10 -0700 Subject: [PATCH] Add check for an already running nav Fixes #250 --- js/theme.js | 41 ++++++++++++++++------------- sphinx_rtd_theme/static/js/theme.js | 41 ++++++++++++++++------------- 2 files changed, 44 insertions(+), 38 deletions(-) diff --git a/js/theme.js b/js/theme.js index b1f0c1b9..f7fcbdf4 100644 --- a/js/theme.js +++ b/js/theme.js @@ -12,33 +12,36 @@ function ThemeNav () { winPosition: 0, winHeight: null, docHeight: null, - isRunning: null + isRunning: false }; nav.enable = function () { var self = this; - jQuery(function ($) { - self.init($); + if (!self.isRunning) { + self.isRunning = true; + jQuery(function ($) { + self.init($); - self.reset(); - self.win.on('hashchange', self.reset); + self.reset(); + self.win.on('hashchange', self.reset); - // Set scroll monitor - self.win.on('scroll', function () { - if (!self.linkScroll) { - self.winScroll = true; - } + // Set scroll monitor + self.win.on('scroll', function () { + if (!self.linkScroll) { + self.winScroll = true; + } + }); + setInterval(function () { if (self.winScroll) self.onScroll(); }, 25); + + // Set resize monitor + self.win.on('resize', function () { + self.winResize = true; + }); + setInterval(function () { if (self.winResize) self.onResize(); }, 25); + self.onResize(); }); - setInterval(function () { if (self.winScroll) self.onScroll(); }, 25); - - // Set resize monitor - self.win.on('resize', function () { - self.winResize = true; - }); - setInterval(function () { if (self.winResize) self.onResize(); }, 25); - self.onResize(); - }); + }; }; nav.init = function ($) { diff --git a/sphinx_rtd_theme/static/js/theme.js b/sphinx_rtd_theme/static/js/theme.js index 48a9f06b..432dc0c0 100644 --- a/sphinx_rtd_theme/static/js/theme.js +++ b/sphinx_rtd_theme/static/js/theme.js @@ -13,33 +13,36 @@ function ThemeNav () { winPosition: 0, winHeight: null, docHeight: null, - isRunning: null + isRunning: false }; nav.enable = function () { var self = this; - jQuery(function ($) { - self.init($); + if (!self.isRunning) { + self.isRunning = true; + jQuery(function ($) { + self.init($); - self.reset(); - self.win.on('hashchange', self.reset); + self.reset(); + self.win.on('hashchange', self.reset); - // Set scroll monitor - self.win.on('scroll', function () { - if (!self.linkScroll) { - self.winScroll = true; - } + // Set scroll monitor + self.win.on('scroll', function () { + if (!self.linkScroll) { + self.winScroll = true; + } + }); + setInterval(function () { if (self.winScroll) self.onScroll(); }, 25); + + // Set resize monitor + self.win.on('resize', function () { + self.winResize = true; + }); + setInterval(function () { if (self.winResize) self.onResize(); }, 25); + self.onResize(); }); - setInterval(function () { if (self.winScroll) self.onScroll(); }, 25); - - // Set resize monitor - self.win.on('resize', function () { - self.winResize = true; - }); - setInterval(function () { if (self.winResize) self.onResize(); }, 25); - self.onResize(); - }); + }; }; nav.init = function ($) {