From 8066367ecdf9ddd4f00cbf6c0bfdf9eebd844f0c Mon Sep 17 00:00:00 2001 From: Joris Guyonvarch Date: Sat, 7 Mar 2015 20:28:24 +0100 Subject: Replacing var by const in javascript --- router.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/router.js b/router.js index 8af98ab..c6c2c03 100644 --- a/router.js +++ b/router.js @@ -4,15 +4,15 @@ this.addEventListener('load', router); function router() { - var url = location.hash.slice(2) || 'presentation'; - var contentElement = document.getElementById('content'); - var htmlElement = document.querySelector('html'); + const url = location.hash.slice(2) || 'presentation'; + const contentElement = document.getElementById('content'); + const htmlElement = document.querySelector('html'); addClass(htmlElement, 'waitCursor'); fetchFile('Pages/' + url + '.md', function(contentMd) { removeClass(htmlElement, 'waitCursor'); contentElement.innerHTML = markdown.toHTML(contentMd); }, function() { - var notFoundPage = '

Page non trouvée

Retour à l\'accueil'; + const notFoundPage = '

Page non trouvée

Retour à l\'accueil'; contentElement.innerHTML = notFoundPage; }); } @@ -26,18 +26,16 @@ } function fetchFile(url, successHandler, errorHandler) { - var xhr = typeof XMLHttpRequest != 'undefined' + const xhr = typeof XMLHttpRequest != 'undefined' ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP'); xhr.open('get', url, true); xhr.responseType = 'text'; xhr.onreadystatechange = function() { - var status; - var data; if (xhr.readyState == 4) { - status = xhr.status; + const status = xhr.status; if (status === 200 || status === 0) { - data = xhr.responseText; + const data = xhr.responseText; successHandler && successHandler(data); } else { errorHandler && errorHandler(status); -- cgit v1.2.3