Skip to content

Commit 7a3e6a8

Browse files
committed
Add back the old banner and add a condition to load on docs.pytorch.org
1 parent d61db94 commit 7a3e6a8

File tree

8 files changed

+237
-96
lines changed

8 files changed

+237
-96
lines changed

pytorch_sphinx_theme2/static/css/theme.css

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2357,6 +2357,68 @@ a.btn {
23572357
stroke: var(--pst-color-primary);
23582358
}
23592359

2360+
.cookie-banner-wrapper {
2361+
display: none;
2362+
}
2363+
.cookie-banner-wrapper.is-visible {
2364+
display: block;
2365+
position: fixed;
2366+
bottom: 0;
2367+
background-color: var(--pst-color-background);
2368+
min-height: 100px;
2369+
width: 100%;
2370+
border-top: 3px solid #ededee;
2371+
z-index: 100000;
2372+
}
2373+
.cookie-banner-wrapper .container {
2374+
padding-left: 1.875rem;
2375+
padding-right: 1.875rem;
2376+
max-width: 1240px;
2377+
}
2378+
.cookie-banner-wrapper .gdpr-notice {
2379+
color: var(--pst-color-text-muted);
2380+
margin-top: 1.5625rem;
2381+
text-align: left;
2382+
max-width: 1440px;
2383+
}
2384+
@media screen and (min-width: 768px) {
2385+
.cookie-banner-wrapper .gdpr-notice {
2386+
width: 77%;
2387+
}
2388+
}
2389+
@media (min-width: 768px) and (max-width: 1239px) {
2390+
.cookie-banner-wrapper .gdpr-notice {
2391+
width: inherit;
2392+
}
2393+
}
2394+
.cookie-banner-wrapper .gdpr-notice .cookie-policy-link {
2395+
color: var(--pst-color-text-muted);
2396+
}
2397+
.cookie-banner-wrapper .close-button {
2398+
appearance: none;
2399+
background: transparent;
2400+
border: 1px solid var(--pst-color-background);
2401+
height: 1.3125rem;
2402+
position: absolute;
2403+
bottom: 42px;
2404+
right: 0;
2405+
top: 0;
2406+
cursor: pointer;
2407+
outline: none;
2408+
}
2409+
@media screen and (min-width: 768px) {
2410+
.cookie-banner-wrapper .close-button {
2411+
right: 20%;
2412+
top: inherit;
2413+
}
2414+
}
2415+
@media (min-width: 768px) and (max-width: 1239px) {
2416+
.cookie-banner-wrapper .close-button {
2417+
right: 0;
2418+
top: 0;
2419+
}
2420+
}
2421+
23602422
.version-switcher__button {
23612423
margin-bottom: 0 !important;
23622424
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
var cookieBanner = {
2+
init: function() {
3+
cookieBanner.bind();
4+
5+
var cookieExists = cookieBanner.cookieExists();
6+
7+
if (!cookieExists) {
8+
cookieBanner.showCookieNotice();
9+
}
10+
},
11+
12+
bind: function() {
13+
$(".close-button").on("click", function() {
14+
cookieBanner.hideCookieNotice();
15+
cookieBanner.setCookie(); // Set the cookie or local storage item when the banner is closed
16+
});
17+
},
18+
19+
cookieExists: function() {
20+
return localStorage.getItem("returningPytorchUser") !== null;
21+
},
22+
23+
setCookie: function() {
24+
localStorage.setItem("returningPytorchUser", true);
25+
},
26+
27+
showCookieNotice: function() {
28+
$(".cookie-banner-wrapper").addClass("is-visible");
29+
},
30+
31+
hideCookieNotice: function() {
32+
$(".cookie-banner-wrapper").removeClass("is-visible");
33+
}
34+
};
35+
36+
$(function() {
37+
cookieBanner.init();
38+
});

pytorch_sphinx_theme2/static/js/theme.js

Lines changed: 39 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pytorch_sphinx_theme2/static/scss/_components.scss

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ a.btn {
194194
}
195195
}
196196

197-
// privacy notice
197+
// Cookie banner LF
198198

