includes/clientside/static/autofill.js
author Dan
Tue, 22 Jul 2008 17:00:54 -0500
changeset 653 3ea1c552e734
parent 649 74e03196fd43
child 687 ea43ac1ff2ee
permissions -rw-r--r--
Fixed installer path check in Admin:Home; made admin-menu more compatible with componentized JS
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
649
74e03196fd43 Fixed typo (missing equals sign) in allow_anon param to autofill username
Dan
parents: 647
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
{
582
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
    51
  if ( !Spry.Data );
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
    52
    load_spry_data();
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
    53
  
581
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
    54
  params = params || {};
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
    55
  // 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
    56
  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
    57
  {
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
    58
    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
    59
  }
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
    60
  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
    61
  
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
    62
  // 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
    63
  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
    64
  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
    65
  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
    66
  
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
    67
  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
    68
  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
    69
  {
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
    70
    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
    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(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
    73
  
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
    74
  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
    75
}
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
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
    78
{
582
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
    79
  if ( this.loaded )
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
    80
  {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
    81
    return true;
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
  
581
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
    84
  autofill_schemas.username = {
582
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
    85
    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
    86
              '  <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
    87
              '    <tr>' + "\n" +
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
    88
              '      <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
    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
              '    <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
    91
              '      <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
    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
              '  </table>' + "\n" +
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
    94
              '</div>',
184
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    95
    
581
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
    96
    init: function(element, fillclass, params)
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
      // 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
    99
      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
   100
      var left = $dynano(element).Left();
184
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   101
      
581
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
   102
      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
   103
      // setup the dataset
582
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
   104
      if ( !window.autofill_ds_username )
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
   105
      {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
   106
        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
   107
      }
581
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
   108
      
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
   109
      // 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
   110
      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
   111
      var wrapper = element.parentNode; // document.createElement('div');
647
6bb3d447b4b8 Fixed autofill ignoring existing ID for text box parent node. (yes, again)
Dan
parents: 645
diff changeset
   112
      if ( !wrapper.id )
6bb3d447b4b8 Fixed autofill ignoring existing ID for text box parent node. (yes, again)
Dan
parents: 645
diff changeset
   113
        wrapper.id = 'autofill_wrap_' + element.id;
581
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
   114
      
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
   115
      // 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
   116
      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
   117
      
647
6bb3d447b4b8 Fixed autofill ignoring existing ID for text box parent node. (yes, again)
Dan
parents: 645
diff changeset
   118
      var autosuggest = new Spry.Widget.AutoSuggest(wrapper.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
   119
      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
   120
      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
   121
      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
   122
      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
   123
    }
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
   124
  };
184
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   125
  
581
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
   126
  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
   127
    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
   128
              '  <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
   129
              '    <tr>' + "\n" +
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
   130
              '      <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
   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
              '    <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
   133
              '      <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
   134
              '    </tr>' + "\n" +
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
   135
              '  </table>' + "\n" +
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
   136
              '</div>'
184
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   137
  }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   138
  
581
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
   139
  var inputs = document.getElementsByClassName('input', 'autofill');
184
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   140
  
582
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
   141
  if ( inputs.length > 0 )
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
   142
  {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
   143
    // 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
   144
    // is spry data loaded?
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
   145
    if ( !Spry.Data )
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
   146
    {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
   147
      load_spry_data();
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
   148
      return true;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
   149
    }
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
  this.loaded = true;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
   153
  
581
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
   154
  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
   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
    autofill_init_element(inputs[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
}
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
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
   161
582
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
   162
function autofill_force_region_refresh()
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
   163
{
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
   164
  Spry.Data.initRegions();
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
581
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
   167
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
   168
{
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
   169
  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
   170
  
581
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents: 550
diff changeset
   171
  element.className = 'autofill username';
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
  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
   174
  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
   175
      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
   176
    });
184
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   177
}
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   178
582
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
   179
// load spry data components
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
   180
function load_spry_data()
184
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   181
{
582
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
   182
  var scripts = [ 'SpryData.js', 'SpryJSONDataSet.js', 'SpryAutoSuggest.js' ];
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
   183
  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
   184
  {
582
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
   185
    load_component(scripts[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
  autofill_onload();
184
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   188
}