74 lines
1.7 KiB
Text
74 lines
1.7 KiB
Text
|
var TabCompleter = function(element) {
|
||
|
this.input = element;
|
||
|
};
|
||
|
|
||
|
TabCompleter.prototype = {
|
||
|
input : null,
|
||
|
tabInProgress : false,
|
||
|
tabBase : null,
|
||
|
lastHitIdx : -1,
|
||
|
lastSpace : -1,
|
||
|
matches: null,
|
||
|
reset : function () {
|
||
|
this.tabInProgress = false;
|
||
|
this.tabBase = null;
|
||
|
this.matches = null;
|
||
|
this.lastHitIdx = -1;
|
||
|
this.lastSpace = -1;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
TabCompleter.prototype.complete = function complete()
|
||
|
{
|
||
|
var text = this.input.value;
|
||
|
if (!(this.tabInProgress))
|
||
|
{
|
||
|
var lastWord;
|
||
|
this.lastSpace = text.lastIndexOf(" ");
|
||
|
|
||
|
if (text.length < 1) {
|
||
|
return;
|
||
|
}
|
||
|
else if (this.lastSpace < 0) {
|
||
|
lastWord = text;
|
||
|
}
|
||
|
else if (++(this.lastSpace) >= text.length) {
|
||
|
return;
|
||
|
}
|
||
|
else {
|
||
|
lastWord = text.substring(this.lastSpace);
|
||
|
}
|
||
|
if(lastWord.substr(0,1)=="/"){
|
||
|
lastWord=lastWord.substr(1);
|
||
|
}
|
||
|
this.tabBase = lastWord.toLowerCase();
|
||
|
this.tabInProgress = true;
|
||
|
}
|
||
|
|
||
|
var users = $("a.notice",window.parent.document);
|
||
|
|
||
|
if (this.lastHitIdx >= users.length) {
|
||
|
this.reset();
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
for (var n = 0; n < users.length; n++)
|
||
|
{
|
||
|
i = (n + this.lastHitIdx + 1) % users.length;
|
||
|
|
||
|
if (users.eq(i).attr('id').toLowerCase().indexOf(this.tabBase) == 0)
|
||
|
{
|
||
|
if (this.lastSpace >= 1) {
|
||
|
this.input.value = text.substring(0, this.lastSpace) + users.eq(i).attr('id');
|
||
|
}
|
||
|
else {
|
||
|
this.input.value = users.eq(i).attr('id');
|
||
|
}
|
||
|
|
||
|
this.lastHitIdx = i;
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
};
|