Sixtest Wiki:API3/SearchSuggest

window.TWAPI.addExt("SearchSuggest"); /* temporary */ window.TWAPI.SearchSuggest.addFunc({	   "data": {	       "item": (function  { var type, data = window.TWAPI.Item.Data, output = [], element; // ??? type for what? for (element in data) { if (data.hasOwnProperty(element)) { output[output.length] = element; }				}				return output; })		}	});	window.TWAPI.SearchSuggest.addFunc({		"searchSuggest": function {		    //console.log('searchSuggest ok');			var e = TWAPI.uiElements.SS_Search, input_new = e.value;			if (TWAPI.SearchSuggest.input === undefined && e !== undefined) {				TWAPI.SearchSuggest.input = e.value;			} else if (input_new !== TWAPI.SearchSuggest.input) {				TWAPI.SearchSuggest.input = input_new;				TWAPI.SearchSuggest.suggest(input_new);			}		},		"suggest": function (term) {		    //console.log('suggest ok');			var data = TWAPI.SearchSuggest.cache[term.length][term], s = TWAPI.uiElements.SS_Results;			TWAPI.SearchSuggest.display(s, data);		},		"display": function (p, item) {		    //console.log('display ok');			while (p.hasChildNodes) { // remove all child elements from suggestions container				p.removeChild(p.lastChild);			}			var e = document.createElement('div'), a = {}, v;			for (v in item) {				if (item.hasOwnProperty(v)) { a[v] = document.createElement('div'); a[v].appendChild(document.createTextNode(item[v])); e.appendChild(a[v]); }			}			p.appendChild(e); },		"cache": (function {		    //console.log('cache ok');			var cache = [{}], s = 1, items = window.TWAPI.SearchSuggest.data.item, len = items.length, i, activeItem, activeItemLen, j, stringIndex, c, k, str;			for (s; s < 33; s += 1) {				i = 0;				stringIndex = {};				for (i; i < len; i += 1) {					activeItem = items[i].toLowerCase;					activeItemLen = activeItem.length;					j = 0;					for (j; j < activeItemLen; j += 1) {						if (j + s <= activeItemLen) {							k = 0;							str = '';							for (k; k < s; k += 1) {								str += activeItem.charAt(j + k);							}							if (stringIndex[str] === undefined) {								stringIndex[str] = [];							}							stringIndex[str][stringIndex[str].length] = items[i];						}					}				}				cache[s] = stringIndex;			}			return cache;		}) }); window.TWAPI.SearchSuggest.addUI({ "SS_Search": { "element": "input", "parent": "Content", "properties": { "onkeyup": window.TWAPI.SearchSuggest.searchSuggest }	},	"SS_Results": { "element": "div", "parent": "Content" },	"SS_Results_C1": { "element": "div", "parent": "SS_Results", } });