Skip to content

Commit f32501a

Browse files
committed
Code to support adding additional CSS files requested by problems
via ADD_CSS_FILE() in the PG file, or via a setting of $ce->{pg}->{specialPGEnvironmentVars}->{extra_css_files} which can be set in course.conf (the value should be an anon array). A sample htdocs/css/rtl.css is included with a very preliminary bit of CSS code for RTL courses, in this case to move radio buttons to the right of the text.
1 parent 62cefd9 commit f32501a

File tree

2 files changed

+51
-6
lines changed

2 files changed

+51
-6
lines changed

htdocs/css/rtl.css

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* WeBWorK Online Homework Delivery System
2+
* Copyright © 2000-2019 The WeBWorK Project, http://openwebwork.sf.net/
3+
*
4+
* This program is free software; you can redistribute it and/or modify it under
5+
* the terms of either: (a) the GNU General Public License as published by the
6+
* Free Software Foundation; either version 2, or (at your option) any later
7+
* version, or (b) the "Artistic License" which comes with this package.
8+
*
9+
* This program is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11+
* FOR A PARTICULAR PURPOSE. See either the GNU General Public License or the
12+
* Artistic License for more details.
13+
*/
14+
15+
/* --- Modify some CSS for Right to left courses/problems ---------------------------------------------------- */
16+
17+
input[type="radio"], input[type="checkbox"] {
18+
float: right !important;
19+
}

lib/WeBWorK/ContentGenerator/Problem.pm

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2268,20 +2268,46 @@ sub output_CSS {
22682268
my $site_url = $ce->{webworkURLs}->{htdocs};
22692269

22702270
# Javascript and style for knowls
2271-
print qq{
2272-
<link href="$site_url/css/knowlstyle.css" rel="stylesheet" type="text/css" />};
2271+
print "<link href=\"$site_url/css/knowlstyle.css\" rel=\"stylesheet\" type=\"text/css\" />\n";
22732272

22742273
#style for mathview
22752274
if ($self->{will}->{useMathView}) {
2276-
print "<link href=\"$site_url/js/apps/MathView/mathview.css\" rel=\"stylesheet\" />";
2275+
print "<link href=\"$site_url/js/apps/MathView/mathview.css\" rel=\"stylesheet\" />\n";
22772276
}
22782277

22792278
#style for mathquill
22802279
if ($self->{will}->{useMathQuill}) {
2281-
print "<link href=\"$site_url/js/apps/MathQuill/mathquill.css\" rel=\"stylesheet\" />";
2282-
print "<link href=\"$site_url/js/apps/MathQuill/mqeditor.css\" rel=\"stylesheet\" />";
2280+
print "<link href=\"$site_url/js/apps/MathQuill/mathquill.css\" rel=\"stylesheet\" />\n";
2281+
print "<link href=\"$site_url/js/apps/MathQuill/mqeditor.css\" rel=\"stylesheet\" />\n";
22832282
}
2284-
2283+
2284+
# Add CSS files requested by problems via ADD_CSS_FILE() in the PG file
2285+
# or via a setting of $ce->{pg}->{specialPGEnvironmentVars}->{extra_css_files}
2286+
# which can be set in course.conf (the value should be an anon array).
2287+
my $pg = $self->{pg};
2288+
if ( defined( $pg->{flags}{extra_css_files} ) ) {
2289+
my $baseDir = $ce->{webwork_htdocs_url};
2290+
my $webwork_dir = $WeBWorK::Constants::WEBWORK_DIRECTORY;
2291+
my $cssFile;
2292+
my %cssFiles;
2293+
# Avoid duplicates
2294+
my @courseCssRequests = ();
2295+
if ( defined($ce->{pg}->{specialPGEnvironmentVars}->{extra_css_files} ) ) {
2296+
@courseCssRequests = ( @{$ce->{pg}->{specialPGEnvironmentVars}->{extra_css_files}
2297+
} );
2298+
}
2299+
foreach $cssFile ( @courseCssRequests, @{$pg->{flags}{extra_css_files}} ) {
2300+
$cssFiles{$cssFile} = 1;
2301+
}
2302+
foreach $cssFile ( keys( %cssFiles ) ) {
2303+
if ( -f "$webwork_dir/htdocs/css/$cssFile" ) { # FIXME - test for existence
2304+
print "<link rel=\"stylesheet\" type=\"text/css\" href=\"${baseDir}/css/$cssFile\" />\n";
2305+
} else {
2306+
print "<!-- $cssFile is not available in htdocs/css/ on this server -->\n";
2307+
}
2308+
}
2309+
}
2310+
22852311
return "";
22862312
}
22872313

0 commit comments

Comments
 (0)