author | Dan |
Wed, 13 May 2009 09:47:31 -0400 | |
changeset 973 | 451141c834fe |
parent 787 | b0d0d429d8cf |
child 1046 | cfc6c30c5e2d |
permissions | -rw-r--r-- |
184
d74ff822acc9
Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff
changeset
|
1 |
/** |
699
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
2 |
* Javascript auto-completion for form fields. jQuery based in 1.1.5. |
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
3 |
* Different types of auto-completion fields can be defined (e.g. with different data sets). For each one, a schema |
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
4 |
* can be created describing how to draw each row. |
184
d74ff822acc9
Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff
changeset
|
5 |
*/ |
581
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
6 |
|
701
dd80cde96a6c
Autocomplete further stabilized. Made Special:PasswordReset and Special:Register prevent use if logged in.
Dan
parents:
699
diff
changeset
|
7 |
var autofill_schemas = window.autofill_schemas || {}; |
581
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
8 |
|
699
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
9 |
/** |
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
10 |
* SCHEMA - GENERIC |
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
11 |
*/ |
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
12 |
|
581
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
13 |
autofill_schemas.generic = { |
699
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
14 |
init: function(element, fillclass, params) |
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
15 |
{ |
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
16 |
$(element).autocomplete(makeUrlNS('Special', 'Autofill', 'type=' + fillclass) + '&userinput=', { |
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
17 |
minChars: 3 |
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
18 |
}); |
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
19 |
} |
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
20 |
} |
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
21 |
|
701
dd80cde96a6c
Autocomplete further stabilized. Made Special:PasswordReset and Special:Register prevent use if logged in.
Dan
parents:
699
diff
changeset
|
22 |
/** |
dd80cde96a6c
Autocomplete further stabilized. Made Special:PasswordReset and Special:Register prevent use if logged in.
Dan
parents:
699
diff
changeset
|
23 |
* SCHEMA - USERNAME |
dd80cde96a6c
Autocomplete further stabilized. Made Special:PasswordReset and Special:Register prevent use if logged in.
Dan
parents:
699
diff
changeset
|
24 |
*/ |
dd80cde96a6c
Autocomplete further stabilized. Made Special:PasswordReset and Special:Register prevent use if logged in.
Dan
parents:
699
diff
changeset
|
25 |
|
699
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
26 |
autofill_schemas.username = { |
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
27 |
init: function(element, fillclass, params) |
184
d74ff822acc9
Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff
changeset
|
28 |
{ |
701
dd80cde96a6c
Autocomplete further stabilized. Made Special:PasswordReset and Special:Register prevent use if logged in.
Dan
parents:
699
diff
changeset
|
29 |
params = params || {}; |
dd80cde96a6c
Autocomplete further stabilized. Made Special:PasswordReset and Special:Register prevent use if logged in.
Dan
parents:
699
diff
changeset
|
30 |
var allow_anon = params.allow_anon ? '1' : '0'; |
dd80cde96a6c
Autocomplete further stabilized. Made Special:PasswordReset and Special:Register prevent use if logged in.
Dan
parents:
699
diff
changeset
|
31 |
$(element).autocomplete(makeUrlNS('Special', 'Autofill', 'type=' + fillclass + '&allow_anon=' + allow_anon) + '&userinput=', { |
dd80cde96a6c
Autocomplete further stabilized. Made Special:PasswordReset and Special:Register prevent use if logged in.
Dan
parents:
699
diff
changeset
|
32 |
minChars: 3, |
dd80cde96a6c
Autocomplete further stabilized. Made Special:PasswordReset and Special:Register prevent use if logged in.
Dan
parents:
699
diff
changeset
|
33 |
formatItem: function(row, _, __) |
dd80cde96a6c
Autocomplete further stabilized. Made Special:PasswordReset and Special:Register prevent use if logged in.
Dan
parents:
699
diff
changeset
|
34 |
{ |
dd80cde96a6c
Autocomplete further stabilized. Made Special:PasswordReset and Special:Register prevent use if logged in.
Dan
parents:
699
diff
changeset
|
35 |
var html = row.name_highlight + ' – '; |
dd80cde96a6c
Autocomplete further stabilized. Made Special:PasswordReset and Special:Register prevent use if logged in.
Dan
parents:
699
diff
changeset
|
36 |
html += '<span style="' + row.rank_style + '">' + row.rank_title + '</span>'; |
dd80cde96a6c
Autocomplete further stabilized. Made Special:PasswordReset and Special:Register prevent use if logged in.
Dan
parents:
699
diff
changeset
|
37 |
return html; |
dd80cde96a6c
Autocomplete further stabilized. Made Special:PasswordReset and Special:Register prevent use if logged in.
Dan
parents:
699
diff
changeset
|
38 |
}, |
dd80cde96a6c
Autocomplete further stabilized. Made Special:PasswordReset and Special:Register prevent use if logged in.
Dan
parents:
699
diff
changeset
|
39 |
tableHeader: '<tr><th>' + $lang.get('user_autofill_heading_suggestions') + '</th></tr>', |
dd80cde96a6c
Autocomplete further stabilized. Made Special:PasswordReset and Special:Register prevent use if logged in.
Dan
parents:
699
diff
changeset
|
40 |
showWhenNoResults: true, |
dd80cde96a6c
Autocomplete further stabilized. Made Special:PasswordReset and Special:Register prevent use if logged in.
Dan
parents:
699
diff
changeset
|
41 |
noResultsHTML: '<tr><td class="row1" style="font-size: smaller;">' + $lang.get('user_autofill_msg_no_suggestions') + '</td></tr>', |
dd80cde96a6c
Autocomplete further stabilized. Made Special:PasswordReset and Special:Register prevent use if logged in.
Dan
parents:
699
diff
changeset
|
42 |
}); |
dd80cde96a6c
Autocomplete further stabilized. Made Special:PasswordReset and Special:Register prevent use if logged in.
Dan
parents:
699
diff
changeset
|
43 |
} |
dd80cde96a6c
Autocomplete further stabilized. Made Special:PasswordReset and Special:Register prevent use if logged in.
Dan
parents:
699
diff
changeset
|
44 |
} |
dd80cde96a6c
Autocomplete further stabilized. Made Special:PasswordReset and Special:Register prevent use if logged in.
Dan
parents:
699
diff
changeset
|
45 |
|
dd80cde96a6c
Autocomplete further stabilized. Made Special:PasswordReset and Special:Register prevent use if logged in.
Dan
parents:
699
diff
changeset
|
46 |
autofill_schemas.page = { |
dd80cde96a6c
Autocomplete further stabilized. Made Special:PasswordReset and Special:Register prevent use if logged in.
Dan
parents:
699
diff
changeset
|
47 |
init: function(element, fillclass, params) |
dd80cde96a6c
Autocomplete further stabilized. Made Special:PasswordReset and Special:Register prevent use if logged in.
Dan
parents:
699
diff
changeset
|
48 |
{ |
699
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
49 |
$(element).autocomplete(makeUrlNS('Special', 'Autofill', 'type=' + fillclass) + '&userinput=', { |
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
50 |
minChars: 3, |
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
51 |
formatItem: function(row, _, __) |
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
52 |
{ |
701
dd80cde96a6c
Autocomplete further stabilized. Made Special:PasswordReset and Special:Register prevent use if logged in.
Dan
parents:
699
diff
changeset
|
53 |
var html = '<u>' + row.name_highlight + '</u>'; |
dd80cde96a6c
Autocomplete further stabilized. Made Special:PasswordReset and Special:Register prevent use if logged in.
Dan
parents:
699
diff
changeset
|
54 |
html += ' – ' + row.pid_highlight; |
699
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
55 |
return html; |
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
56 |
}, |
701
dd80cde96a6c
Autocomplete further stabilized. Made Special:PasswordReset and Special:Register prevent use if logged in.
Dan
parents:
699
diff
changeset
|
57 |
showWhenNoResults: true, |
dd80cde96a6c
Autocomplete further stabilized. Made Special:PasswordReset and Special:Register prevent use if logged in.
Dan
parents:
699
diff
changeset
|
58 |
noResultsHTML: '<tr><td class="row1" style="font-size: smaller;">' + $lang.get('user_autofill_msg_no_suggestions') + '</td></tr>', |
699
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
59 |
}); |
581
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
60 |
} |
699
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
61 |
} |
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
62 |
|
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
63 |
window.autofill_onload = function() |
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
64 |
{ |
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
65 |
if ( this.loaded ) |
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
66 |
{ |
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
67 |
return true; |
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
68 |
} |
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
69 |
|
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
70 |
var inputs = document.getElementsByClassName('input', 'autofill'); |
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
71 |
|
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
72 |
if ( inputs.length > 0 ) |
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
73 |
{ |
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
74 |
// we have at least one input that needs to be made an autofill element. |
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
75 |
// is spry data loaded? |
701
dd80cde96a6c
Autocomplete further stabilized. Made Special:PasswordReset and Special:Register prevent use if logged in.
Dan
parents:
699
diff
changeset
|
76 |
load_component('l10n'); |
699
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
77 |
} |
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
78 |
|
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
79 |
this.loaded = true; |
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
80 |
|
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
81 |
for ( var i = 0; i < inputs.length; i++ ) |
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
82 |
{ |
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
83 |
autofill_init_element(inputs[i]); |
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
84 |
} |
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
85 |
} |
581
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
86 |
|
701
dd80cde96a6c
Autocomplete further stabilized. Made Special:PasswordReset and Special:Register prevent use if logged in.
Dan
parents:
699
diff
changeset
|
87 |
window.autofill_init_element = function(element, params) |
581
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
88 |
{ |
701
dd80cde96a6c
Autocomplete further stabilized. Made Special:PasswordReset and Special:Register prevent use if logged in.
Dan
parents:
699
diff
changeset
|
89 |
if ( element.af_initted ) |
dd80cde96a6c
Autocomplete further stabilized. Made Special:PasswordReset and Special:Register prevent use if logged in.
Dan
parents:
699
diff
changeset
|
90 |
return false; |
dd80cde96a6c
Autocomplete further stabilized. Made Special:PasswordReset and Special:Register prevent use if logged in.
Dan
parents:
699
diff
changeset
|
91 |
|
581
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
92 |
params = params || {}; |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
93 |
// assign an ID if it doesn't have one yet |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
94 |
if ( !element.id ) |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
95 |
{ |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
96 |
element.id = 'autofill_' + Math.floor(Math.random() * 100000); |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
97 |
} |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
98 |
var id = element.id; |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
99 |
|
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
100 |
// get the fill type |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
101 |
var fillclass = element.className; |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
102 |
fillclass = fillclass.split(' '); |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
103 |
fillclass = fillclass[1]; |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
104 |
|
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
105 |
var schema = ( autofill_schemas[fillclass] ) ? autofill_schemas[fillclass] : autofill_schemas['generic']; |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
106 |
if ( typeof(schema.init) != 'function' ) |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
107 |
{ |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
108 |
schema.init = autofill_schemas.generic.init; |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
109 |
} |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
110 |
schema.init(element, fillclass, params); |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
111 |
|
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
112 |
element.af_initted = true; |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
113 |
} |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
114 |
|
701
dd80cde96a6c
Autocomplete further stabilized. Made Special:PasswordReset and Special:Register prevent use if logged in.
Dan
parents:
699
diff
changeset
|
115 |
window.AutofillUsername = function(el, allow_anon) |
581
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
116 |
{ |
699
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
117 |
el.onkeyup = null; |
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
118 |
el.className = 'autofill username'; |
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
119 |
autofill_init_element(el, { allow_anon: allow_anon }); |
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
120 |
} |
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
121 |
|
701
dd80cde96a6c
Autocomplete further stabilized. Made Special:PasswordReset and Special:Register prevent use if logged in.
Dan
parents:
699
diff
changeset
|
122 |
window.AutofillPage = function(el) |
699
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
123 |
{ |
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
124 |
el.onkeyup = null; |
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
125 |
el.className = 'autofill page'; |
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
126 |
autofill_init_element(el, {}); |
581
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
127 |
} |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
128 |
|
787 | 129 |
window.autofill_init = function() |
130 |
{ |
|
131 |
load_component(['l10n', 'jquery', 'jquery-ui']); |
|
132 |
||
133 |
if ( !window.jQuery ) |
|
184
d74ff822acc9
Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff
changeset
|
134 |
{ |
787 | 135 |
throw('jQuery didn\'t load properly. Aborting auto-complete init.'); |
136 |
} |
|
137 |
||
138 |
jQuery.autocomplete = function(input, options) { |
|
139 |
// Create a link to self |
|
140 |
var me = this; |
|
141 |
||
142 |
// Create jQuery object for input element |
|
143 |
var $input = $(input).attr("autocomplete", "off"); |
|
144 |
||
145 |
// Apply inputClass if necessary |
|
146 |
if (options.inputClass) { |
|
147 |
$input.addClass(options.inputClass); |
|
148 |
} |
|
149 |
||
150 |
// Create results |
|
151 |
var results = document.createElement("div"); |
|
152 |
$(results).addClass('tblholder').css('z-index', getHighestZ() + 1).css('margin-top', 0); |
|
153 |
$(results).css('clip', 'rect(0px,auto,auto,0px)').css('overflow', 'auto').css('max-height', '300px'); |
|
154 |
||
155 |
// Create jQuery object for results |
|
156 |
// var $results = $(results); |
|
157 |
var $results = $(results).hide().addClass(options.resultsClass).css("position", "absolute"); |
|
158 |
if( options.width > 0 ) { |
|
159 |
$results.css("width", options.width); |
|
699
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
160 |
} |
787 | 161 |
|
162 |
// Add to body element |
|
163 |
$("body").append(results); |
|
164 |
||
165 |
input.autocompleter = me; |
|
166 |
||
167 |
var timeout = null; |
|
168 |
var prev = ""; |
|
169 |
var active = -1; |
|
170 |
var cache = {}; |
|
171 |
var keyb = false; |
|
172 |
// hasFocus was false by default, see if making it true helps |
|
173 |
var hasFocus = true; |
|
174 |
var hasNoResults = false; |
|
175 |
var lastKeyPressCode = null; |
|
176 |
var mouseDownOnSelect = false; |
|
177 |
var hidingResults = false; |
|
178 |
||
179 |
// flush cache |
|
180 |
function flushCache(){ |
|
181 |
cache = {}; |
|
182 |
cache.data = {}; |
|
183 |
cache.length = 0; |
|
184 |
}; |
|
185 |
||
186 |
// flush cache |
|
187 |
flushCache(); |
|
188 |
||
189 |
// if there is a data array supplied |
|
190 |
if( options.data != null ){ |
|
191 |
var sFirstChar = "", stMatchSets = {}, row = []; |
|
192 |
||
193 |
// no url was specified, we need to adjust the cache length to make sure it fits the local data store |
|
194 |
if( typeof options.url != "string" ) { |
|
195 |
options.cacheLength = 1; |
|
699
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
196 |
} |
787 | 197 |
|
198 |
// loop through the array and create a lookup structure |
|
199 |
for( var i=0; i < options.data.length; i++ ){ |
|
200 |
// if row is a string, make an array otherwise just reference the array |
|
201 |
row = ((typeof options.data[i] == "string") ? [options.data[i]] : options.data[i]); |
|
202 |
||
203 |
// if the length is zero, don't add to list |
|
204 |
if( row[0].length > 0 ){ |
|
205 |
// get the first character |
|
206 |
sFirstChar = row[0].substring(0, 1).toLowerCase(); |
|
207 |
// if no lookup array for this character exists, look it up now |
|
208 |
if( !stMatchSets[sFirstChar] ) stMatchSets[sFirstChar] = []; |
|
209 |
// if the match is a string |
|
210 |
stMatchSets[sFirstChar].push(row); |
|
699
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
211 |
} |
787 | 212 |
} |
213 |
||
214 |
// add the data items to the cache |
|
215 |
if ( options.cacheLength ) |
|
216 |
{ |
|
217 |
for( var k in stMatchSets ) { |
|
218 |
// increase the cache size |
|
219 |
options.cacheLength++; |
|
220 |
// add to the cache |
|
221 |
addToCache(k, stMatchSets[k]); |
|
699
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
222 |
} |
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
223 |
} |
787 | 224 |
} |
225 |
||
226 |
$input |
|
227 |
.keydown(function(e) { |
|
228 |
// track last key pressed |
|
229 |
lastKeyPressCode = e.keyCode; |
|
230 |
switch(e.keyCode) { |
|
231 |
case 38: // up |
|
232 |
e.preventDefault(); |
|
233 |
moveSelect(-1); |
|
234 |
break; |
|
235 |
case 40: // down |
|
236 |
e.preventDefault(); |
|
237 |
moveSelect(1); |
|
238 |
break; |
|
239 |
case 9: // tab |
|
240 |
case 13: // return |
|
241 |
if( selectCurrent() ){ |
|
242 |
// make sure to blur off the current field |
|
243 |
// (Enano edit - why do we want this, again?) |
|
244 |
// $input.get(0).blur(); |
|
699
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
245 |
e.preventDefault(); |
787 | 246 |
} |
247 |
break; |
|
248 |
default: |
|
249 |
active = -1; |
|
250 |
if (timeout) clearTimeout(timeout); |
|
251 |
timeout = setTimeout(function(){onChange();}, options.delay); |
|
252 |
break; |
|
253 |
} |
|
254 |
}) |
|
255 |
.focus(function(){ |
|
256 |
// track whether the field has focus, we shouldn't process any results if the field no longer has focus |
|
257 |
hasFocus = true; |
|
258 |
}) |
|
259 |
.blur(function() { |
|
260 |
// track whether the field has focus |
|
261 |
hasFocus = false; |
|
262 |
if (!mouseDownOnSelect) { |
|
263 |
hideResults(); |
|
264 |
} |
|
265 |
}); |
|
266 |
||
267 |
hideResultsNow(); |
|
268 |
||
269 |
function onChange() { |
|
270 |
// ignore if the following keys are pressed: [del] [shift] [capslock] |
|
271 |
if( lastKeyPressCode == 46 || (lastKeyPressCode > 8 && lastKeyPressCode < 32) ) return $results.hide(); |
|
272 |
var v = $input.val(); |
|
273 |
if (v == prev) return; |
|
274 |
prev = v; |
|
275 |
if (v.length >= options.minChars) { |
|
276 |
$input.addClass(options.loadingClass); |
|
277 |
requestData(v); |
|
278 |
} else { |
|
279 |
$input.removeClass(options.loadingClass); |
|
280 |
$results.hide(); |
|
281 |
} |
|
282 |
}; |
|
283 |
||
284 |
function moveSelect(step) { |
|
285 |
||
286 |
var lis = $("td", results); |
|
287 |
if (!lis || hasNoResults) return; |
|
288 |
||
289 |
active += step; |
|
290 |
||
291 |
if (active < 0) { |
|
292 |
active = 0; |
|
293 |
} else if (active >= lis.size()) { |
|
294 |
active = lis.size() - 1; |
|
295 |
} |
|
296 |
||
297 |
lis.removeClass("row2"); |
|
298 |
||
299 |
$(lis[active]).addClass("row2"); |
|
300 |
||
301 |
// scroll the results div |
|
302 |
// are we going up or down? |
|
303 |
var td_top = $dynano(lis[active]).Top() - $dynano(results).Top(); |
|
304 |
var td_height = $dynano(lis[active]).Height(); |
|
305 |
var td_bottom = td_top + td_height; |
|
306 |
var visibleTopBoundary = getScrollOffset(results); |
|
307 |
var results_height = $dynano(results).Height(); |
|
308 |
var visibleBottomBoundary = visibleTopBoundary + results_height; |
|
309 |
var scrollTo = false; |
|
310 |
if ( td_top < visibleTopBoundary && step < 0 ) |
|
311 |
{ |
|
312 |
// going up: scroll the results div to just higher than the result we're trying to see |
|
313 |
scrollTo = td_top - 7; |
|
314 |
} |
|
315 |
else if ( td_bottom > visibleBottomBoundary && step > 0 ) |
|
316 |
{ |
|
317 |
// going down is a little harder, we want the result to be at the bottom |
|
318 |
scrollTo = td_top - results_height + td_height + 7; |
|
319 |
} |
|
320 |
if ( scrollTo ) |
|
321 |
{ |
|
322 |
results.scrollTop = scrollTo; |
|
323 |
} |
|
324 |
||
325 |
// Weird behaviour in IE |
|
326 |
// if (lis[active] && lis[active].scrollIntoView) { |
|
327 |
// lis[active].scrollIntoView(false); |
|
328 |
// } |
|
329 |
||
330 |
}; |
|
331 |
||
332 |
function selectCurrent() { |
|
333 |
var li = $("td.row2", results)[0]; |
|
334 |
if (!li) { |
|
335 |
var $li = $("td", results); |
|
336 |
if (options.selectOnly) { |
|
337 |
if ($li.length == 1) li = $li[0]; |
|
338 |
} else if (options.selectFirst) { |
|
339 |
li = $li[0]; |
|
699
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
340 |
} |
787 | 341 |
} |
342 |
if (li) { |
|
343 |
selectItem(li); |
|
344 |
return true; |
|
345 |
} else { |
|
346 |
return false; |
|
347 |
} |
|
348 |
}; |
|
349 |
||
350 |
function selectItem(li) { |
|
351 |
if (!li) { |
|
352 |
li = document.createElement("li"); |
|
353 |
li.extra = []; |
|
354 |
li.selectValue = ""; |
|
355 |
} |
|
356 |
var v = $.trim(li.selectValue ? li.selectValue : li.innerHTML); |
|
357 |
input.lastSelected = v; |
|
358 |
prev = v; |
|
359 |
$results.html(""); |
|
360 |
$input.val(v); |
|
361 |
hideResultsNow(); |
|
362 |
if (options.onItemSelect) { |
|
363 |
setTimeout(function() { options.onItemSelect(li) }, 1); |
|
364 |
} |
|
365 |
}; |
|
366 |
||
367 |
// selects a portion of the input string |
|
368 |
function createSelection(start, end){ |
|
369 |
// get a reference to the input element |
|
370 |
var field = $input.get(0); |
|
371 |
if( field.createTextRange ){ |
|
372 |
var selRange = field.createTextRange(); |
|
373 |
selRange.collapse(true); |
|
374 |
selRange.moveStart("character", start); |
|
375 |
selRange.moveEnd("character", end); |
|
376 |
selRange.select(); |
|
377 |
} else if( field.setSelectionRange ){ |
|
378 |
field.setSelectionRange(start, end); |
|
379 |
} else { |
|
380 |
if( field.selectionStart ){ |
|
381 |
field.selectionStart = start; |
|
382 |
field.selectionEnd = end; |
|
699
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
383 |
} |
787 | 384 |
} |
385 |
field.focus(); |
|
386 |
}; |
|
387 |
||
388 |
// fills in the input box w/the first match (assumed to be the best match) |
|
389 |
function autoFill(sValue){ |
|
390 |
// if the last user key pressed was backspace, don't autofill |
|
391 |
if( lastKeyPressCode != 8 ){ |
|
392 |
// fill in the value (keep the case the user has typed) |
|
393 |
$input.val($input.val() + sValue.substring(prev.length)); |
|
394 |
// select the portion of the value not typed by the user (so the next character will erase) |
|
395 |
createSelection(prev.length, sValue.length); |
|
396 |
} |
|
397 |
}; |
|
398 |
||
399 |
function showResults() { |
|
400 |
// get the position of the input field right now (in case the DOM is shifted) |
|
401 |
var pos = findPos(input); |
|
402 |
// either use the specified width, or autocalculate based on form element |
|
403 |
var iWidth = (options.width > 0) ? options.width : $input.width(); |
|
404 |
// reposition |
|
405 |
$results.css({ |
|
406 |
width: parseInt(iWidth) + "px", |
|
407 |
top: (pos.y + input.offsetHeight) + "px", |
|
408 |
left: pos.x + "px" |
|
409 |
}); |
|
410 |
if ( !$results.is(":visible") ) |
|
411 |
{ |
|
412 |
$results.show("blind", {}, 200); |
|
413 |
} |
|
414 |
else |
|
415 |
{ |
|
416 |
$results.show(); |
|
417 |
} |
|
418 |
}; |
|
419 |
||
420 |
function hideResults() { |
|
421 |
if (timeout) clearTimeout(timeout); |
|
422 |
timeout = setTimeout(hideResultsNow, 200); |
|
423 |
}; |
|
424 |
||
425 |
function hideResultsNow() { |
|
426 |
if (hidingResults) { |
|
427 |
return; |
|
428 |
} |
|
429 |
hidingResults = true; |
|
699
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
430 |
|
787 | 431 |
if (timeout) { |
432 |
clearTimeout(timeout); |
|
433 |
} |
|
434 |
||
435 |
var v = $input.removeClass(options.loadingClass).val(); |
|
436 |
||
437 |
if ($results.is(":visible")) { |
|
438 |
$results.hide(); |
|
439 |
} |
|
440 |
||
441 |
if (options.mustMatch) { |
|
442 |
if (!input.lastSelected || input.lastSelected != v) { |
|
443 |
selectItem(null); |
|
444 |
} |
|
445 |
} |
|
446 |
||
447 |
hidingResults = false; |
|
448 |
}; |
|
449 |
||
450 |
function receiveData(q, data) { |
|
451 |
if (data) { |
|
452 |
$input.removeClass(options.loadingClass); |
|
453 |
results.innerHTML = ""; |
|
454 |
||
455 |
// if the field no longer has focus or if there are no matches, do not display the drop down |
|
456 |
if( !hasFocus ) |
|
704
077887be639d
More work on auto-completion - it auto-scrolls now and limits result divs to 300px height
Dan
parents:
701
diff
changeset
|
457 |
{ |
787 | 458 |
return hideResultsNow(); |
704
077887be639d
More work on auto-completion - it auto-scrolls now and limits result divs to 300px height
Dan
parents:
701
diff
changeset
|
459 |
} |
787 | 460 |
if ( data.length == 0 && !options.showWhenNoResults ) |
704
077887be639d
More work on auto-completion - it auto-scrolls now and limits result divs to 300px height
Dan
parents:
701
diff
changeset
|
461 |
{ |
787 | 462 |
return hideResultsNow(); |
704
077887be639d
More work on auto-completion - it auto-scrolls now and limits result divs to 300px height
Dan
parents:
701
diff
changeset
|
463 |
} |
787 | 464 |
hasNoResults = false; |
465 |
||
466 |
if ($.browser.msie) { |
|
467 |
// we put a styled iframe behind the calendar so HTML SELECT elements don't show through |
|
468 |
$results.append(document.createElement('iframe')); |
|
704
077887be639d
More work on auto-completion - it auto-scrolls now and limits result divs to 300px height
Dan
parents:
701
diff
changeset
|
469 |
} |
787 | 470 |
results.appendChild(dataToDom(data)); |
471 |
// autofill in the complete box w/the first match as long as the user hasn't entered in more data |
|
472 |
if( options.autoFill && ($input.val().toLowerCase() == q.toLowerCase()) ) autoFill(data[0][0]); |
|
473 |
showResults(); |
|
474 |
} else { |
|
475 |
hideResultsNow(); |
|
476 |
} |
|
477 |
}; |
|
478 |
||
479 |
function parseData(data) { |
|
480 |
if (!data) return null; |
|
481 |
var parsed = parseJSON(data); |
|
482 |
return parsed; |
|
483 |
}; |
|
484 |
||
485 |
function dataToDom(data) { |
|
486 |
var ul = document.createElement("table"); |
|
487 |
$(ul).attr("border", "0").attr("cellspacing", "1").attr("cellpadding", "3"); |
|
488 |
var num = data.length; |
|
489 |
||
490 |
if ( options.tableHeader ) |
|
491 |
{ |
|
492 |
ul.innerHTML = options.tableHeader; |
|
493 |
} |
|
494 |
||
495 |
if ( num == 0 ) |
|
496 |
{ |
|
497 |
// not showing any results |
|
498 |
if ( options.noResultsHTML ) |
|
499 |
ul.innerHTML += options.noResultsHTML; |
|
500 |
||
501 |
hasNoResults = true; |
|
502 |
return ul; |
|
503 |
} |
|
504 |
||
505 |
// limited results to a max number |
|
506 |
if( (options.maxItemsToShow > 0) && (options.maxItemsToShow < num) ) num = options.maxItemsToShow; |
|
507 |
||
508 |
for (var i=0; i < num; i++) { |
|
509 |
var row = data[i]; |
|
510 |
if (!row) continue; |
|
511 |
||
512 |
if ( typeof(row[0]) != 'string' ) |
|
513 |
{ |
|
514 |
// last ditch resort if it's a 1.1.4 autocomplete plugin that doesn't provide an automatic result. |
|
515 |
// hopefully this doesn't slow it down a lot. |
|
516 |
for ( var i in row ) |
|
517 |
{ |
|
518 |
if ( i == "0" || i == 0 ) |
|
519 |
break; |
|
520 |
row[0] = row[i]; |
|
521 |
break; |
|
699
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
522 |
} |
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
523 |
} |
787 | 524 |
|
525 |
var li = document.createElement("tr"); |
|
526 |
var td = document.createElement("td"); |
|
527 |
td.selectValue = row[0]; |
|
528 |
$(td).addClass('row1'); |
|
529 |
$(td).css("font-size", "smaller"); |
|
530 |
||
531 |
if ( options.formatItem ) |
|
699
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
532 |
{ |
787 | 533 |
td.innerHTML = options.formatItem(row, i, num); |
701
dd80cde96a6c
Autocomplete further stabilized. Made Special:PasswordReset and Special:Register prevent use if logged in.
Dan
parents:
699
diff
changeset
|
534 |
} |
dd80cde96a6c
Autocomplete further stabilized. Made Special:PasswordReset and Special:Register prevent use if logged in.
Dan
parents:
699
diff
changeset
|
535 |
else |
dd80cde96a6c
Autocomplete further stabilized. Made Special:PasswordReset and Special:Register prevent use if logged in.
Dan
parents:
699
diff
changeset
|
536 |
{ |
787 | 537 |
td.innerHTML = row[0]; |
699
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
538 |
} |
787 | 539 |
li.appendChild(td); |
540 |
ul.appendChild(li); |
|
699
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
541 |
|
787 | 542 |
$(td).hover( |
543 |
function() { $("tr", ul).removeClass("row2"); $(this).addClass("row2"); active = $("tr", ul).indexOf($(this).get(0)); }, |
|
544 |
function() { $(this).removeClass("row2"); } |
|
545 |
).click(function(e) { |
|
546 |
e.preventDefault(); |
|
547 |
e.stopPropagation(); |
|
548 |
selectItem(this) |
|
549 |
}); |
|
550 |
} |
|
551 |
||
552 |
$(ul).mousedown(function() { |
|
553 |
mouseDownOnSelect = true; |
|
554 |
}).mouseup(function() { |
|
555 |
mouseDownOnSelect = false; |
|
556 |
}); |
|
557 |
return ul; |
|
558 |
}; |
|
559 |
||
560 |
function requestData(q) { |
|
561 |
if (!options.matchCase) q = q.toLowerCase(); |
|
562 |
var data = options.cacheLength ? loadFromCache(q) : null; |
|
563 |
// recieve the cached data |
|
564 |
if (data) { |
|
565 |
receiveData(q, data); |
|
566 |
// if an AJAX url has been supplied, try loading the data now |
|
567 |
} else if( (typeof options.url == "string") && (options.url.length > 0) ){ |
|
568 |
$.get(makeUrl(q), function(data) { |
|
569 |
data = parseData(data); |
|
570 |
addToCache(q, data); |
|
571 |
receiveData(q, data); |
|
572 |
}); |
|
573 |
// if there's been no data found, remove the loading class |
|
574 |
} else { |
|
575 |
$input.removeClass(options.loadingClass); |
|
576 |
} |
|
577 |
}; |
|
578 |
||
579 |
function makeUrl(q) { |
|
580 |
var sep = options.url.indexOf('?') == -1 ? '?' : '&'; |
|
581 |
var url = options.url + encodeURI(q); |
|
582 |
for (var i in options.extraParams) { |
|
583 |
url += "&" + i + "=" + encodeURI(options.extraParams[i]); |
|
584 |
} |
|
585 |
return url; |
|
586 |
}; |
|
587 |
||
588 |
function loadFromCache(q) { |
|
589 |
if (!q) return null; |
|
590 |
if (cache.data[q]) return cache.data[q]; |
|
591 |
if (options.matchSubset) { |
|
592 |
for (var i = q.length - 1; i >= options.minChars; i--) { |
|
593 |
var qs = q.substr(0, i); |
|
594 |
var c = cache.data[qs]; |
|
595 |
if (c) { |
|
596 |
var csub = []; |
|
597 |
for (var j = 0; j < c.length; j++) { |
|
598 |
var x = c[j]; |
|
599 |
var x0 = x[0]; |
|
600 |
if (matchSubset(x0, q)) { |
|
601 |
csub[csub.length] = x; |
|
602 |
} |
|
603 |
} |
|
604 |
return csub; |
|
699
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
605 |
} |
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
606 |
} |
787 | 607 |
} |
608 |
return null; |
|
609 |
}; |
|
610 |
||
611 |
function matchSubset(s, sub) { |
|
612 |
if (!options.matchCase) s = s.toLowerCase(); |
|
613 |
var i = s.indexOf(sub); |
|
614 |
if (i == -1) return false; |
|
615 |
return i == 0 || options.matchContains; |
|
616 |
}; |
|
617 |
||
618 |
this.flushCache = function() { |
|
619 |
flushCache(); |
|
620 |
}; |
|
621 |
||
622 |
this.setExtraParams = function(p) { |
|
623 |
options.extraParams = p; |
|
624 |
}; |
|
625 |
||
626 |
this.findValue = function(){ |
|
627 |
var q = $input.val(); |
|
628 |
||
629 |
if (!options.matchCase) q = q.toLowerCase(); |
|
630 |
var data = options.cacheLength ? loadFromCache(q) : null; |
|
631 |
if (data) { |
|
632 |
findValueCallback(q, data); |
|
633 |
} else if( (typeof options.url == "string") && (options.url.length > 0) ){ |
|
634 |
$.get(makeUrl(q), function(data) { |
|
635 |
data = parseData(data) |
|
636 |
addToCache(q, data); |
|
637 |
findValueCallback(q, data); |
|
638 |
}); |
|
639 |
} else { |
|
640 |
// no matches |
|
641 |
findValueCallback(q, null); |
|
642 |
} |
|
643 |
} |
|
644 |
||
645 |
function findValueCallback(q, data){ |
|
646 |
if (data) $input.removeClass(options.loadingClass); |
|
647 |
||
648 |
var num = (data) ? data.length : 0; |
|
649 |
var li = null; |
|
650 |
||
651 |
for (var i=0; i < num; i++) { |
|
652 |
var row = data[i]; |
|
653 |
||
654 |
if( row[0].toLowerCase() == q.toLowerCase() ){ |
|
655 |
li = document.createElement("li"); |
|
656 |
if (options.formatItem) { |
|
657 |
li.innerHTML = options.formatItem(row, i, num); |
|
658 |
li.selectValue = row[0]; |
|
659 |
} else { |
|
660 |
li.innerHTML = row[0]; |
|
661 |
li.selectValue = row[0]; |
|
699
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
662 |
} |
787 | 663 |
var extra = null; |
664 |
if( row.length > 1 ){ |
|
665 |
extra = []; |
|
666 |
for (var j=1; j < row.length; j++) { |
|
667 |
extra[extra.length] = row[j]; |
|
701
dd80cde96a6c
Autocomplete further stabilized. Made Special:PasswordReset and Special:Register prevent use if logged in.
Dan
parents:
699
diff
changeset
|
668 |
} |
dd80cde96a6c
Autocomplete further stabilized. Made Special:PasswordReset and Special:Register prevent use if logged in.
Dan
parents:
699
diff
changeset
|
669 |
} |
787 | 670 |
li.extra = extra; |
699
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
671 |
} |
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
672 |
} |
787 | 673 |
|
674 |
if( options.onFindValue ) setTimeout(function() { options.onFindValue(li) }, 1); |
|
675 |
} |
|
676 |
||
677 |
function addToCache(q, data) { |
|
678 |
if (!data || !q || !options.cacheLength) return; |
|
679 |
if (!cache.length || cache.length > options.cacheLength) { |
|
680 |
flushCache(); |
|
681 |
cache.length++; |
|
682 |
} else if (!cache[q]) { |
|
683 |
cache.length++; |
|
699
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
684 |
} |
787 | 685 |
cache.data[q] = data; |
686 |
}; |
|
687 |
||
688 |
function findPos(obj) { |
|
689 |
var curleft = obj.offsetLeft || 0; |
|
690 |
var curtop = obj.offsetTop || 0; |
|
691 |
while (obj = obj.offsetParent) { |
|
692 |
curleft += obj.offsetLeft |
|
693 |
curtop += obj.offsetTop |
|
699
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
694 |
} |
787 | 695 |
return {x:curleft,y:curtop}; |
699
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
696 |
} |
787 | 697 |
} |
698 |
||
699 |
jQuery.fn.autocomplete = function(url, options, data) { |
|
700 |
// Make sure options exists |
|
701 |
options = options || {}; |
|
702 |
// Set url as option |
|
703 |
options.url = url; |
|
704 |
// set some bulk local data |
|
705 |
options.data = ((typeof data == "object") && (data.constructor == Array)) ? data : null; |
|
706 |
||
707 |
// Set default values for required options |
|
708 |
options = $.extend({ |
|
709 |
inputClass: "ac_input", |
|
710 |
resultsClass: "ac_results", |
|
711 |
lineSeparator: "\n", |
|
712 |
cellSeparator: "|", |
|
713 |
minChars: 1, |
|
714 |
delay: 400, |
|
715 |
matchCase: 0, |
|
716 |
matchSubset: 1, |
|
717 |
matchContains: 0, |
|
718 |
cacheLength: false, |
|
719 |
mustMatch: 0, |
|
720 |
extraParams: {}, |
|
721 |
loadingClass: "ac_loading", |
|
722 |
selectFirst: false, |
|
723 |
selectOnly: false, |
|
724 |
maxItemsToShow: -1, |
|
725 |
autoFill: false, |
|
726 |
showWhenNoResults: false, |
|
727 |
width: 0 |
|
728 |
}, options); |
|
729 |
options.width = parseInt(options.width, 10); |
|
730 |
||
731 |
this.each(function() { |
|
732 |
var input = this; |
|
733 |
new jQuery.autocomplete(input, options); |
|
734 |
}); |
|
735 |
||
736 |
// Don't break the chain |
|
737 |
return this; |
|
738 |
} |
|
739 |
||
740 |
jQuery.fn.autocompleteArray = function(data, options) { |
|
741 |
return this.autocomplete(null, options, data); |
|
742 |
} |
|
743 |
||
744 |
jQuery.fn.indexOf = function(e){ |
|
745 |
for( var i=0; i<this.length; i++ ){ |
|
746 |
if( this[i] == e ) return i; |
|
699
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
687
diff
changeset
|
747 |
} |
787 | 748 |
return -1; |
749 |
}; |
|
750 |
||
751 |
autofill_onload(); |
|
752 |
}; |
|
753 |
||
754 |
addOnloadHook(autofill_init); |