Skip to content

Commit

Permalink
Add "debugMode" setting and jump-to-any-chapter functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
mrfatguy committed Nov 5, 2024
1 parent 5668dc2 commit 7eb053a
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 32 deletions.
57 changes: 30 additions & 27 deletions engine/autoloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,43 @@ const AutoLoader = {
'theme-dark': 'Negative'
},

debugMode: false,
defaultLanguage: 'en',
defaultParagraph: 'i',
defaultTheme: 'bootstrap-yeti',
defaultTransformation: 'theme-dark',

promises: [],

updateDefaultValues: function() {
const attributes = [
'themes',
'languages',
'debugMode',
'defaultTheme',
'transformations',
'defaultLanguage',
'defaultParagraph',
'defaultTransformation'
];

attributes.forEach(attribute => {
const value = SettingsEngine.getSettingValue(attribute);

if (value !== undefined) {
if (
(typeof value === 'object') ||
(typeof value === 'boolean') ||
(Array.isArray(value) && value.length > 0) ||
(typeof value === 'number' && !isNaN(value)) ||
(typeof value === 'string' && value.trim() !== '')
) {
this[attribute] = value;
}
}
});
},

loadResources() {

Object.keys(this.stylesheets).forEach(function (key) {
Expand Down Expand Up @@ -110,33 +140,6 @@ const AutoLoader = {
let filenameWithExtension = fullPath.substring(fullPath.lastIndexOf('/') + 1);

return filenameWithExtension.split('.')[0];
},

updateDefaultValues: function() {
const attributes = [
'themes',
'languages',
'defaultTheme',
'transformations',
'defaultLanguage',
'defaultParagraph',
'defaultTransformation'
];

attributes.forEach(attribute => {
const value = SettingsEngine.getSettingValue(attribute);

if (value !== undefined) {
if (
(typeof value === 'object') ||
(Array.isArray(value) && value.length > 0) ||
(typeof value === 'number' && !isNaN(value)) ||
(typeof value === 'string' && value.trim() !== '')
) {
this[attribute] = value;
}
}
});
}
};

Expand Down
28 changes: 26 additions & 2 deletions engine/paragraph-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,14 @@ const ParagraphEngine = {
generateButtons: function(buttons) {
let buttonGroup = document.getElementById('paragraph-buttons');
const classes = ['w-25', 'w-50', 'w-75', 'w-100'];
const newClass = `w-${buttons.length * 25}`;

buttonGroup.innerHTML = '';

buttons.forEach((button) => {
let btn = document.createElement('button');
btn.type = 'button';
btn.className = 'btn btn-success button-25 me-2'; // Adjust class if needed
btn.className = 'btn btn-success button-25 me-2';
btn.classList.add(`w-${100 / buttons.length}`);
btn.innerText = button.label;
btn.onclick = () => {
Expand All @@ -205,8 +206,31 @@ const ParagraphEngine = {
}

buttonGroup.classList.remove(...classes);
const newClass = `w-${buttons.length * 25}`;
buttonGroup.classList.add(newClass);

if (AutoLoader.debugMode) {
const buttonGroup = document.getElementById('control-buttons');
const newButton = document.createElement('button');

newButton.id = 'debug-button';
newButton.type = 'button';
newButton.className = 'btn btn-danger me-2';
newButton.innerHTML = 'Jump';

buttonGroup.appendChild(newButton);
buttonGroup.classList.add('w-75');
buttonGroup.classList.remove('w-50');

newButton.addEventListener('click', function() {
const userValue = prompt('Where do you want to go today?');
if (userValue !== null && userValue !== "" && userValue !== undefined && !isNaN(userValue)) {
const numericValue = Number(userValue);

ParagraphEngine.setCurrentParagraphIndex(numericValue);
window.location.href = 'paragraph.html';
}
});
}
},

goToParagraph: function(paragraph) {
Expand Down
6 changes: 3 additions & 3 deletions paragraph.html
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ <h3><span id="paragraph-title"></span> (<span id="paragraph-number"></span>)</h3
<button type="button" class="btn btn-success button-25 me-2">Button 3</button>
<button type="button" class="btn btn-success button-25 me-2">Button 4</button>
</div>
<div class="btn-group justify-content-between w-50">
<button type="button" data-text="Options" class="btn btn-info w-50 me-2" data-target="settings"></button>
<button type="button" data-text="Menu" class="btn btn-warning w-50 me-2" data-target="menu"></button>
<div id="control-buttons" class="btn-group justify-content-between w-50">
<button id="settings-button" type="button" data-text="Options" class="btn btn-info me-2" data-target="settings"></button>
<button id="menu-button" type="button" data-text="Menu" class="btn btn-warning me-2" data-target="menu"></button>
</div>
</div>
</div>
Expand Down

0 comments on commit 7eb053a

Please sign in to comment.