Skip to content

Commit

Permalink
Add an output_CSS method to GatewayQuiz.pm and the corresponding item in
Browse files Browse the repository at this point in the history
the template.  Add the method for adding css files passed from PG in
gateway quizzes to that method.
Also make it so that js and css files can be added that are not in the
css or js subdirectories, but any sub-directory of htdocs on the server.
Generally clean up the coding of those methods.
  • Loading branch information
drgrice1 committed Mar 17, 2021
1 parent 8d1fd45 commit 2a7ea3e
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 58 deletions.
7 changes: 6 additions & 1 deletion htdocs/themes/math4/gateway.template
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@
<!-- [gateway] since the left-side menus are gone, don't indent the main content area -->

<title><!--#path style="text" text=" : " textonly="1"--></title>
<!--#output_JS-->
<!--#if can="output_CSS"-->
<!--#output_CSS-->
<!--#endif-->
<!--#if can="output_JS"-->
<!--#output_JS-->
<!--#endif-->
<!--#head-->
</head>
<body>
Expand Down
78 changes: 55 additions & 23 deletions lib/WeBWorK/ContentGenerator/GatewayQuiz.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2323,18 +2323,13 @@ sub output_JS{

# This is for MathView.
if ($self->{will}->{useMathView}) {
if ((grep(/MathJax/,@{$ce->{pg}->{displayModes}}))) {
print "<link href=\"$site_url/js/apps/MathView/mathview.css\" rel=\"stylesheet\" />";
print CGI::start_script({type=>"text/javascript"});
print "mathView_basepath = \"$site_url/images/mathview/\";";
print CGI::end_script();
print CGI::start_script({type=>"text/javascript",
src=>"$site_url/js/apps/MathView/$ce->{pg}->{options}->{mathViewLocale}"}), CGI::end_script();
print CGI::start_script({type=>"text/javascript",
src=>"$site_url/js/apps/MathView/mathview.js"}), CGI::end_script();
} else {
warn ("MathJax must be installed and enabled as a display mode for the math viewer to work");
}
print CGI::start_script({type=>"text/javascript"});
print "mathView_basepath = \"$site_url/images/mathview/\";";
print CGI::end_script();
print CGI::start_script({type=>"text/javascript",
src=>"$site_url/js/apps/MathView/$ce->{pg}->{options}->{mathViewLocale}"}), CGI::end_script();
print CGI::start_script({type=>"text/javascript",
src=>"$site_url/js/apps/MathView/mathview.js"}), CGI::end_script();
}

# WIRIS EDITOR
Expand All @@ -2350,8 +2345,6 @@ sub output_JS{

# MathQuill interface
if ($self->{will}->{useMathQuill}) {
print "<link href=\"$site_url/js/apps/MathQuill/mathquill.css\" rel=\"stylesheet\" />";
print "<link href=\"$site_url/js/apps/MathQuill/mqeditor.css\" rel=\"stylesheet\" />";
print CGI::start_script({type=>"text/javascript",
src=>"$site_url/js/apps/MathQuill/mathquill.min.js"}), CGI::end_script();
print CGI::start_script({type=>"text/javascript",
Expand All @@ -2371,29 +2364,68 @@ sub output_JS{
print CGI::start_script({type=>"text/javascript", src=>"$site_url/js/apps/GatewayQuiz/gateway.js"}), CGI::end_script();

# This is for the image dialog
print "<link href=\"$site_url/js/apps/ImageView/imageview.css\" rel=\"stylesheet\" />\n";
print CGI::start_script({type=>"text/javascript", src=>"$site_url/js/apps/ImageView/imageview.js"}), CGI::end_script();

# Add JS files requested by problems via ADD_JS_FILE() in the PG file.
my %jsFiles;
for my $pg (@{$self->{ra_pg_results}}) {
next unless ref($pg);
if (defined($pg->{flags}{extra_js_files})) {
if (ref($pg->{flags}{extra_js_files}) eq "ARRAY") {
# Avoid duplicates
for (@{$pg->{flags}{extra_js_files}}) {
$jsFiles{$_->{file}} = $_->{local};
}
$jsFiles{$_->{file}} = $_->{local} for @{$pg->{flags}{extra_js_files}};
}
}
for (keys(%jsFiles)) {
if ($jsFiles{$_} && -f "$WeBWorK::Constants::WEBWORK_DIRECTORY/htdocs/js/$_") {
if ($jsFiles{$_} && -f "$WeBWorK::Constants::WEBWORK_DIRECTORY/htdocs/$_") {
print CGI::start_script({type => "text/javascript",
src => "$site_url/js/$_"}), CGI::end_script();
src => "$site_url/$_"}), CGI::end_script();
} elsif (!$jsFiles{$_}) {
print CGI::start_script({type => "text/javascript",
src => "$_"}), CGI::end_script();
src => $_}), CGI::end_script();
} else {
print "<!-- $_ is not available in htdocs/ on this server -->\n";
}
}

return "";
}

sub output_CSS{
my $self = shift;
my $r = $self->r;
my $ce = $r->ce;
my $site_url = $ce->{webworkURLs}{htdocs};

# This is for MathView.
print qq{<link href="$site_url/js/apps/MathView/mathview.css" rel="stylesheet" />} if ($self->{will}{useMathView});

# MathQuill interface
if ($self->{will}->{useMathQuill}) {
print qq{<link href="$site_url/js/apps/MathQuill/mathquill.css" rel="stylesheet" />"};
print qq{<link href="$site_url/js/apps/MathQuill/mqeditor.css" rel="stylesheet" />"};
}

# This is for the image dialog
print qq{<link href="$site_url/js/apps/ImageView/imageview.css" rel="stylesheet" />"};

# Add 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 anonomous array).
my %cssFiles;
if (ref($ce->{pg}{specialPGEnvironmentVars}{extra_css_files}) eq "ARRAY") {
$cssFiles{$_} = 1 for @{$ce->{pg}{specialPGEnvironmentVars}{extra_css_files}};
}
for my $pg (@{$self->{ra_pg_results}}) {
next unless ref($pg);
if (ref($pg->{flags}{extra_css_files}) eq "ARRAY") {
$cssFiles{$_} = 1 for @{$pg->{flags}{extra_css_files}};
}
}
for (keys(%cssFiles)) {
if (-f "$WeBWorK::Constants::WEBWORK_DIRECTORY/htdocs/$_") {
print "<link rel=\"stylesheet\" type=\"text/css\" href=\"${site_url}/$_\" />\n";
} else {
print "<!-- $_ is not available in htdocs/js/ on this server -->\n";
print "<!-- $_ is not available in htdocs/ on this server -->\n";
}
}

Expand Down
55 changes: 21 additions & 34 deletions lib/WeBWorK/ContentGenerator/Problem.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2390,21 +2390,19 @@ sub output_JS{
print CGI::start_script({type=>"text/javascript", src=>"$site_url/js/apps/ImageView/imageview.js"}), CGI::end_script();

# Add JS files requested by problems via ADD_JS_FILE() in the PG file.
if (defined($self->{pg}{flags}{extra_js_files})) {
if (ref($self->{pg}{flags}{extra_js_files}) eq "ARRAY") {
my %jsFiles;
# Avoid duplicates
for (@{$self->{pg}{flags}{extra_js_files}}) {
$jsFiles{$_->{file}} = $_->{local};
}
$jsFiles{$_->{file}} = $_->{local} for @{$self->{pg}{flags}{extra_js_files}};
for (keys(%jsFiles)) {
if ($jsFiles{$_} && -f "$WeBWorK::Constants::WEBWORK_DIRECTORY/htdocs/js/$_") {
if ($jsFiles{$_} && -f "$WeBWorK::Constants::WEBWORK_DIRECTORY/htdocs/$_") {
print CGI::start_script({type => "text/javascript",
src => "$site_url/js/$_"}), CGI::end_script();
src => "$site_url/$_"}), CGI::end_script();
} elsif (!$jsFiles{$_}) {
print CGI::start_script({type => "text/javascript",
src => "$_"}), CGI::end_script();
src => $_}), CGI::end_script();
} else {
print "<!-- $_ is not available in htdocs/js/ on this server -->\n";
print "<!-- $_ is not available in htdocs/ on this server -->\n";
}
}
}
Expand Down Expand Up @@ -2437,32 +2435,21 @@ sub output_CSS {
print "<link href=\"$site_url/js/apps/ImageView/imageview.css\" rel=\"stylesheet\" />\n";

# Add 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).
my $pg = $self->{pg};
if ( defined( $pg->{flags}{extra_css_files} ) ||
( defined( $ce->{pg}->{specialPGEnvironmentVars}->{extra_css_files} ) &&
scalar( @{$ce->{pg}->{specialPGEnvironmentVars}->{extra_css_files}} ) > 0 )
) {
my $baseDir = $ce->{webwork_htdocs_url};
my $webwork_dir = $WeBWorK::Constants::WEBWORK_DIRECTORY;
my $cssFile;
my %cssFiles;
# Avoid duplicates
my @courseCssRequests = ();
if ( defined($ce->{pg}->{specialPGEnvironmentVars}->{extra_css_files} ) ) {
@courseCssRequests = ( @{$ce->{pg}->{specialPGEnvironmentVars}->{extra_css_files}
} );
}
foreach $cssFile ( @courseCssRequests, @{$pg->{flags}{extra_css_files}} ) {
$cssFiles{$cssFile} = 1;
}
foreach $cssFile ( keys( %cssFiles ) ) {
if ( -f "$webwork_dir/htdocs/css/$cssFile" ) { # FIXME - test for existence
print "<link rel=\"stylesheet\" type=\"text/css\" href=\"${baseDir}/css/$cssFile\" />\n";
} else {
print "<!-- $cssFile is not available in htdocs/css/ on this server -->\n";
}
# or via a setting of $ce->{pg}{specialPGEnvironmentVars}{extra_css_files}
# which can be set in course.conf (the value should be an anonomous array).
my %cssFiles;
# Avoid duplicates
if (ref($ce->{pg}{specialPGEnvironmentVars}{extra_css_files}) eq "ARRAY") {
$cssFiles{$_} = 1 for @{$ce->{pg}{specialPGEnvironmentVars}{extra_css_files}};
}
if (ref($self->{pg}{flags}{extra_css_files}) eq "ARRAY") {
$cssFiles{$_} = 1 for @{$self->{pg}{flags}{extra_css_files}};
}
for (keys(%cssFiles)) {
if (-f "$WeBWorK::Constants::WEBWORK_DIRECTORY/htdocs/$_") {
print "<link rel=\"stylesheet\" type=\"text/css\" href=\"${site_url}/$_\" />\n";
} else {
print "<!-- $_ is not available in htdocs/ on this server -->\n";
}
}

Expand Down

0 comments on commit 2a7ea3e

Please sign in to comment.