Where should javascript functions of a filter go?

Where should javascript functions of a filter go?

by Jan Dierckx -
Number of replies: 8
I would like to implement the mouseovers for the glossary as a filter.
At the moment I have added a line to javascript.php which includes the javascript I want to use. This works, but I don't like Moodle addons for which you have to alter a bunch of other files. Filters are nice because you can just drop your own in the filter directory and it will be available.
Is there a more standard way to make sure a filter adds a javascript function to a page?
Average of ratings: -
In reply to Jan Dierckx

Re: Where should javascript functions of a filter go?

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
We already have the overlib functions included (cvs:/moodle/lib/overlib.js) which will do what you want.  I would recommend using those.  (This is how the popups in the calendar are done, for example).  See this site for examples of what is possible.

If this doesn't work for you let me know.  I am happy to add generic functions to lib/javascript*
In reply to Martin Dougiamas

Re: Where should javascript functions of a filter go?

by Jan Dierckx -
Martin, the script (demo is here) already uses overlib.js to display the mouseover. That's no problem as it is already included on every page.
The script I want to add is a xmlhttp request to get the content for the mouseover without having to refresh the page. It's not ready for inclusion in lib/javascript (I expect problems with older browsers / it waits till it gets something back instead of producing a message when nothing comes back / etc...) That's why I asked for a place to put it other than the official Moodle javascript functions so people could test it on different browsers  without having to hack existing code of their Moodle site. I don't know if that is possible.

I've looked around for a more generic xmlhttp request library and it seems JPspan looks promising. I don't know if it's worth to include it though...


In reply to Jan Dierckx

Re: Where should javascript functions of a filter go?

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
I think for now just tell them to add a line like this to their theme header

<script language="JavaScript" type="text/javascript" src="/filter/yourfilter/javascript.php"></script>

I'll add code to lib/javascript.php to include lib/javascript-mod.php, which will search the filters, blocks and modules for javascript.php files and automatically include them if any are found. That should be fairly efficient because the browser can cache the results.

I think .php is better than .js because it allows you to customise your javascript to suit the site.
In reply to Jan Dierckx

Re: Where should javascript functions of a filter go?

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

When I recently discovered the existence of the overlibs functions in Moodle I was thrilled and thought I would use that library to provide tooltips in various parts of my Moodle courses. I especially need the tooltips inside the Glossary definitions and in the Quiz and Lesson modules.

Alas! I have found out that Moodle's over-zealous javascript filter replaces all occurences of onmouseover & onmouseout by Xonmouseover & Xonmouseout, which obviously makes the overlib tooltips unavailable (except in uploaded HTML ressources & in a composed Web page, fortunately).

This question has already been asked on several threads and I ask it again: is there a way to stop the filtering of javascript commands such as onmouseover, etc. in Moodle parts which are authored by the teacher?

I do appreciate that public postings (e.g. forums, etc.) should be filtered in order to avoid potentially dangerous javascript scripts, but I am irritated that, as a course designer, I am not allowed to do what I want.

Maybe there is a simple workaround that I am unaware of? wink

Hopefully waiting,

Joseph

In reply to Joseph Rézeau

Re: Where should javascript functions of a filter go?

by Jan Dierckx -

Joseph, I am not aware of a simple workaround. I propose to add another filter plugin which looks for constructs like {popuphover "This text should be in a popup"} and {popupclick "This is another example of a popup"}

and replaces this on all moodle's pages with the proper javascript call to the overlib library.

That way...

  • students will also get the ability to add popup notes where they think it will simplify reading of their text

poem.JPG

  • it will be easier for non-technical teachers to use the overlib functions (which are included in every Moodle page but up to now are only used by the calendar)

  • you will no longer have to type out all of the onmouseover, onmouseout javascript calls, but can focus on the text.

  • you don't need to cripple the security restrictions.

edit:

I've just found out that Eloy's customlinker script allows extra tags to be added to forum posts / glossary entries which are then picked up by the custom linker script and changed before being displayed on screen.

Instead of { and } he uses the normal < and > tags. It should be possible to add extra <cf_popup> and </cf_popup> as tags to this filter and make the filter change the enclosed text into a popup note. I'm not sure if the HTML editor likes this kind of self-invented html tags.... mixed

Average of ratings: Useful (1)
In reply to Jan Dierckx

Re: Where should javascript functions of a filter go?

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Jan, thanks for your prompt reply.

However, I do not understand what you mean by "I propose to add another filter plugin which looks for constructs like {popuphover "This text should be in a popup"} and {popupclick "This is another example of a popup"}".

Have you actually made that "filter plugin" yourself? what does it look like? where does it go?

I am actually looking for a solution which does not involve any modification of Moodle's php files, since I do not have admin rights.

Thanks,

Joseph
In reply to Joseph Rézeau

Re: Where should javascript functions of a filter go?

by Jan Dierckx -

Filter plugins go inside the moodle/filter/ directory. I haven't made a filter plugin for this. the screenshot is from a more (read too) ambitious project which allowed teachers to add little popups to a text in which students could add notes / opinions / etc to discuss a text.

I have made a popupfilter which adds popups to all the words in a glossary. The javascript involved still needs some work though mixed