Created
November 18, 2019 18:32
-
-
Save bluemango/d128ffd10acce42496fea6e28d2df300 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/kohovez
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
<script src="https://code.jquery.com/jquery-3.1.0.js"></script> | |
<style id="jsbin-css"> | |
.page { | |
display: none; | |
} | |
.completed-lesson { | |
background-color: yellow; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="progress"> | |
<ul> | |
<li data-lesson-id="lesson-1"> | |
<a href="#lesson-1" class="nav-link"> | |
Lesson 1 | |
</a> | |
</li> | |
<li data-lesson-id="lesson-2"> | |
<a href="#lesson-2" class="nav-link"> | |
Lesson 2 | |
</a> | |
</li> | |
<li data-lesson-id="lesson-3"> | |
<a href="#lesson-3" class="nav-link"> | |
Lesson 3 | |
</a> | |
</li> | |
<li data-lesson-id="lesson-4"> | |
<a href="#lesson-4" class="nav-link"> | |
Lesson 4 | |
</a> | |
</li> | |
</ul> | |
<div id="progress-bar"></div> | |
</div> | |
<div id="home" class="page"> | |
<h1>Manual Title</h1> | |
<ul> | |
<li> | |
<a href="#lesson-1" class="nav-link"> | |
Lesson 1 | |
</a> | |
</li> | |
<li> | |
<a href="#lesson-2" class="nav-link"> | |
Lesson 2 | |
</a> | |
</li> | |
<li> | |
<a href="#lesson-3" class="nav-link"> | |
Lesson 3 | |
</a> | |
</li> | |
<li> | |
<a href="#lesson-4" class="nav-link"> | |
Lesson 4 | |
</a> | |
</li> | |
</ul> | |
</div> | |
<div id="lesson-1" class="lesson-content page"> | |
<h1>Lesson 1 - title</h1> | |
<a href="#lesson-2" class="nav-link"> | |
Next | |
</a> | |
</div> | |
<div id="lesson-2" class="lesson-content page"> | |
<h1>Lesson 2 - title</h1> | |
<a href="#lesson-3" class="nav-link"> | |
Next | |
</a> | |
</div> | |
<div id="lesson-3" class="lesson-content page"> | |
<h1>Lesson 3 - title</h1> | |
<a href="#lesson-4" class="nav-link"> | |
Next | |
</a> | |
</div> | |
<div id="lesson-4" class="lesson-content page"> | |
<h1>Lesson 4 - title</h1> | |
<a href="#home" class="nav-link"> | |
Done | |
</a> | |
</div> | |
<script id="jsbin-javascript"> | |
var currentPage = 'home'; | |
var lessonStatus = { | |
"lesson-1": null, | |
"lesson-2": null, | |
"lesson-3": null, | |
"lesson-4": null | |
} | |
$( document ).ready(function() { | |
$('#home').show(); | |
$('.nav-link').click(function(e) { | |
e.preventDefault(); | |
const id = $(e.target).attr('href'); | |
showPage(id); | |
}); | |
setProgress(); | |
}); | |
function setProgress() { | |
let completed = getCompletedLessons(); | |
let completedCount = completed.length; | |
let length = Object.keys(lessonStatus).length; | |
let count = 0; | |
if (completedCount > 0) { | |
count = Math.round(completedCount/length *100); | |
} | |
let text = count + "%"; | |
$('#progress-bar').text(text); | |
setCompletedStatus(completed); | |
} | |
function setCompletedStatus(keys) { | |
let finder = keys.map(function(key) { | |
return '[data-lesson-id=' + key + ']'; | |
}).join(', '); | |
$(finder).addClass('completed-lesson'); | |
} | |
function getCompletedLessons() { | |
const entries = Object.entries(lessonStatus); | |
const completed = entries.filter(function(value) { | |
return value[1] === true; | |
}); | |
return completed.map(function(value) { | |
return value[0]; | |
}); | |
} | |
function showPage(id) { | |
const currentPage = $('.page:visible').attr('id'); | |
$('.page').hide(); | |
$(id).show(); | |
if (currentPage.includes('lesson-')) { | |
lessonStatus[currentPage] = true; | |
setProgress(); | |
} | |
} | |
</script> | |
<script id="jsbin-source-css" type="text/css">.page { | |
display: none; | |
} | |
.completed-lesson { | |
background-color: yellow; | |
}</script> | |
<script id="jsbin-source-javascript" type="text/javascript">var currentPage = 'home'; | |
var lessonStatus = { | |
"lesson-1": null, | |
"lesson-2": null, | |
"lesson-3": null, | |
"lesson-4": null | |
} | |
$( document ).ready(function() { | |
$('#home').show(); | |
$('.nav-link').click(function(e) { | |
e.preventDefault(); | |
const id = $(e.target).attr('href'); | |
showPage(id); | |
}); | |
setProgress(); | |
}); | |
function setProgress() { | |
let completed = getCompletedLessons(); | |
let completedCount = completed.length; | |
let length = Object.keys(lessonStatus).length; | |
let count = 0; | |
if (completedCount > 0) { | |
count = Math.round(completedCount/length *100); | |
} | |
let text = count + "%"; | |
$('#progress-bar').text(text); | |
setCompletedStatus(completed); | |
} | |
function setCompletedStatus(keys) { | |
let finder = keys.map(function(key) { | |
return '[data-lesson-id=' + key + ']'; | |
}).join(', '); | |
$(finder).addClass('completed-lesson'); | |
} | |
function getCompletedLessons() { | |
const entries = Object.entries(lessonStatus); | |
const completed = entries.filter(function(value) { | |
return value[1] === true; | |
}); | |
return completed.map(function(value) { | |
return value[0]; | |
}); | |
} | |
function showPage(id) { | |
const currentPage = $('.page:visible').attr('id'); | |
$('.page').hide(); | |
$(id).show(); | |
if (currentPage.includes('lesson-')) { | |
lessonStatus[currentPage] = true; | |
setProgress(); | |
} | |
}</script></body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.page { | |
display: none; | |
} | |
.completed-lesson { | |
background-color: yellow; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var currentPage = 'home'; | |
var lessonStatus = { | |
"lesson-1": null, | |
"lesson-2": null, | |
"lesson-3": null, | |
"lesson-4": null | |
} | |
$( document ).ready(function() { | |
$('#home').show(); | |
$('.nav-link').click(function(e) { | |
e.preventDefault(); | |
const id = $(e.target).attr('href'); | |
showPage(id); | |
}); | |
setProgress(); | |
}); | |
function setProgress() { | |
let completed = getCompletedLessons(); | |
let completedCount = completed.length; | |
let length = Object.keys(lessonStatus).length; | |
let count = 0; | |
if (completedCount > 0) { | |
count = Math.round(completedCount/length *100); | |
} | |
let text = count + "%"; | |
$('#progress-bar').text(text); | |
setCompletedStatus(completed); | |
} | |
function setCompletedStatus(keys) { | |
let finder = keys.map(function(key) { | |
return '[data-lesson-id=' + key + ']'; | |
}).join(', '); | |
$(finder).addClass('completed-lesson'); | |
} | |
function getCompletedLessons() { | |
const entries = Object.entries(lessonStatus); | |
const completed = entries.filter(function(value) { | |
return value[1] === true; | |
}); | |
return completed.map(function(value) { | |
return value[0]; | |
}); | |
} | |
function showPage(id) { | |
const currentPage = $('.page:visible').attr('id'); | |
$('.page').hide(); | |
$(id).show(); | |
if (currentPage.includes('lesson-')) { | |
lessonStatus[currentPage] = true; | |
setProgress(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment