-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Peixuan Ding <[email protected]>
- Loading branch information
Showing
10 changed files
with
253 additions
and
46 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
<!-- start: minikube override body-end partial --> | ||
<script language="javascript">initTabs();</script> | ||
<script language="javascript">initQuiz();</script> | ||
<!-- end: minikube override body-end partial --> |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<button data-quiz-id="{{ .Parent.Get "base" }}/{{ .Get "option" }}" type="button" class="btn btn-outline-primary option-button">{{ .Get "option" }}</button> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<div data-quiz-id="{{ with .Get "type"}}{{.}}{{end}}" class="quiz-instruction hide"> | ||
<p>Installation instructions:</p> | ||
{{ .Inner }} | ||
</div> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{{ $level := .Get "base" | strings.Count "/" }} | ||
|
||
{{ $hide := "" }} | ||
{{ if gt $level 0 }} | ||
{{ $hide = "hide" }} | ||
{{ end }} | ||
|
||
<div data-quiz-id="{{ .Get "base" }}" data-level="{{ $level }}" class="row option-row {{ $hide }}"> | ||
<div class="col-lg-2 my-auto"> | ||
<span>{{ with .Get "name"}}{{.}}{{end}}</span> | ||
</div> | ||
<div class="col-lg-10">{{ .Inner }}</div> | ||
</div> | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
function selectQuizOption(selectedId) { | ||
const currentLevel = selectedId.split('/').length - 1; | ||
$('.option-row').each(function (i) { | ||
const rowId = $(this).attr('data-quiz-id'); | ||
// don't hide option rows if it has a lower level | ||
// e.g. when clicking "x86_64" under Linux, we don't want to hide the operating system row | ||
if ($(this).attr('data-level') < currentLevel) { | ||
return; | ||
} | ||
if (rowId === selectedId) { | ||
$(this).removeClass('hide'); | ||
$(this).find('.option-button').removeClass('active'); | ||
return; | ||
} | ||
// hide all other option rows | ||
$(this).addClass('hide'); | ||
}); | ||
// hide other answers | ||
$('.quiz-instruction').addClass('hide'); | ||
// show the selected answer | ||
$('.quiz-instruction[data-quiz-id=\'' + selectedId + '\']').removeClass('hide'); | ||
|
||
const buttons = $('.option-row[data-quiz-id=\'' + selectedId + '\']').find('.option-button'); | ||
// if there is only one option, auto-select that option for the user | ||
if (buttons.length === 1) { | ||
const btn = $(buttons[0]); | ||
btn.addClass('active'); | ||
selectQuizOption(btn.attr('data-quiz-id')); | ||
} | ||
} | ||
|
||
function initQuiz() { | ||
try { | ||
$('.option-button').click(function(e) { | ||
$(this).parent().find('.option-button').removeClass('active'); | ||
$(this).addClass('active'); | ||
const dataContainerId = $(this).attr('data-quiz-id'); | ||
|
||
selectQuizOption(dataContainerId); | ||
}); | ||
const userOS = getQuizUserOS(); | ||
const buttons = $('.option-button[data-quiz-id=\'/' + userOS + '\']'); | ||
if (buttons.length === 1) { | ||
const btn = $(buttons[0]); | ||
btn.addClass('active'); | ||
selectQuizOption(btn.attr('data-quiz-id')); | ||
} | ||
|
||
} catch(e) { | ||
console.log(e); | ||
const elements = document.getElementsByClassName("quiz-instruction"); | ||
for (let element of elements) { | ||
element.classList.remove("hide"); | ||
} | ||
} | ||
} | ||
|
||
const getQuizUserOS = () => { | ||
let os = ['Linux', 'Mac', 'Windows']; | ||
let userAgent = navigator.userAgent; | ||
for (let currentOS of os) { | ||
if (userAgent.indexOf(currentOS) !== -1) { | ||
if (currentOS === 'Mac') { | ||
// return the official OS name "macOS" instead | ||
return 'macOS'; | ||
} | ||
return currentOS; | ||
} | ||
} | ||
return 'Linux'; | ||
} |
Oops, something went wrong.