getaddress-autocomplete
Advanced tools
Comparing version 1.0.24 to 1.1.0
{ | ||
"name": "getaddress-autocomplete", | ||
"version": "1.0.24", | ||
"version": "1.1.0", | ||
"description": "GetAddress.io - Autocomplete plug-in", | ||
@@ -5,0 +5,0 @@ "main": "./dist/getaddress-autocomplete.mjs", |
@@ -11,3 +11,3 @@ Javascript - Autocomplete. | ||
``` | ||
<script src="https://cdn.getaddress.io/scripts/getaddress-autocomplete-1.0.22.min.js"></script> | ||
<script src="https://cdn.getaddress.io/scripts/getaddress-autocomplete-1.1.0.min.js"></script> | ||
``` | ||
@@ -14,0 +14,0 @@ |
@@ -16,3 +16,2 @@ import AttributeValues from "./AttributeValues"; | ||
private showAllClicked:boolean; | ||
private documentClick: EventListenerObject; | ||
@@ -28,2 +27,71 @@ | ||
public destroy(){ | ||
this.destroyContainer(); | ||
this.destroyInput(); | ||
this.destroyList(); | ||
} | ||
private destroyList() | ||
{ | ||
this.list.remove(); | ||
} | ||
private destroyContainer(){ | ||
this.container.removeEventListener('keydown',this.onContainerKeyDown); | ||
this.container.removeEventListener('keyup',this.onContainerKeyUp); | ||
this.container.removeEventListener('focusout',this.onContainerFocusOut); | ||
const children = Array.from(this.container.childNodes); | ||
this.container.replaceWith(...children); | ||
} | ||
private destroyInput(){ | ||
this.input.classList.remove(this.attributeValues.inputClassName); | ||
if(this.attributeValues.inputAdditionalClassNames){ | ||
for(const name of this.attributeValues.inputAdditionalClassNames){ | ||
this.input.classList.remove(name); | ||
} | ||
} | ||
this.removeInputShowClassNames(); | ||
this.input.removeAttribute('aria-expanded'); | ||
this.input.removeAttribute('autocomplete'); | ||
this.input.removeAttribute('aria-autocomplete'); | ||
this.input.removeAttribute('role'); | ||
this.input.removeAttribute('aria-owns'); | ||
this.input.removeEventListener('focus',this.onInputFocus); | ||
this.input.removeEventListener('paste',this.onInputPaste); | ||
} | ||
private onInputFocus = (event) => { | ||
this.addContainerFocusedClassNames(); | ||
if(this.attributeValues.options.select_on_focus){ | ||
this.input.select(); | ||
} | ||
this.selectedIndex = -1; | ||
}; | ||
private onInputPaste = (event) => { | ||
setTimeout(()=>{this.populateList(false);},100); | ||
}; | ||
private onContainerKeyUp = (event:KeyboardEvent) => { | ||
this.debug(event); | ||
this.handleKeyUp(event); | ||
}; | ||
private onContainerKeyDown = (event:KeyboardEvent) => { | ||
this.debug(event); | ||
this.keyDownHandler(event); | ||
}; | ||
private onContainerFocusOut = (event) => { | ||
this.handleComponentBlur(event, false); | ||
} | ||
public build() | ||
@@ -39,2 +107,3 @@ { | ||
} | ||
this.input.setAttribute('aria-expanded', 'false'); | ||
@@ -58,19 +127,7 @@ this.input.setAttribute('autocomplete', 'off'); | ||
this.input.addEventListener('focus', (event) => { | ||
this.addContainerFocusedClassNames(); | ||
if(this.attributeValues.options.select_on_focus){ | ||
this.input.select(); | ||
} | ||
this.selectedIndex = -1; | ||
}); | ||
this.input.addEventListener('focus', this.onInputFocus); | ||
this.input.addEventListener('paste', (event) => { | ||
setTimeout(()=>{this.populateList(false);},100); | ||
}); | ||
this.input.addEventListener('paste', this.onInputPaste); | ||
this.container.addEventListener('focusout', (event) => { | ||
this.handleComponentBlur(event, false); | ||
}); | ||
this.container.addEventListener('focusout', this.onContainerFocusOut); | ||
@@ -91,3 +148,2 @@ this.container.appendChild(this.input); | ||
this.list.addEventListener('mouseenter', (event) => { | ||
@@ -110,10 +166,4 @@ const suggestions = this.list.children; | ||
this.container.addEventListener('keydown', (event:KeyboardEvent) => { | ||
this.debug(event); | ||
this.keyDownHandler(event); | ||
}); | ||
this.container.addEventListener('keyup', (event:KeyboardEvent) => { | ||
this.debug(event); | ||
this.handleKeyUp(event); | ||
}); | ||
this.container.addEventListener('keydown', this.onContainerKeyDown); | ||
this.container.addEventListener('keyup', this.onContainerKeyUp); | ||
@@ -120,0 +170,0 @@ this.container.appendChild(this.list); |
@@ -10,11 +10,13 @@ import Autocomplete from "./Autocomplete"; | ||
{ | ||
private static index = 0; | ||
static Next(){ | ||
const returnValue = InstanceCounter.index; | ||
InstanceCounter.index+=1; | ||
return returnValue; | ||
public static instances:Autocomplete[] = []; | ||
static add(autocomplete:Autocomplete){ | ||
this.instances.push(autocomplete); | ||
} | ||
} | ||
export function autocomplete(id:string,api_key:string, options?: IOptions){ | ||
export function autocomplete(id:string,api_key:string, options?: IOptions) | ||
{ | ||
@@ -38,3 +40,3 @@ if(!id){ | ||
const index = InstanceCounter.Next(); | ||
const index = InstanceCounter.instances.length; | ||
@@ -45,2 +47,3 @@ const attributeValues = new AttributeValues(allOptions,index); | ||
autocomplete.build(); | ||
if(index === 0){ | ||
@@ -51,2 +54,11 @@ const style = new Style(attributeValues); | ||
InstanceCounter.add(autocomplete); | ||
} | ||
export function destroy() | ||
{ | ||
for(const instance of InstanceCounter.instances){ | ||
instance.destroy(); | ||
} | ||
InstanceCounter.instances = []; | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
49803
1013