/* MARKUP:
EVENTS: * Typing: EV_SEARCH w/ params * Selection: EV_DONE w/o params */ $.fn.uaAutoComplete = function(options) { options = $.extend({ bMandatory: true , bToolTip: true , //true, TYPE_OPTIONAL, TYPE_IGNORE bDisabled: false , bReadOnly: false , iMinChars: 10 , //min number of characters iMaxChars: 100 , //max number f characters hint: '' , iTriggerChars: 3 }, options); this. on(EV_RESPONSE,function(ev) { ev.stopImmediatePropagation(); pWrapper.trigger($.Event(EV_RESPONSE,{uaData:{data:ev.uaData.data}})); pInput.trigger($.Event(EV_ENABLE,{uaData:{data:{bEnable:true}}})); }). on(EV_INIT,function(ev) { ev.stopImmediatePropagation(); //position the list below the input pWrapper.css({top: pInput.height()*1.6}); $.each([pWrapper,pInput],function() { $(this).trigger(EV_INIT); }); }). on(EV_UPDATE,function(ev) {//sets pInput ONLY. Needed if the AutoComplete must be set as a result of an external call ev.stopImmediatePropagation(); pInput.trigger($.Event(EV_SET,{uaData:{data:{label:ev.uaData.data.label,id:ev.uaData.data.id}}})); }). on(EV_CLEAR,function(ev) { ev.stopImmediatePropagation(); //if cleared = nothing to show. pInput.trigger(EV_CLEAR); pWrapper.trigger(EV_CLEAR).trigger($.Event(EV_SHOW,{uaData:{data:{bShow:false}}})); }). on(EV_SET_DEFAULT,function(ev) { ev.stopImmediatePropagation(); $.each([pInput,pWrapper],function() { $(this).trigger(EV_SET_DEFAULT); }); }). on(EV_CHECK_FOR_ERRORS,function(ev) { ev.stopImmediatePropagation(); pInput.trigger(EV_CHECK_FOR_ERRORS); }). on(EV_SHOW,function(ev) { ev.stopImmediatePropagation(); pWrapper.trigger($.Event(EV_SHOW,{uaData:ev.uaData})); }). on(EV_SET,function(ev) { ev.stopImmediatePropagation(); pWrapper.trigger($.Event(EV_SET,{uaData:ev.uaData})); }). on(EV_NOTIFY,function(ev) { ev.stopImmediatePropagation(); switch(ev.uaData.info.ev) { case EV_DONE: //user made selection pWrapper.trigger($.Event(EV_SHOW,{uaData:{data:{bShow:false}}})); pInput.trigger($.Event(EV_SET,{uaData:{data:{ label: $(ev.uaData.data.label).html() || ev.uaData.data.label, id: ev.uaData.data.id }}})); break; case EV_SEARCH: //list NOT displayed and cleared of contents pWrapper. trigger($.Event(EV_SHOW,{uaData:{data:{bShow:false}}})). trigger(EV_CLEAR); break; default: break; }; //extern call -> collect nerw data $(this).trigger($.Event(EV_EXTERN,{uaData:ev.uaData})); }); //Objects wrapping the pList $.fn.uaWrapper = function() { this. hover( function(ev) {}, function(ev) { $( this ).trigger(EV_TOGGLE); } ). on(EV_RESPONSE,function(ev) { ev.stopImmediatePropagation(); $(this). trigger(EV_CLEAR). trigger($.Event(EV_SET,{uaData:ev.uaData})). trigger($.Event(EV_SHOW,{uaData:{data:{bShow:true}}})); }). on(EV_INIT,function(ev) { ev.stopImmediatePropagation(); }). on(EV_CLEAR, function(ev) { ev.stopImmediatePropagation(); pList.trigger(EV_CLEAR); }). on(EV_SET_DEFAULT,function(ev) { ev.stopImmediatePropagation(); pList.trigger(EV_SET_DEFAULT); //if($(this).css('display')==='none') return; //$(this).trigger(EV_TOGGLE); }). on(EV_SET, function(ev) { ev.stopImmediatePropagation(); pList.trigger($.Event(EV_SET,{uaData:ev.uaData})); }). on(EV_SHOW,function(ev) { ev.stopImmediatePropagation(); switch(ev.uaData.data.bShow) { case true: $(this).css({display:'',zIndex:100,height: '100%!important'}); break; default: $(this).css({display:'none',zIndex:-1}); break; }; }). on(EV_TOGGLE,function(ev) {//EXCLUSIVELY USED for lists in support of combo, autocomplete,etc. ev.stopImmediatePropagation(); switch($(this).css('display')) { case 'none': $(this).css({display:'',zIndex:100,height: '100%!important'}); break; default: $(this).css({display:'none',zIndex:-1}); break; };//switch($(this).css('display')) }). on(EV_NOTIFY,function(ev) { ev.stopImmediatePropagation(); $(this). //trigger(EV_TOGGLE).//close list aftyer selection & pass {label,id} to input trigger($.Event(EV_SHOW,{uaData:{data:{bShow:false}}})). trigger($.Event(EV_EXTERN,{uaData:ev.uaData})); }); const pList = $('ul',this).uaList_Floater(). on(EV_EXTERN,function(ev) { ev.stopImmediatePropagation(); //ignoire selection if id=ID_SELECTION_NONE if(ev.uaData.data.id===ID_SELECTION_NONE) return; //user selection $(this).parent().trigger($.Event(EV_NOTIFY,{uaData:{info:{ev:EV_DONE},data:ev.uaData.data}})); }); return this; };//$.fn.uaWrapper = function() //Instantiation const pInput = $('input',this).uaString(options). off(EV_SET). on(EV_SET,function(ev) { ev.stopImmediatePropagation(); $(this).val(ev.uaData.data.label); $(this).data("id",JSON.stringify(ev.uaData.data.id)); }). on( "keyup", function(ev) { ev.stopImmediatePropagation(); //blocked while searching. One character at a time if($(this).hasClass('uaDisabled')) return; //not enough characters? if($(this).val().length