refinements to the media page

pull/8/head
Stephen Searles 8 years ago
parent 83236d846f
commit d86a64d03b
  1. 25
      media.go

@ -178,7 +178,10 @@ func (ch *CaddyHugo) serveMediaPage(w http.ResponseWriter, r *http.Request) (int
}
io.WriteString(w, `<html>
<head><style>.img { float: left; text-align: center; }</style></head>
<head><style>
.img { float: left; text-align: center; max-width: 19.9vw; min-height: 120px;}
.copy { cursor: pointer; }
</style></head>
<body>
<div style="position: fixed; top: 0; height: 10vh; width: 100%;">
<div style="float: left; width: 100%; height: 10vh;">
@ -193,17 +196,31 @@ func (ch *CaddyHugo) serveMediaPage(w http.ResponseWriter, r *http.Request) (int
}
for _, m := range media {
fmt.Fprintf(w, `<div class="img">`)
src, width, height, err := ch.Media.ThumbMax(*m, 100)
if err != nil {
fmt.Fprintf(w, `<div class="img">error rendering %q: %v</div>`, m.Name, err)
continue
}
fmt.Fprintf(w, `<div class="img"><img width=%d height=%d src=%q /><br /><input type="text" disabled value=%q /></div>`, width, height, src, src)
fmt.Fprintf(w, `<div class="img"><img width=%d height=%d src=%q /><br /><input type="text" readonly value=%q /><span class="copy">&#x1F4CB;</span></div>`, width, height, src, src)
}
}
io.WriteString(w, `</body><html>`)
io.WriteString(w, `<script>
document.querySelector('body').onclick = function (evt) {
if (evt.target.tagName === "INPUT" && evt.target.type === "text") {
evt.target.select();
}
if (evt.target.tagName === "SPAN" && evt.target.className === "copy") {
evt.target.previousSibling.select();
document.execCommand("copy");
}
}
document.querySelector('body').onmouseup = function (evt) {
if (evt.target.tagName === "INPUT" && evt.target.type === "text") {
return false;
}
}
</script></body><html>`)
return 200, nil
}

Loading…
Cancel
Save