includes/clientside/static/autofill.js
author Dan
Sat, 19 Jul 2008 20:47:00 -0400
changeset 645 24f2fa13a2a0
parent 582 a38876c0793c
child 647 6bb3d447b4b8
permissions -rw-r--r--
Fixed autofill ignoring existing ID for text box parent node. Note that autofill is still in a nonworking state.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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');
645
24f2fa13a2a0 Fixed autofill ignoring existing ID for text box parent node. Note that autofill is still in a nonworking state.
Dan
parents: 582
diff changeset
    35
    if ( !wrapper.id )
24f2fa13a2a0 Fixed autofill ignoring existing ID for text box parent node. Note that autofill is still in a nonworking state.
Dan
parents: 582
diff changeset
    36
      wrapper.id = 'autofill_wrap_' + element.id;
184
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    37
    
581
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
    38
    // 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
    39
    wrapper.innerHTML = template + wrapper.innerHTML;
184
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    40
    
645
24f2fa13a2a0 Fixed autofill ignoring existing ID for text box parent node. Note that autofill is still in a nonworking state.
Dan
parents: 582
diff changeset
    41
    var autosuggest = new Spry.Widget.AutoSuggest(wrapper.id, element.id + '_region', window[ds_name], 'name', {loadFromServer: true, urlParam: 'userinput', hoverSuggestClass: 'row2', minCharsType: 3});
582
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
    42
    var regiondiv = document.getElementById(element.id + '_region');
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
    43
    regiondiv.style.position = 'absolute';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
    44
    regiondiv.style.top = top + 'px';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
    45
    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
    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
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
    49
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
    50
{
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
    51
  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
    52
    return false;
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
    53
  
582
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
    54
  if ( !Spry.Data );
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
    55
    load_spry_data();
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
    56
  
581
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
    57
  params = params || {};
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
    58
  // 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
    59
  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
    60
  {
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
    61
    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
    62
  }
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
    63
  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
    64
  
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
    65
  // 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
    66
  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
    67
  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
    68
  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
    69
  
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
    70
  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
    71
  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
    72
  {
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
    73
    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
    74
  }
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
    75
  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
    76
  
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
    77
  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
    78
}
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
    79
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
    80
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
    81
{
582
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
    82
  if ( this.loaded )
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
    83
  {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
    84
    return true;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
    85
  }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
    86
  
581
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
    87
  autofill_schemas.username = {
582
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
    88
    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
    89
              '  <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
    90
              '    <tr>' + "\n" +
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
    91
              '      <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
    92
              '    </tr>' + "\n" +
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
    93
              '    <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
    94
              '      <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
    95
              '    </tr>' + "\n" +
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
    96
              '  </table>' + "\n" +
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
    97
              '</div>',
184
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    98
    
581
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
    99
    init: function(element, fillclass, params)
184
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   100
    {
581
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
   101
      // 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
   102
      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
   103
      var left = $dynano(element).Left();
184
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   104
      
581
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
   105
      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
   106
      // setup the dataset
582
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
   107
      if ( !window.autofill_ds_username )
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
   108
      {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
   109
        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
   110
      }
581
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
      // 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
   113
      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
   114
      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
   115
      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
   116
      
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
   117
      // 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
   118
      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
   119
      
582
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
   120
      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
   121
      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
   122
      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
   123
      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
   124
      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
   125
    }
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
   126
  };
184
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   127
  
581
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
   128
  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
   129
    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
   130
              '  <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
   131
              '    <tr>' + "\n" +
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
   132
              '      <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
   133
              '    </tr>' + "\n" +
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
   134
              '    <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
   135
              '      <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
   136
              '    </tr>' + "\n" +
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
   137
              '  </table>' + "\n" +
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
   138
              '</div>'
184
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   139
  }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   140
  
581
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
   141
  var inputs = document.getElementsByClassName('input', 'autofill');
184
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   142
  
582
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
   143
  if ( inputs.length > 0 )
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
   144
  {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
   145
    // 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
   146
    // is spry data loaded?
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
   147
    if ( !Spry.Data )
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
   148
    {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
   149
      load_spry_data();
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
   150
      return true;
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
  
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
   154
  this.loaded = true;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
   155
  
581
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
   156
  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
   157
  {
581
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
   158
    autofill_init_element(inputs[i]);
184
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   159
  }
581
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
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
   162
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
   163
582
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
   164
function autofill_force_region_refresh()
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
   165
{
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
   166
  Spry.Data.initRegions();
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
   167
}
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
   168
581
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
   169
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
   170
{
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
   171
  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
   172
  
581
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
   173
  element.className = 'autofill username';
184
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   174
  
581
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
   175
  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
   176
  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
   177
      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
   178
    });
184
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   179
}
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   180
582
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
   181
// load spry data components
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
   182
function load_spry_data()
184
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   183
{
582
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
   184
  var scripts = [ 'SpryData.js', 'SpryJSONDataSet.js', 'SpryAutoSuggest.js' ];
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
   185
  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
   186
  {
582
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
   187
    load_component(scripts[i]);
184
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   188
  }
582
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
   189
  autofill_onload();
184
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   190
}