Skip to content

Commit

Permalink
New: Add prettyembedPlay Method
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnitto committed Dec 24, 2023
1 parent 0c5af1d commit cdf7f04
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion Resources/Private/Assets/Plugins/Methods.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
export default function (Alpine) {
Alpine.magic('prettyembedPause', () => pause);

Alpine.magic('prettyembedReset', () => reset);
Alpine.magic('prettyembedPlay', () => play);
}

window.addEventListener('prettyembedReset', ({ detail }) => reset(detail));
window.addEventListener('prettyembedPause', ({ detail }) => pause(detail));
window.addEventListener('prettyembedPlay', ({ detail }) => play(detail));

function reset(subject) {
return getElements(subject).forEach((element) => {
Expand All @@ -26,6 +27,19 @@ function pause(subject) {
});
}

function play(subject) {
return getElements(subject).every((element) => {
const data = Alpine.$data(element);
if (typeof data.play === 'function') {
data.play();
// This cancels the loop
return false;
}
// This continues the loop
return true;
});
}

const className = 'jonnitto-prettyembed';
function getElements(subject) {
if (typeof subject === 'string') {
Expand Down

0 comments on commit cdf7f04

Please sign in to comment.