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
3 changes: 1 addition & 2 deletions htdocs/js/GatewayQuiz/gateway.scss
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,8 @@ div.gwDivider {
margin: 0px 0px 10px 0px;
}

/* Override the pg style so that the problem-content is not offset in gateway quizzes and force a light color scheme. */
/* Override the pg style so that the problem-content is not offset in gateway quizzes. */
.problem-content {
color-scheme: light;
padding: unset;
background-color: unset;
border: unset;
Expand Down
9 changes: 9 additions & 0 deletions htdocs/js/PGProblemEditor/pgproblemeditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,15 @@
iframe.title = 'Rendered content';
iframe.id = 'pgedit-render-iframe';

window.addEventListener('message', (event) => {
if (event.data !== 'render-iframe-ready' || iframe.contentWindow !== event.source) return;
iframe.contentWindow.postMessage({
theme:
localStorage.getItem('WW.color-scheme') ??
(window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')
});
});

// Adjust editor dimensions when the window is resized and when the iframe loads.
const adjustIFrameHeight = () => {
if (document.body.clientWidth < 992) {
Expand Down
19 changes: 18 additions & 1 deletion htdocs/js/RenderProblem/renderproblem.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
(() => {
const renderedIframes = [];

window.addEventListener('message', (event) => {
if (event.data !== 'render-iframe-ready') return;
renderedIframes
.find((i) => i.contentWindow === event.source)
?.contentWindow.postMessage({
theme:
localStorage.getItem('WW.color-scheme') ??
(window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')
});
});

// renderElement may either be the id of an html element, or directly an html element.
// If it is an html element, then that element must have an id.
webworkConfig.renderProblem = (renderElement, renderOptions) =>
Expand Down Expand Up @@ -28,7 +41,10 @@
send_pg_flags: 1,
extra_header_text:
'<style>' +
'html{overflow-y:hidden;}body{padding:1px;background:#f5f5f5;}.container-fluid{padding:0px;}' +
'html{overflow-y:hidden;}' +
'body{padding:1px;background:#f5f5f5;}' +
'[data-bs-theme="dark"] body{background:var(--bs-primary-bg-subtle);}' +
'.container-fluid{padding:0px;}' +
'</style>',
...renderOptions
};
Expand Down Expand Up @@ -70,6 +86,7 @@
iframe.style.border = 'none';
while (renderArea.firstChild) renderArea.firstChild.remove();
renderArea.append(iframe);
renderedIframes.push(iframe);

if (data.pg_flags && data.pg_flags.comment) {
const container = document.createElement('div');
Expand Down
6 changes: 6 additions & 0 deletions htdocs/js/System/color-scheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
if (themeValue === 'dark') document.head.append(flatpickrDarkTheme);
else flatpickrDarkTheme.remove();
}

for (const renderArea of document.querySelectorAll('.rpc_render_area')) {
for (const iframe of renderArea.getElementsByTagName('iframe')) {
iframe.contentDocument.documentElement.dataset.bsTheme = themeValue;
}
}
};

setTheme(getPreferredTheme());
Expand Down
9 changes: 1 addition & 8 deletions lib/WeBWorK/ContentGenerator/Problem.pm
Original file line number Diff line number Diff line change
Expand Up @@ -977,14 +977,7 @@ sub output_problem_body ($c) {
}
}

return $c->tag(
'div',
id => 'output_problem_body',
class => 'text-dark',
style => 'color-scheme: light',
data => { bs_theme => 'light' },
$c->b($c->{pg}{body_text})
);
return $c->tag('div', id => 'output_problem_body', $c->b($c->{pg}{body_text}));
}

# Output messages about the problem
Expand Down
3 changes: 1 addition & 2 deletions templates/ContentGenerator/GatewayQuiz.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -638,10 +638,9 @@
% delete stash->{briefErrorOutput};
% } else {
<div
class="problem-content text-dark col-lg-10"
class="problem-content col-lg-10"
<%== get_problem_lang_and_dir($pg->{flags}, $ce->{perProblemLangAndDirSettingMode},
$ce->{language}) %>
data-bs-theme="light"
>
<%== $pg->{body_text} =%>
</div>
Expand Down
7 changes: 7 additions & 0 deletions templates/RPCRenderFormats/default.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
course: <%= $courseID %>
</title>
<link href="<%= "$ce->{webworkURLs}{htdocs}/images/favicon.ico" %>" rel="shortcut icon">
<script>
window.parent.postMessage('render-iframe-ready');
window.addEventListener('message', (event) => {
if (!event.data || !event.data.theme) return;
document.documentElement.dataset.bsTheme = event.data.theme;
});
</script>
% # Add third party css and javascript as well as css and javascript requested by the problem.
% for (@$third_party_css) {
%= stylesheet $_
Expand Down