Issue Details (XML | Word | Printable)

Key: MDL-16695
Type: Sub-task Sub-task
Status: Resolved Resolved
Resolution: Fixed
Priority: Minor Minor
Assignee: Tim Hunt
Reporter: Tim Hunt
Votes: 0
Watchers: 2
Operations

Add/Edit UI Mockup to this issue
If you were logged in you would be able to see more operations.
Moodle
MDL-16583

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

Created: 26/Sep/08 12:29 PM   Updated: 12/Jun/09 11:14 AM
Return to search
Component/s: Lib
Affects Version/s: 2.0
Fix Version/s: 2.0

File Attachments: 1. Text File page_requirements_manager.patch (64 kB)
2. Text File page_requirements_manager.patch (62 kB)


Participants: Penny Leach and Tim Hunt
Security Level: None
Resolved date: 12/Jun/09
Affected Branches: MOODLE_20_STABLE
Fixed Branches: MOODLE_20_STABLE


 Description  « Hide
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.

 All   Comments   Change History   Version Control      Sort Order: Ascending order - Click to sort in descending order
Tim Hunt added a comment - 11/Jun/09 05:11 PM
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.


Penny Leach added a comment - 11/Jun/09 06:27 PM
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.


Tim Hunt added a comment - 11/Jun/09 06:49 PM
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.


Tim Hunt added a comment - 12/Jun/09 11:14 AM
OK. Committed.

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