Moodle

Make a new requirements_manager to hold the implementation of requrie_js and friends

Details

  • Type: Sub-task Sub-task
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 2.0
  • Fix Version/s: 2.0
  • Component/s: Libraries
  • Labels:
    None
  • Affected Branches:
    MOODLE_20_STABLE
  • Fixed Branches:
    MOODLE_20_STABLE

Description

This will help with storing lists of scripts, etc. and allow us to get the output without nasty hacks like the current $extracthtml argument to require_js.

Activity

Hide
Tim Hunt added a comment -

OK, here is a patch that implements a page_requirements_manager class, with unit tests and plenty of inline documentation.

I have not yet rewritten require_js and friends to use it, and then deprecated them. Nor have I changed print_header and friends to get the data from the class. I first want to know that the way I have made this class and its API is sensible.

Draft commit comment:

ajaxlib: MDL-16695 New page_requirements_manager class, soon to replace require_js

This new class does the work that require_js used to do, and more.
It can track a number of different things that may be required to
be output somewhere on the page, including:

  • Links to JS files
  • Links to CSS files
  • Links to YUI libraries (this class knows about the dependancies between the different libs).
  • Skip links that go from the top of <body> to various places in the content.
  • Calls to JavaScript functions (for example to initialise things)
  • Bits of data from PHP that need to be available to JavaScript
  • As a special case of that, an easy way to pass language strings to JS.

The new API looks like
$PAGE->requires->css('mod/mymod/styles.css');
$PAGE->requires->js('mod/mymod/script.js');
$PAGE->requires->js('mod/mymod/small_but_urgent.js')->in_head();
$PAGE->requires->js_function_call('init_mymod', array($data))->on_dom_ready();
$PAGE->requires is the canonical instances of this new class.

The commit also includes unit tests.

Show
Tim Hunt added a comment - OK, here is a patch that implements a page_requirements_manager class, with unit tests and plenty of inline documentation. I have not yet rewritten require_js and friends to use it, and then deprecated them. Nor have I changed print_header and friends to get the data from the class. I first want to know that the way I have made this class and its API is sensible. Draft commit comment: ajaxlib: MDL-16695 New page_requirements_manager class, soon to replace require_js This new class does the work that require_js used to do, and more. It can track a number of different things that may be required to be output somewhere on the page, including:
  • Links to JS files
  • Links to CSS files
  • Links to YUI libraries (this class knows about the dependancies between the different libs).
  • Skip links that go from the top of <body> to various places in the content.
  • Calls to JavaScript functions (for example to initialise things)
  • Bits of data from PHP that need to be available to JavaScript
  • As a special case of that, an easy way to pass language strings to JS.
The new API looks like $PAGE->requires->css('mod/mymod/styles.css'); $PAGE->requires->js('mod/mymod/script.js'); $PAGE->requires->js('mod/mymod/small_but_urgent.js')->in_head(); $PAGE->requires->js_function_call('init_mymod', array($data))->on_dom_ready(); $PAGE->requires is the canonical instances of this new class. The commit also includes unit tests.
Hide
Penny Leach added a comment -

we had a long conversation about this in jabber, but to make it official (other than all my tiny nitpicking):

Well Done Tim, Excellent Work Tim. Gold Star.

Show
Penny Leach added a comment - we had a long conversation about this in jabber, but to make it official (other than all my tiny nitpicking): Well Done Tim, Excellent Work Tim. Gold Star.
Hide
Tim Hunt added a comment -

OK, revised version of the patch is attached, benefiting from all Penny's detailed comments. Most of the changes are in the comments.

I will probably commit tomorrow morning, if there are no objections.

Show
Tim Hunt added a comment - OK, revised version of the patch is attached, benefiting from all Penny's detailed comments. Most of the changes are in the comments. I will probably commit tomorrow morning, if there are no objections.
Hide
Tim Hunt added a comment -

OK. Committed.

I'm sorry Penny, but in the end life was too short to do the boiler-plate change in a different commit.

Show
Tim Hunt added a comment - OK. Committed. I'm sorry Penny, but in the end life was too short to do the boiler-plate change in a different commit.

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: