1/* 2var XmlHttp = false; 3 4if ( window.XMLHttpRequest ) 5{ 6 XmlHttp = new XMLHttpRequest(); 7 8} else if ( window.ActiveXObject ) 9{ 10 XmlHttp = new ActiveXObject( 'Microsoft.XMLHTTP' ); 11} 12*/ 13 14// --- 15 16function GSInstance( aReference, aControlID, aValueControlID ) { 17 this.reference = aReference; 18 this.controlID = aControlID; 19 this.valueControlID = aValueControlID; 20} 21 22var Instances = new Array( 0 ); 23 24 25function getGSIndexByReference( ref ) { 26 for ( var i = 0; i < Instances.length; i++ ) { 27 if ( Instances[i].reference == ref ) { 28 return i; 29 } 30 } 31 return 0; 32} 33 34function getGSReferenceByIndex( index ) { 35 return Instances[index].reference; 36} 37 38 39// --- 40 41function GSClass( aControlID, aLink, aContentID, aValueControlID ) { 42 43 this.m_ControlID = aControlID; 44 this.m_ValueControlID = aValueControlID; 45 this.m_Link = aLink; 46 this.m_ContentID = aContentID; 47 this.m_SearchText = ""; 48 // 49 50 this.m_Data = new Array(); 51 this.m_Values = new Array(); 52 this.m_NumberOfRecords = 0; 53 54 this.m_IsContentVisible = false; 55 this.m_IsCursorEnabled = false; 56 this.m_CursorIndex = 0; 57 58 // 59 60 this.MoveCursorUp = GSMoveCursorUp; 61 this.MoveCursorDown = GSMoveCursorDown; 62 63 // methods 64 65 this.ShowContent = GSShowContent; 66 this.WriteContent = GSWriteContent; 67 this.InitValues = GSInitValues; 68 this.Attach = GSAttach; 69 this.Clear = GSClear; 70 71 this.doMyKeyUp = GSOnKeyUp; 72 this.doMyKeyDown = GSOnKeyDown; 73 this.doMyBlur = GSOnBlur; 74 this.doMyFocus = GSOnFocus; 75 76 // onload 77 this.Clear(); 78 this.Attach(); 79 80 // register ourselves in the instances array for the static functions 81 Instances.splice( Instances.length, 0, new GSInstance( this, this.m_ControlID, this.m_ValueControlID ) ); 82} 83 84 85function GSClear() { 86 this.ShowContent( false ); 87 88 this.m_IsCursorEnabled = false; 89 this.m_CursorIndex = 0; 90 this.m_SearchText = ""; 91} 92 93 94function GSSelectIndex( selIndex, gsIndex ) { 95 96 var gs = getGSReferenceByIndex( gsIndex ); 97 gs.m_CursorIndex = selIndex; 98 gs.m_IsCursorEnabled = true; 99 100 var anObject = GetObjectByID( gs.m_ControlID ); 101 102 var o = document.getElementById( gs.m_ValueControlID ); 103 if ( o ) { 104 o.value = gs.m_Values[gs.m_CursorIndex]; 105 anObject.value = gs.m_Data[gs.m_CursorIndex ]; 106 } 107 108 gs.WriteContent(); 109} 110 111 112function GSMoveCursorUp() { 113 this.m_CursorIndex --; 114 if ( this.m_CursorIndex < 0 ) { 115 this.m_IsCursorEnabled = false; 116 this.m_CursorIndex = 0; 117 } 118 119 var o = document.getElementById( this.m_ValueControlID ); 120 if ( o ) { 121 o.value = this.m_Values[this.m_CursorIndex]; 122 } 123 124 this.WriteContent(); 125} 126 127 128 129function GSMoveCursorDown() { 130 if ( !this.m_IsCursorEnabled ) { 131 this.m_IsCursorEnabled = true; 132 this.m_CursorIndex = 0; 133 } else { 134 this.m_CursorIndex ++; 135 if ( this.m_CursorIndex >= this.m_NumberOfRecords ) { 136 this.m_CursorIndex = this.m_NumberOfRecords - 1; 137 } 138 } 139 140 var o = document.getElementById( this.m_ValueControlID ); 141 if ( o ) { 142 o.value = this.m_Values[this.m_CursorIndex]; 143 } 144 145 this.WriteContent(); 146} 147 148 149function GSOnKeyUp( e ) { 150 151 var theKey = 0; 152 anObject = GetObjectByID( this.m_ControlID ); 153 if ( !e ) var e = window.event; 154 theKey = e["keyCode"]; 155 156 if ( theKey == 40 ) return; 157 if ( theKey == 38 ) return; 158 if ( theKey == 27 ) return; 159 160 if ( anObject.value.length < 1 ) { 161 this.ShowContent( false ); 162 163 } else { 164 165 if ( !this.m_IsContentVisible ) { 166 this.WriteContent(); 167 this.ShowContent( true ); 168 } 169 170 if ( this.m_SearchText != anObject.value ) { 171 this.m_SearchText = anObject.value; 172 var theLink = this.m_Link + this.m_SearchText + "&anticache=" + Math.random(); 173 174 this.m_CursorIndex = 0; 175 176 this.InitValues( GetFileContent( theLink ) ); 177 this.WriteContent(); 178 179 if ( !this.m_IsContentVisible ) this.ShowContent( true ); 180 } 181 } // end of if anobject.value.length < 1 182 183} 184 185 186function GSOnKeyDown( e ) { 187 188 var theKey = 0; 189 anObject = GetObjectByID( this.m_ControlID ); 190 if ( !e ) var e = window.event; 191 theKey = e["keyCode"]; 192 193 // down 194 if ( theKey == 40 && this.m_IsContentVisible ) { 195 this.MoveCursorDown(); 196 anObject.value = this.m_Data[ this.m_CursorIndex ]; 197 } 198 199 // up 200 if ( theKey == 38 && this.m_IsContentVisible ) { 201 this.MoveCursorUp(); 202 anObject.value = this.m_Data[ this.m_CursorIndex ]; 203 } 204 205 // escape pressed ? 206 if ( theKey == 27 && this.m_IsContentVisible ) { 207 anObject.value = ""; 208 this.Clear(); 209 } 210} 211 212 213 214function GSOnBlur() { 215 SetObjectVisibility( this.m_ContentID, false ); 216} 217 218 219function GSOnFocus() { 220 if ( this.m_IsContentVisible ) { 221 SetObjectVisibility( this.m_ContentID, true ); 222 } 223} 224 225 226 227function GSAttach() { 228 var theObject = GetObjectByID( this.m_ControlID ); 229 230 // position teh content div under the control 231 232 x = GetObjectLeft( this.m_ControlID ); 233 y = GetObjectTop( this.m_ControlID ); 234 height = GetObjectHeight( this.m_ControlID ); 235 236 SetObjectPosition( this.m_ContentID, x, y + height ); 237 238 // hook the control events we need. events need to be attached to "this" before hooking the control 239 240 theObject.onkeydown = GSOnKeyDownStatic; 241 theObject.onkeyup = GSOnKeyUpStatic; 242 theObject.onblur = GSOnBlurStatic; 243 theObject.onfocus = GSOnFocusStatic; 244} 245 246 247 248function GSInitValues( aString ) { 249 250 if ( !aString || aString == "" ) { 251 this.m_Data = new Array(); 252 this.m_NumberOfRecords = 0; 253 this.ShowContent( false ); 254 } else { 255 256 var dataStrings = String( aString ).split( "#" ); 257 if ( dataStrings.length > 1 ) { 258 this.m_Values = String( dataStrings[1] ).split( "|" ); 259 this.m_Data = String( dataStrings[0] ).split( "|" ); 260 } else { 261 this.m_Data = String( aString ).split( "|" ); 262 } 263 this.m_NumberOfRecords = this.m_Data.length; 264 this.WriteContent(); 265 this.ShowContent( true ); 266 } 267} 268 269 270 271function GSShowContent( aState ) { 272 this.m_IsContentVisible = aState; 273 SetObjectVisibility( this.m_ContentID, aState ); 274} 275 276 277 278function GSWriteContent() { 279 280 var theObject = GetObjectByID( this.m_ContentID ); 281 var theContent = new String(); 282 theContent = "<table cellspacing=\"0\" cellpadding=\"0\" class=\"suggest\">"; 283 284 var gsIndex = getGSIndexByReference( this ); 285 286 for ( var i = 0; i < this.m_NumberOfRecords; i++ ) { 287 var theTDClass = ( this.m_IsCursorEnabled && i == this.m_CursorIndex ) ? "over" : ""; 288 theContent += "<tr><td onmouseover=\"GSSelectIndex( " + i + ", " + gsIndex + " );\" class=\"" + theTDClass + "\">" + this.m_Data[i] + "</td></tr>"; 289 } 290 291 theContent += "</table>"; 292 theObject.innerHTML = theContent; 293} 294 295 296/* 297function GetFileContent( url ) 298{ 299 alert(url); 300 XmlHttp.open( "GET", url, false ); // sync request 301 XmlHttp.send( null ); 302 return ( XmlHttp.responseText ); 303} 304*/ 305 306function GSOnKeyDownStatic( e ) { 307 // look for our instance and route the event 308 for ( var i = 0; i < Instances.length; i++ ) { 309 if ( Instances[i].controlID == this.id ) { 310 Instances[i].reference.doMyKeyDown( e ); 311 break; 312 } 313 } 314} 315 316 317function GSOnKeyUpStatic( e ) { 318 // look for our instance and route the event 319 for ( var i = 0; i < Instances.length; i++ ) { 320 if ( Instances[i].controlID == this.id ) { 321 Instances[i].reference.doMyKeyUp( e ); 322 break; 323 } 324 } 325} 326 327 328function GSOnBlurStatic() { 329 // look for our instance and route the event 330 for ( var i = 0; i < Instances.length; i++ ) { 331 if ( Instances[i].controlID == this.id ) { 332 Instances[i].reference.doMyBlur(); 333 break; 334 } 335 } 336} 337 338function GSOnFocusStatic() { 339 // look for our instance and route the event 340 for ( var i = 0; i < Instances.length; i++ ) { 341 if ( Instances[i].controlID == this.id ) { 342 Instances[i].reference.doMyFocus(); 343 break; 344 } 345 } 346}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.