閉め切られた!

静的自動補完への道
http://oshiete.goo.ne.jp/qa/7873896.html

明日以降に持ち越し&質問者は逃げたな。

<!DOCTYPE html>
<title></title>
<meta charset="UTF-8">
<style>
</style>

<body>
<form action="#">
<p>
 <input type="text" name="hoge" value="">
</p>
</form>


<script type="text/javascript">

var v = [
 ['Mac Air', 'apple', 'air', 'mac note'],
 ['Macintosh', 'apple', 'mac'],
 ['Mac mini', 'apple', 'mac', 'mini'],
 ['google', 'グーグル', 'ぐーぐる'],
 ['ごん蔵', 'ごんぞう', 'gonzou']
];


(function () {
 if(!Array.prototype.map)
  Array.prototype.map=
   function(b,e){
    var c=this.length;
    if(typeof b!="function")throw new TypeError;
    for(var d=Array(c),a=0;a<c;a++)
     a in this&&(d[a]=b.call(e,this[a],a,this));return d
    };

 //________
 
 function Referee (list) {
  this.list = list;
 }
 
 
 function getList (key) {
  var cb = { result: [], length: key.length, key: key, keyLow: key.toLowerCase ()} ;
  this.list.map (wordCheck, cb);
  return cb.result.sort (oerder).map (firstValue);
 }
 

 function wordCheck (list) {
  (this.key === list[0])
  ? this.result.push ([list[0], 1])
  : list.map (secondLatterCheck, (this.word = list[0], this));
 }
 
 
 function secondLatterCheck (word) {
  if (0 === word.indexOf (this.keyLow))
   this.result.push ([this.word, this.length / word.length]);
 }

 function firstValue (ary) { return ary[0] }
 
 function toLowerCase (str) { return String (str).toLowerCase () }
 
 function oerder (a, b) { return a[1] === b[1] ? 0: b[1] - a[1] }
 
 function create (list) {
  if (1 > arguments.length)
   return null;
  return new Referee (list);
 }
 
 //____________
 
 Referee.prototype.getList = getList;
 Referee.create = create;

 this.Referee = Referee;
}) ();


(function () {
  if(!Array.prototype.some)
    Array.prototype.some=function(b,c){
	  var d=this.length;if(typeof b!="function")throw new TypeError;
	  for(var a=0;a<d;a++)if(a in this&&b.call(c,this[a],a,this))return true;
	  return false};

  if(!Array.prototype.indexOf)
    Array.prototype.indexOf=function(){
	var c=Math.ceil,d=Math.floor;
	return function(e,f){
	  var b=this.length,a=Number(f)||0,a=0>a?c(a):d(a);
	  for(0>a&&(a+=b);a<b;++a)if(a in this&&this[a]===e)return a;
	  return-1}};

//_____________
  
  function Singleton () {
    this.target = [];
    this.option = [];
  }


  function contains (/*target, target2, ..*/) {
    return Array.prototype.some.call (arguments, function (target) {
      return (-1 < this.indexOf (target)); }, this.target);
  }


  function add (target, option) {
    if (! contains.call (this, target)) {
      this.target.push (target);
      this.option.push (option);
    }
  }


  function getOption (target) {
    var index = this.target.indexOf (target);
    return (-1 < index) ? this.option[index]: null;
  }


  //______________________________

  function create () {
    var obj = new Singleton;
    var func = new Function;
    
    func.contains =
      function () { return contains.apply (obj, arguments); };
    
    func.add =
      function () { add.apply (obj, arguments); };
	
	func.getOption =
	  function () { return getOption.apply (obj, arguments); };
	
	return func;
  }
    
  //______________________________

  Singleton.create = create;

  this.Singleton = Singleton;
})();


(function () {
  var KEY_WAIT = 350;//ms

  function Auxiliary (target, referee) {
    this.target = target;
	this.referee = referee;
	this.timerId = null;
  }
  
  
  function listView () {
    alert (this.referee.getList(this.target.value));
	this.timerId = null;
  }
  
  function focus (event) {
    if (! this.timerId){
	  var that = this;
	  var cbFunc = function () { listView.call (that); };
	  this.timerId = setTimeout (cbFunc, KEY_WAIT);
	}
  }
  
  

  function dispatchEvent (event) {
    switch (event.type) {
	case 'focusin' : case 'focus' :
	  focus.call (this, event);
	  break;
	
	
	} 
  }
  
  function create (target, list) {
    return new Auxiliary (target, Referee.create (list));
  }

  //___________
   
  
  Auxiliary.prototype.dispatchEvent = dispatchEvent;

  Auxiliary.create = create;
  
  this.Auxiliary = Auxiliary;
}) ();


(function () { //@cc_on @set @mode = (@_jscript_version < 9);
  var buffer = Singleton.create ();

  var AuxiliaryInput = new Function;
  
  function listener (event) {
    if (AuxiliaryInput.disabled)
      return null;

	var target = event./*@if (@mode) srcElement @else@*/ target /*@end@*/;
	if (buffer.contains (target)) {
	  (buffer.getOption (target)).dispatchEvent (event);
	}
  }
  

  function add (target, list) {
    if (2 > arguments.length)
	  return false;
    buffer.add (target, Auxiliary.create (target, list));
  }
  
  
  function init () {
    document./*@if (@mode) attachEvent('on' + @else@*/ addEventListener(/*@end@*/
             /*@if (@mode) 'focusin' @else@*/ 'focus' /*@end@*/, listener, true);
      
    document./*@if (@mode) attachEvent('on' + @else@*/ addEventListener(/*@end@*/
             /*@if (@mode) 'focusout' @else@*/ 'blur' /*@end@*/, listener, true);
  }
  
  
  AuxiliaryInput.add = add;
  AuxiliaryInput.init = init;
  AuxiliaryInput.disabled = false;
  
  this.AuxiliaryInput = AuxiliaryInput;
}) ();

AuxiliaryInput.init ();
AuxiliaryInput.add (document.querySelector ('form input[name="hoge"]'), v);

var s = Singleton.create ();

</script>