Wrong displaying of glossary entry popup window in HTML files

Wrong displaying of glossary entry popup window in HTML files

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

Hello!

When one clicks on an autolinked word or phrase in a resource text, a "Glossary entry" popup window is displayed. This popup window is created with the following parameters:

menubar=0,location=0,scrollbars,resizable,width=600,height=450

For all types of text resources created online & residing within the Moodle database, i.e. text page, web page & label, the popup window is indeed displayed with those parameters.

However, the appearance of that popup window is not correct when the resource text is an uploaded HTML file.

The reason is as follows: both types of resources are parsed for the detection of terms present in the glossaries and autolink links are then dynamically created, including the parameters mentioned above. So far, so good. But only the resources of "online type" are output as HTML with the appropriate javascript function openpopup(). That function is not added to the <head></head> section of an uploaded HTML file. Consequently, the popup window opens as a "normal" window, complete with menubar, not located in the top-left corner and not sized 600x450.

I posted this as a bug report some time ago but it has not been answered. For anyone irritated by this glossary entry popup window wrong behavior, I can propose 2 workarounds.

Workaround 1: modifying Moodle file \lib\filterlib.php

using latest version 1.5.2, around line 220, just before returning the modified text with autolinks in it, add this:

if (!empty($ignoretags)) {

$text = str_replace(array_keys($ignoretags),$ignoretags,$text);

}

//MODIFIED JOSEPH REZEAU 22 JULY 2005

$nopopupfunction = '</head>';

$popupfunction = '<script language="javascript" type="text/javascript">function openpopup(url,name,options,fullscreen) {var _url = top.location.href;var _start =_url.indexOf("/mod/");var startUrl = _url.substring(0,_start);fullUrl = startUrl + url;windowobj = window.open(fullUrl,name, options);windowobj.moveTo(0,0);windowobj.focus();return false;}</script></head>';

$text = str_replace($nopopupfunction, $popupfunction, $text);

//END MODIF JR

return $text;

caveat: this relies on the presence of a <head></head> section in the uploaded HTML file, i.e. we suppose it is "correct" HTML

Workaround 2: modifying your HTML files

simply add the script for the missing openpopup() function in the head of your HTML FILES before uploading them to your Moodle course; if you have a large number of such files, that function could of course reside in an external *.js file and you would refer to it in the head of all your HTML files. Here is the script:
<script language="javascript" type="text/javascript">
function openpopup(url,name,options,fullscreen) {
var _url = top.location.href;
var _start =_url.indexOf("/mod/");
var startUrl = _url.substring(0,_start);
fullUrl = startUrl + url;
windowobj = window.open(fullUrl,name,options);windowobj.moveTo(0,0);
windowobj.focus();
return false;
}
</script>

I hope this will be useful and am looking forward to your testing it...

Joseph

NOTE: in the scripts above, you will notice that the HTML editor has replaced language with Xlanguage; please remove the superfluous X to make the scripts work...

Average of ratings: -
In reply to Joseph Rézeau

Re: Wrong displaying of glossary entry popup window in HTML files

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Hello there!
Answering my own message...
I'm a little surprised that my previous message has not triggered any response and I've been wondering:
  1. maybe most moodle users do not mind the glossary definition window popping up full-size when triggered by an autolinked word from an uploaded HTML file;
  2. maybe not many moodle users actually have courses with uploaded HTML files and autolinks to a glossary;
  3. maybe not many moodle users actually use uploaded HTML files at all...
Just curious to find out whether my two proposed workarounds have been useful to anyone out there (and if they actually work on other people's Moodle sites)thoughtful.

All the best,

Joseph