Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
13 changes: 8 additions & 5 deletions functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ function scoreClass(score) {
function error(res, code) {
res.status(code);
res.locals = {
sidebarDisabled: true
sidebarDisabled: true,
embed: res.locals.embed
}
return res.render('error', {code});
}
Expand Down Expand Up @@ -123,14 +124,16 @@ app.use((req, res, next) => {
res.locals.firebaseClientConfig = firebaseClientConfig;
res.locals.isBeta = isBeta;

if (req.user && req.user.showWelcomeMsg && !req.query.latest && !req.path.includes('/api')) {
if (req.user && req.user.showWelcomeMsg && !req.query.latest && !('embed' in req.query) &&!req.path.includes('/api')) {
userDB.doc(req.user.uid) // async
.update({showWelcomeMsg: false})
.catch(() => console.error('Failed to update welcome msg', req.user.uid));
}

if (req.query.iframe) {
res.locals.insideIframe = true;
if ('embed' in req.query) {
res.locals.embed = true;
res.locals.privacyModalDisabled = true;
res.set('Content-Security-Policy', "frame-ancestors 'self' http://localhost:*");
}

for (let l of LEVELS) {
Expand Down Expand Up @@ -470,7 +473,7 @@ for (let p of ['about', 'introduction', 'parents', 'teachers', 'privacy-notice',
const content = fs.readFileSync(path.join(__dirname, `build/${p}.html`));
app.get('/' + p, (_, res) => {
res.locals.sidebarDisabled = pagesWithoutSidebar.includes(p);
res.locals.privacyModalDisabled = pagesWithoutPrivacyModal.includes(p);
res.locals.privacyModalDisabled = res.locals.embed || pagesWithoutPrivacyModal.includes(p);
res.render('_layout', {content})
});
}
Expand Down
92 changes: 47 additions & 45 deletions functions/views/_layout.pug
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
doctype html
html
html(class=embed ? 'embed' : undefined)
head
meta(charset="utf-8")
meta(http-equiv="X-UA-Compatible" content="IE=edge")
Expand All @@ -26,7 +26,7 @@ html

//- Stylesheets
link(href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,600,300,400italic" rel="stylesheet")
link(href="/parallel.css?v=34" rel="stylesheet")
link(href="/parallel.css?v=37" rel="stylesheet")

if isProduction
include scripts/newrelic.html
Expand All @@ -38,39 +38,40 @@ html

body
#vue
if isBeta
if isBeta && !embed
.beta
div You are on our Beta Testing Site!
div The information & events on this page are for testing purposes and should not be followed.
a(href="https://parallel.org.uk") Click here to return to the production site.
.headerWrapper
.header
if !sidebarDisabled
#menu(v-on:click="showSidebar=true")
svg(width=24 height=24)
rect(y=2 width=24 height=3 fill="white")
rect(y=10 width=24 height=3 fill="white")
rect(y=18 width=24 height=3 fill="white")

if path && !noNavigation
div(class="homeButtonsLeft")
a#home(href="/" title="Home" class="homeButton homeButtonWithSvg")
include svgs/home.svg
| Home

if user
div(class="homeButtonsRight")
a#home(href="/account" title="Home" class="homeButton")
| Settings
a#home(href="/" title="Home" class="homeButton" @click="user.logout")
| Sign out

if noNavigation
div#logo(href="/" title="Home" class=(sidebarDisabled ? 'sidebarDisabled' : ''))
else
a#logo(href="/" title="Home" class=(sidebarDisabled ? 'sidebarDisabled' : ''))

#shadow(v-on:click="showSidebar=false" v-bind:class="{visible: showSidebar}")
if !embed
.headerWrapper
.header
if !sidebarDisabled
#menu(v-on:click="showSidebar=true")
svg(width=24 height=24)
rect(y=2 width=24 height=3 fill="white")
rect(y=10 width=24 height=3 fill="white")
rect(y=18 width=24 height=3 fill="white")

if path && !noNavigation
div(class="homeButtonsLeft")
a#home(href="/" title="Home" class="homeButton homeButtonWithSvg")
include svgs/home.svg
| Home

if user
div(class="homeButtonsRight")
a#home(href="/account" title="Home" class="homeButton")
| Settings
a#home(href="/" title="Home" class="homeButton" @click="user.logout")
| Sign out

if noNavigation
div#logo(href="/" title="Home" class=(sidebarDisabled ? 'sidebarDisabled' : ''))
else
a#logo(href="/" title="Home" class=(sidebarDisabled ? 'sidebarDisabled' : ''))

#shadow(v-on:click="showSidebar=false" v-bind:class="{visible: showSidebar}")

#container
if !sidebarDisabled
Expand Down Expand Up @@ -138,7 +139,7 @@ html
for l in user ? user.sidebarLevels : levels
nav(v-show=`user.level == '${l}'`)
for p in pages[l]
a(href=("/" + p.url) class=('/' + p.url === path ? 'active' : ''))
a(href=(embed ? "/secret/" : "/") + p.url class=('/' + p.url === path ? 'active' : ''))
.title-meta PG #{p.index} #[span.spaced •] #{p.date}
.title= p.title
if user && user.answers[p.url] && user.answers[p.url].submitted
Expand All @@ -161,25 +162,26 @@ html
//- label(for="terms-modal") We will email you when a new Parallelogram challenge is released, when the next Parallel Circles session is scheduled, and when there are special competitions, prizes and opportunities. By checking this box you consent to receiving these emails, in accordance with our #[a(href="/privacy-notice" target="_blank") Data Privacy policy].
//- button(type="submit") Continue

if user && !user.code && user.showWelcomeMsg
if user && !user.code && user.showWelcomeMsg && !embed
.modal(v-if="showWelcomeMsg")
.modal-background
.modal-body
h2 Welcome back to Parallel!
p.text-center We’ve updated your level to #[strong #{levelNamesWithAges[user.level]}]. You can always change it on your #[a(href="/account") account settings] page. The first Parallelogram is now available, but officially it is launched in early September. We will be releasing new Parallelograms every week, from mid-September.
button(type="submit" v-on:click="showWelcomeMsg = false") Continue

footer
a(href="/about") About
| •
a(href="/contact") Contact
| •
a(href="/privacy-notice") Privacy Notice
br
| Created by
a(href="http://goodthinkingsociety.org" target="_blank") #[img(src="/images/good-thinking.png" width=10 height=16)] Good Thinking Society
| and
a(href="https://mathigon.org" target="_blank") #[img(src="/images/mathigon.png" width=16 height=16)] Mathigon
if !embed
footer
a(href="/about") About
| •
a(href="/contact") Contact
| •
a(href="/privacy-notice") Privacy Notice
br
| Created by
a(href="http://goodthinkingsociety.org" target="_blank") #[img(src="/images/good-thinking.png" width=10 height=16)] Good Thinking Society
| and
a(href="https://mathigon.org" target="_blank") #[img(src="/images/mathigon.png" width=16 height=16)] Mathigon

if user && user.privacy && user.privacy.visible && !privacyModalDisabled
iframe(src="/privacy-modal" id="privacy-iframe" style="height: 100%;width: 100%;position: absolute;z-index: 10000000000;top: 0;left: 0;border: none;")
Expand All @@ -188,7 +190,7 @@ html
script(defer src="https://www.gstatic.com/firebasejs/8.10.0/firebase-auth.js")
script(defer src="https://www.gstatic.com/firebasejs/8.10.0/firebase-firestore.js")
script(defer src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.9/vue.min.js")
script(defer src="/parallel.js?v=39")
script(defer src="/parallel.js?v=40")

script.
if (typeof window !== 'undefined' && window.newrelic && window.newrelic.setCustomAttribute) {
Expand Down
4 changes: 3 additions & 1 deletion static/scripts/challenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ export default function() {

testPasswordSubmit(e) {
e.preventDefault();
window.location.search = `?p=${challenge.testPassword}`;
const params = new URLSearchParams(window.location.search);
params.set('p', challenge.testPassword);
window.location.search = params.toString();
},

// Only used by teachers
Expand Down
58 changes: 58 additions & 0 deletions static/scripts/embed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// =============================================================================
// Embed height reporting (used when ?embed is set and inside an iframe)
// =============================================================================


const MESSAGE_TYPE = 'parallel:embed:height';

export default function initEmbed() {
const root = document.documentElement;
if (!root.classList.contains('embed')) return;

// Embed mode hides the privacy modal, so only allow it inside a frame.
if (window.parent === window) {
const url = new URL(window.location.href);
if (!url.searchParams.has('embed')) return;
url.searchParams.delete('embed');
return window.location.replace(url.toString());
}

// Links to other pages open in the top window; in-page anchors stay in the frame.
document.addEventListener('click', (e) => {
const link = e.target.closest && e.target.closest('a[href]');
if (!link || link.target) return;
const samePage = link.href.split('#')[0] === window.location.href.split('#')[0];
if (!samePage) link.target = '_top';
}, true);

let lastHeight = 0;
let frame = 0;

const post = () => {
frame = 0;
const height = Math.ceil(root.getBoundingClientRect().height);
// Body is hidden (height 0) while reloading after a submission.
if (!height || height === lastHeight) return;
lastHeight = height;
window.parent.postMessage({type: MESSAGE_TYPE, height}, '*');
};

const schedule = () => {
if (!frame) frame = window.requestAnimationFrame(post);
};

if (window.ResizeObserver) {
const observer = new ResizeObserver(schedule);
observer.observe(root);
observer.observe(document.body);
} else {
window.setInterval(schedule, 500);
}

window.addEventListener('resize', schedule);
window.addEventListener('load', schedule);
document.addEventListener('load', schedule, true);
if (document.fonts && document.fonts.ready) document.fonts.ready.then(schedule);

schedule();
}
5 changes: 4 additions & 1 deletion static/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import '../../node_modules/babel-polyfill/dist/polyfill';
import getUser from './user';
import getChallenge from './challenge';
import initEmbed from './embed';
import '../../node_modules/@johmun/vue-tags-input/dist/vue-tags-input';

function removeStudent(id, index, level) {
Expand Down Expand Up @@ -128,7 +129,7 @@ document.addEventListener('DOMContentLoaded', function() {
});

if (window.self !== window.top) {
document.body.className = 'insideIframe'
document.body.classList.add('insideIframe');
}

window.app = new Vue({
Expand All @@ -137,4 +138,6 @@ document.addEventListener('DOMContentLoaded', function() {
data: {showSidebar: false, showWelcomeMsg: true, user, c: challenge,
removeStudent, sortTable}
});

initEmbed();
});
2 changes: 1 addition & 1 deletion static/styles/forms.less
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ form.loading button[type="submit"] {
.toggle {
display: flex;
flex-direction: row;
margin: 6px 0 4px;;
margin: 0px 0 6px 4px;
justify-content: center;
padding: 0 2px;
}
Expand Down
43 changes: 43 additions & 0 deletions static/styles/iframe.less
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,46 @@
max-width: 100%;
}
}


// -----------------------------------------------------------------------------
// Embedded within the Parallel Squared site (?embed)

html.embed {
background: transparent;
overflow: hidden;

&, body { height: auto; min-height: 0; }

#container {
width: 100%;
max-width: 100%;
}

.intros,
.sidebar-circles-item,
.sidebar-field {
display: none;
}

.sidebar { margin: 0 6px 0 0; }

.sidebar-wrap {
position: static;
max-height: none;
overflow: visible;
border-radius: 4px;
}

article, article.sidebarDisabled {
box-shadow: none;
min-height: 0;
}

@media screen and (max-width: 720px) {
#container { display: flex; flex-direction: column; }
article, article.sidebarDisabled { width: auto; order: -1; padding: 24px; border-radius: 4px; }
.sidebar { margin: 24px 0 0; width: 100%; }
.sidebar-wrap { transform: none; box-shadow: none; width: auto; }
}
}