Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added fixed navbar #46

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open

added fixed navbar #46

wants to merge 31 commits into from

Conversation

nathanchi
Copy link

No description provided.

source-browser.html Show resolved Hide resolved
@@ -42,6 +69,16 @@
</style>
</head>
<body class="m2">
<ul class = "navbar" id="navbar">
<li><a href="#languages" id="lilang">languages</a></li>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should not be hardcoded. They should be generated by the JS.

@@ -72,16 +109,16 @@ <h1 id="loading" class="m1 center display-none">⌛</h1>
name: topic,
repoUrl: `https://github.com/${ORGANIZATION}/apertium-${topic}`,
}));

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove all these extra trailing spaces.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are not fixed...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have removed these from throughout the code.

@@ -132,7 +169,7 @@ <h1 id="loading" class="m1 center display-none">⌛</h1>
$('#topics').append(
$('<div class="topic flex-auto">').append(
$('<div>').append(
$('<h2 class="inline-block m0">').text(name),
$('<h2 class="inline-block m0" id='+name+'>').text(name),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use concatenation. Use a jQuery function to set the id.

$(window).scroll(function() {
var top = $(window).scrollTop();
var bottom = $(window).scrollTop() + $(window).height();
var langtop = $("#languages").position();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be adjusted via a loop that goes through the topics, not hardcoded to only work with these.

Copy link
Member

@sushain97 sushain97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initial comments. You might find it easiest to run this code through Prettier with the correct settings.

@@ -42,6 +65,7 @@
</style>
</head>
<body class="m2">
<ul class = "navbar" id="navbar"></ul>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove spacing around first equal sign.

@@ -72,16 +109,16 @@ <h1 id="loading" class="m1 center display-none">⌛</h1>
name: topic,
repoUrl: `https://github.com/${ORGANIZATION}/apertium-${topic}`,
}));

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are not fixed...




var array = ['languages', 'trunk', 'staging', 'nursery', 'incubator', 'tools'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already defined above as TOPICS.


var array = ['languages', 'trunk', 'staging', 'nursery', 'incubator', 'tools'];
array.forEach(function(header) {
$("#navbar").append("<li><a href=#"+header+" id=li"+header+">"+header+"</a></li>");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be no concatenation here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try using the href and text methods. jQuery elements can also take a list of attributes. Nested elements should be constructed via append for readability.

var array = ['languages', 'trunk', 'staging', 'nursery', 'incubator', 'tools'];
array.forEach(function(header) {
$("#navbar").append("<li><a href=#"+header+" id=li"+header+">"+header+"</a></li>");
$("#inline-block m0").attr("id", name);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What element is this adding to? Why is there an element with this misleading id that sounds like a class?

$("#inline-block m0").attr("id", name);
});
$(window).scroll(function() {
var top = $(window).scrollTop();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use only const or let, never var.

var bottom = $(window).scrollTop() + $(window).height();
var titles = ['languages', 'trunk', 'staging', 'nursery', 'incubator', 'tools'];
var i;
for(i = 0; i<titles.length; i++){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need spacing between binary operators and i should be declared inline here.

$(window).scroll(function() {
var top = $(window).scrollTop();
var bottom = $(window).scrollTop() + $(window).height();
var titles = ['languages', 'trunk', 'staging', 'nursery', 'incubator', 'tools'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this declared again?

for(i = 0; i<titles.length; i++){
var header = titles[i];
var vartop = $('#'+header).position();
if(top < vartop.top && vartop.top < bottom){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please emulate spacing in the rest of this code.

if(vartop.top>bottom){
$tools.text(header+'↓')
}
else
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always use braces.

Copy link
Member

@sushain97 sushain97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some further suggestions. There are a number of old ones that have not been actioned on either.

@@ -67,21 +91,21 @@ <h1 id="loading" class="m1 center display-none">⌛</h1>
CACHE_KEY = `${ORGANIZATION}-cache`,
EXPIRY_KEY = `${ORGANIZATION}-expiry`,
EXPIRY_MILLIS = 60000,
TOPICS = ['languages', 'trunk', 'staging', 'nursery', 'incubator', 'tools'].map(topic => ({
LIST = ['languages', 'trunk', 'staging', 'nursery', 'incubator', 'tools'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't use entirely unhelpful variables names like list. In fact, this change isn't necessary at all. Just use the previous TOPICS variable for iteration and access the name attribute. e.g. TOPICS[0].name.

async function getReposByTopic(organization) {
const headers = new Headers({ Accept: 'application/vnd.github.mercy-preview+json' });
const cacheStale = !(CACHE_KEY in localStorage) || localStorage[EXPIRY_KEY] < Date.now();

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are still unnecessary whitespace additions throughout this entire file that should be deleted. Something like 10 of them.

@@ -132,7 +156,7 @@ <h1 id="loading" class="m1 center display-none">⌛</h1>
$('#topics').append(
$('<div class="topic flex-auto">').append(
$('<div>').append(
$('<h2 class="inline-block m0">').text(name),
$('<h2 class="inline-block m0" id="topic" style="padding-top:75px; margin-top:-75px;">').text(name),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use inline styling. Instead, style the associated class. Furthermore, this creates multiple elements with the same id, i.e. topic. This is illegal HTML. Instead, something like topic-languages etc. might work for your purposes.

@@ -141,7 +165,8 @@ <h1 id="loading" class="m1 center display-none">⌛</h1>
repoList,
),
);

$("[id=topic]").attr("id", name);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above comment.

else{
$('#li'+heading).show();
let $heading = $('#li'+heading);
if(vartop.top>bottom){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spacing between binary operations here and throughout should be consistent with existing code.

$(document).ready(() => {
$("#navbar").append('<li id="li"></li>');
for(let i = 0; i < LIST.length; i++){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the sake of stylistic consistency, use forEach here. It might even be nicer with a map to create the elements and then appending the entire list to the container.

$("#navbar").append('<li id="li"></li>');
for(let i = 0; i < LIST.length; i++){
$("#li").append('<a id="placeholder"></a>');
$("[id=placeholder]").attr({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an anti-pattern. Use the way that multiple attributes are added to an element throughout the existing code, i.e. an object containing the attributes is passed as the second argument to $(...) when creating the element.

setInterval(refreshTopics, EXPIRY_MILLIS * 2);
showTopics();
});
</script>
</body>
</html>
</html>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert your changes that deleted the final blank line in this file.

Copy link
Member

@sushain97 sushain97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a number of still unresolved comments (at least 3).

padding: 14px 16px;
text-decoration: none;
}
h2[class$="inline-block m0"] {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What..?

@@ -72,16 +100,13 @@ <h1 id="loading" class="m1 center display-none">⌛</h1>
name: topic,
repoUrl: `https://github.com/${ORGANIZATION}/apertium-${topic}`,
}));

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert this spacing change and the others.

padding: 14px 16px;
text-decoration: none;
}
h2[class="inline-block m0"] {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please look into how to use CSS selectors, especially selecting using classes.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I'll take a look at that.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have fixed the CSS.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll fix the spacing.

Copy link
Member

@sushain97 sushain97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are still numerous style issues. I've pointed out some of them. As I mentioned, running this through prettier is probably the best option.

function createNavbar(item) {
$('#li').append(
$('<a>', {
id: 'li' + item,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use string interpolation instead of concatenation i.e.

`li${item}`

Also, ids should be id-agnostic if possible. So, something like ${item}-nav-link perhaps?

@@ -181,13 +209,51 @@ <h1 id="loading" class="m1 center display-none">⌛</h1>
.focus();
}

function createNavbar(item) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function createNavbar(item) {
function createNavbar(topic) {

for(let i = 0; i < TOPICS.length; i++){
let heading = TOPICS[i].name;
list.push(heading);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation is off here.

$(document).ready(() => {
let list = [];
$("#navbar").append('<li id="li"></li>');
for(let i = 0; i < TOPICS.length; i++){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a forEach instead for consistency.

$('#github-link').attr('href', `https://github.com/${ORGANIZATION}`);
$('#refresh').click(({ currentTarget }) => {
currentTarget.blur();
refreshTopics();
});

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert spacing change here.

let heading = TOPICS[i].name;
let vartop = $('#' + heading).position();
if(top < vartop.top && vartop.top < bottom){
$('#li' + heading).hide();
Copy link
Member

@sushain97 sushain97 Nov 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use string interpolation concatenation.

for(let i = 0; i < TOPICS.length; i++){
let heading = TOPICS[i].name;
let vartop = $('#' + heading).position();
if(top < vartop.top && vartop.top < bottom){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(top < vartop.top && vartop.top < bottom){
if (top < vartop.top && vartop.top < bottom) {

$(window).scroll(() => {
let top = $(window).scrollTop();
let bottom = $(window).scrollTop() + $(window).height();
for(let i = 0; i < TOPICS.length; i++){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be possible with forEach. Don't create a new function, just use an anonymous arrow function.

if(top < vartop.top && vartop.top < bottom){
$('#li' + heading).hide();
}
else{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spacing and indentation

else{
$('#li' + heading).show();
let $heading = $('#li' + heading);
if(vartop.top > bottom){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(vartop.top > bottom){
if (vartop.top > bottom) {

Copy link
Member

@sushain97 sushain97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting close!

padding: 14px 16px;
text-decoration: none;
}
.inline-block.m0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not be styling all of them with this. Instead, should use a custom class in the JS and style that.

ul:nth-child(1) {
list-style-type: none;
position: absolute;
margin: 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many of these rules should be replaced with the basscss v7 rules. e.g. .m0 is margin: 0.

@@ -42,6 +69,7 @@
</style>
</head>
<body class="m2">
<ul class="navbar" id="navbar"></ul>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just the id should suffice unless you have multiple navbars.

@@ -181,7 +209,46 @@ <h1 id="loading" class="m1 center display-none">⌛</h1>
.focus();
}

function createNavbar(topic) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline this function where it is used.

function createNavbar(topic) {
$('.li').append(
$('<a>', {
id: `li${topic}`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I mentioned in my previous review, use a tag-agnostic id.

});
});

$(window).scroll(() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this also happen on window resize?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added that, as well.

let top = $(window).scrollTop();
let bottom = $(window).scrollTop() + $(window).height();
list.forEach(heading => {
let vartop = $(`#${heading}`).position();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does the var in vartop refer to?

Copy link
Author

@nathanchi nathanchi Nov 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It refers to variable, for each of the heading variables. Would you suggest I rename it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to name a variable var to indicate that it's a variable? Something like heading_position maybe.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I'll rename that.

});

$(window).scroll(() => {
let top = $(window).scrollTop();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variables that do not change should be const.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I'll update that tomorrow.

$(`#li${heading}`).hide();
} else {
$(`#li${heading}`).show();
let $heading = $(`#li${heading}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let $heading = $(`#li${heading}`);
$(`#li${heading}`).text(`${heading} ${vartop.top > bottom ? '↓' : '↑'}`);

$(document).ready(() => {
$('#navbar').append('<li class="li"></li>');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is there an extra list element?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's only one list element. Would you like me to make this list element hard-coded in the html instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, I'll do that. :)

@nathanchi
Copy link
Author

I'm using my dad's computer. That's why the name is different.

}
.topic {
padding-top:75px;
margin-top:-75px;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spacing between colon and value.

@@ -42,6 +50,9 @@
</style>
</head>
<body class="m2">
<ul class="fixed m0 p0 overflow-hidden bg-black bottom-0 col-12 z2" id="navbar">
<li class="li left"></li>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this li class do?

Copy link
Author

@nathanchi nathanchi Nov 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the hardcoded li class that I added. The goes within the <li>, which goes within the <ul>.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's used for the .append() method later on in the code, to select only those values.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just #navbar li?.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unresolved?

const top = $(window).scrollTop();
const bottom = $(window).scrollTop() + $(window).height();
TOPICS.forEach(heading => {
heading = heading.name;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use destructuring in the function argument.

const bottom = $(window).scrollTop() + $(window).height();
TOPICS.forEach(heading => {
heading = heading.name;
let heading_position = $(`#${heading}`).position();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Const

TOPICS.forEach(heading => {
heading = heading.name;
let heading_position = $(`#${heading}`).position();
if (top < heading_position.top && heading_position.top < bottom) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're only ever using top, just save that instead.

@@ -182,6 +193,32 @@ <h1 id="loading" class="m1 center display-none">⌛</h1>
}

$(document).ready(() => {
$(window).on('scroll resize', function(){
const top = $(window).scrollTop();
const bottom = $(window).scrollTop() + $(window).height();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use top here instead of another call.

$(`#${heading}-nav-link`).hide();
} else {
$(`#${heading}-nav-link`).show();
$(`#${heading}-nav-link`).text(`${heading} ${heading_position.top > bottom ? '↓' : '↑'}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These calls can be chained.

});

TOPICS.forEach(topic => {
topic = topic.name;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Destructuring here as well.

topic = topic.name;
$('.li').append(
$('<a>', {
class: `inline-block white center btn:hover`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just add this to the string part since there's no interpolation.

$(window).on('scroll resize', function(){
const top = $(window).scrollTop();
const bottom = $(window).scrollTop() + $(window).height();
TOPICS.forEach(heading => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think append can take a list, right? In that case, use a map to create the list and append that.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which append are you referring to?
$('.li').append( ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I understand, that area of the code doesn't need appending.

$(window).on('scroll resize', function(){
const top = $(window).scrollTop();
const bottom = top + $(window).height();
TOPICS.forEach(topic => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
TOPICS.forEach(topic => {
TOPICS.forEach(({name}) => {

const bottom = top + $(window).height();
TOPICS.forEach(topic => {
let {name} = topic;
const name_position = $(`#${name}`).position().top;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const name_position = $(`#${name}`).position().top;
const navLinkPosition = $(`#${name}`).position().top;

@@ -182,6 +193,29 @@ <h1 id="loading" class="m1 center display-none">⌛</h1>
}

$(document).ready(() => {
$(window).on('scroll resize', function(){
const top = $(window).scrollTop();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rest of the code is indented two spaces but now it's 4?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll run it through Prettier again, then.

@@ -182,6 +193,29 @@ <h1 id="loading" class="m1 center display-none">⌛</h1>
}

$(document).ready(() => {
$(window).on('scroll resize', function(){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$(window).on('scroll resize', function(){
$(window).on('scroll resize', () => {

if (top < name_position && name_position < bottom) {
$(`#${name}-nav-link`).hide();
} else {
$(`#${name}-nav-link`).text(`${name} ${name_position > bottom ? '↓' : '↑'}`).show();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can replace the entire block with something like:

Suggested change
$(`#${name}-nav-link`).text(`${name} ${name_position > bottom ? '↓' : '↑'}`).show();
$(`#${name}-nav-link`)
.text(`${name} ${name_position > bottom ? '↓' : '↑'}`)
.toggle(top >= name_position || name_position >= bottom);

}
});
});
TOPICS.forEach(topic => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This entire block can be replaced with $('.li').append(TOPICS.map(({name}) => ...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, why are you appending all the links to the same list element? There should be one list element (<li>) per entry inside the <ul>.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried replacing TOPICS.forEach(topic => { as you recommended, but it didn't work.

I also tried to make one list element (each containing one / element), but it didn't quite work. I tried doing this:

TOPICS.map(({name}) => { $('#navbar').append( $('<li></li>', {class:${name} left}) $('#navbar li').append( $('<a class = "inline-block white center btn:hover">', { id: ${name}-nav-link, href: #${name} }).text(name) ); ); });, which failed. Do you have any suggestions?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, it works now.

Copy link
Member

@sushain97 sushain97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there!


TOPICS.map(({name}) => {
$('#navbar').append(
$('<li class = "left">').append(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$('<li class = "left">').append(
$('<li class="left">').append(

});

TOPICS.map(({name}) => {
$('#navbar').append(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I suggested using map, I didn't mean directly instead of forEach. You should map to create the <li> elements and then append that list to #navbar.

Copy link
Author

@nathanchi nathanchi Nov 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So something like this?
$('#navbar').append(
TOPICS.map(({ name }) => {

Copy link
Author

@nathanchi nathanchi Nov 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The js syntax seems to not work when I do that, however. Do you have any suggestions on how to do this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should work. What is the error and where is it occurring?

Copy link
Author

@nathanchi nathanchi Nov 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, that's interesting:

$('#navbar').append(TOPICS.map(({name}) => {
$('<li class="left">').append(
$('<a class="inline-block white center btn:hover">', {
id:${name}-nav-link,
href:#${name},
}).text(name)
)
});
);

That is the code that I edited.

The error message was "Uncaught SyntaxError: missing ) after argument list," which is strange, because I'm pretty sure every bracket and parentheses is closed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know what the error might be?

Copy link
Member

@sushain97 sushain97 Nov 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't have multiple semicolons in one statement. That is, your first semicolon should probably be removed.

Copy link
Author

@nathanchi nathanchi Nov 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I edited the jquery as you suggested, and now the code looks like this:

https://pastebin.com/T1RPg36n

It still doesn't work, though...I'm pretty sure the syntax is correct, though. Every parentheses/bracket is balanced and closed.

The error message is still the same, however.

Copy link
Member

@sushain97 sushain97 Nov 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please just paste code here using the code formatting (4 spaces).

I don't understand why you have two lines that are almost identical? Also, your arrow function needs a return if you use braces. If you omit them (which is fine here), you can also omit the return.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I've fixed it.

TOPICS.map(({name}) => {
$('#navbar').append(
$('<li class = "left">').append(
$('<a class = "inline-block white center btn:hover">', {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$('<a class = "inline-block white center btn:hover">', {
$('<a class="inline-block white center btn:hover">', {

$('<a class = "inline-block white center btn:hover">', {
id: `${name}-nav-link`,
href: `#${name}`,
class: `inline-block white center btn:hover`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't needed anymore?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, I'm not quite sure if I understand. Why don't I need it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You already have it above in the string.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On 200? It doesn't define the id, href, or class.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not saying the id and href aren't needed. This comment is on the line with the class.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I'm sorry, I misunderstood what you meant.

$('#github-link').attr('href', `https://github.com/${ORGANIZATION}`);
$('#refresh').click(({ currentTarget }) => {
$('#refresh').click(({currentTarget}) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use the proper prettifier settings to revert this change and also use the same spacing elsewhere?

@@ -42,6 +50,8 @@
</style>
</head>
<body class="m2">
<ul class="fixed m0 p0 overflow-hidden bg-black bottom-0 col-12 z2" id="navbar">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<ul class="fixed m0 p0 overflow-hidden bg-black bottom-0 col-12 z2" id="navbar">
<ul id="navbar" class="fixed m0 p0 overflow-hidden bg-black bottom-0 col-12 z2"></ul>

Copy link
Member

@sushain97 sushain97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor concerns when I tried it out:

  • When I load the page, all 5 navbar entries are visible despite all the headings also being visible.
  • The navbar starts strangely offset from the left?
  • Clicking the navbar link should go above the header. This is possible with some CSS tricks I think.
  • The navbar covers the refresh button.
  • The empty navbar still takes up a bunch of space? Was this intentional?

}).text(name)
),
),
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spacing is very suspicious here. Try running this through Prettier.

@nathanchi
Copy link
Author

The navbar is 2 pixels offset from the left, because
<ul id="navbar" class="fixed m0 p0 overflow-hidden bg-black bottom-0 col-12 z2">
is under
<body class="m2">
which gives it a margin of 2. Should set the margin to m0 instead? This would resolve the issue, but the margin would be gone.

@nathanchi
Copy link
Author

Nevermind, I got it to work! :)

@nathanchi
Copy link
Author

I fixed everything, but there's something wrong about the anchor links: any header that's on the top of the page doesn't work, for some reason. Do you have any ideas about this? I fixed everything else, though.

@nathanchi
Copy link
Author

Currently, I'm using

.heading {
padding-top: 75px;
margin-top: -75px;
}

which works for all of the other links besides the ones on the top. I also tried using some of the solutions from here: https://css-tricks.com/hash-tag-links-padding/ but it didn't quite work...

@nathanchi
Copy link
Author

I think that there might be something wrong with the header (with the apertium & github logos), which is making the text headers below messed up.

Copy link
Member

@sushain97 sushain97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some extra comments and there's a comment from before re. chaining that hasn't been resolved.

#content {
margin: 1rem;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spacing?

const navLinkPosition = $(`#${name}`).position().top;
$(`#${name}-nav-link`)
.text(`${name} ${navLinkPosition > bottom ? '↓' : '↑'}`)
$(`#${name}-nav-list`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why isn't this chained?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to use a different value for the li and a, so I couldn't chain it. I can remove the space, though.

@@ -132,7 +143,7 @@ <h1 id="loading" class="m1 center display-none">⌛</h1>
$('#topics').append(
$('<div class="topic flex-auto">').append(
$('<div>').append(
$('<h2 class="inline-block m0">').text(name),
$('<h2 class="inline-block m0 heading">', {id: name}).text(name),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heading is a super generic class name. How about something like topic-heading?

#navbar li a {
padding: 14px 16px;
}
.heading {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation is off in this entire block.

margin-top: 75px;
margin-bottom: 100px;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using 3 margin rules, just use one with 4 values.

@@ -41,8 +52,10 @@
}
</style>
</head>
<body class="m2">
<div class="fixed top-0 col-12 py1 mr3 bg-white z1">
<body class="">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the empty class attribute.

<body class="m2">
<div class="fixed top-0 col-12 py1 mr3 bg-white z1">
<body class="">
<ul id="navbar" class="fixed m0 p0 overflow-hidden bg-black bottom-0 col-12 z2">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<ul id="navbar" class="fixed m0 p0 overflow-hidden bg-black bottom-0 col-12 z2">
<ul id="navbar" class="fixed m0 p0 overflow-hidden bg-black bottom-0 col-12 z2"></ul>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(i.e. on the same line)

@@ -132,7 +145,8 @@ <h1 id="loading" class="m1 center display-none">⌛</h1>
$('#topics').append(
$('<div class="topic flex-auto">').append(
$('<div>').append(
$('<h2 class="inline-block m0">').text(name),
$('<h2 class="inline-block m0 relative heading">', {id: `${name}-space`}),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just id: name like before? The space suffix seems odd.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to use a different id for the empty space above the h2 header, that's why I'm using name-space.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you recommend a different name?

Copy link
Member

@sushain97 sushain97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there! Just some tweaks here and there.

source-browser.html Outdated Show resolved Hide resolved
source-browser.html Outdated Show resolved Hide resolved
source-browser.html Show resolved Hide resolved
source-browser.html Outdated Show resolved Hide resolved
source-browser.html Show resolved Hide resolved
@@ -182,6 +193,27 @@ <h1 id="loading" class="m1 center display-none">⌛</h1>
}

$(document).ready(() => {
$(window).on('scroll resize load', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's pull the anonymous function here into a function called updateNavbarVisibility.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been fixed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I didn't mean the whole thing, I meant just the arrow function.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I'll fix that.

Copy link
Author

@nathanchi nathanchi Nov 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So just

TOPICS.forEach(({ name }) => { const navLinkPosition = $(#${name}).position().top; $(#${name}-nav-link).text(${name} ${navLinkPosition > bottom ? '↓' : '↑'}); $(#${name}-nav-list).toggle(top >= navLinkPosition || navLinkPosition >= bottom); });?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I mentioned earlier, please use code blocks via 4 space indents.

$(window).on('scroll resize load', updateNavbarVisibility)

is what I'm looking for.

source-browser.html Show resolved Hide resolved
@nathanchi
Copy link
Author

I accidentally resolved the conversation...I have tried the solutions at https://stackoverflow.com/questions/4086107/fixed-page-header-overlaps-in-page-anchors, but they didn't entirely work. The hacky solution was the only solution that has worked entirely, so far.

@nathanchi
Copy link
Author

These are the CSS solutions.

source-browser.html Outdated Show resolved Hide resolved
source-browser.html Show resolved Hide resolved
source-browser.html Show resolved Hide resolved
@sushain97
Copy link
Member

for future readers: blocking on merge till I can look into whether there's a cleaner solution to offsetting the anchor jump location

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants