var tmpobj; /** * An autosuggest textbox control. * @class * @scope public */ function AutoSuggestControl(oTextbox /*:HTMLInputElement*/, oProvider /*:SuggestionProvider*/, oSearch /*:Search*/, oParams /*: Object*/) { if (!oTextbox || !oProvider) { return; } /** * The currently selected suggestions. * @scope private */ this.cur /*:int*/ = -1; /** * The dropdown list layer. * @scope private */ this.layer = null; /** * Suggestion provider for the autosuggest feature. * @scope private. */ this.provider /*:SuggestionProvider*/ = oProvider; /** * oSearch * Check if Autosuggest must be added */ this.search /*:Search*/ = oSearch; /** * The textbox to capture. * @scope private */ this.textbox /*:HTMLInputElement*/ = oTextbox; this.textbox.autocomplete='off'; this.textbox.setAttribute('autocomplete', 'off'); if(oParams) { this.id = oParams.id || false; this.container = document.getElementById(oParams.container) || document.body; } // Désactiver le formulaire if (typeof oParams.autoSubmit == "undefined" || oParams.autoSubmit == false) { this.form = getParentByTagName(this.textbox, "form"); } //initialize the control this.init(); } /** * GET form element * @scope private */ function getParentByTagName (elm, tagName) { var node = elm.parentNode; while (elm && elm.tagName.toLowerCase() != "body") { if (elm.tagName.toLowerCase() == tagName) { return elm; } elm = elm.parentNode; } return false; } /** * GET the suggestion nodes * @scope private */ AutoSuggestControl.prototype.getSuggestionNodes = function() { var tmp = this.layer.childNodes; var result = []; for (var i=0; i= 0 && indice < len) { this.suggestionElements[indice].onmouseover(oEvent); this.textbox.value = this.suggestionElements[indice].title; } // Bornes: on sort des résultats else { this.suggestionElements[this.cur].onmouseout(oEvent); this.cur = -1; this.textbox.value = this.defaultValue; } }; /** * Initializes the textbox with event handlers for * auto suggest functionality. * @scope private */ AutoSuggestControl.prototype.init = function () { //save a reference to this object var oThis = this; // assign CACHE this.setCache(this.search.typeAutosuggested); this.textbox.onkeyup = function (oEvent) { oThis.handleKeyUp(oEvent || window.event); }; this.textbox.onkeydown = function (oEvent) { oThis.handleKeyDown(oEvent || window.event); }; // Affiche/Masque l'autosuggestion this.textbox.onblur = function () { if (oThis.cur < 0 || !hasClass(oThis.suggestionElements[oThis.cur], "current")) { oThis.layer.active = false; oThis.showSuggestionElement(); } }; /* Hack qui permet de rester appuyer sur la fleche du haut et du bas et de naviguer ainsi dans l'autosuggest */ if (!document.all) { this.textbox.onkeypress = this.textbox.onkeydown; this.textbox.onkeydown = null; } //create the suggestions dropdown this.createDropDown(); }; /** * Highlights the next suggestion in the dropdown and * places the suggestion into the textbox. * @scope private */ AutoSuggestControl.prototype.nextSuggestion = function (oEvent /*:Event*/) { this.highlightSuggestion(this.cur + 1, oEvent); }; /** * Highlights the previous suggestion in the dropdown and * places the suggestion into the textbox. * @scope private */ AutoSuggestControl.prototype.previousSuggestion = function (oEvent /*:Event*/) { this.highlightSuggestion(this.cur - 1, oEvent); }; /** * Selects a range of text in the textbox. * @scope public * @param iStart The start index (base 0) of the selection. * @param iLength The number of characters to select. */ AutoSuggestControl.prototype.selectRange = function (iStart /*:int*/, iLength /*:int*/) { //use text ranges for Internet Explorer if (this.textbox.createTextRange) { var oRange = this.textbox.createTextRange(); oRange.moveStart("character", iStart); oRange.moveEnd("character", iLength - this.textbox.value.length); oRange.select(); //use setSelectionRange() for Mozilla } else if (this.textbox.setSelectionRange) { this.textbox.setSelectionRange(iStart, iLength); } //set focus back to the textbox this.textbox.focus(); }; /* * Catch the results from AjaxRequest * @scope private * @param result the ajaxResponseDocument */ AutoSuggestControl.prototype.catchNodes = function (result) { if (!result) { return false; } result = result.replace(/[\t\r\n\v\f]/gi, ''); var tab = []; // Si le résultat est du code HTML en format texte, // on considére que chaque réponse est séparée par un commentaire vide var res = (!this.search.html) ? result.getElementsByTagName("n") : result.split(""); var len = res.length; for (var i=0; i= 0) { var suggestion = this.suggestionElements[this.cur]; if (typeof suggestion != "undefined") { this.textbox.value = suggestion.title; } } // Masque l'autosuggestion this.layer.active = false; this.showSuggestionElement(); }; /* 1. Masquer l'ancienne suggestion active 2. Rendre active la nouvelle suggestion */ AutoSuggestControl.prototype.handleMouseover = function(suggestion, e) { // Contenu inactif if (this.cur >= 0 && this.cur < this.suggestionElements.length) { this.suggestionElements[this.cur].onmouseout(e); } // Contenu actif addClass(suggestion, "current"); this.cur = suggestion.cur; this.layer.active = true; }; AutoSuggestControl.prototype.handleMouseout = function(suggestion, e) { removeClass(suggestion, "current"); return false; }; AutoSuggestControl.prototype.setCache = function(keys /*:Array*/) { if (!keys) { this.cache = false; return false; } this.cache = {}; for (var i=0; i 42) oCache.shift(); } // provide suggestions to the control oAutoSuggestControl.setAutosuggestElement(tbl); } }; oHttp.send(null); return true; }