Skip to content

Commit e76f963

Browse files
committed
Berry animation add index.html API
1 parent 2f63ff0 commit e76f963

1 file changed

Lines changed: 42 additions & 5 deletions

File tree

docs/Tasmota-Berry-emulator/index.html

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,15 +1177,52 @@ <h2>Tasmota Berry LED Simulator</h2>
11771177
});
11781178
}
11791179

1180+
// Check for URL parameter to load a specific example
1181+
// Supports: ?example=<id> or ?ex=<id>
1182+
function getExampleFromURL() {
1183+
var params = new URLSearchParams(window.location.search);
1184+
return params.get('example') || params.get('ex');
1185+
}
1186+
11801187
// Auto-compile and run the default example after everything is loaded
11811188
// Wait a bit to ensure all modules are fully initialized
11821189
setTimeout(function() {
1183-
var compileRunBtn = document.getElementById('btn-compile-run');
1184-
if (compileRunBtn && !compileRunBtn.disabled) {
1185-
if (window.consoleManager) {
1186-
window.consoleManager.info('Auto-running default example...');
1190+
var requestedExample = getExampleFromURL();
1191+
1192+
if (requestedExample && window.animationExamples) {
1193+
// Try to load the requested example
1194+
var example = window.animationExamples.getById(requestedExample);
1195+
if (example) {
1196+
if (window.consoleManager) {
1197+
window.consoleManager.info('Loading example from URL: ' + example.name);
1198+
}
1199+
// Use the library's selectExample method which handles loading and running
1200+
if (window.animationLibrary) {
1201+
window.animationLibrary.selectExample(requestedExample);
1202+
}
1203+
} else {
1204+
// Example not found - log available examples
1205+
if (window.consoleManager) {
1206+
window.consoleManager.warn('Example not found: ' + requestedExample);
1207+
var allExamples = window.animationExamples.getAll();
1208+
var ids = allExamples.map(function(e) { return e.id; }).join(', ');
1209+
window.consoleManager.info('Available examples: ' + ids);
1210+
}
1211+
// Fall back to default behavior
1212+
var compileRunBtn = document.getElementById('btn-compile-run');
1213+
if (compileRunBtn && !compileRunBtn.disabled) {
1214+
compileRunBtn.click();
1215+
}
1216+
}
1217+
} else {
1218+
// No URL parameter - run default example
1219+
var compileRunBtn = document.getElementById('btn-compile-run');
1220+
if (compileRunBtn && !compileRunBtn.disabled) {
1221+
if (window.consoleManager) {
1222+
window.consoleManager.info('Auto-running default example...');
1223+
}
1224+
compileRunBtn.click();
11871225
}
1188-
compileRunBtn.click();
11891226
}
11901227
}, 50);
11911228
});

0 commit comments

Comments
 (0)