<commit_before>/**
 * This class is the client part of phpFreeChat
 * (depends on prototype library)
 * @author <NAME>
 */
var pfcClient = Class.create();

//defining the rest of the class implmentation
pfcClient.prototype = {
  
  initialize: function()
  {
    /* user description */
    this.nickname      = '';
    
    this.timeout       = null;
    this.refresh_delay = <?php echo $refresh_delay; ?>;
    /* unique client id for each windows used to identify a open window
     * this id is passed every time the JS communicate with server
     * (2 clients can use the same session: then only the nickname is shared) */
    this.clientid      = '<?php echo md5(uniqid(rand(), true)); ?>';

    this.el_words     = $('<?php echo $prefix; ?>words');
    this.el_handle    = $('<?php echo $prefix; ?>handle');
    this.el_container = $('<?php echo $prefix; ?>container');
    this.el_online    = $('<?php echo $prefix; ?>online');
    this.el_errors    = $('<?php echo $prefix; ?>errors');

    this.minmax_status = <?php echo $start_minimized ? "true" : "false"; ?>;
    var cookie = getCookie('<?php echo $prefix; ?>minmax_status');
    if (cookie != null)
      this.minmax_status = (cookie == 'true');

    cookie = getCookie('<?php echo $prefix; ?>nickmarker');
    this.nickmarker = (cookie == 'true');
    if (cookie == '' || cookie == null)
      this.nickmarker = <?php echo $nickmarker ? "true" : "false"; ?>;
    
    cookie = getCookie('<?php echo $prefix; ?>clock');
    this.clock = (cookie == 'true');
    if (cookie == '' || cookie == null)
      this.clock = <?php echo $clock ? "true" : "false"; ?>;

    cookie = getCookie('<?php echo $prefix; ?>showsmileys');
    this.showsmileys = (cookie == 'true');
    if (cookie == '' || cookie == null)
      this.showsmileys = <?php echo $showsmileys ? "true" : "false"; ?>;
    
    cookie = getCookie('<?php echo $prefix; ?>showwhosonline');
    this.showwhosonline = (cookie == 'true');
    if (cookie == '' || cookie == null)
      this.showwhosonline = <?php echo $showwhosonline ? "true" : "false"; ?>;

    /* '' means no forced color, let CSS choose the text color */
    this.current_text_color = '';
    cookie = getCookie('<?php echo $prefix; ?>current_text_color');
    if (cookie != null)
      this.switch_text_color(cookie);
             
    this.isconnected   = false;
    this.nicklist      = Array();
    this.nickcolor     = Array();
    this.colorlist     = Array();

    this.blinktmp     = Array();
    this.blinkloop    = Array();
    this.blinktimeout = Array();

    /* the events callbacks */
    this.el_words.onkeypress = this.callbackWords_OnKeypress.bindAsEventListener(this);
    this.el_words.onkeydown  = this.callbackWords_OnKeydown.bindAsEventListener(this);
    this.el_words.onfocus    = this.callbackWords_OnFocus.bindAsEventListener(this);
    this.el_handle.onkeydown = this.callbackHandle_OnKeydown.bindAsEventListener(this);
    this.el_handle.onchange  = this.callbackHandle_OnChange.bindAsEventListener(this);
    this.el_container.onmousemove = this.callbackContainer_OnMousemove.bindAsEventListener(this);
    this.el_container.onmousedown = this.callbackContainer_OnMousedown.bindAsEventListener(this);
    this.el_container.onmouseup   = this.callbackContainer_OnMouseup.bindAsEventListener(this);
    document.body.onunload = this.callback_OnUnload.bindAsEventListener(this);

    /* the i18n translations */
    var i18n = {
      hide_nickname_color: '<?php echo _pfc("Hide nickname marker"); ?>',
      show_nickname_color: '<?php echo _pfc("Show nickname marker"); ?>',
      hide_clock:          '<?php echo _pfc("Hide dates and hours"); ?>',
      show_clock:          '<?php echo _pfc("Show dates and hours"); ?>',
      logout:              '<?php echo _pfc("Disconnect"); ?>',
      login:               '<?php echo _pfc("Connect"); ?>',
      maximize:            '<?php echo _pfc("Magnify"); ?>',
      minimize:            '<?php echo _pfc("Cut down"); ?>',
      hidesmiley:          '<?php echo _pfc("Hide smiley box"); ?>',
      showsmiley:          '<?php echo _pfc("Show smiley box"); ?>',
      hideonline:          '<?php echo _pfc("Hide online users box"); ?>',
      showonline:          '<?php echo _pfc("Show online users box"); ?>'
    };
    this.i18n = $H(i18n);

    /* the smileys */
    var smileys = {
      <?php
      $output = "";
      foreach($smileys as $s_file => $s_str) { 
	for($j = 0; $j<count($s_str) ; $j++) {
	  $s = $s_str[$j];
	  $output .= "'".$s."': '".$s_file."',";
	}
      }
      $output = substr($output, 0, strlen($output)-1); // remove last ','
      echo $output;
      ?>
    }
    this.smileys = $H(smileys);
  },

  /**
   * Try to complete a nickname like on IRC when pressing the TAB key
   * @todo: improve the algorithme, it should take into account the cursor position
   */
  completeNick: function()
  {
    var w = this.el_words;
    var nick_src = w.value.substring(w.value.lastIndexOf(' ')+1,w.value.length);
    if (nick_src != '')
    {
      var ul_online = this.el_online.firstChild;
      for (var i=0; i<ul_online.childNodes.length; i++)
      {
	var nick = ul_online.childNodes[i].innerHTML;
	if (nick.indexOf(nick_src) == 0)
	  w.value = w.value.replace(nick_src, nick);
      }
    }
  },

  /**
   * Handle the pressed keys
   * see also callbackWords_OnKeydown
   */
  callbackWords_OnKeypress: function(evt)
  {
    var code = (evt.which) ? evt.which : evt.keyCode
    if (code == 9) /* tab key */
    {
      /* FF & Konqueror workaround : ignore TAB key here */
      /* do the nickname completion work like on IRC */
      this.completeNick();
      return false; /* do not leave the tab key default behavior */
    }
    else if (code == 13) /* enter key */
    {
      var w = this.el_words;
      var wval = w.value;
      re = new RegExp("^(\/[a-z]+)( (.*)|)");
      if (wval.match(re))
      {
	/* a user command */
	cmd   = wval.replace(re, '$1');
	param = wval.replace(re, '$2');
	this.handleRequest(cmd, param.substr(0,<?php echo $max_text_len; ?> + this.clientid.length));
      }
      else
      {
	/* a classic 'send' command*/

	/* truncate the text length */
	wval = wval.substr(0, <?php echo $max_text_len; ?>);

	/* colorize the text with current_text_color */
	if (this.current_text_color != '')
  	  wval = '[color=#' + this.current_text_color + ']' + wval + '[/color]';

	this.handleRequest('/send', wval);
      }
      w.value = '';
      return false;
    }
    else
    {
      /* allow other keys */
      return true;
    }
  },
  /**
   * Handle the pressed keys
   * see also callbackWords_OnKeypress
   */<commit_msg>Bug fix: When a empty text is typed, nothing should be sent. Only a error message must be shown.<commit_after>/**
 * This class is the client part of phpFreeChat
 * (depends on prototype library)
 * @author <NAME>
 */
var pfcClient = Class.create();

//defining the rest of the class implmentation
pfcClient.prototype = {
  
  initialize: function()
  {
    /* user description */
    this.nickname      = '';
    
    this.timeout       = null;
    this.refresh_delay = <?php echo $refresh_delay; ?>;
    /* unique client id for each windows used to identify a open window
     * this id is passed every time the JS communicate with server
     * (2 clients can use the same session: then only the nickname is shared) */
    this.clientid      = '<?php echo md5(uniqid(rand(), true)); ?>';

    this.el_words     = $('<?php echo $prefix; ?>words');
    this.el_handle    = $('<?php echo $prefix; ?>handle');
    this.el_container = $('<?php echo $prefix; ?>container');
    this.el_online    = $('<?php echo $prefix; ?>online');
    this.el_errors    = $('<?php echo $prefix; ?>errors');

    this.minmax_status = <?php echo $start_minimized ? "true" : "false"; ?>;
    var cookie = getCookie('<?php echo $prefix; ?>minmax_status');
    if (cookie != null)
      this.minmax_status = (cookie == 'true');

    cookie = getCookie('<?php echo $prefix; ?>nickmarker');
    this.nickmarker = (cookie == 'true');
    if (cookie == '' || cookie == null)
      this.nickmarker = <?php echo $nickmarker ? "true" : "false"; ?>;
    
    cookie = getCookie('<?php echo $prefix; ?>clock');
    this.clock = (cookie == 'true');
    if (cookie == '' || cookie == null)
      this.clock = <?php echo $clock ? "true" : "false"; ?>;

    cookie = getCookie('<?php echo $prefix; ?>showsmileys');
    this.showsmileys = (cookie == 'true');
    if (cookie == '' || cookie == null)
      this.showsmileys = <?php echo $showsmileys ? "true" : "false"; ?>;
    
    cookie = getCookie('<?php echo $prefix; ?>showwhosonline');
    this.showwhosonline = (cookie == 'true');
    if (cookie == '' || cookie == null)
      this.showwhosonline = <?php echo $showwhosonline ? "true" : "false"; ?>;

    /* '' means no forced color, let CSS choose the text color */
    this.current_text_color = '';
    cookie = getCookie('<?php echo $prefix; ?>current_text_color');
    if (cookie != null)
      this.switch_text_color(cookie);
             
    this.isconnected   = false;
    this.nicklist      = Array();
    this.nickcolor     = Array();
    this.colorlist     = Array();

    this.blinktmp     = Array();
    this.blinkloop    = Array();
    this.blinktimeout = Array();

    /* the events callbacks */
    this.el_words.onkeypress = this.callbackWords_OnKeypress.bindAsEventListener(this);
    this.el_words.onkeydown  = this.callbackWords_OnKeydown.bindAsEventListener(this);
    this.el_words.onfocus    = this.callbackWords_OnFocus.bindAsEventListener(this);
    this.el_handle.onkeydown = this.callbackHandle_OnKeydown.bindAsEventListener(this);
    this.el_handle.onchange  = this.callbackHandle_OnChange.bindAsEventListener(this);
    this.el_container.onmousemove = this.callbackContainer_OnMousemove.bindAsEventListener(this);
    this.el_container.onmousedown = this.callbackContainer_OnMousedown.bindAsEventListener(this);
    this.el_container.onmouseup   = this.callbackContainer_OnMouseup.bindAsEventListener(this);
    document.body.onunload = this.callback_OnUnload.bindAsEventListener(this);

    /* the i18n translations */
    var i18n = {
      hide_nickname_color: '<?php echo _pfc("Hide nickname marker"); ?>',
      show_nickname_color: '<?php echo _pfc("Show nickname marker"); ?>',
      hide_clock:          '<?php echo _pfc("Hide dates and hours"); ?>',
      show_clock:          '<?php echo _pfc("Show dates and hours"); ?>',
      logout:              '<?php echo _pfc("Disconnect"); ?>',
      login:               '<?php echo _pfc("Connect"); ?>',
      maximize:            '<?php echo _pfc("Magnify"); ?>',
      minimize:            '<?php echo _pfc("Cut down"); ?>',
      hidesmiley:          '<?php echo _pfc("Hide smiley box"); ?>',
      showsmiley:          '<?php echo _pfc("Show smiley box"); ?>',
      hideonline:          '<?php echo _pfc("Hide online users box"); ?>',
      showonline:          '<?php echo _pfc("Show online users box"); ?>'
    };
    this.i18n = $H(i18n);

    /* the smileys */
    var smileys = {
      <?php
      $output = "";
      foreach($smileys as $s_file => $s_str) { 
	for($j = 0; $j<count($s_str) ; $j++) {
	  $s = $s_str[$j];
	  $output .= "'".$s."': '".$s_file."',";
	}
      }
      $output = substr($output, 0, strlen($output)-1); // remove last ','
      echo $output;
      ?>
    }
    this.smileys = $H(smileys);
  },

  /**
   * Try to complete a nickname like on IRC when pressing the TAB key
   * @todo: improve the algorithme, it should take into account the cursor position
   */
  completeNick: function()
  {
    var w = this.el_words;
    var nick_src = w.value.substring(w.value.lastIndexOf(' ')+1,w.value.length);
    if (nick_src != '')
    {
      var ul_online = this.el_online.firstChild;
      for (var i=0; i<ul_online.childNodes.length; i++)
      {
	var nick = ul_online.childNodes[i].innerHTML;
	if (nick.indexOf(nick_src) == 0)
	  w.value = w.value.replace(nick_src, nick);
      }
    }
  },

  /**
   * Handle the pressed keys
   * see also callbackWords_OnKeydown
   */
  callbackWords_OnKeypress: function(evt)
  {
    var code = (evt.which) ? evt.which : evt.keyCode
    if (code == 9) /* tab key */
    {
      /* FF & Konqueror workaround : ignore TAB key here */
      /* do the nickname completion work like on IRC */
      this.completeNick();
      return false; /* do not leave the tab key default behavior */
    }
    else if (code == 13) /* enter key */
    {
      var w = this.el_words;
      var wval = w.value;
      re = new RegExp("^(\/[a-z]+)( (.*)|)");
      if (wval.match(re))
      {
	/* a user command */
	cmd   = wval.replace(re, '$1');
	param = wval.replace(re, '$2');
	this.handleRequest(cmd, param.substr(0,<?php echo $max_text_len; ?> + this.clientid.length));
      }
      else
      {
	/* a classic 'send' command*/

	/* truncate the text length */
	wval = wval.substr(0, <?php echo $max_text_len; ?>);

	/* colorize the text with current_text_color */
	if (this.current_text_color != '' && wval.length != '')
  	  wval = '[color=#' + this.current_text_color + ']' + wval + '[/color]';

	this.handleRequest('/send', wval);
      }
      w.value = '';
      return false;
    }
    else
    {
      /* allow other keys */
      return true;
    }
  },
  /**
   * Handle the pressed keys
   * see also callbackWords_OnKeypress
   */
{'fraction_non_alphanumeric': 0.16149021950126924, 'fraction_numerical': 0.0034343736001194564, 'mean_word_length': 2.7542040358744395, 'pattern_counts': {'":': 0, '<': 75, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2550053', 'n_tokens_mistral': 4416, 'n_tokens_neox': 4304, 'n_words': 1071}