199199
.osano-cm-dialog {
200200
background-color: var(--pst-color-background);
@@ -286,6 +286,72 @@ a.btn {
286286
stroke: var(--pst-color-primary);
287287
}
288288

289+
// Cookie banner pytorch
290+
291+
.cookie-banner-wrapper {
292+
display: none;
293+
294+
&.is-visible {
295+
display: block;
296+
position: fixed;
297+
bottom: 0;
298+
background-color: var(--pst-color-background);
299+
min-height: 100px;
300+
width: 100%;
301+
border-top: 3px solid #ededee;
302+
z-index: 100000;
303+
}
304+
305+
.container {
306+
padding-left: 1.875rem;
307+
padding-right: 1.875rem;
308+
max-width: 1240px;
309+
}
310+
311+
.gdpr-notice {
312+
color: var(--pst-color-text-muted);
313+
margin-top: 1.5625rem;
314+
text-align: left;
315+
max-width: 1440px;
316+
317+
@media screen and (min-width: 768px) {
318+
width: 77%;
319+
}
320+
321+
@media (min-width: 768px) and (max-width: 1239px) {
322+
width: inherit;
323+
}
324+
325+
.cookie-policy-link {
326+
color: var(--pst-color-text-muted);
327+
}
328+
}
329+
330+
.close-button {
331+
appearance: none;
332+
background: transparent;
333+
border: 1px solid var(--pst-color-background);
334+
height: 1.3125rem;
335+
position: absolute;
336+
bottom: 42px;
337+
right: 0;
338+
top: 0;
339+
cursor: pointer;
340+
outline: none;
341+
342+
@media screen and (min-width: 768px) {
343+
right: 20%;
344+
top: inherit;
345+
}
346+
347+
348+
@media (min-width: 768px) and (max-width: 1239px) {
349+
right: 0;
350+
top: 0;
351+
}
352+
}
353+
}
354+
289355
// Version switcher
290356
.version-switcher {
291357
&__button {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<div class="cookie-banner-wrapper">
2+
<div class="container">
3+
<p class="gdpr-notice">To analyze traffic and optimize your experience, we serve cookies on this site. By clicking or navigating, you agree to allow our usage of cookies. As the current maintainers of this site, Facebook’s Cookies Policy applies. Learn more, including about available controls: <a href="https://www.facebook.com/policies/cookies/">Cookies Policy</a>.</p>
4+
<img class="close-button" src="{{ pathto('_static/img/pytorch-x.svg', 1) }}">
5+
</div>
6+
</div>

pytorch_sphinx_theme2/templates/layout.html

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,28 @@
55
<link rel="canonical" href="{{ canonical_url|default((url_root if url_root is defined else '/') + pagename + '.html', true) }}" crossorigin="anonymous">
66
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
77
<script src="https://cdnjs.cloudflare.com/ajax/libs/list.js/2.3.1/list.min.js"></script>
8-
<script src="https://cmp.osano.com/16A0DbT9yDNIaQkvZ/31b1b91a-e0b6-47ea-bde2-7f2bd13dbe5c/osano.js?variant=one"></script>
8+
<script>
9+
if (window.location.hostname === 'docs.pytorch.org' || window.location.hostname === 'docs-preview.pytorch.org') {
10+
const script = document.createElement('script');
11+
script.src = 'https://cmp.osano.com/16A0DbT9yDNIaQkvZ/31b1b91a-e0b6-47ea-bde2-7f2bd13dbe5c/osano.js?variant=one';
12+
document.head.appendChild(script);
13+
}
14+
</script>
15+
<script>
16+
// Cookie banner for non-LF projects.
17+
document.addEventListener('DOMContentLoaded', function() {
18+
// Hide cookie banner on local environments
19+
if (window.location.hostname === 'localhost' ||
20+
window.location.hostname === '0.0.0.0' ||
21+
window.location.hostname === '127.0.0.1' ||
22+
window.location.hostname.startsWith('192.168.')) {
23+
const banner = document.querySelector('.cookie-banner-wrapper');
24+
if (banner) {
25+
banner.style.display = 'none';
26+
}
27+
}
28+
});
29+
</script>
930
<link rel="stylesheet" type="text/css" href="{{ pathto('_static/css/theme.css', 1) }}" crossorigin="anonymous">
1031
<script type="text/javascript" src="{{ pathto('_static/js/theme.js', 1) }}"></script>
1132
<link rel="preconnect" href="https://fonts.googleapis.com">

pytorch_sphinx_theme2/templates/pytorch_footer.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,6 @@ <h2>Resources</h2>
8383

8484
</div>
8585
</footer>
86+
87+
{% include "cookie_banner.html" %}
88+

pytorch_sphinx_theme2/templates/sections/footer.html

Lines changed: 0 additions & 93 deletions
This file was deleted.

0 commit comments

Comments
 (0)