mirror of https://github.com/dirtbags/moth.git
Fix inline images, only award to extant teams
This commit is contained in:
parent
b1f16d3733
commit
55800efe3f
|
@ -46,3 +46,10 @@ nav li, .category li {
|
||||||
display: inline;
|
display: inline;
|
||||||
margin: 1em;
|
margin: 1em;
|
||||||
}
|
}
|
||||||
|
iframe#body {
|
||||||
|
border: inherit;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
img {
|
||||||
|
max-width: 100%;
|
||||||
|
}
|
|
@ -7,10 +7,16 @@
|
||||||
<link rel="icon" href="res/icon.svg" type="image/svg+xml">
|
<link rel="icon" href="res/icon.svg" type="image/svg+xml">
|
||||||
<link rel="icon" href="res/icon.png" type="image/png">
|
<link rel="icon" href="res/icon.png" type="image/png">
|
||||||
<script>
|
<script>
|
||||||
function render(obj) {
|
function resize() {
|
||||||
let body = document.getElementById("body");
|
let frame = document.getElementById("body");
|
||||||
body.innerHTML = obj.body;
|
frame.height = frame.contentDocument.documentElement.scrollHeight;
|
||||||
console.log("XXX: Munge relative URLs (src= and href=) in body")
|
}
|
||||||
|
function render(obj, base) {
|
||||||
|
let frame = document.getElementById("body");
|
||||||
|
let html = "<base href='" + base + "'><link rel='stylesheet' href='../../../basic.css'>" + obj.body;
|
||||||
|
|
||||||
|
frame.addEventListener("load", resize);
|
||||||
|
frame.srcdoc = html;
|
||||||
}
|
}
|
||||||
function init() {
|
function init() {
|
||||||
let params = new URLSearchParams(window.location.search);
|
let params = new URLSearchParams(window.location.search);
|
||||||
|
@ -18,13 +24,14 @@ function init() {
|
||||||
let points = params.get("points");
|
let points = params.get("points");
|
||||||
let puzzleId = params.get("pid");
|
let puzzleId = params.get("pid");
|
||||||
|
|
||||||
let fn = "content/" + categoryName + "/" + puzzleId + "/puzzle.json";
|
let base = "content/" + categoryName + "/" + puzzleId + "/";
|
||||||
|
let fn = base + "puzzle.json";
|
||||||
|
|
||||||
fetch(fn)
|
fetch(fn)
|
||||||
.then(function(resp) {
|
.then(function(resp) {
|
||||||
return resp.json();
|
return resp.json();
|
||||||
}).then(function(obj) {
|
}).then(function(obj) {
|
||||||
render(obj);
|
render(obj, base);
|
||||||
}).catch(function(err) {
|
}).catch(function(err) {
|
||||||
console.log("Error", err);
|
console.log("Error", err);
|
||||||
});
|
});
|
||||||
|
@ -39,7 +46,7 @@ document.addEventListener("DOMContentLoaded", init);
|
||||||
<body>
|
<body>
|
||||||
<h1>Puzzle</h1>
|
<h1>Puzzle</h1>
|
||||||
<section>
|
<section>
|
||||||
<div id="body">Loading...</div>
|
<iframe seamless id="body">Loading...</iframe>
|
||||||
</section>
|
</section>
|
||||||
<form action="answer" method="post">
|
<form action="answer" method="post">
|
||||||
<input type="hidden" name="cat">
|
<input type="hidden" name="cat">
|
||||||
|
|
|
@ -131,6 +131,11 @@ func (ctx *Instance) AwardPoints(teamid, category string, points int) error {
|
||||||
Points: points,
|
Points: points,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
teamName, err := ctx.TeamName(teamid)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("No registered team with this hash")
|
||||||
|
}
|
||||||
|
|
||||||
for _, e := range ctx.PointsLog() {
|
for _, e := range ctx.PointsLog() {
|
||||||
if a.Same(e) {
|
if a.Same(e) {
|
||||||
return fmt.Errorf("Points already awarded to this team in this category")
|
return fmt.Errorf("Points already awarded to this team in this category")
|
||||||
|
@ -150,7 +155,7 @@ func (ctx *Instance) AwardPoints(teamid, category string, points int) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.update <- true
|
ctx.update <- true
|
||||||
log.Printf("Award %s %s %d", teamid, category, points)
|
log.Printf("Award %s %s %d", teamName, category, points)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue