Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add css files requested by problems to gateway quizzes #1258

Merged
merged 2 commits into from
Mar 22, 2021
Merged
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
47 changes: 34 additions & 13 deletions lib/WeBWorK/ContentGenerator/GatewayQuiz.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2318,13 +2318,36 @@ sub output_JS{

my $site_url = $ce->{webworkURLs}->{htdocs};

# 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{$_} = 0 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{$_->{file}} = $_->{external} for @{$pg->{flags}{extra_css_files}};
}
}
for (keys(%cssFiles)) {
if ($cssFiles{$_}) {
print "<link rel=\"stylesheet\" type=\"text/css\" href=\"$_\" />\n";
} elsif (!$cssFiles{$_} && -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";
}
}

# The Base64.js file, which handles base64 encoding and decoding
print CGI::start_script({type=>"text/javascript", src=>"$site_url/js/apps/Base64/Base64.js"}), CGI::end_script();

# 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 qq{<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();
Expand All @@ -2350,8 +2373,8 @@ 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 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" />};
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 +2394,27 @@ 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 qq{<link href="$site_url/js/apps/ImageView/imageview.css" rel="stylesheet" />};
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}} = $_->{external} for @{$pg->{flags}{extra_js_files}};
}
}
for (keys(%jsFiles)) {
if ($jsFiles{$_} && -f "$WeBWorK::Constants::WEBWORK_DIRECTORY/htdocs/js/$_") {
if ($jsFiles{$_}) {
print CGI::start_script({type => "text/javascript",
src => "$site_url/js/$_"}), CGI::end_script();
} elsif (!$jsFiles{$_}) {
src => $_}), CGI::end_script();
} elsif (!$jsFiles{$_} && -f "$WeBWorK::Constants::WEBWORK_DIRECTORY/htdocs/$_") {
print CGI::start_script({type => "text/javascript",
src => "$_"}), CGI::end_script();
src => "$site_url/$_"}), 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
59 changes: 24 additions & 35 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}} = $_->{external} for @{$self->{pg}{flags}{extra_js_files}};
for (keys(%jsFiles)) {
if ($jsFiles{$_} && -f "$WeBWorK::Constants::WEBWORK_DIRECTORY/htdocs/js/$_") {
if ($jsFiles{$_}) {
print CGI::start_script({type => "text/javascript",
src => "$site_url/js/$_"}), CGI::end_script();
} elsif (!$jsFiles{$_}) {
src => $_}), CGI::end_script();
} elsif (!$jsFiles{$_} && -f "$WeBWorK::Constants::WEBWORK_DIRECTORY/htdocs/$_") {
print CGI::start_script({type => "text/javascript",
src => "$_"}), CGI::end_script();
src => "$site_url/$_"}), 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,23 @@ 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{$_} = 0 for @{$ce->{pg}{specialPGEnvironmentVars}{extra_css_files}};
}
if (ref($self->{pg}{flags}{extra_css_files}) eq "ARRAY") {
$cssFiles{$_->{file}} = $_->{external} for @{$self->{pg}{flags}{extra_css_files}};
}
for (keys(%cssFiles)) {
if ($cssFiles{$_}) {
print "<link rel=\"stylesheet\" type=\"text/css\" href=\"$_\" />\n";
} elsif (!$cssFiles{$_} && -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