Skip to content

Commit

Permalink
add ToC
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanzhangxiao committed Jan 15, 2024
1 parent 330c774 commit 746b70e
Show file tree
Hide file tree
Showing 8 changed files with 209 additions and 21 deletions.
2 changes: 1 addition & 1 deletion _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# SITE SPECIFIC: The following fields are typically changed for each site
name: EE 643 Spring 2024
baseurl: /ee643spring2024
morea_theme: zephyr
morea_theme: cerulean-original
timezone: Pacific/Honolulu
morea_navbar_items:
# - Prerequisites
Expand Down
6 changes: 3 additions & 3 deletions _includes/breadcrumb-4.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!-- Internal fragment for displaying the breadcrumb bar -->
<div class="breadcrumb-background" style="padding-top: 1em; padding-bottom: .01em">
<div class="container">
<div class="breadcrumb-background" style="padding-top: 1em; padding-bottom: .01em;">
<!-- <div class="container"> -->
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
{% if site.morea_head_breadcrumb_link %}
Expand All @@ -12,5 +12,5 @@
<li class="breadcrumb-item active">{{ page.title }}</li>
</ol>
</nav>
</div>
<!-- </div> -->
</div>
13 changes: 13 additions & 0 deletions _layouts/page original.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
layout: core
---
{% include breadcrumb-4.html %}

{% if page.topdiv == 'container' %}
<div class="container">
{{ content }}
</div>
{% else %}
{{ content }}
{% endif %}

105 changes: 103 additions & 2 deletions _layouts/page.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,114 @@
---
layout: core
---
{% include breadcrumb-4.html %}

{% if page.topdiv == 'container' %}
<div class="container">
{{ content }}
<div class="row">
<!-- Main Content -->
<div class="col-md-9">
{% include breadcrumb-4.html %}
{{ content }}
</div>

<!-- ToC Sidebar -->
<div class="col-md-3 d-none d-md-block">
<div class="toc-sidebar">
<div id="toc-container" class="toc__left-border"></div>
</div>
</div>
</div>
</div>
{% else %}
{{ content }}
{% endif %}

<script>

// Generate the table of content including sections (h2) and subsections (h3)
document.addEventListener('DOMContentLoaded', function() {
const tocContainer = document.getElementById('toc-container');
const h2Headings = document.querySelectorAll('.col-md-9 h2');
const h2List = document.createElement('ul');

h2Headings.forEach(h2 => {
const h2Item = document.createElement('li');
const h2Link = document.createElement('a');
h2Link.href = '#' + h2.id;
h2Link.textContent = h2.textContent;
h2Item.appendChild(h2Link);

// Create a sublist for h3 headings under this h2
const h3List = document.createElement('ul');

// Get all next siblings until the next h2 or end of container
let nextElem = h2.nextElementSibling;
while (nextElem && nextElem.tagName !== 'H2') {
if (nextElem.tagName === 'H3') {
const h3Item = document.createElement('li');
const h3Link = document.createElement('a');
h3Link.href = '#' + nextElem.id;
h3Link.textContent = nextElem.textContent;
h3Item.appendChild(h3Link);
h3List.appendChild(h3Item);
}
nextElem = nextElem.nextElementSibling;
}

if (h3List.hasChildNodes()) {
h2Item.appendChild(h3List);
}

h2List.appendChild(h2Item);
});

tocContainer.appendChild(h2List);
});

// Assign the active link based on the scroll position
document.addEventListener('scroll', function() {
const headings = document.querySelectorAll('.col-md-9 h2, .col-md-9 h3');
const scrollPosition = window.pageYOffset || document.documentElement.scrollTop;
const halfScreenHeight = window.innerHeight / 2;

// First, remove 'active' class from all ToC links
document.querySelectorAll('#toc-container a').forEach(a => {
a.classList.remove('active');
});

// Then, find and highlight the active link
foundActive = false

// Check all the sections/subsections except the last one
for (let i = 0; i < headings.length-1; i++) {
const heading = headings[i];
const headingTop = heading.offsetTop;
const headingHeight = heading.offsetHeight;
const nextHeadingTop = headings[i+1].offsetTop;
const nextHeadingHeight = headings[i+1].offsetHeight;

console.log('Heading:', heading.id, 'Top:', headingTop, 'Height:', headingHeight, 'Scroll:', scrollPosition, 'Half screen height:', halfScreenHeight);

// Check if the scroll position is within the current heading
if (scrollPosition + halfScreenHeight >= headingTop - headingHeight && (scrollPosition < headingTop - headingHeight || scrollPosition + halfScreenHeight < nextHeadingTop - nextHeadingHeight)) {
console.log('Found active link', heading.id); // Debugging
const activeLink = document.querySelector(`#toc-container a[href="#${heading.id}"]`);
activeLink.classList.add('active');
foundActive = true;
break; // Stop the loop once the active link is found
}
}
// Check the last section/subsection under a different rule
if (foundActive == false) {
lastHeading = headings[headings.length-1];
const headingTop = lastHeading.offsetTop;
const headingHeight = lastHeading.offsetHeight;
if (scrollPosition + halfScreenHeight >= headingTop - headingHeight) {
const activeLink = document.querySelector(`#toc-container a[href="#${lastHeading.id}"]`);
activeLink.classList.add('active');
}
}
});

