Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
64 changes: 59 additions & 5 deletions build/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ let privateKey;
let publicKey;
let message;
let signature;
let $backButton;
// For lesson 7
let transaction = lessonLogic.mockTxToSign;

Expand Down Expand Up @@ -204,13 +205,29 @@ function startLesson(newLessonNumber) {
$("#nextButton").prop("hidden", false);
$("#nextButton").prop("disabled", true);
}

// Back button: show for lessons after the first, hide on welcome and final pages
if (newLessonNumber > 1 && finalLesson === false) {
$("#backButton").prop("hidden", false);
$("#backButton").prop("disabled", false);
} else {
$("#backButton").prop("hidden", true);
}
}

// Increment the current lesson counter, save to local storage, and call
// startLesson() to refresh the lesson page
function advanceLesson() {
startLesson(currentLesson + 1);
}

// Decrement the current lesson counter and refresh the lesson page
function goToPreviousLesson() {
const previousLesson = currentLesson - 1;
if (previousLesson >= 1) {
startLesson(previousLesson);
}
}
function saveToLocalStorage(key, value) {
localData[key] = value;
localStorage.setItem('localData', JSON.stringify(localData));
Expand Down Expand Up @@ -311,7 +328,7 @@ function printResult($userInput, $consolePrompt, isError, aResult) {
const userInputString = $('.console-input').val();

// take the user input and dispaly as a label
$('.prompt-completed').clone().removeClass('prompt-completed').insertBefore($consolePrompt).find('code').text(userInputString);
$('.prompt-completed').clone().removeClass('prompt-completed').addClass('console-line').insertBefore($('.console-input-container')).find('code').text(userInputString);

// clear the user input
$userInput.val('');
Expand All @@ -320,7 +337,7 @@ function printResult($userInput, $consolePrompt, isError, aResult) {
}

// print the result
$('.prompt-result').clone().removeClass('prompt-result').insertBefore($consolePrompt).find('code')[isError ? 'html' : 'text'](result);
$('.prompt-result').clone().removeClass('prompt-result').addClass('console-line').insertBefore($('.console-input-container')).find('code')[isError ? 'html' : 'text'](result);
}

// This is the same opening line as 'document ready()'
Expand All @@ -336,6 +353,7 @@ $(function () {
const $consolePrompt = $('.console-prompt');
const $userInput = $('.console-input');
const $nextButton = $('#nextButton');
$backButton = $('#backButton');
const $lessonArea = $('.lessons');

// Focus on the user input box
Expand All @@ -359,10 +377,23 @@ $(function () {
$nextButton.prop("disabled", true);
});

// If the user clicks anywhere in the console box, focus the cursor on the input line
$console.on('click', function (e) {
$userInput.trigger('focus');
// Click-to-copy: clicking any past console line copies its text
$console.on('click', '.console-line code', async function () {
const textToCopy = $(this).text();
if (navigator.clipboard && navigator.clipboard.writeText) {
try {
await navigator.clipboard.writeText(textToCopy);
} catch (e) {}
}
});

// When the back button is pressed, go to the previous lesson
$backButton.on('click', function () {
goToPreviousLesson();
// Disable the next button in the lesson we just navigated to until it is completed
$nextButton.prop("disabled", true);
});

$userInput.on('keydown', async function (e) {
const userInputString = $('.console-input').val();

Expand Down Expand Up @@ -414,6 +445,29 @@ $(function () {
if (lowercaseUserInputString.includes('showanswer()')) {
// TODO show the answer
}

// Allow users to type 'next' to move to the next lesson,
// but only if the current lesson has been completed and the
// Next button is enabled.
if (lowercaseUserInputString === 'next') {
let result = '';
let error = true;

if (!$nextButton.prop('disabled')) {
error = false;
advanceLesson();
$nextButton.prop('disabled', true);
} else {
result = 'Please complete this lesson before moving to the next one.';
}

printResult($userInput, $consolePrompt, error, result);

// Auto scroll to the bottom of the console
const newConsoleHeight = $console[0].scrollHeight;
$console.scrollTop(newConsoleHeight);
return;
}
let result = '';
let error = true;
const sanityCheckResult = validation.userInputSanityCheck(currentLesson, lowercaseUserInputString);
Expand Down
2 changes: 1 addition & 1 deletion build/main.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ <h3>Bitcoin Core Development:</h3>

<div class="lessonFooter">
<div class="navigationButtonArea">
<center><button hidden="true">Back</button></center>
<center><button id="backButton" hidden="true" disabled>Back</button></center>
</div>
<div class="progressIndicator">
<strong><p id="lessonNumber" align="center"></p></strong>
Expand Down
75 changes: 66 additions & 9 deletions js/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ let privateKey;
let publicKey;
let message;
let signature;
let $backButton;
// For lesson 7
let transaction = lessonLogic.mockTxToSign;

Expand Down Expand Up @@ -80,6 +81,14 @@ function startLesson(newLessonNumber) {
$("#nextButton").prop("disabled", true);
}

// Back button: show for lessons after the first, hide on welcome and final pages
if (newLessonNumber > 1 && finalLesson === false) {
$("#backButton").prop("hidden", false);
$("#backButton").prop("disabled", false);
} else {
$("#backButton").prop("hidden", true);
}


}

Expand All @@ -89,6 +98,14 @@ function advanceLesson() {
startLesson(currentLesson + 1);
}

// Decrement the current lesson counter and refresh the lesson page
function goToPreviousLesson() {
const previousLesson = currentLesson - 1;
if (previousLesson >= 1) {
startLesson(previousLesson);
}
}

function saveToLocalStorage(key, value) {
localData[key] = value;
localStorage.setItem('localData', JSON.stringify(localData));
Expand Down Expand Up @@ -195,7 +212,8 @@ function printResult($userInput, $consolePrompt, isError, aResult) {
// take the user input and dispaly as a label
$('.prompt-completed').clone()
.removeClass('prompt-completed')
.insertBefore($consolePrompt)
.addClass('console-line')
.insertBefore($('.console-input-container'))
.find('code')
.text(userInputString);

Expand All @@ -207,11 +225,12 @@ function printResult($userInput, $consolePrompt, isError, aResult) {
}

// print the result
$('.prompt-result').clone()
.removeClass('prompt-result')
.insertBefore($consolePrompt)
.find('code')
[isError ? 'html' : 'text'](result);
$('.prompt-result').clone()
.removeClass('prompt-result')
.addClass('console-line')
.insertBefore($('.console-input-container'))
.find('code')
[isError ? 'html' : 'text'](result);
}

// This is the same opening line as 'document ready()'
Expand All @@ -228,6 +247,7 @@ $(function() {
const $consolePrompt = $('.console-prompt');
const $userInput = $('.console-input');
const $nextButton = $('#nextButton');
$backButton = $('#backButton');
const $lessonArea = $('.lessons');

// Focus on the user input box
Expand All @@ -253,9 +273,23 @@ $(function() {
$nextButton.prop("disabled", true);
});

// If the user clicks anywhere in the console box, focus the cursor on the input line
$console.on('click', function (e) {
$userInput.trigger('focus');
// Click-to-copy: clicking any past console line copies its text
$console.on('click', '.console-line code', async function () {
const textToCopy = $(this).text();
if (navigator.clipboard && navigator.clipboard.writeText) {
try {
await navigator.clipboard.writeText(textToCopy);
} catch (e) {
// ignore clipboard errors
}
}
});

// When the back button is pressed, go to the previous lesson
$backButton.on('click', function() {
goToPreviousLesson();
// Disable the next button in the lesson we just navigated to until it is completed
$nextButton.prop("disabled", true);
});

$userInput.on('keydown', async function (e) {
Expand Down Expand Up @@ -314,6 +348,29 @@ $(function() {
// TODO show the answer
}

// Allow users to type 'next' to move to the next lesson,
// but only if the current lesson has been completed and the
// Next button is enabled.
if (lowercaseUserInputString === 'next') {
let result = '';
let error = true;

if (!$nextButton.prop('disabled')) {
error = false;
advanceLesson();
$nextButton.prop('disabled', true);
} else {
result = 'Please complete this lesson before moving to the next one.';
}

printResult($userInput, $consolePrompt, error, result);

// Auto scroll to the bottom of the console
const newConsoleHeight = $console[0].scrollHeight;
$console.scrollTop(newConsoleHeight);
return;
}

let result = '';
let error = true;

Expand Down
6 changes: 6 additions & 0 deletions less/main.less
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
border-width: thin;
overflow-y: scroll;
flex: 3;
user-select: text;

.console-header {
color: @orangeColor;
Expand Down Expand Up @@ -314,6 +315,11 @@
border: none
}

#backButton:enabled {
background-color: black;
color: white;
}

button:hover:enabled {
transform: translate(2px, 2px);
box-shadow: 2px 2px @retroGreenColor;
Expand Down
Loading