Skip to content

Commit

Permalink
Feature: added Livewire support, the search will now be re-run after …
Browse files Browse the repository at this point in the history
…Livewire events are fired, to show the popups for newly created elements
  • Loading branch information
Capevace committed Oct 18, 2024
1 parent 1b7ec5a commit 0d1455c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ You can change the URL that the analytics are being exposed on by changing the `

## Changelog

- 1.0.2
- Feature: added Livewire support, the `[data-pan]` search will now be re-run after Livewire `morph.updated` events are fired, to show the popups for newly created elements
- 1.0.1
- Fix: removed livewire specific script inclusion
- 1.0.0
Expand Down
45 changes: 35 additions & 10 deletions resources/views/components/viewer.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,17 @@ function buildPanWidget(analytic) {
return html;
}
let button = null;
async function buildPanToggle() {
let destroyViewer = await initPanViewer();
@if ($toggle)
const button = document.createElement('button');
if (button) {
button.remove();
}
button = document.createElement('button');
button.textContent = 'Hide Pan Analytics';
button.classList.add('pan-toggle');
button.classList.add('inactive');
Expand Down Expand Up @@ -190,17 +196,36 @@ function buildPanWidget(analytic) {
let destroyViewer = null;
window.pan = {
async show() {
destroyViewer = await buildPanToggle();
},
hide() {
if (destroyViewer) {
destroyViewer();
destroyViewer = null;
}
const show = async () => {
destroyViewer = await buildPanToggle();
};
const hide = () => {
if (destroyViewer) {
destroyViewer();
destroyViewer = null;
}
};
const refresh = () => {
hide();
show();
};
window.pan = {
show,
hide,
refresh
};
window.pan.show();
if (window.Livewire) {
let timeout = null;
window.Livewire.hook('morph.updated', () => {
if (timeout) {
clearTimeout(timeout);
}
timeout = setTimeout(window.pan.refresh, 500);
});
}
</script>

0 comments on commit 0d1455c

Please sign in to comment.