Poster lagt til av David Scotson

Helen,

I tried to change my MoodleDocs user theme to whatever the first in the list is ('classic' or 'simple' I think) and it appears to have broken the site completely. Whenever I'm logged in a get a blank screen and if I view the source I only see as far as the body tag before it cuts off:

<body bgcolor='#FFFFFF' onload=''>

Is it possible for you to switch my theme back to something else? It's too busted for me to do anything,

cheers,

dave

From looking at the HTML source it appears that it was done within the template itself with javascript (and a tiny little bit of CSS). The code for the row looks like this:

<tr class="trnormal" onmouseover="this.className='trhighlight'" onmouseout="this.className='trnormal'">

(note the extra X's are a Moodle forum security feature, not part of the original code)

Obviously in your CSS you just need to specify the styles for trnormal and trhighlight. Note that you can apply :hover styles with just CSS but, and I think you can guess what I'm about to say, it doesn't work in Internet Explorer, which only supports :hover on a tags.

There are slightly cleaner ways to do this with techniques called unobtrusive javascript but there's no point getting fancy if it does what you want, and the database module is a bit of a special case.

This post's a bit disjointed so I'll use bullets:

  • I had a look at the resource stuff too. I duplicated the current text resource and hacked it so that it automatically ran the contents through Geshi as if it was a php file. It all worked pretty seamlessly and I'm now convinced it's a good idea and relatively easy to do.
  • Interesting idea about the directory structure, however I'm thinking that if you're dealing with code as 'code' (i.e. a whole directory of the stuff rather than a file or two being referenced, ideally containing helpful comments) then you'd be as well downloading it into an editor, which can do the source highlighting for you. Note that Moodle supports uploading, unzipping and displaying files in several places, but not the the current directory resource. It's a little bit icky whichever way you do it (manipulating files via the web generally is) but for the show directory functionality you currently need to go into 'files' and upload then extract the zip, before going into 'show a directory' and simply choosing the newly created directory from the list.
  • similarly to the above, I thought another possible use of the filter would be spotting (via filenames) uploads of code to forums, glossaries etc.. Currently the multimedia filters turns uploaded images into <img> tags, uploaded mp3s into flash players etc. Basically these filters just rewrite the text so the output includes a link to the upleaded file and some standard HTML/Flash makes the magic happen. Maybe the Geshi filter could create an extra link/form that takes you to a hypothetical geshi_renderer.php which accepts the location of a local file as a parameter and returns the highlighted version (the Geshi demo page already does something like this, no)? I like the idea of making peer code review easier and if this filter function existed then any text containing hyperlinks to code, i.e. a manually created 'directory' list of files could be transformed in the same way. You'd need to limit it to files within the Moodle upload directories though or else every link to a php page would trigger it!
  • The extra line was only appearing when I used the Markdown format. There's a few weird interactions where e.g. if you leave a space before and after the code then escaped HTML starts appearing within the highlighted code block. I think the square bracket syntax may interfering with markdown's own syntax. Somewhat ironically, Markdown is designed to let you add raw HTML unmolested so I think the old syntax was a much better fit with markdown.
  • I looked into the numbered code listing thing in some detail, and I've come to the conclusion that the only viable way to make it work is to use javascript to delete/write the linenumber (appropriately padded with spaces) from/into a span at the start of a preformatted line with the entire code contained within <pre> tags. I've not actually got around to writing some test code (which will have to wait till after MoodleMoot) but my thoughts so far are
    • Mozilla intentionally adds linenumbers to the copy paste and considers it a feature that copying half a numbered list will result in it being renumbered automatically. But, at least on my Mac copying anything less than the whole list results in the numbers being replaced with hash marks, and an unwanted line-break appears to be getting added. Summary: broken (at least partly) by design
    • IE doesn't add the line-numbers when you copy and paste, but a) you're demographics when dealing with coders probably means a 50/50 split between IE and Firefox, and b) there are occasions when you actually want to copy and paste the numbers as well as the code so your odds are low of your users actually being able to achieve what they want, and you have zero chance if they want to do both (i.e. copy with and without linenumbers) at different times.
    • I looked at some other ideas, like Koders.com which has a two celled table with a list of numbers separated by <br> tags in the first cell. Ingenious but again only useful for copying without the linenumbers.
    • If you put the code in a standard table then Firefox lets you copy only certain parts of a table by holding down control as you drag. Again neat, but a mostly unknown feature even to the geeky users of Firefox, and not cross-browser.
    • I thought you could just display:none the numbers as appropriate, changing the class with standard javascript but both IE and Firefox cut and paste content that isn't visible as a result of this style declaration.
    • adding and removing entire tags is made difficult because each line within the <pre> doesn't have a tag each
    • so it's perhaps best to have a span that's sometimes empty/contains empty spaces and sometimes has the linenumbers (right-padded with spaces) . You could perhaps use the sometimes useless span to add linenumber anchors (though I'm not sure how you'd avoid duplicating ids if you have more than one listing per page). This has the extra benefit of letting you highlight lines simply by putting the anchor in the URL and using :target (or whatever the CSS pseudo-selector is for that). Naturally that doesn't work in Internet Explorer, at least I think it doesn't.
    • so then you'd have to specify linenumbers or not, and whether the user has the option to toggle them with javascript (bearing in mind that if they don't have javascript then they're stuck with whatever you give them).
    • maybe you could autogenerate the plain text file in javascript too, but I have no idea if that's possible.
  • regarding the lopsided padding when not using linenumbers, I'd consider putting the line-numbers outside the colored background in a 'gutter' type thing to balance it better but as that might be tricky depending on the markup I'd maybe just add extra space on the other side of the code as well to balance it.

I hope that all makes sense!

You can see my quick hack version of a Geshi resource here:

log in as a teacher with username/password quickform/quickform

It doesn't even have any Geshi options, and assumes the text is PHP for the time being but you get the idea. Feel free to edit that resource or create a new one, that sites only for testing.