Skip to content

Commit

Permalink
Read style from GET params in embed_snippet view
Browse files Browse the repository at this point in the history
  • Loading branch information
neoformit committed Oct 14, 2024
1 parent 5017a39 commit d102625
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
4 changes: 2 additions & 2 deletions webapp/home/templates/embed-snippet.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
{% block script %}
<script>
window.onload = function() {
const height = document.body.scrollHeight;
window.parent.postMessage({ height: height }, "*");
window.parent.postMessage({ height: document.body.scrollHeight }, "*");
window.parent.postMessage({ width: document.body.scrollWidth }, "*");
};
</script>
{% endblock %}
2 changes: 1 addition & 1 deletion webapp/home/templates/home/header-export.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</style>
</head>

<body>
<body {% if body_style %}style="{{ body_style }}"{% endif %}>

{% block content %}
{% endblock %}
Expand Down
17 changes: 16 additions & 1 deletion webapp/home/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,13 +313,28 @@ def custom_400(request, exception, template_name="400.html"):

def embed_snippet(request, snippet_path):
"""Serve an embeddable snippet."""
ALLOW_STYLE_PARAMS = ['overflow']
body_style_data = {
k: request.GET.get(k)
for k in ALLOW_STYLE_PARAMS
if k in request.GET
}
body_style = ' '.join(
f'{k}: {v};'
for k, v in body_style_data.items()
)
try:
if 'snippets' not in snippet_path:
raise Http404
return render(request, 'embed-snippet.html', {
'title': 'Galaxy Media - embedded snippet',
'snippet_path': snippet_path,
'crop_margin': True, # could make this configurable in future
# Can be referenced in snippet templates:
'crop_margin': request.GET.get(
'crop',
'true',
).lower() in ('true', '1', 'yes'),
'body_style': body_style,
})
except TemplateDoesNotExist:
raise Http404

0 comments on commit d102625

Please sign in to comment.