daily pastebin goal
8%
SHARE
TWEET

Untitled

a guest Apr 16th, 2018 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Element.addMethods('INPUT', {
  2.   autoCompletion: function(input, afterUpdateElement){
  3.     if(!input.ac){
  4.       input.ac = new Ajax.Autocompleter(input, input.id+'_auto_complete', input.getAttribute('src'), {
  5.           method: 'get',
  6.           select: 'value',
  7.           callback: function(element, value){
  8.             document.enabled = true;
  9.             return element.serialize();
  10.           },
  11.           afterUpdateElement: function(input, element){
  12.             input.indicate();
  13.             document.ajaxRequest(input, input.getAttribute('usemap'), 'put', null, input.serialize())
  14.             if(input.hasClassName('clear')) input.value = '';
  15.             if(afterUpdateElement) afterUpdateElement(input, element);
  16.           }
  17.       });
  18.     };
  19.   }
  20. });
  21.  
  22. Element.addMethods({
  23.   observeAutoCompletion: function(element){
  24.     if( !(element = $(element))) return;
  25.     element.select('input.ac').each(function(input){
  26.       // adding autocompletion to that input (needs to observe keypress directly)
  27.       input.autoCompletion();
  28.     });
  29.     // delegate onClick & onMouseMove to that element for all input.autocomplete inside
  30.     if(!element.autoCompletion){
  31.       element.observe('click', autoCompletionClick) // SelectButton
  32.       element.observe('mousemove', autoCompletionMouseMove) // IE6 fix (ScrollBug)
  33.       element.autoCompletion = true;
  34.     };
  35.   },
  36.   unobserveAutoCompletion: function(element){
  37.     if(element.autoCompletion){
  38.       // remove observed Events (autoCompletionClick/ autoCompletionMouseMove/ KEYUP)
  39.       element.stopObserving('click', autoCompletionClick)
  40.       element.stopObserving('mousemove', autoCompletionMouseMove)
  41.       element.select('input.ac').each(function(input){
  42.         input.stopObserving('keyup');
  43.         input.ac = null;
  44.       });
  45.       element.autoCompletion = false;
  46.     };
  47.   }
  48. })
RAW Paste Data
Top