⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pfcclient.js.tpl.php

📁 一个开源免费的php chat.采用txt作数据库,性能不错.
💻 PHP
📖 第 1 页 / 共 3 页
字号:
/** * This class is the client part of phpFreeChat * (depends on prototype library) * @author Stephane Gully */var pfcClient = Class.create();//defining the rest of the class implmentationpfcClient.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*/        // empty messages with only spaces        rx = new RegExp('^[ ]*$','g');        wval = wval.replace(rx,'');        	/* 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   */  callbackWords_OnKeydown: function(evt)  {    if (!this.isconnected) return false;    this.clearError(Array(this.el_words));    var code = (evt.which) ? evt.which : event.keyCode    if (code == 9) /* tab key */    {      /* IE 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    {      return true;    }  },  callbackWords_OnFocus: function(evt)  {    //    if (this.el_handle && this.el_handle.value == '' && !this.minmax_status)    //      this.el_handle.focus();  },  callbackHandle_OnKeydown: function(evt)  {  },  callbackHandle_OnChange: function(evt)  {  },  callback_OnUnload: function(evt)  {    /* don't disconnect users when they reload the window     * this event doesn't only occurs when the page is closed but also when the page is reloaded */    <?php if ($c->quit_on_closedwindow) { ?>    if (!this.isconnected) return false;    this.handleRequest('/quit');    <?php } ?>  },  callbackContainer_OnMousemove: function(evt)  {    this.isdraging = true;  },  callbackContainer_OnMousedown: function(evt)  {    this.isdraging = false;  },  callbackContainer_OnMouseup: function(evt)  {    if (!this.isdraging)      if (this.el_words && !this.minmax_status)        this.el_words.focus();  },  /**   * hide error area and stop blinking fields   */  clearError: function(ids)  {     this.el_errors.style.display = 'none';    for (var i=0; i<ids.length; i++)      this.blink(ids[i].id, 'stop');  },  /**   * show error area and assign to it an error message and start the blinking of given fields   */  setError: function(str, ids)  {    this.el_errors.innerHTML = str;    this.el_errors.style.display = 'block';    for (var i=0; i<ids.length; i++)      this.blink(ids[i].id, 'start');  },  /**   * blink routines used by Error functions   */  blink: function(id, action)  {    clearTimeout(this.blinktimeout[id]);    if ($(id) == null) return;    if (action == 'start')    {      this.blinktmp[id] = $(id).style.backgroundColor;      clearTimeout(this.blinktimeout[id]);      this.blinktimeout[id] = setTimeout('pfc.blink(\'' + id + '\',\'loop\')', 500);    }    if (action == 'stop')    {      $(id).style.backgroundColor = this.blinktmp[id];    }    if (action == 'loop')    {      if (this.blinkloop[id] == 1)      {	$(id).style.backgroundColor = '#FFDFC0';	this.blinkloop[id] = 2;      }      else      {	$(id).style.backgroundColor = '#FFFFFF';	this.blinkloop[id] = 1;      }      this.blinktimeout[id] = setTimeout('pfc.blink(\'' + id + '\',\'loop\')', 500);    }  },  /**   * Call the ajax request function   * Will query the server   */  handleRequest: function(cmd, param)  {    return <?php echo $prefix; ?>handleRequest(cmd + " " + this.clientid + (param ? " " + param : ""));  },  /**   * update function to poll the server each 'refresh_delay' time   */  updateChat: function(start)  {    clearTimeout(this.timeout);    if (start)    {      var res = this.handleRequest('/update');      // adjust the refresh_delay if the connection was lost      if (res == false) { this.refresh_delay = this.refresh_delay * 2; }      // setup the next update      this.timeout = setTimeout('pfc.updateChat(true)', this.refresh_delay);    }  },  /**   * insert a smiley   */  insertSmiley: function(s)  {    this.el_words.value += s;    this.el_words.focus();  },  /**   * fill the nickname list with connected nicknames   */  updateNickList: function(lst)  {    this.nicklist = lst;    var nicks   = lst;    var nickdiv = this.el_online;    var ul = document.createElement('ul');    for (var i=0; i<nicks.length; i++)    {      var li = document.createElement('li');

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -