[Phpfreechat-svn] SF.net SVN: phpfreechat: [1116] trunk/data/public/js
Status: Beta
Brought to you by:
kerphi
From: <gpi...@us...> - 2007-08-12 04:27:13
|
Revision: 1116 http://phpfreechat.svn.sourceforge.net/phpfreechat/?rev=1116&view=rev Author: gpinzone Date: 2007-08-11 21:27:16 -0700 (Sat, 11 Aug 2007) Log Message: ----------- pfcclient.js: Major browser compatibility updates for Nickname completion. Safari and Opera work as well as IE and Firefox. Documented all known issues with Konqueror. pfcprompt.js: Forgot to change is_ff to is_gecko. Fixed. Modified Paths: -------------- trunk/data/public/js/pfcclient.js trunk/data/public/js/pfcprompt.js Modified: trunk/data/public/js/pfcclient.js =================================================================== --- trunk/data/public/js/pfcclient.js 2007-08-11 06:41:57 UTC (rev 1115) +++ trunk/data/public/js/pfcclient.js 2007-08-12 04:27:16 UTC (rev 1116) @@ -1,3 +1,4 @@ +// Browser detection mostly taken from prototype.js 1.5.1.1. var is_ie = !!(window.attachEvent && !window.opera); var is_khtml = !!(navigator.appName.match("Konqueror") || navigator.appVersion.match("KHTML")); var is_gecko = navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1; @@ -189,7 +190,6 @@ trace('handleResponse: '+cmd + "-"+resp+"-"+param); } - // store the new refresh time this.last_response_time = new Date().getTime(); @@ -321,10 +321,10 @@ } else if (resp == "notallowed") { - // when frozen_nick is true and the nickname is allready used, server will return + // When frozen_nick is true and the nickname is already used, server will return // the 'notallowed' status. It will display a message and stop chat update. - // if the chat update is not stopped, this will loop forever - // as long as the forced nickname is not changed + // If the chat update is not stopped, this will loop forever + // as long as the forced nickname is not changed. // display a message this.setError(this.res.getLabel('Choosen nickname is not allowed'), Array()); @@ -556,32 +556,32 @@ var w = this.el_words; var wval = w.value; - // append the string to the history + // Append the string to the history. this.cmdhistory.push(wval); this.cmdhistoryid = this.cmdhistory.length; this.cmdhistoryissearching = false; - // send the string to the server + // Send the string to the server. re = new RegExp("^(\/[a-zA-Z0-9]+)( (.*)|)"); if (wval.match(re)) { - // a user command + // A user command. cmd = wval.replace(re, '$1'); param = wval.replace(re, '$3'); this.sendRequest(cmd +' '+ param.substr(0, pfc_max_text_len + 2*this.clientid.length)); } else { - // a classic 'send' command + // A classic 'send' command. - // empty messages with only spaces + // Empty messages with only spaces. rx = new RegExp('^[ ]*$','g'); wval = wval.replace(rx,''); - // truncate the text length + // Truncate the text length. wval = wval.substr(0,pfc_max_text_len); - // colorize the text with current_text_color + // Colorize the text with current_text_color. if (this.current_text_color != '' && wval.length != '') wval = '[color=#' + this.current_text_color + '] ' + wval + ' [/color]'; @@ -592,19 +592,19 @@ }, /** - * Try to complete a nickname like on IRC when pressing the TAB key - * Nicks with spaces may not work under certain circumstances - * Replacing standards spaces with alternate spaces (e.g., ) helps - * Gecko browsers convert the to regular spaces - * TODO: Move cursor to end of line after nick completion in Konqueror and Webkit browsers - * Note: IRC does not allow nicks with spaces + * Try to complete a nickname like on IRC when pressing the TAB key. + * Nicks with spaces may not work under certain circumstances. + * Replacing spaces with alternate spaces (e.g., ) helps. + * Gecko browsers convert the to regular spaces, so no help for these browsers. + * Note: IRC does not allow nicks with spaces, so it's much easier for those clients. :) + * @author Gerard Pinzone */ completeNick: function() { var w = this.el_words; var last_space = w.value.lastIndexOf(' '); var nick_src = w.value.substring(last_space+1, w.value.length); - var non_nick_src = w.value.substring(0,last_space+1); + var non_nick_src = w.value.substring(0, last_space+1); if (nick_src != '') { @@ -641,12 +641,13 @@ w.value = non_nick_src + nick_src.replace(nick_src, nick_replace); } }, + /** * Cycle to older entry in history */ historyUp: function() { - // write the previous command in the history + // Write the previous command in the history. if (this.cmdhistory.length > 0) { var w = this.el_words; @@ -665,7 +666,7 @@ */ historyDown: function() { - // write the next command in the history + // Write the next command in the history. if (this.cmdhistory.length > 0) { var w = this.el_words; @@ -684,32 +685,26 @@ }, /** - * Handle the pressed keys + * Handle the pressed keys. * see also callbackWords_OnKeydown */ callbackWords_OnKeypress: function(evt) { - // All browsers except for IE should use evt.which + // All browsers except for IE should use "evt.which." var code = (evt.which) ? evt.which : evt.keyCode; - if (code == Event.KEY_TAB) /* tab key */ + if (code == Event.KEY_RETURN) /* ENTER 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 == Event.KEY_RETURN) /* enter key */ - { return this.doSendMessage(); } else { - /* allow other keys */ + // Allow other key defaults. return true; } }, + /** - * Handle the pressed keys + * Handle the pressed keys. * see also callbackWords_OnKeypress * WARNING: Suppressing defaults on the keydown event * may prevent keypress and/or keyup events @@ -720,31 +715,69 @@ if (!this.isconnected) return false; this.clearError(Array(this.el_words)); var code = (evt.which) ? evt.which : evt.keyCode - if (code == 9) /* tab key */ + if (code == 38 && (is_gecko || is_ie || is_opera || is_webkit)) // up arrow 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 if (code == 38 && (is_gecko || is_ie || is_opera || is_webkit)) // up arrow key - { - /* TODO: Fix up arrow issue in Opera */ - // Konqueror does not work due to keycode conflicts - // write the previous command in the history + /* TODO: Fix up arrow issue in Opera - may be a bug in Opera. See TAB handler comments below. */ + /* Konqueror cannot use this feature due to keycode conflicts. */ + + // Write the previous command in the history. this.historyUp(); - return false; // do not leave the tab key default behavior + + if (evt.returnValue) // IE + evt.returnValue = false; + if (evt.preventDefault) // DOM + evt.preventDefault(); + return false; // should work in all browsers } else if (code == 40 && (is_gecko || is_ie || is_opera || is_webkit)) // down arrow key { - // Konqueror does not work due to keycode conflicts - // write the next command in the history + /* Konqueror cannot use this feature due to keycode conflicts. */ + + // Write the previous command in the history. this.historyDown(); - return false; // do not leave the tab key default behavior + + if (evt.returnValue) // IE + evt.returnValue = false; + if (evt.preventDefault) // DOM + evt.preventDefault(); + return false; // should work in all browsers } + else if (code == 9) /* TAB key */ + { + /* Konqueror has the same problem as Webkit (Safari), + but setSelectionRange() won't work on + KDE versions <3.5.2. Therefore, I'm leaving + the Webkit fix out for these browsers. */ + + // Do nickname completion like on IRC / Unix command line. + this.completeNick(); + + var tb = evt.srcElement || evt.target; + if (is_webkit) + { + // Move cursor to end of line for Webkit (Safari). + var selEnd = this.el_words.value.length; + tb.setSelectionRange(selEnd, selEnd); + } + if (is_opera) + { + // Fixes Opera's loss of focus after TAB key is pressed. + // This is most likely due to a bug in Opera + // that executes the default key operation BEFORE the + // keydown and keypress event handler. + // This is probably the reason for the "up arrow" issue above. + window.setTimeout(function(){tb.focus();}, 0); + } + + if (evt.returnValue) // IE + evt.returnValue = false; + if (evt.preventDefault) // DOM + evt.preventDefault(); + return false; // Should work in all browsers. + } else { - /* allow other keys */ + // Allow other key defaults. return true; } }, Modified: trunk/data/public/js/pfcprompt.js =================================================================== --- trunk/data/public/js/pfcprompt.js 2007-08-11 06:41:57 UTC (rev 1115) +++ trunk/data/public/js/pfcprompt.js 2007-08-12 04:27:16 UTC (rev 1116) @@ -27,7 +27,7 @@ this.box.style.zIndex = 100; this.box.style.display = 'none'; - if (is_ff) { + if (is_gecko) { this.box.style.overflow = 'auto'; } @@ -119,7 +119,7 @@ { // _doSubmit is called when the user enters or cancels the box. var val = this.prompt_field.value; - if (is_ff) this.box.focus(); // test is_ff because it doesn't work on KHTML browser, the popup shows infinitly + if (is_gecko) this.box.focus(); // test is_ff because it doesn't work on KHTML browser, the popup shows infinitly this.box.style.display = 'none'; // clear out the dialog box this.bgbox.style.display = 'none'; // clear out the screen this.prompt_field.value = ''; // clear out the text field This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |