[Phpfreechat-svn] SF.net SVN: phpfreechat: [1125] trunk/data/public/js/pfcclient.js
Status: Beta
Brought to you by:
kerphi
|
From: <gpi...@us...> - 2007-08-15 19:36:06
|
Revision: 1125
http://phpfreechat.svn.sourceforge.net/phpfreechat/?rev=1125&view=rev
Author: gpinzone
Date: 2007-08-15 12:35:55 -0700 (Wed, 15 Aug 2007)
Log Message:
-----------
Modified nickname completion to work anywhere within a string rather than only working at the end. Uses caret/selection position. Need to test on non-compliant browser like older Konqueror.
Modified Paths:
--------------
trunk/data/public/js/pfcclient.js
Modified: trunk/data/public/js/pfcclient.js
===================================================================
--- trunk/data/public/js/pfcclient.js 2007-08-15 03:57:47 UTC (rev 1124)
+++ trunk/data/public/js/pfcclient.js 2007-08-15 19:35:55 UTC (rev 1125)
@@ -604,10 +604,30 @@
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 selStart = w.value.length; // Default for browsers that don't support selection/caret position commands.
+ var selEnd = selStart;
+ // Get selection/caret position.
+ if (w.setSelectionRange)
+ {
+ // We don't rely on the stored values for browsers that support
+ // the selectionStart and selectionEnd commands.
+ selStart = w.selectionStart;
+ selEnd = w.selectionEnd;
+ }
+ else if (w.createTextRange && document.selection)
+ {
+ // We must rely on the stored values for IE browsers.
+ selStart = (w.selStart != null) ? w.selStart : w.value.length;
+ selEnd = (w.selEnd != null) ? w.selEnd : w.value.length;
+ }
+
+ var begin = w.value.lastIndexOf(' ', selStart - 1) + 1;
+ var end = (w.value.indexOf(' ', selStart) >= 0) ? w.value.indexOf(' ', selStart) : w.value.length;
+ var nick_src = w.value.substring(begin, end);
+ var non_nick_begin = w.value.substring(0, begin);
+ var non_nick_end = w.value.substring(end, w.value.length);
+
if (nick_src != '')
{
var tabid = this.gui.getTabId();
@@ -641,15 +661,14 @@
}
if (nick_match)
{
- w.value = non_nick_src + nick_src.replace(nick_src, nick_replace);
- // Move cursor to end of line.
- // This fixes Webkit (Safari) and hopefully newer Konqueror releases.
- /* Konqueror does not support setSelectionRange() on KDE versions <3.5.2. */
+ w.value = non_nick_begin + nick_src.replace(nick_src, nick_replace) + non_nick_end;
+ w.selStart = w.selEnd = non_nick_begin.length + nick_replace.length;
+
+ // Move cursor to end of completed nick.
if (w.setSelectionRange)
- {
- var selEnd = w.value.length;
- w.setSelectionRange(selEnd, selEnd);
- }
+ w.setSelectionRange(w.selEnd, w.selEnd); // Gecko
+ else
+ this.setSelection(w); // IE
}
}
},
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|