</script>

89 changes: 81 additions & 8 deletions css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,46 @@ body {
}
}

/* Add margins to paragraphs for larger devices */
@media (min-width: 768px) {
p {
display: block;
margin-block-start: 1em;
margin-block-end: 1em;
margin-inline-start: 0px;
margin-inline-end: 0px;
}
}

/* Add top margin to h2 heading for larger devices */
@media (min-width: 768px) {
h2 {
margin-top: 1rem;
display: block;
margin-block-start: 0.83em;
margin-block-end: 0.83em;
margin-inline-start: 0px;
margin-inline-end: 0px
}

h2 {
margin-top: 2.5rem;
margin-bottom: 1.25rem;
}
}

/* Add top margin to h3 heading for larger devices */
@media (min-width: 768px) {
h3 {
display: block;
margin-block-start: 1em;
margin-block-end: 1em;
margin-inline-start: 0px;
margin-inline-end: 0px;
}

h3 {
margin-top: 1.875rem;
margin-bottom: 1.25rem;
}
}

Expand Down Expand Up @@ -65,12 +101,6 @@ body {
background-color: var(--bs-white);
}

/*
h1, h2, h3 {
margin-top: .20em;
}
*/

small {
font-size: .7em
}
Expand All @@ -87,4 +117,47 @@ small {
padding-bottom: 2rem;
margin-top: 2em;
}
}
}

/* Define a toc-sidebar class for the table of content on the sidebar */
.toc-sidebar {
position: fixed; /* or 'sticky' */
top: 70px; /* Adjust based on your navbar height */
/* margin: 0.5rem; */
/* font-weight: 50; /* lighter weight */
/* line-height: 2rem; */
}

.toc__left-border {
border-left: 1px solid var(--bs-border-color);
}

#toc-container, #toc-container ul {
list-style: none;
padding-left: 0.5rem;
}

#toc-container {
font-size: .875rem;
margin-bottom: 0;
padding: 0.5rem 0;
}

#toc-container li {
margin: 0.5rem 0.5rem;
}

#toc-container a {
color: var(--bs-primary-color); /* lighter color */
display: block;
text-decoration: none;
}

#toc-container a:hover {
color: var(--bs-link-hover-color); /* Color changes on hover */
}

#toc-container a.active {
color: var(--bs-link-hover-color); /* Color for active section link */
}

2 changes: 1 addition & 1 deletion morea/01-introduction/experience-introduce-yourself.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ morea_start_date: "2024-01-08T23:00"
morea_labels:
---

# E01: Introduce yourself
# Introduce yourself

## Task

Expand Down
9 changes: 5 additions & 4 deletions morea/02-overview/reading-building-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Here is the block diagram of a typical <span style="color: red;">point-to-point<

Note that for each block in the transmitter, there is a counterpart in the receiver. Let us divide into each block and discuss their roles.

## Source Encoder and Source Decoder
## Source encoder and source decoder

<figure style="text-align: center;">
<img src="02-building-blocks-source-coding.png" alt="Source coding in a typical communication system" width="500">
Expand All @@ -32,7 +32,7 @@ Even if the source is already a binary sequence (e.g., a text message that is na

Source coding is an important topic in information theory. But we will not dive deep into this topic in this course.

## Channel Encoder and Channel Decoder
## Channel encoder and channel decoder

<figure style="text-align: center;">
<img src="02-building-blocks-channel-coding.png" alt="Channel coding in a typical communication system" width="500">
Expand All @@ -44,7 +44,7 @@ Well, the source encoder removes the inherent redundancy in the source signal, w

We will discuss some simple channel coding and decoding schemes in this course.

## Modulator and Demodulator
## Modulator and demodulator

<figure style="text-align: center;">
<img src="02-building-blocks-modulation.png" alt="Modulation in a typical communication system" width="500">
Expand All @@ -63,4 +63,5 @@ Therefore, the transmitter needs to carefully "modulate" the signal into the cor

Modulation is also important in avoiding *multi-user interference*. For example, in LTE, if two AT&T cell phones are making phone calls in the same room, their signals will be modulated into different frequency bins withint the AT&T spectrum.

Of course, the frequency is not the only degree of freedom. Modulation can place signals in different space and time. We will elaborate on this important topic later.
Of course, the frequency is not the only degree of freedom. Modulation can place signals in different space and time. We will elaborate on this important topic later.

4 changes: 2 additions & 2 deletions morea/02-overview/reading-fading-interference.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ There are two key challenges in wireless communications:

Both challenges are *unique* in wireless communications.

## How to Deal With Fading?
## How to deal with fading?

<figure style="text-align: center;">
<img src="02-building-blocks-channel-coding.png" alt="Channel coding in a typical communication system" width="500">
Expand All @@ -27,7 +27,7 @@ As we discussed earlier, the channel encoder adds redundancy to combat the imper

As we will see later, compared to other channel imperfections (e.g., noises), fading is much harder to deal with. Therefore, channel coding is particularly important in wireless communication systems.

## How to Deal With Interference
## How to deal with interference

<figure style="text-align: center;">
<img src="02-building-blocks-modulation.png" alt="Modulation in a typical communication system" width="500">
Expand Down

0 comments on commit 746b70e

Please sign in to comment.