Merge pull request #251 from snide/check-running

Add check for an already running nav
This commit is contained in:
Eric Holscher 2015-09-23 13:50:55 -07:00
commit 8c880a64fa
2 changed files with 44 additions and 38 deletions

View File

@ -12,33 +12,36 @@ function ThemeNav () {
winPosition: 0, winPosition: 0,
winHeight: null, winHeight: null,
docHeight: null, docHeight: null,
isRunning: null isRunning: false
}; };
nav.enable = function () { nav.enable = function () {
var self = this; var self = this;
jQuery(function ($) { if (!self.isRunning) {
self.init($); self.isRunning = true;
jQuery(function ($) {
self.init($);
self.reset(); self.reset();
self.win.on('hashchange', self.reset); self.win.on('hashchange', self.reset);
// Set scroll monitor // Set scroll monitor
self.win.on('scroll', function () { self.win.on('scroll', function () {
if (!self.linkScroll) { if (!self.linkScroll) {
self.winScroll = true; 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 ($) { nav.init = function ($) {

View File

@ -13,33 +13,36 @@ function ThemeNav () {
winPosition: 0, winPosition: 0,
winHeight: null, winHeight: null,
docHeight: null, docHeight: null,
isRunning: null isRunning: false
}; };
nav.enable = function () { nav.enable = function () {
var self = this; var self = this;
jQuery(function ($) { if (!self.isRunning) {
self.init($); self.isRunning = true;
jQuery(function ($) {
self.init($);
self.reset(); self.reset();
self.win.on('hashchange', self.reset); self.win.on('hashchange', self.reset);
// Set scroll monitor // Set scroll monitor
self.win.on('scroll', function () { self.win.on('scroll', function () {
if (!self.linkScroll) { if (!self.linkScroll) {
self.winScroll = true; 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 ($) { nav.init = function ($) {