WeBWorK Main Forum

Possible to add Javascript to course_info.txt? Not able to do it.

Possible to add Javascript to course_info.txt? Not able to do it.

by Christian Seberino -
Number of replies: 6
I have a working fresh install of Webwork 2.9.

I tried adding the following to course_info.txt but it looks like the 
Javascript didn't run.  I was hoping "here." would have been replaced
with "NEW TEXT".

My ultimate goal is to scrape the course name and username from the
Webwork page and create a special URL for the link.

The link is

<a id = "some_link" href = "https://google.com">here.</a>

<script>
function myFunction() {
    document.getElementById("some_link").innerHTML = "NEW TEXT";
}
</script>
In reply to Christian Seberino

Re: Possible to add Javascript to course_info.txt? Not able to do it.

by Davor Cubranic -
This snippet creates the function, but do you actually call it?
In reply to Christian Seberino

Re: Possible to add Javascript to course_info.txt? Not able to do it.

by Davor Cubranic -
On a more general note, why would you need to scrape the page when the username is available in $studentLogin?
In reply to Davor Cubranic

Re: Possible to add Javascript to course_info.txt? Not able to do it.

by Christian Seberino -
Thanks for the help.  I was able to get Javascript working in course_info.txt with your corrections.  I guess I'm a Javascript beginner who needs more learning.

I think $studentLogin is available in Perl code but not sure if it is available in Javascript....if it is that would be quite nice.

Much more exciting is fact I was able to add extra links to the left main menu box by using variables like the one you mentioned, and, adding new links in ContentGenerator.pm.  I love Webwork!

cs
In reply to Davor Cubranic

Re: Possible to add Javascript to course_info.txt? Not able to do it.

by Davide Cervone -
why would you need to scrape the page when the username is available in $studentLogin?

Because the course info box shows an HTML file, not a PG file (like the one used to create the info box for a homework set). This is inconsistent, and it means that the course info can not use any of the PG values. That is unfortunate, and the reason that Christian needs to use javascript to accomplish his needs.
In reply to Davide Cervone

Re: Possible to add Javascript to course_info.txt? Not able to do it.

by Michael Gage -
It's also mostly historical since there are some values such as set number problem number that were not defined on this page and the environment would not be complete. (set headers were given problem number 0 on each homework set page so that the environment would be complete).  

We've developed ways to work around incomplete environments (the most robust is probably John Jones techniques implemented for the library browser) and they could be applied to the course_info page as well.

There are some downsides -- the set header files are currently very complicated because there are separate hardcopy and screen versions. 
It would be better to only have one combined version of these files.  The resistance to having just one version has been that people like to write pure HTML in those files (and also in the course_info.txt files) and this requires the use of MODES() which can be a bit confusing.
 
If we convert consistently to using .pg files then it will be best to use the PG aliases for HTML markup (or PGML). This makes the course_info files a bit more complicated, although using PGML notation might make the complication minimal.

Creating a model combined set header file using PGML would be a good test project along these lines.
In reply to Michael Gage

Re: Possible to add Javascript to course_info.txt? Not able to do it.

by Davide Cervone -
These are good points. I was thinking that for course_info.txt, if it started with DOCUMENT(); then it would be processed by PG, and if not, then it would be treated as it currently is. That would give backward compatibility. I hadn't thought about the missing variables or incomplete environment, but I suppose that could be handled as you have indicated.

I know that the dual set header files have been a pain historically. I went to a common screen-and-print file myself long ago, so have not given it much thought recently. I think you are right that PGML might be a good format for those. I should give that a try.