Moodle

Question types cannot easily define their own JavaScript functions

Details

  • Type: Sub-task Sub-task
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 1.7
  • Fix Version/s: 1.9
  • Component/s: Questions
  • Labels:
    None
  • Affected Branches:
    MOODLE_17_STABLE
  • Fixed Branches:
    MOODLE_19_STABLE

Description

Any javascript that a question type wants has to be written inline in the HTML. It would be better if each qtype was allowed a .js file that was automatically loaded by any page where that qtype was displayed or edited. (We should also ensure that YUI is always available to qtypes).

Activity

Hide
Dmitry Pupinin added a comment -

Why you can't insert link to .js in display.html?

Show
Dmitry Pupinin added a comment - Why you can't insert link to .js in display.html?
Hide
Tim Hunt added a comment -

This was already fixed by the require_js function in lib/ajaxlib.php which is part of Moodle 1.8. Cool.

However, I will add a bit to the base question type, so if you have a script.js or scripts.php file in your plugin, it will automatically require_js them for you!

Show
Tim Hunt added a comment - This was already fixed by the require_js function in lib/ajaxlib.php which is part of Moodle 1.8. Cool. However, I will add a bit to the base question type, so if you have a script.js or scripts.php file in your plugin, it will automatically require_js them for you!
Hide
Tim Hunt added a comment -

To use this, you just need to put a script.js or script.php file in the question type folder. If you want to do something more complicated, override the get_html_head_contributions method defined in the base class (or just use the require_js function elsewhere in your code).

Show
Tim Hunt added a comment - To use this, you just need to put a script.js or script.php file in the question type folder. If you want to do something more complicated, override the get_html_head_contributions method defined in the base class (or just use the require_js function elsewhere in your code).

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: