File size: 2,234 Bytes
7929f62 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | /*!
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
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();
}
}
// don't initiate the handler until the page had a chance to render,
// since some rowactions depend on what's been loaded.
private onPopoverParamChangedInitial() {
$(() => {
setTimeout(() => {
this.openOrClose();
});
});
}
private onPopoverParamChanged() {
// make sure all popover handles were registered
$(() => {
this.openOrClose();
});
}
private openOrClose() {
this.close();
// should be rather done by routing
const popoverParam = MatomoUrl.parsed.value.popover as string;
if (popoverParam) {
this.open(popoverParam);
} else {
// the URL should only be set to an empty popover if there are no popovers in the stack.
// to avoid avoid any strange inconsistent states, we reset the popover stack here.
window.broadcast.resetPopoverStack();
}
}
private close() {
window.Piwik_Popover.close();
}
private open(thePopoverParam: string) {
// in case the $ was encoded (e.g. when using copy&paste on urls in some browsers)
let popoverParam = decodeURIComponent(thePopoverParam);
// revert special encoding from broadcast.propagateNewPopoverParameter()
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();
|