author | Dan |
Wed, 09 Jul 2008 21:02:28 -0400 | |
changeset 618 | 587b393f1e5e |
parent 582 | a38876c0793c |
child 645 | 24f2fa13a2a0 |
permissions | -rw-r--r-- |
184
d74ff822acc9
Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff
changeset
|
1 |
/** |
263
d57af0b0302e
Major improvements in the security of the CAPTCHA system (no SQL injection or anything like that); fixed denied form submission due to _af_acting on form object wrongly switched to true
Dan
parents:
184
diff
changeset
|
2 |
* Javascript auto-completion for form fields. This supercedes the code in autocomplete.js for MOZILLA ONLY. It doesn't seem to work real |
d57af0b0302e
Major improvements in the security of the CAPTCHA system (no SQL injection or anything like that); fixed denied form submission due to _af_acting on form object wrongly switched to true
Dan
parents:
184
diff
changeset
|
3 |
* well with other browsers yet. |
184
d74ff822acc9
Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff
changeset
|
4 |
*/ |
581
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
5 |
|
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
6 |
// fill schemas |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
7 |
var autofill_schemas = {}; |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
8 |
|
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
9 |
// default, generic schema |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
10 |
autofill_schemas.generic = { |
582
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
11 |
template: '<div id="--ID--_region" spry:region="autofill_ds_--CLASS--" class="tblholder">' + "\n" + |
581
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
12 |
' <table border="0" cellspacing="1" cellpadding="3" style="font-size: smaller;">' + "\n" + |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
13 |
' <tr spry:repeat="autofill_region_--ID--">' + "\n" + |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
14 |
' <td class="row1" spry:suggest="{name}">{name}</td>' + "\n" + |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
15 |
' </tr>' + "\n" + |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
16 |
' </table>' + "\n" + |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
17 |
'</div>', |
184
d74ff822acc9
Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff
changeset
|
18 |
|
581
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
19 |
init: function(element, fillclass) |
184
d74ff822acc9
Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff
changeset
|
20 |
{ |
582
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
21 |
// calculate positions before spry f***s everything up |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
22 |
var top = $dynano(element).Top() + $dynano(element).Height() - 10; // tblholder has 10px top margin |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
23 |
var left = $dynano(element).Left(); |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
24 |
|
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
25 |
// dataset name |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
26 |
var ds_name = 'autofill_ds_' + fillclass; |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
27 |
|
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
28 |
var allow_anon = ( params.allow_anon ) ? '1' : '0'; |
581
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
29 |
// setup the dataset |
582
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
30 |
window[ds_name] = new Spry.Data.JSONDataSet(makeUrlNS('Special', 'Autofill', 'type=' + fillclass + '&allow_anon' + allow_anon)); |
184
d74ff822acc9
Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff
changeset
|
31 |
|
581
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
32 |
// inject our HTML wrapper |
582
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
33 |
var template = this.template.replace(new RegExp('--ID--', 'g'), element.id).replace(new RegExp('--CLASS--', 'g', fillclass)); |
581
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
34 |
var wrapper = element.parentNode; // document.createElement('div'); |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
35 |
wrapper.id = 'autofill_wrap_' + element.id; |
184
d74ff822acc9
Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff
changeset
|
36 |
|
581
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
37 |
// a bunch of hacks to add a spry wrapper |
582
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
38 |
wrapper.innerHTML = template + wrapper.innerHTML; |
184
d74ff822acc9
Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff
changeset
|
39 |
|
582
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
40 |
var autosuggest = new Spry.Widget.AutoSuggest("autofill_wrap_" + element.id, element.id + '_region', window[ds_name], 'name', {loadFromServer: true, urlParam: 'userinput', hoverSuggestClass: 'row2', minCharsType: 3}); |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
41 |
var regiondiv = document.getElementById(element.id + '_region'); |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
42 |
regiondiv.style.position = 'absolute'; |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
43 |
regiondiv.style.top = top + 'px'; |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
44 |
regiondiv.style.left = left + 'px'; |
581
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
45 |
} |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
46 |
}; |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
47 |
|
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
48 |
function autofill_init_element(element, params) |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
49 |
{ |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
50 |
if ( element.parentNode.id.match(/^autofill_wrap_/) ) |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
51 |
return false; |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
52 |
|
582
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
53 |
if ( !Spry.Data ); |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
54 |
load_spry_data(); |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
55 |
|
581
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
56 |
params = params || {}; |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
57 |
// 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
|
58 |
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
|
59 |
{ |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
60 |
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
|
61 |
} |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
62 |
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
|
63 |
|
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
64 |
// 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
|
65 |
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
|
66 |
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
|
67 |
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
|
68 |
|
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
69 |
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
|
70 |
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
|
71 |
{ |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
72 |
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
|
73 |
} |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
74 |
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
|
75 |
|
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
76 |
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
|
77 |
} |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
78 |
|
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
79 |
var autofill_onload = function() |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
80 |
{ |
582
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
81 |
if ( this.loaded ) |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
82 |
{ |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
83 |
return true; |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
84 |
} |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
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 |
autofill_schemas.username = { |
582
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
87 |
template: '<div id="--ID--_region" spry:region="autofill_ds_username" class="tblholder">' + "\n" + |
581
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
88 |
' <table border="0" cellspacing="1" cellpadding="3" style="font-size: smaller;">' + "\n" + |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
89 |
' <tr>' + "\n" + |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
90 |
' <th>' + $lang.get('user_autofill_heading_suggestions') + '</th>' + "\n" + |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
91 |
' </tr>' + "\n" + |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
92 |
' <tr spry:repeat="autofill_region_--ID--">' + "\n" + |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
93 |
' <td class="row1" spry:suggest="{name}">{name_highlight}<br /><small style="{rank_style}">{rank_title}</small></td>' + "\n" + |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
94 |
' </tr>' + "\n" + |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
95 |
' </table>' + "\n" + |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
96 |
'</div>', |
184
d74ff822acc9
Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff
changeset
|
97 |
|
581
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
98 |
init: function(element, fillclass, params) |
184
d74ff822acc9
Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff
changeset
|
99 |
{ |
581
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
100 |
// calculate positions before spry f***s everything up |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
101 |
var top = $dynano(element).Top() + $dynano(element).Height() - 10; // tblholder has 10px top margin |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
102 |
var left = $dynano(element).Left(); |
184
d74ff822acc9
Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff
changeset
|
103 |
|
581
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
104 |
var allow_anon = ( params.allow_anon ) ? '1' : '0'; |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
105 |
// setup the dataset |
582
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
106 |
if ( !window.autofill_ds_username ) |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
107 |
{ |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
108 |
window.autofill_ds_username = new Spry.Data.JSONDataSet(makeUrlNS('Special', 'Autofill', 'type=' + fillclass + '&allow_anon' + allow_anon)); |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
109 |
} |
581
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
110 |
|
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
111 |
// inject our HTML wrapper |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
112 |
var template = this.template.replace(new RegExp('--ID--', 'g'), element.id); |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
113 |
var wrapper = element.parentNode; // document.createElement('div'); |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
114 |
wrapper.id = 'autofill_wrap_' + element.id; |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
115 |
|
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
116 |
// a bunch of hacks to add a spry wrapper |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
117 |
wrapper.innerHTML = template + wrapper.innerHTML; |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
118 |
|
582
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
119 |
var autosuggest = new Spry.Widget.AutoSuggest("autofill_wrap_" + element.id, element.id + '_region', window.autofill_ds_username, 'name', {loadFromServer: true, urlParam: 'userinput', hoverSuggestClass: 'row2', minCharsType: 3}); |
581
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
120 |
var regiondiv = document.getElementById(element.id + '_region'); |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
121 |
regiondiv.style.position = 'absolute'; |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
122 |
regiondiv.style.top = top + 'px'; |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
123 |
regiondiv.style.left = left + 'px'; |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
124 |
} |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
125 |
}; |
184
d74ff822acc9
Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff
changeset
|
126 |
|
581
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
127 |
autofill_schemas.page = { |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
128 |
template: '<div id="--ID--_region" spry:region="autofill_region_--ID--" class="tblholder">' + "\n" + |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
129 |
' <table border="0" cellspacing="1" cellpadding="3" style="font-size: smaller;">' + "\n" + |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
130 |
' <tr>' + "\n" + |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
131 |
' <th colspan="2">' + $lang.get('page_autosuggest_heading') + '</th>' + "\n" + |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
132 |
' </tr>' + "\n" + |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
133 |
' <tr spry:repeat="autofill_region_--ID--">' + "\n" + |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
134 |
' <td class="row1" spry:suggest="{page_id}">{pid_highlight}<br /><small>{name_highlight}</small></td>' + "\n" + |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
135 |
' </tr>' + "\n" + |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
136 |
' </table>' + "\n" + |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
137 |
'</div>' |
184
d74ff822acc9
Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff
changeset
|
138 |
} |
d74ff822acc9
Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff
changeset
|
139 |
|
581
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
140 |
var inputs = document.getElementsByClassName('input', 'autofill'); |
184
d74ff822acc9
Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff
changeset
|
141 |
|
582
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
142 |
if ( inputs.length > 0 ) |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
143 |
{ |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
144 |
// we have at least one input that needs to be made an autofill element. |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
145 |
// is spry data loaded? |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
146 |
if ( !Spry.Data ) |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
147 |
{ |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
148 |
load_spry_data(); |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
149 |
return true; |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
150 |
} |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
151 |
} |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
152 |
|
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
153 |
this.loaded = true; |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
154 |
|
581
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
155 |
for ( var i = 0; i < inputs.length; i++ ) |
184
d74ff822acc9
Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff
changeset
|
156 |
{ |
581
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
157 |
autofill_init_element(inputs[i]); |
184
d74ff822acc9
Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff
changeset
|
158 |
} |
581
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
159 |
} |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
160 |
|
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
161 |
addOnloadHook(autofill_onload); |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
162 |
|
582
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
163 |
function autofill_force_region_refresh() |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
164 |
{ |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
165 |
Spry.Data.initRegions(); |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
166 |
} |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
167 |
|
581
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
168 |
function AutofillUsername(element, event, allowanon) |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
169 |
{ |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
170 |
element.onkeyup = element.onkeydown = element.onkeypress = function(e) {}; |
184
d74ff822acc9
Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff
changeset
|
171 |
|
581
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
172 |
element.className = 'autofill username'; |
184
d74ff822acc9
Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff
changeset
|
173 |
|
581
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
174 |
allowanon = allowanon ? true : false; |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
175 |
autofill_init_element(element, { |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
176 |
allow_anon: allowanon |
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
550
diff
changeset
|
177 |
}); |
184
d74ff822acc9
Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff
changeset
|
178 |
} |
d74ff822acc9
Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff
changeset
|
179 |
|
582
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
180 |
// load spry data components |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
181 |
function load_spry_data() |
184
d74ff822acc9
Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff
changeset
|
182 |
{ |
582
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
183 |
var scripts = [ 'SpryData.js', 'SpryJSONDataSet.js', 'SpryAutoSuggest.js' ]; |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
184 |
for ( var i = 0; i < scripts.length; i++ ) |
184
d74ff822acc9
Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff
changeset
|
185 |
{ |
582
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
186 |
load_component(scripts[i]); |
184
d74ff822acc9
Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff
changeset
|
187 |
} |
582
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
188 |
autofill_onload(); |
184
d74ff822acc9
Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff
changeset
|
189 |
} |