@@ -19,10 +19,10 @@ interface Params {
1919 Url : string ;
2020
2121 // Keyboard mapping event
22- KeyboardMappings : { [ name : string ] : MappingEvent ; } ;
22+ KeyboardMappings : { [ _ : string ] : MappingEvent ; } ;
2323
2424 // Workable elements
25- DOMResults : Element ;
25+ DOMResults : HTMLElement ;
2626 Request : XMLHttpRequest ;
2727 Input : Element ;
2828 Select : Element ;
@@ -43,7 +43,7 @@ interface Params {
4343 _Url : any ;
4444
4545 // Internal item
46- $AjaxTimer : WindowTimers ;
46+ $AjaxTimer : number ;
4747}
4848
4949interface MappingCondition {
@@ -148,7 +148,6 @@ class AutoComplete {
148148 first . setAttribute ( "class" , "active" ) ;
149149 }
150150 } ,
151- Not : false ,
152151 Operator : ConditionOperator . OR
153152 } ,
154153 "AlphaNum" : {
@@ -275,8 +274,8 @@ class AutoComplete {
275274 _Render : function ( response : ResponseItem [ ] | string ) : void {
276275 console . log ( "_Render" , this , "Response" , response ) ;
277276
278- var ul : Element = document . createElement ( "ul" ) ,
279- li : Element = document . createElement ( "li" ) ;
277+ var ul : HTMLElement = document . createElement ( "ul" ) ,
278+ li : HTMLElement = document . createElement ( "li" ) ;
280279
281280 if ( typeof response == "string" ) {
282281 if ( response . length > 0 ) {
@@ -323,7 +322,7 @@ class AutoComplete {
323322 if ( Array . isArray ( json ) ) {
324323 console . log ( "Response is a JSON Array" ) ;
325324
326- for ( var i = 0 ; i < Array . prototype . length ( json ) ; i ++ ) {
325+ for ( var i = 0 ; i < Object . keys ( json ) . length ; i ++ ) {
327326 returnResponse [ returnResponse . length ] = { "Value" : json [ i ] , "Label" : json [ i ] } ;
328327 }
329328 } else {
@@ -350,14 +349,18 @@ class AutoComplete {
350349
351350 return this . Input . value ;
352351 } ,
353- _Select : function ( item : Element ) : void {
352+ _Select : function ( item : HTMLElement ) : void {
354353 console . log ( "Select" , this ) ;
355354
356- this . Input . value = item . getAttribute ( "data-autocomplete-value" , item . innerHTML ) ;
355+ if ( item . hasAttribute ( "data-autocomplete-value" ) ) {
356+ this . Input . value = item . getAttribute ( "data-autocomplete-value" ) ;
357+ } else {
358+ this . Input . value = item . innerHTML ;
359+ }
357360 this . Input . setAttribute ( "data-autocomplete-old-value" , this . Input . value ) ;
358361
359362 if ( this . Select !== void 0 ) {
360- var option : Element = document . createElement ( "option" ) ;
363+ var option : HTMLElement = document . createElement ( "option" ) ;
361364 option . setAttribute ( "value" , this . Input . value ) ;
362365 option . setAttribute ( "selected" , "selected" ) ;
363366 option . innerHTML = item . innerHTML ;
@@ -381,7 +384,7 @@ class AutoComplete {
381384 } ) ;
382385 } else if ( typeof selector == "string" ) {
383386 var elements : NodeList = document . querySelectorAll ( selector ) ;
384- Array . prototype . forEach . call ( elements , function ( input : Element ) {
387+ Array . prototype . forEach . call ( elements , function ( input : HTMLElement ) {
385388 new AutoComplete ( params , input ) ;
386389 } ) ;
387390 } else {
@@ -398,7 +401,7 @@ class AutoComplete {
398401 }
399402 }
400403
401- create ( params : Params , element : Element ) : void {
404+ create ( params : Params , element : HTMLElement ) : void {
402405 console . log ( "Object" , params ) ;
403406
404407 if ( element . nodeName . match ( / ^ S E L E C T $ / i) ) {
@@ -448,7 +451,12 @@ class AutoComplete {
448451 } , params . KeyboardMappings [ name ] ) ,
449452 match : boolean = ConditionOperator . AND == mapping . Operator ;
450453
451- mapping . Conditions . forEach ( function ( condition : MappingCondition ) {
454+ mapping . Conditions . forEach ( function ( condition : {
455+ From : number ,
456+ Is : number ,
457+ Not : boolean ,
458+ To : number
459+ } ) {
452460 if ( ( match == true && mapping . Operator == ConditionOperator . AND ) || ( match == false && ConditionOperator . OR ) ) {
453461 condition = AutoComplete . merge ( {
454462 Not : false
0 commit comments