Skip to content

Commit

Permalink
Merge pull request #73 from adobe-rnd/mystique-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
vtsaplin authored Jun 18, 2024
2 parents ce0fdb7 + 8fb1244 commit 0c3b8f6
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 1 deletion.
2 changes: 1 addition & 1 deletion head.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<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"/>
<link rel="icon" href="data:,">
<script src="./tools/mystique/mystique.js" defer></script>
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
(function (i) {
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 () {
toggleStyle(i);
};
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;
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);
}

// 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');
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);
});
21 changes: 21 additions & 0 deletions tools/mystique/mystique.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const EVENT_NAME = 'mystique-playground';

const mystique = async ({ detail }) => {
const sk = detail.data;
const script = document.createElement('script');
script.src = 'https://localhost:4010/assistant.js';
script.type = 'text/javascript';
script.async = true;
document.head.appendChild(script);
console.log('Load Mystique here...', sk);
};

const sk = document.querySelector('helix-sidekick');
if (sk) {
sk.addEventListener(`custom:${EVENT_NAME}`, mystique);
} else {
document.addEventListener('sidekick-ready', () => {
document.querySelector('helix-sidekick')
.addEventListener(`custom:${EVENT_NAME}`, mystique);
}, { once: true });
}
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-playground",
"title": "Mystique Playground",
"event": "mystique-playground",
"environments": [ "dev", "preview" ]
}
]
}

0 comments on commit 0c3b8f6

Please sign in to comment.