From 67ccc1c38f675fd8ea67a6686b2e33da70f74ca8 Mon Sep 17 00:00:00 2001 From: Anselm Christophersen Date: Sun, 8 Feb 2015 17:33:26 +0100 Subject: [PATCH] IE8 Compatibility --- javascript/betternavigator.js | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/javascript/betternavigator.js b/javascript/betternavigator.js index 60d6d5e..b714cbe 100755 --- a/javascript/betternavigator.js +++ b/javascript/betternavigator.js @@ -14,23 +14,31 @@ function getCookie(cname) { return ""; } -//Do some stuff when the dom is loaded. (Won't work in IE8 or lower) -document.addEventListener("DOMContentLoaded", function() { - +function initialiseBetterNavigator() { //Dom elements var BetterNavigator = document.getElementById("BetterNavigator"); var BetterNavigatorStatus = document.getElementById("BetterNavigatorStatus"); //Toggle visibility of menu by clicking status - BetterNavigatorStatus.onclick=function(){ + BetterNavigatorStatus.onclick = function () { BetterNavigator.className = BetterNavigator.className === 'collapsed' ? 'open' : 'collapsed'; //Set cookie to remember state - document.cookie="BetterNavigator=" + BetterNavigator.className + ";path=/"; + document.cookie = "BetterNavigator=" + BetterNavigator.className + ";path=/"; }; - + //Restore menu state if (getCookie('BetterNavigator') === 'open') { BetterNavigator.className = 'open'; } - -}); \ No newline at end of file +} + +if (document.addEventListener) { + document.addEventListener("DOMContentLoaded", function () { + //wait til DOM is ready + initialiseBetterNavigator(); + }); +} else { + //This is the case for IE8 and below + //initialise straight away - fine if script is loaded after BN dom element + initialiseBetterNavigator(); +} \ No newline at end of file