Mercurial > piecrust2
comparison 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 |
comparison
equal
deleted
inserted
replaced
555:daf8df5ade7d | 556:93b656f0af54 |
---|---|
261 return result; | 261 return result; |
262 }; | 262 }; |
263 | 263 |
264 /////////////////////////////////////////////////////////////////////////////// | 264 /////////////////////////////////////////////////////////////////////////////// |
265 | 265 |
266 function toggleDebugInfo() { | |
267 var info = document.querySelector('.piecrust-debug-info'); | |
268 if (info.classList.contains('piecrust-debug-info-unloaded')) { | |
269 loadDebugInfo(); | |
270 info.classList.remove('piecrust-debug-info-unloaded'); | |
271 } | |
272 if (this.innerHTML == '[+]') { | |
273 this.innerHTML = '[-]'; | |
274 info.style = ""; | |
275 } else { | |
276 this.innerHTML = '[+]'; | |
277 info.style = "display: none;"; | |
278 } | |
279 } | |
280 | |
281 function loadDebugInfo() { | |
282 var xmlHttp = new XMLHttpRequest(); | |
283 | |
284 xmlHttp.onreadystatechange = function() { | |
285 if (xmlHttp.readyState == XMLHttpRequest.DONE) { | |
286 var info = document.querySelector('.piecrust-debug-info'); | |
287 if(xmlHttp.status == 200) { | |
288 info.innerHTML = xmlHttp.responseText; | |
289 } | |
290 else if(xmlHttp.status == 400) { | |
291 info.innerHTML = "Error fetching debug info."; | |
292 } | |
293 else { | |
294 info.innerHTML = "Unknown error."; | |
295 } | |
296 } | |
297 } | |
298 | |
299 var pageUrl = window.location.pathname; | |
300 xmlHttp.open("GET", "/__piecrust_debug/debug_info?page=" + pageUrl, true); | |
301 xmlHttp.send(); | |
302 } | |
303 | |
304 /////////////////////////////////////////////////////////////////////////////// | |
305 | |
266 var notification = new NotificationArea(); | 306 var notification = new NotificationArea(); |
267 var assetReloader = new AssetReloader(); | 307 var assetReloader = new AssetReloader(); |
268 | 308 |
269 window.onload = function() { | 309 window.onload = function() { |
270 var cacheBust = '?' + new Date().getTime(); | 310 var cacheBust = '?' + new Date().getTime(); |
272 var style = document.createElement('link'); | 312 var style = document.createElement('link'); |
273 style.rel = 'stylesheet'; | 313 style.rel = 'stylesheet'; |
274 style.type = 'text/css'; | 314 style.type = 'text/css'; |
275 style.href = '/__piecrust_static/piecrust-debug-info.css' + cacheBust; | 315 style.href = '/__piecrust_static/piecrust-debug-info.css' + cacheBust; |
276 document.head.appendChild(style); | 316 document.head.appendChild(style); |
317 | |
318 var expander = document.querySelector('.piecrust-debug-expander'); | |
319 expander.onclick = toggleDebugInfo; | |
277 }; | 320 }; |
278 | 321 |
279 | 322 |
280 window.onbeforeunload = function(e) { | 323 window.onbeforeunload = function(e) { |
281 if (eventSource != null) | 324 if (eventSource != null) |