Mercurial > piecrust2
diff piecrust/resources/server/piecrust-debug-info.js @ 556:93b656f0af54
serve: Improve debug information in the preview server.
Now the debug window only loads debug info on demand.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Wed, 12 Aug 2015 23:18:35 -0700 |
parents | 9612cfc6455a |
children | 8d5b8a3dca02 |
line wrap: on
line diff
--- a/piecrust/resources/server/piecrust-debug-info.js Wed Aug 12 23:04:46 2015 -0700 +++ b/piecrust/resources/server/piecrust-debug-info.js Wed Aug 12 23:18:35 2015 -0700 @@ -263,6 +263,46 @@ /////////////////////////////////////////////////////////////////////////////// +function toggleDebugInfo() { + var info = document.querySelector('.piecrust-debug-info'); + if (info.classList.contains('piecrust-debug-info-unloaded')) { + loadDebugInfo(); + info.classList.remove('piecrust-debug-info-unloaded'); + } + if (this.innerHTML == '[+]') { + this.innerHTML = '[-]'; + info.style = ""; + } else { + this.innerHTML = '[+]'; + info.style = "display: none;"; + } +} + +function loadDebugInfo() { + var xmlHttp = new XMLHttpRequest(); + + xmlHttp.onreadystatechange = function() { + if (xmlHttp.readyState == XMLHttpRequest.DONE) { + var info = document.querySelector('.piecrust-debug-info'); + if(xmlHttp.status == 200) { + info.innerHTML = xmlHttp.responseText; + } + else if(xmlHttp.status == 400) { + info.innerHTML = "Error fetching debug info."; + } + else { + info.innerHTML = "Unknown error."; + } + } + } + + var pageUrl = window.location.pathname; + xmlHttp.open("GET", "/__piecrust_debug/debug_info?page=" + pageUrl, true); + xmlHttp.send(); +} + +/////////////////////////////////////////////////////////////////////////////// + var notification = new NotificationArea(); var assetReloader = new AssetReloader(); @@ -274,6 +314,9 @@ style.type = 'text/css'; style.href = '/__piecrust_static/piecrust-debug-info.css' + cacheBust; document.head.appendChild(style); + + var expander = document.querySelector('.piecrust-debug-expander'); + expander.onclick = toggleDebugInfo; };