From d912d1406cf06729edfd6af9da6cdaa5eed49e17 Mon Sep 17 00:00:00 2001 From: Martin Ratinaud Date: Thu, 10 Sep 2015 15:51:29 +0200 Subject: [PATCH] Add guard on classList function if element does not exist anymore --- nprogress.js | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/nprogress.js b/nprogress.js index b23b300..ef69871 100644 --- a/nprogress.js +++ b/nprogress.js @@ -83,16 +83,16 @@ if (n === 1) { // Fade out - css(progress, { - transition: 'none', - opacity: 1 + css(progress, { + transition: 'none', + opacity: 1 }); progress.offsetWidth; /* Repaint */ setTimeout(function() { - css(progress, { - transition: 'all ' + speed + 'ms linear', - opacity: 0 + css(progress, { + transition: 'all ' + speed + 'ms linear', + opacity: 0 }); setTimeout(function() { NProgress.remove(); @@ -220,7 +220,7 @@ if (NProgress.isRendered()) return document.getElementById('nprogress'); addClass(document.documentElement, 'nprogress-busy'); - + var progress = document.createElement('div'); progress.id = 'nprogress'; progress.innerHTML = Settings.template; @@ -229,7 +229,7 @@ perc = fromStart ? '-100' : toBarPerc(NProgress.status || 0), parent = document.querySelector(Settings.parent), spinner; - + css(bar, { transition: 'all 0 linear', transform: 'translate3d(' + perc + '%,0,0)' @@ -340,7 +340,7 @@ var queue = (function() { var pending = []; - + function next() { var fn = pending.shift(); if (fn) { @@ -355,10 +355,10 @@ })(); /** - * (Internal) Applies css properties to an element, similar to the jQuery + * (Internal) Applies css properties to an element, similar to the jQuery * css method. * - * While this helper does assist with vendor prefixed property names, it + * While this helper does assist with vendor prefixed property names, it * does not perform any manipulation of values prior to setting styles. */ @@ -399,7 +399,7 @@ return function(element, properties) { var args = arguments, - prop, + prop, value; if (args.length == 2) { @@ -430,7 +430,7 @@ var oldList = classList(element), newList = oldList + name; - if (hasClass(oldList, name)) return; + if (hasClass(oldList, name)) return; // Trim the opening space. element.className = newList.substring(1); @@ -454,13 +454,13 @@ } /** - * (Internal) Gets a space separated list of the class names on the element. - * The list is wrapped with a single space on each end to facilitate finding + * (Internal) Gets a space separated list of the class names on the element. + * The list is wrapped with a single space on each end to facilitate finding * matches within the list. */ function classList(element) { - return (' ' + (element.className || '') + ' ').replace(/\s+/gi, ' '); + return (' ' + (element && element.className || '') + ' ').replace(/\s+/gi, ' '); } /** @@ -473,4 +473,3 @@ return NProgress; }); -