Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Mystique plugin #73

Merged
merged 3 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions head.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<script src="/scripts/scripts.js" type="module"></script>
<link rel="stylesheet" href="/styles/styles.css"/>
<script src="toggleStyles.js" defer></script>
<link rel="icon" href="data:,">
18 changes: 18 additions & 0 deletions scripts/delayed.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,21 @@
if (analyticsConsent) {
await analyticsSetConsent(analyticsConsent === 'ALLOW');
}

const mystique = async ({ detail }) => {

Check failure on line 23 in scripts/delayed.js

View workflow job for this annotation

GitHub Actions / build

'detail' is defined but never used
// const sk = detail.data;
// // your custom code from button.action goes here
console.log('Load Mystique here...', sk);

Check warning on line 26 in scripts/delayed.js

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement

Check failure on line 26 in scripts/delayed.js

View workflow job for this annotation

GitHub Actions / build

'sk' was used before it was defined
};

const sk = document.querySelector('helix-sidekick');
if (sk) {
// sidekick already loaded
sk.addEventListener('custom:mystique', mystique);
} else {
// wait for sidekick to be loaded
document.addEventListener('sidekick-ready', () => {
document.querySelector('helix-sidekick')
.addEventListener('custom:mystique', mystique);
}, { once: true });
}

Check failure on line 39 in scripts/delayed.js

View workflow job for this annotation

GitHub Actions / build

Newline required at end of file but not found
108 changes: 108 additions & 0 deletions toggleStyles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
document.addEventListener('DOMContentLoaded', () => {
// Check query parameters
const urlParams = new URLSearchParams(window.location.search);
const useGeneratedStyles = urlParams.has('generatedStyles');

// Create stylesheets and buttons
const stylesheets = [];
const buttons = [];

if (useGeneratedStyles) {
// Create and add the generatedStyles.css stylesheet
const stylesheet = document.createElement('link');
stylesheet.id = 'generatedStyles';
stylesheet.rel = 'stylesheet';
stylesheet.href = '/generatedStyles.css';
stylesheet.disabled = false;
document.head.appendChild(stylesheet);
} else {
// Add stylesheets and buttons for files in the /generated folder
for (let i = 0; i <= 5; i++) { // Assuming there are 5 stylesheets for this example

Check failure on line 20 in toggleStyles.js

View workflow job for this annotation

GitHub Actions / build

Unary operator '++' used
(function (i) {

Check warning on line 21 in toggleStyles.js

View workflow job for this annotation

GitHub Actions / build

Unexpected unnamed function

Check failure on line 21 in toggleStyles.js

View workflow job for this annotation

GitHub Actions / build

'i' is already declared in the upper scope on line 20 column 14
const stylesheet = document.createElement('link');
stylesheet.id = `style${i}`;
stylesheet.rel = 'stylesheet';
stylesheet.href = `/generated/styles${i}.css`;
stylesheet.disabled = true;
document.head.appendChild(stylesheet);
stylesheets.push(stylesheet);

const button = document.createElement('button');
button.className = 'toggle-button';
button.innerHTML = `Enable Variation ${i}`;
button.style.bottom = `${20 + (i + 1) * 50}px`; // Adjust vertical position
button.onclick = function () {

Check warning on line 34 in toggleStyles.js

View workflow job for this annotation

GitHub Actions / build

Unexpected unnamed function
toggleStyle(i);

Check failure on line 35 in toggleStyles.js

View workflow job for this annotation

GitHub Actions / build

'toggleStyle' was used before it was defined
};
document.body.appendChild(button);
buttons.push(button);
}(i));
}

// Add the disable all styles button
const disableAllButton = document.createElement('button');
disableAllButton.className = 'toggle-button';
disableAllButton.innerHTML = 'Original Styles';
disableAllButton.style.bottom = '20px'; // Position at the bottom
disableAllButton.onclick = disableAllStyles;

Check failure on line 47 in toggleStyles.js

View workflow job for this annotation

GitHub Actions / build

'disableAllStyles' was used before it was defined
document.body.appendChild(disableAllButton);
}

// Define the toggle function for each stylesheet
function toggleStyle(index) {
stylesheets.forEach((stylesheet, i) => {
stylesheet.disabled = true;
buttons[i].innerHTML = `Enable Variation ${i}`;
buttons[i].style.backgroundColor = '#007BFF';
});

const stylesheet = document.getElementById(`style${index}`);
stylesheet.disabled = false;
updateButtonState(index);

Check failure on line 61 in toggleStyles.js

View workflow job for this annotation

GitHub Actions / build

'updateButtonState' was used before it was defined
}

// Define the function to disable all stylesheets
function disableAllStyles() {
stylesheets.forEach((stylesheet, i) => {
stylesheet.disabled = true;
buttons[i].innerHTML = `Enable Variation ${i}`;
buttons[i].style.backgroundColor = '#007BFF';
});
}

// Define the function to update the button state
function updateButtonState(index) {
const button = buttons[index];
button.innerHTML = `Disable Variation ${index}`;
button.style.backgroundColor = '#FF0000';
}

// Hide buttons if using generatedStyles.css
if (useGeneratedStyles) {
console.log('Hiding buttons');

Check warning on line 82 in toggleStyles.js

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
buttons.forEach((button) => {
button.style.display = 'none';
});
}

// Add styles for the buttons
const style = document.createElement('style');
style.innerHTML = `
.toggle-button {
position: fixed;
right: 20px;
padding: 10px 20px;
background-color: #007BFF;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
z-index: 1000;
}

.toggle-button:hover {
opacity: 0.8;
}
`;
document.head.appendChild(style);
});
6 changes: 6 additions & 0 deletions tools/sidekick/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
"passConfig": true,
"environments": [ "preview", "live", "edit" ],
"includePaths": ["**.docx**"]
},
{
"id": "mystique",
"title": "Mystique",
"event": "mystique",
"environments": [ "dev", "preview" ]
}
]
}
Loading