[js] php.net function completion bij search

Pagina: 1
Acties:

  • HurrI
  • Registratie: Maart 2001
  • Laatst online: 19-06 15:04

HurrI

No fear... I is here

Topicstarter
sinds 4 nov heeft http://www.php.net een nieuwe functie op haar zoekmachine geintroduceerd. Als je de zoekmachine aldaar op function list zet en je geeft een deel van een functie in het textfield zal er een lijstje met mogelijke functies verschijnen.

Ik vond dit wel een grappige feature en kon niet zo 123 bedenken hoe ze dat gedaan hebben en ben dus ff gaan snuffelen in de code. Koude kermis. Het script ( http://www.php.net/functions.js ) is deels encrypted, en niet naar het bekende truukje, hex-code. Ik kon er via zoekmachines niet veel over vinden, dus ik ben erg benieuwd wat deze encryptie is (en dan uiteindelijk natuurlijk hoe die function completion werkt :p). Heeft iemand een id?

Ohja, de functie zit op dit moment alleen op de zoek pagina zelf, niet op de zoek functie op de frontpage. De zoek pagina vind je op: http://www.php.net/search.php

[ Voor 11% gewijzigd door HurrI op 11-11-2003 01:36 ]

If it's just us, it seems like an awful waste of space


  • Pelle
  • Registratie: Januari 2001
  • Laatst online: 19-08 21:19

Pelle

🚴‍♂️

Ik vermoed dat ze ergens een array hebben met functie-namen, en bij een onkeyup-event daar doorheen loopen om te checken of de substring (lengte 1 tot lengte van textveld-waarde) van die functienamen overeenkomt met die textveld-waarde. Zo ja, plak een divje en stop ze er allemaal in.
Vang de up/down keys af en verschuif zo de 'focus' op die div (door een class ofzo aan te passen). Doe tenslotte de textveld-value completen naar de gefocusde waarde en je bent klaar :)

  • Pelle
  • Registratie: Januari 2001
  • Laatst online: 19-08 21:19

Pelle

🚴‍♂️

Btw, topic mag open blijven onder voorwaarde dat dit GEEN scriptrequest achtige sporen gaat vertonen.

Verwijderd

Misschien kun je hier wat mee:


HTML:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<html>
<head>

</head>
<body>

Values to search from:<BR>
<script type=text/javascript>
var _values = ["one","two","three","four","five","fireman","firstplace","first place","oneton"]
for (i in _values)
document.write(" "+_values[i]);
document.write("<BR>");
var _lastValue='';

function replaceText(_v)
{
  var _count = 0;// number of different strings pattern was found in.
  var _index = -1;// index in the array of the item found.
  var _str = "";// the new value in the text-box
  var _tempArray = new Array();
  if (document.f1.t1.value) _str = document.f1.t1.value;
  if (_lastValue == _str) return;// nothing need be done
  if (_lastValue.length>_str.length) {_lastValue=_str;return;}// deleted a char
  for (i in _values) {
   // is this new value in one of the items in the array?
   // (it must start at the begining of the item'string)
    if (_values[i].indexOf(_str) == 0) {
      _tempArray[_tempArray.length] = _values[i];
      _count++;
      _index = i;
      }
  }
  if (_index >= 0 && _index < _values.length && _count>0) {
    if (_count == 1) {
      _str = _values[_index];
    } else {
      _str = _values[_index].substring(0,lenToUse(_tempArray));
    }
    document.f1.t1.value=_str;
    _lastValue = _str;
  }

}// this returns an integer that represents the length of
  // the given strings in _index where all parameters are// equal up to
  // 1 -> first char's match only.// 0 -> no match.

function lenToUse(_list)
{
  var mismatchFound = false;
  var _return = 0;
  var _shortestLength = 99;
  for (i=0;i<_list.length;i++) {
   // find out the shortest string's length
    if (_list[i].length < _shortestLength)
      _shortestLength = _list[i].length;
  }
  for (i=0;i<_shortestLength;i++) {
   // see if each charater in all _list's strings are equal intil their are
// not - then that is the return value.
    _matchStr = _list[0].substring(i,i+1);
    for (j=1;j<_list.length;j++) {
      if (_list[j].substring(i,i+1) != _matchStr) {
        if (!mismatchFound)// only track upto the first time a mismatch is found.
          _return = i-1;// last round was succesful.
        mismatchFound = true;
      }
    }
    if (!mismatchFound) {
      _return = i;
    }
  }
  return (_return+1);// this makes the return value start at 1 for first position
}

function compute(e) {
  setTimeout('replaceText()',30);// 30 msecs later...
}
</script>
<form name="f1">
<input name="t1" type="text" onKeyPress="compute()" value="">
</form>

</body>
</html>