JAVASCRIPT   43

debug js

Guest on 28th July 2022 06:47:08 PM

  1. otp.debug = {};
  2.  
  3. (function (self) {
  4.     var enabled = false,
  5.         debugWindow, debugEl;
  6.  
  7.     self.debugEl = debugEl;
  8.     self.enable = function () {
  9.         console.info('Debug mode enabled (persistent).');
  10.         console.info('    To disable put debug=false in the url parameters');
  11.         window.localStorage['otpDebug'] = 'true'; // Save in localstorage to make it persistant!
  12.         otp.config.debug = enabled = true;
  13.  
  14.         if (enabled) {
  15.             debugWindow = window.open('','OpenTripPlanner Debug','toolbar=yes, scrollbars=yes, height=500, width=800');
  16.             debugWindow.document.write('<div class="debug-content"></div>');
  17.             debugEl = $(debugWindow.document).find('.debug-content');
  18.             debugEl.html('<div class="request-json"><h2>Request JSON</h2><pre></pre></div>');
  19.             self.debugEl = debugEl;
  20.         }
  21.     };
  22.     self.disable = function () {
  23.         delete window.localStorage['otpDebug']; // Reset the debug value
  24.     };
  25.  
  26.     self.processRequest = function (data) {
  27.         console.warn('processRequest', enabled, data);
  28.         if (enabled) {
  29.             debugEl.find('.request-json pre').html(JSON.stringify(data, null, 4));
  30.         }
  31.     };
  32. })(otp.debug);

Raw Paste


Login or Register to edit or fork this paste. It's free.