b2evolution PHP Cross Reference Blogging Systems

Source: /rsc/js/debug_jslog.js - 180 lines - 5469 bytes - Summary - Text - Print

Description: This javascript gets included in debug jslog mode. b2evolution - http://b2evolution.net/

   1  /**

   2   * This javascript gets included in debug jslog mode.

   3   * b2evolution - http://b2evolution.net/

   4   * @version $Id: debug_jslog.js 699 2012-01-18 15:26:36Z yura $

   5   */
   6  
   7  
   8  /**** AJAX Debug functions ****/

   9  var debug_ajax_request_number = 1;
  10  
  11  jQuery( document ).ready( function()
  12  {
  13      jQuery( 'a.jslog_switcher' ).click( function()
  14      {    // Click event of link "JS Log" in the eveobar (Hide & Show log)
  15          jQuery( 'div#debug_ajax_info' ).toggle();
  16          jQuery.cookie( 'jslog_style', jQuery( 'div#debug_ajax_info' ).attr( 'style' ), { path: '/' } );
  17          if( jQuery( 'div#debug_ajax_info' ).is( ':hidden' ) )
  18          {    // Delete cookie with jslog password
  19              jQuery.cookie( 'jslog', null, { path: '/' } );
  20          }
  21          return false;
  22      } );
  23  
  24      jQuery( 'a.jslog_clear' ).click( function()
  25      {    // Clear the log
  26          jQuery( 'div#jslog_container' ).html( '' );
  27          return false;
  28      } );
  29  
  30      var jslog_style_top;
  31      jQuery( 'div#debug_ajax_info' ).resizable(
  32      {    // Plugin to resize
  33          resize: function( event, ui )
  34          {
  35              var new_height = jQuery( this ).height() - 40;
  36              jQuery( 'div#debug_ajax_info #jslog_container' ).css( { 'height': new_height, 'max-height': new_height } );
  37          },
  38          stop: function( event, ui )
  39          {    // Write the jslog block styles into the cookies
  40              jQuery( this ).css( { 'position': 'fixed', top: jQuery( this ).offset().top - jQuery( window ).scrollTop() } );
  41              jQuery.cookie( 'jslog_style', jQuery( this ).attr( 'style' ), { path: '/' } );
  42          }
  43      } );
  44      jQuery( 'div#debug_ajax_info' ).draggable(
  45      {    // Plugin to drag
  46          snap: '#evo_toolbar',
  47          handle: 'div.jslog_titlebar',
  48          stop: function( event, ui )
  49          {    // Write the jslog block styles into the cookies
  50              jQuery.cookie( 'jslog_style', jQuery( this ).attr( 'style' ), { path: '/' } );
  51          }
  52      } );
  53  
  54      var debug_ajax_date_start = new Date();
  55      jQuery( 'div#debug_ajax_info' ).ajaxStart( function()
  56      {    // Save a start time of execution
  57          debug_ajax_date_start = new Date();
  58      } );
  59  
  60      jQuery( 'div#debug_ajax_info' ).ajaxSuccess( function( event, request, settings )
  61      { // AJAX request is success, Add debug info into the list
  62          var debug_ajax_date_end = new Date();
  63  
  64          var log = '<h4>Request #' + debug_ajax_request_number + ':</h4>';
  65          log += '<b>request time</b>: ' + get_formated_date( debug_ajax_date_start ) + '<br />';
  66          log += '<b>response time</b>: ' + get_formated_date( debug_ajax_date_end ) + '<br />';
  67          log += '<b>roundtrip time</b>: ' + get_interval_time( debug_ajax_date_start, debug_ajax_date_end ) + '<br />';
  68          log += '<b>url</b>: ' + settings.url + '<br />';
  69          log += '<b>' + settings.type + ' data</b>: ' + settings.data + '<br />';
  70          if( settings.dataType != undefined )
  71          {
  72              log += '<b>response data type</b>: ' + settings.dataType + '<br />';
  73          }
  74          log += ajax_debug_extract_log( request.responseText, this );
  75  
  76          ajax_debug_info_add( log );
  77      } );
  78  
  79      jQuery( 'div#debug_ajax_info' ).ajaxError( function( event, request, settings, thrownError )
  80      { // AJAX request is failed, Add debug info into the list
  81          jQuery( this ).show();
  82  
  83          var log = '<h4 class="error">Request ERROR #' + debug_ajax_request_number + ':</h4>';
  84          log += '<b>url</b>: ' + settings.url + '<br />';
  85          log += '<b>' + settings.type + ' data</b>: ' + settings.data + '<br />';
  86          log += '<b>error</b>: <b class="red">' + thrownError + '</b><br />';
  87          log += ajax_debug_extract_log( request.responseText, this );
  88  
  89          ajax_debug_info_add( log );
  90      } );
  91  } );
  92  
  93  /**

  94   * Add info data to the ajax debug info

  95   *

  96   * @param string Info

  97   */
  98  function ajax_debug_info_add( log )
  99  {
 100      var debug_info_div = jQuery( 'div#debug_ajax_info' );
 101  
 102      // Insert a new log info

 103      jQuery( '#jslog_container' ).append( log );
 104      // Scroll a list to bottom

 105      debug_info_div.scrollTop( debug_info_div[0].scrollHeight );
 106  
 107      debug_ajax_request_number++;
 108  }
 109  
 110  
 111  /**

 112   * Extract JS log from response text

 113   *

 114   * @param string Response text

 115   * @param object Object of div with JS log

 116   * @return string JS log text

 117   */
 118  function ajax_debug_extract_log( text, div_obj )
 119  {
 120      var log = '';
 121      var data = jQuery( '<div/>' );
 122      data.html( text.replace( /(<script[^>]+><\/script>|<link[^>]+\/>)/gim, '' ) );
 123      var jslog = data.find( 'div.jslog' );
 124  
 125      if( jslog.length > 0 )
 126      { // AJAX Debug exist in the response text
 127          log += '<p>Remote debug info:</p>';
 128          log += jslog.html();
 129  
 130          if( jslog.find( 'ul.jslog_error' ).length > 0 )
 131          { // AJAX Response has the errors
 132              jQuery( div_obj ).show();
 133          }
 134      }
 135  
 136      return log;
 137  }
 138  
 139  
 140  /**

 141   * Get date in format Y-m-d H:i:s.ms

 142   *

 143   * @param object Date

 144   * @return string Date

 145   */
 146  function get_formated_date( Date )
 147  {
 148      return Date.getFullYear() + '-' + ( Date.getMonth() + 1 )+ '-' + Date.getDate() + ' ' + 
 149              Date.getHours() + ':' + Date.getMinutes() + ':' + Date.getSeconds() + '.' + Date.getMilliseconds();
 150  }
 151  
 152  
 153  /**

 154   * Get time beetween two dates in format #minutes #seconds #miliseconds

 155   *

 156   * @param object Date start

 157   * @param object Date end

 158   * @return string Time

 159   */
 160  function get_interval_time( Date_start, Date_end )
 161  {
 162      var time = Date_end.getTime() - Date_start.getTime();
 163  
 164      var ms = time % 1000;
 165      var seconds = ( time % 60000 - ms ) / 1000;
 166      var minutes = ( time - seconds * 1000 - ms ) / 60000;
 167  
 168      var result = ms + ' ms';
 169      if( seconds > 0 )
 170      {    // Display seconds
 171          result = seconds + 'sec ' + result;
 172      }
 173  
 174      if( minutes > 0 )
 175      {    // Display minutes
 176          result = minutes + 'min ' + result;
 177      }
 178  
 179      return result;
 180  }

title

Description

title

Description

title

Description

title

title

Body