Skip to content

Commit

Permalink
added 'setLocation' method, a slightly more robust means of setting t…
Browse files Browse the repository at this point in the history
…he location than just setting the property value
  • Loading branch information
sporritt committed Aug 19, 2022
1 parent d1a9306 commit a46ee46
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion ts/core/overlay/overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ export abstract class Overlay extends EventGenerator {
p = p || {}
this.id = p.id || uuid()
this.cssClass = p.cssClass || ""
this.location = p.location || 0.5

this.setLocation(p.location as any)

this.events = p.events || {}
this.attributes = p.attributes || {}

Expand All @@ -55,6 +57,22 @@ export abstract class Overlay extends EventGenerator {
}
}

setLocation(l:number|string) {
let newLocation = this.location == null ? 0.5 : this.location
if (l != null) {
try {
const _l = typeof l === "string" ? parseFloat(l) : l
if (!isNaN(_l)) {
newLocation = _l
}
} catch (e) {
// not parsable. use default.
}
}

this.location = newLocation
}

shouldFireEvent(event: string, value: any, originalEvent?: Event): boolean {
return true
}
Expand Down

0 comments on commit a46ee46

Please sign in to comment.