| |
| |
| |
| |
| |
| |
|
|
| import { watch } from 'vue'; |
| import MatomoUrl from '../MatomoUrl/MatomoUrl'; |
|
|
| const { $ } = window; |
|
|
| class PopoverHandler { |
| constructor() { |
| this.setup(); |
| } |
|
|
| private setup() { |
| watch(() => MatomoUrl.parsed.value.popover, () => this.onPopoverParamChanged()); |
|
|
| if (MatomoUrl.parsed.value.popover) { |
| this.onPopoverParamChangedInitial(); |
| } |
| } |
|
|
| |
| |
| private onPopoverParamChangedInitial() { |
| $(() => { |
| setTimeout(() => { |
| this.openOrClose(); |
| }); |
| }); |
| } |
|
|
| private onPopoverParamChanged() { |
| |
| $(() => { |
| this.openOrClose(); |
| }); |
| } |
|
|
| private openOrClose() { |
| this.close(); |
|
|
| |
| const popoverParam = MatomoUrl.parsed.value.popover as string; |
| if (popoverParam) { |
| this.open(popoverParam); |
| } else { |
| |
| |
| window.broadcast.resetPopoverStack(); |
| } |
| } |
|
|
| private close() { |
| window.Piwik_Popover.close(); |
| } |
|
|
| private open(thePopoverParam: string) { |
| |
| let popoverParam = decodeURIComponent(thePopoverParam); |
|
|
| |
| popoverParam = popoverParam.replace(/\$/g, '%'); |
| popoverParam = decodeURIComponent(popoverParam); |
|
|
| const popoverParamParts = popoverParam.split(':'); |
| const handlerName = popoverParamParts[0]; |
| popoverParamParts.shift(); |
|
|
| const param = popoverParamParts.join(':'); |
| if (typeof window.broadcast.popoverHandlers[handlerName] !== 'undefined' |
| && !window.broadcast.isLoginPage() |
| ) { |
| window.broadcast.popoverHandlers[handlerName](param); |
| } |
| } |
| } |
|
|
| export default new PopoverHandler(); |
|
|