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

Create a scroll back to top button #216

Closed
Show file tree
Hide file tree
Changes from 12 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
149 changes: 149 additions & 0 deletions docs/_layouts/listing.html
Copy link
Contributor

Choose a reason for hiding this comment

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

@SamarthShukla17 I think you've accidentally added a bunch of html here you didn't mean to?

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 about 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 reverted the changes in the commit, kindly review.

Original file line number Diff line number Diff line change
@@ -1,5 +1,153 @@
<!doctype html>
<html lang="en">

<head>
<span id="the-top"></span>
<title>{{ page.title }} | Creative Commons Resource Archive</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="/style.css" />


{% if page.title == "All" %}

<script>

(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-2010376-29', 'auto');
ga('send', 'pageview');


function getUrlVars()
{
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}

document.write("<style>.thumbnailbox { display: none; }</style>");

var topic = getUrlVars()["topic"];
var language = getUrlVars()["language"];
var medium = getUrlVars()["medium"];

if (topic === undefined && medium === undefined && language === undefined) {
document.write("<style>.thumbnailbox { display: block; }</style>");
}
else {
document.write("<style>");
if (topic != undefined) {document.write("."+topic)};
if (medium != undefined) {document.write("."+medium)};
if (language != undefined) {document.write("."+language)};
document.write(" { display: block; }</style>");
};

document.write("<style>");
if (topic != undefined) {document.write(" .resourcenavtopicknown");}
else {document.write(" .resourcenavtopicunknown");};
if (medium != undefined) {document.write(", .resourcenavmediumknown");}
else {document.write(", .resourcenavmediumunknown");};
if (language != undefined) {document.write(", .resourcenavlanguageknown");}
else {document.write(", .resourcenavlanguageunknown");};
document.write(" { display: block; }</style>");
</script>

{% endif %}

</head>


<body>

{% include header.html %}

<h1>
{% unless page.title == 'Home' %}
<a href="/">
{% endunless %}
Creative Commons Resource Archive
{% unless page.title == 'Home' %}
</a>
{% endunless %}
</h1>

{{content}}

<p style="text-align: center; padding:1em; "><a href="/submit/">Submit a resource</a></p>



<div id="thumbnaillist">

{% for i in (1..16) %}
{% for page in site.pages %}
{% if page.layout == 'resource' %}
{% if page.featured == i %}
{% if page.topic contains topicfilter or topicfilter == null %}
{% if page.medium contains mediumfilter or mediumfilter == null %}
{% if page.language contains languagefilter or languagefilter == null %}
<div class="thumbnailbox {{ page.topic }} {{ page.medium }} {{page.language}}">
<a class="thumbnailLink" href="{{ page.permalink }}" >
<div class="thumbnailtitle"><h3>{{ page.title }}</h3></div>
<div class="thumbnail" style="background-image: url('{{ page.image-thumb }}'); "></div>
<div class="thumbnailblurb" style="color: rgb(0, 0, 0)">{{ page.blurb }}</div>
</a>
</div>
{% endif %}{% endif %}{% endif %}
{% endif %}
{% endif %}
{% endfor %}
{% endfor %}

{% unless page.title == 'Home' %}
{% for i in (1..4) %}
{% for page in site.pages %}
{% if page.layout == 'resource' %}
{% if page.weight == i %}
{% unless page.featured %}
{% if page.paramfilter == page.paramvalue %}
{% if page.topic contains topicfilter or topicfilter == null %}
{% if page.medium contains mediumfilter or mediumfilter == null %}
{% if page.language contains languagefilter or languagefilter == null %}
<div class="thumbnailbox {{ page.topic }} {{ page.medium }} {{page.language}}">
<a class="thumbnailLink" href="{{ page.permalink }}">
<div class="thumbnailtitle"><h3>{{ page.title }}</h3></div>
<div class="thumbnail" style="background-image: url('{{ page.image-thumb }}'); "></div>
<div class="thumbnailblurb" style="color: rgb(0, 0, 0)">{{ page.blurb }}</div>
</a>
</div>
{% endif %}{% endif %}{% endif %}
{% endif %}
{% endunless %}
{% endif %}
{% endif %}
{% endfor %}
{% endfor %}
{% endunless %}

</div>



</body>
<script>
const globalHeader = document.getElementById("global-header");
const handleExplore = (event) => {
globalHeader.classList.toggle("active");
event.preventDefault();
}
</script>

<head>
<title>{{ page.title }} | Creative Commons Resource Archive</title>
<meta charset="UTF-8" />
Expand Down Expand Up @@ -287,4 +435,5 @@ <h2>Support Our Work</h2>
</body>

<script src="../vocabulary/js/vocabulary.js"></script>

</html>
8 changes: 8 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,12 @@ <h2>Language</h2>
</div>
</div>


<h2 style="text-align: center; "><a href="/all">See all</a></h2>

<a href="#the-top" class="stt" id="stt" title="scroll to top">Back To Top</a>
Copy link
Contributor

@possumbilities possumbilities Apr 15, 2024

Choose a reason for hiding this comment

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

I'd opt for a class here, rather than an id. We don't need both. If there's good cause for the id instead, I'm open to it, but its redundant to have both.

I'd also suggest it be spelled out to be more semantic and descriptive.

So rather than a class or id of: stt, it would be better as scroll-to-top

Copy link
Author

Choose a reason for hiding this comment

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

Done.


<script src="scroll.js"></script>

TimidRobot marked this conversation as resolved.
Show resolved Hide resolved
<h2 style="text-align: center"><a href="/all">See all</a></h2>

11 changes: 11 additions & 0 deletions docs/scroll.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
document.addEventListener("DOMContentLoaded", function() {
let stt = document.getElementById("stt");
Copy link
Contributor

@possumbilities possumbilities Apr 15, 2024

Choose a reason for hiding this comment

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

if the element in question is changed to only have a class, you'd need to use a querySelector to grab it by class here, but if not then disregard.

Copy link
Author

Choose a reason for hiding this comment

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

Done.


window.onscroll = function() {
if (window.scrollY > 400) {
stt.style.display = "block";
} else {
stt.style.display = "none";
}
};
});
Loading