Business web site - var startRegExp = “^”; 418 CHAPTER 10 Type-ahead

var startRegExp = “^”; 418 CHAPTER 10 Type-ahead suggest if ( this.options.matchAnywhere ) startRegExp = ; var regExp = new RegExp( startRegExp + this.lastRequestString, regExpFlags ); var suggestionSpans = []; for ( var i = 0 ; i < this.suggestions.length ; i++ ) suggestionSpans.push( this.createSuggestionSpan( i, regExp ) ); return suggestionSpans; }, This method first looks at our options object to find the value of the ignoreCase and matchAnywhere properties. This has to be done so that a regular expression can be created with the appropriate parameters that will facilitate the retrieval of the portion of the string in the response that actually matches what the user has typed in. The method then iterates over the suggestions property, which you will recall is an array of objects that have a .text and a .value property. For each sug- gestion in the array, the createSuggestionSpan() method is called with the index of the suggestion and the regular expression created earlier. All the real work is done in createSuggestionSpan(), shown in listing 10.37. Listing 10.37 Creation of a list item span createSuggestionSpan: function( n, regExp ) { var suggestion = this.suggestions[n]; var suggestionSpan = document.createElement("span"); suggestionSpan.className = this.options.suggestionClassName; suggestionSpan.style.width = 100% ; suggestionSpan.style.display = block ; suggestionSpan.id = this.id + "_" + n; suggestionSpan.onmouseover = this.mouseoverHandler.bindAsEventListener(this); suggestionSpan.onclick
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.

Leave a Reply