|
| __construct () |
| Page fragment constructor. More...
|
|
| css ($stylesheet) |
| Ensure that the specified CSS file is linked to from this page. More...
|
|
| css_theme (moodle_url $stylesheet) |
| Add theme stylesheet to page - do not use from plugin code, this should be called only from the core renderer! More...
|
|
| data_for_js ($variable, $data, $inhead=false) |
| !!!!!!DEPRECATED!!!!!! please use js_init_call() for everything now. More...
|
|
| event_handler ($selector, $event, $function, array $arguments=null) |
| Creates a YUI event handler. More...
|
|
| get_config_for_javascript (moodle_page $page, renderer_base $renderer) |
| Return the safe config values that get set for javascript in "M.cfg". More...
|
|
| get_end_code () |
| Generate any HTML that needs to go at the end of the page. More...
|
|
| get_head_code (moodle_page $page, core_renderer $renderer) |
| Generate any HTML that needs to go inside the <head> tag. More...
|
|
| get_jsrev () |
| Determine the correct JS Revision to use for this load. More...
|
|
| get_top_of_body_code (renderer_base $renderer) |
| Generate any HTML that needs to go at the start of the <body> tag. More...
|
|
| has_one_time_item_been_created ($thing) |
| Has a particular bit of HTML that is only required once on this page (e.g. More...
|
|
| is_head_done () |
| Have we already output the code in the <head> tag? More...
|
|
| is_top_of_body_done () |
| Have we already output the code at the start of the <body> tag? More...
|
|
| jquery () |
| Request inclusion of jQuery library in the page. More...
|
|
| jquery_override_plugin ($oldplugin, $newplugin) |
| Request replacement of one jQuery plugin by another. More...
|
|
| jquery_plugin ($plugin, $component='core') |
| Request inclusion of jQuery plugin. More...
|
|
| js ($url, $inhead=false) |
| Ensure that the specified JavaScript file is linked to from this page. More...
|
|
| js_amd_inline ($code) |
| This function appends a block of code to the AMD specific javascript block executed in the page footer, just after loading the requirejs library. More...
|
|
| js_call_amd ($fullmodule, $func=null, $params=array()) |
| Load an AMD module and eventually call its method. More...
|
|
| js_function_call ($function, array $arguments=null, $ondomready=false, $delay=0) |
| !!!DEPRECATED!!! please use js_init_call() if possible Ensure that the specified JavaScript function is called from an inline script somewhere on this page. More...
|
|
| js_init_call ($function, array $extraarguments=null, $ondomready=false, array $module=null) |
| Ensure that the specified JavaScript function is called from an inline script from page footer. More...
|
|
| js_init_code ($jscode, $ondomready=false, array $module=null) |
| Add short static javascript code fragment to page footer. More...
|
|
| js_module ($module) |
| Append YUI3 module to default YUI3 JS loader. More...
|
|
| set_one_time_item_created ($thing) |
| Indicate that a particular bit of HTML that is only required once on this page (e.g. More...
|
|
| set_yuicssmodules (array $modules=array()) |
| Set the CSS Modules to be included from YUI. More...
|
|
| should_create_one_time_item_now ($thing) |
| Should we generate a bit of content HTML that is only required once on this page (e.g. More...
|
|
| skip_link_to ($target, $linktext) |
| Ensure that a skip link to a given target is printed at the top of the <body>. More...
|
|
| string_for_js ($identifier, $component, $a=null) |
| Make a language string available to JavaScript. More...
|
|
| strings_for_js ($identifiers, $component, $a=null) |
| Make an array of language strings available for JS. More...
|
|
| yui_module ($modules, $function, array $arguments=null, $galleryversion=null, $ondomready=false) |
| Creates a JavaScript function call that requires one or more modules to be loaded. More...
|
|
|
array | $amdjscode = array('') |
| Inline scripts using RequireJS module loading.
|
|
array | $cssthemeurls = array() |
| of moodle_url Theme sheets, initialised only from core_renderer
|
|
array | $cssurls = array() |
| of moodle_url List of custom theme sheets, these are strongly discouraged! Useful mostly only for CSS submitted by teachers that is not part of the theme.
|
|
array | $eventhandlers = array() |
| List of requested event handlers.
|
|
array | $extramodules = array() |
| Extra modules.
|
|
bool | $headdone = false |
| Flag indicated head stuff already printed.
|
|
array | $jquerypluginoverrides = array() |
| list of jQuery plugin overrides
|
|
array | $jqueryplugins = array() |
| list of requested jQuery plugins
|
|
array | $jscalls = array('normal'=>array(), 'ondomready'=>array()) |
| List of needed function calls.
|
|
array | $jsincludes = array('head'=>array(), 'footer'=>array()) |
| Included JS scripts.
|
|
array | $jsinitcode = array() |
| Javascript code used for initialisation of page, it should be relatively small.
|
|
array | $jsinitvariables = array('head'=>array(), 'footer'=>array()) |
| List of JS variables to be initialised.
|
|
array | $M_cfg |
| Some config vars exposed in JS, please no secret stuff there.
|
|
array | $onetimeitemsoutput = array() |
| trackes the names of bits of HTML that are only required once per page. More...
|
|
array | $skiplinks = array() |
| List of skip links, those are needed for accessibility reasons.
|
|
array | $stringsforjs = array() |
| List of string available from JS.
|
|
array | $stringsforjs_as = array() |
| List of get_string $a parameters - used for validation only.
|
|
bool | $topofbodydone = false |
| Flag indicating top of body already printed.
|
|
stdClass | $yui3loader |
| YUI PHPLoader instance responsible for YUI3 loading from PHP only.
|
|
YUI_config | $YUI_config |
| default YUI loader configuration
|
|
array | $yuicssmodules = array() |
| $yuicssmodules
|
|
page_requirements_manager::css |
( |
|
$stylesheet | ) |
|
|
inherited |
Ensure that the specified CSS file is linked to from this page.
Because stylesheet links must go in the <head> part of the HTML, you must call this function before get_head_code() is called. That normally means before the call to print_header. If you call it when it is too late, an exception will be thrown.
Even if a particular style sheet is requested more than once, it will only be linked to once.
Please note use of this feature is strongly discouraged, it is suitable only for places where CSS is submitted directly by teachers. (Students must not be allowed to submit any external CSS because it may contain embedded javascript!). Example of correct use is mod/data.
- Parameters
-
string | $stylesheet | The path to the .css file, relative to $CFG->wwwroot. For example: $PAGE->requires->css('mod/data/css.php?d='.$data->id); |
page_requirements_manager::jquery_override_plugin |
( |
|
$oldplugin, |
|
|
|
$newplugin |
|
) |
| |
|
inherited |
Request replacement of one jQuery plugin by another.
This is useful when themes want to replace the jQuery UI theme, the problem is that theme can not prevent others from including the core ui-css plugin.
Example: 1/ generate new jQuery UI theme and place it into theme/yourtheme/jquery/ 2/ write theme/yourtheme/jquery/plugins.php 3/ init jQuery from theme
// file theme/yourtheme/lib.php function theme_yourtheme_page_init($page) { $page->requires->jquery_plugin('yourtheme-ui-css', 'theme_yourtheme'); $page->requires->jquery_override_plugin('ui-css', 'yourtheme-ui-css'); }
This code prevents loading of standard 'ui-css' which my be requested by other plugins, the 'yourtheme-ui-css' gets loaded only if some other code requires jquery.
{
- See also
- http://docs.moodle.org/dev/jQuery}
- Parameters
-
string | $oldplugin | original plugin |
string | $newplugin | the replacement |
page_requirements_manager::jquery_plugin |
( |
|
$plugin, |
|
|
|
$component = 'core' |
|
) |
| |
|
inherited |
Request inclusion of jQuery plugin.
NOTE: this should not be used in official Moodle distribution!
jQuery plugins are located in plugin/jquery/* subdirectory, plugin/jquery/plugins.php lists all available plugins.
Included core plugins:
Add-ons may include extra jQuery plugins in jquery/ directory, plugins.php file defines the mapping between plugin names and necessary page includes.
Examples: // file: mod/xxx/view.php $PAGE->requires->jquery(); $PAGE->requires->jquery_plugin('ui'); $PAGE->requires->jquery_plugin('ui-css');
// file: theme/yyy/lib.php function theme_yyy_page_init(moodle_page $page) { $page->requires->jquery(); $page->requires->jquery_plugin('ui'); $page->requires->jquery_plugin('ui-css'); }
// file: blocks/zzz/block_zzz.php public function get_required_javascript() { parent::get_required_javascript(); $this->page->requires->jquery(); $page->requires->jquery_plugin('ui'); $page->requires->jquery_plugin('ui-css'); }
{
- See also
- http://docs.moodle.org/dev/jQuery}
- Parameters
-
string | $plugin | name of the jQuery plugin as defined in jquery/plugins.php |
string | $component | name of the component |
- Return values
-
page_requirements_manager::js_function_call |
( |
|
$function, |
|
|
array |
$arguments = null , |
|
|
|
$ondomready = false , |
|
|
|
$delay = 0 |
|
) |
| |
|
inherited |
!!!DEPRECATED!!! please use js_init_call() if possible Ensure that the specified JavaScript function is called from an inline script somewhere on this page.
By default the call will be put in a script tag at the end of the page after initialising Y instance, since this gives best page-load performance and allows you to use YUI3 library.
If you request that a particular function is called several times, then that is what will happen (unlike linking to a CSS or JS file, where only one link will be output).
The main benefit of the method is the automatic encoding of all function parameters.
- Deprecated:
- Parameters
-
string | $function | the name of the JavaScritp function to call. Can be a compound name like 'Y.Event.purgeElement'. Can also be used to create and object by using a 'function name' like 'new user_selector'. |
array | $arguments | and array of arguments to be passed to the function. When generating the function call, this will be escaped using json_encode, so passing objects and arrays should work. |
bool | $ondomready | If tru the function is only called when the dom is ready for manipulation. |
int | $delay | The delay before the function is called. |
page_requirements_manager::should_create_one_time_item_now |
( |
|
$thing | ) |
|
|
inherited |
Should we generate a bit of content HTML that is only required once on this page (e.g.
the contents of the modchooser), now? Basically, we call has_one_time_item_been_created(), and if the thing has not already been output, we return true to tell the caller to generate it, and also call set_one_time_item_created() to record the fact that it is about to be generated.
That is, a typical usage pattern (in a renderer method) is:
if (!$this->page->requires->should_create_one_time_item_now($thing)) {
return '';
}
// Else generate it.
- Parameters
-
string | $thing | identifier for the bit of content. Should be of the form frankenstyle_things, e.g. core_course_modchooser. |
- Return values
-
bool | if true, the caller should generate that bit of output now, otherwise don't. |
page_requirements_manager::skip_link_to |
( |
|
$target, |
|
|
|
$linktext |
|
) |
| |
|
inherited |
Ensure that a skip link to a given target is printed at the top of the <body>.
You must call this function before get_top_of_body_code(), (if not, an exception will be thrown). That normally means you must call this before the call to print_header.
If you ask for a particular skip link to be printed, it is then your responsibility to ensure that the appropriate tag is printed in the body of the page, so that the skip link goes somewhere.
Even if a particular skip link is requested more than once, only one copy of it will be output.
- Parameters
-
string | $target | the name of anchor this link should go to. For example 'maincontent'. |
string | $linktext | The text to use for the skip link. Normally get_string('skipto', 'access', ...); |
page_requirements_manager::string_for_js |
( |
|
$identifier, |
|
|
|
$component, |
|
|
|
$a = null |
|
) |
| |
|
inherited |
Make a language string available to JavaScript.
All the strings will be available in a M.str object in the global namespace. So, for example, after a call to $PAGE->requires->string_for_js('course', 'moodle'); then the JavaScript variable M.str.moodle.course will be 'Course', or the equivalent in the current language.
The arguments to this function are just like the arguments to get_string except that $component is not optional, and there are some aspects to consider when the string contains {$a} placeholder.
If the string does not contain any {$a} placeholder, you can simply use M.str.component.identifier to obtain it. If you prefer, you can call M.util.get_string(identifier, component) to get the same result.
If you need to use {$a} placeholders, there are two options. Either the placeholder should be substituted in PHP on server side or it should be substituted in Javascript at client side.
To substitute the placeholder at server side, just provide the required value for the placeholder when you require the string. Because each string is only stored once in the JavaScript (based on $identifier and $module) you cannot get the same string with two different values of $a. If you try, an exception will be thrown. Once the placeholder is substituted, you can use M.str or M.util.get_string() as shown above:
// Require the string in PHP and replace the placeholder.
$PAGE->requires->string_for_js('fullnamedisplay', 'moodle', $USER);
// Use the result of the substitution in Javascript.
alert(M.str.moodle.fullnamedisplay);
To substitute the placeholder at client side, use M.util.get_string() function. It implements the same logic as get_string():
// Require the string in PHP but keep {$a} as it is.
$PAGE->requires->string_for_js('fullnamedisplay', 'moodle');
// Provide the values on the fly in Javascript.
user = { firstname : 'Harry', lastname : 'Potter' }
alert(M.util.get_string('fullnamedisplay', 'moodle', user);
If you do need the same string expanded with different $a values in PHP on server side, then the solution is to put them in your own data structure (e.g. and array) that you pass to JavaScript with data_for_js().
- Parameters
-
string | $identifier | the desired string. |
string | $component | the language file to look in. |
mixed | $a | any extra data to add into the string (optional). |
page_requirements_manager::strings_for_js |
( |
|
$identifiers, |
|
|
|
$component, |
|
|
|
$a = null |
|
) |
| |
|
inherited |
Make an array of language strings available for JS.
This function calls the above function string_for_js() for each requested string in the $identifiers array that is passed to the argument for a single module passed in $module.
$PAGE->requires->strings_for_js(array('one', 'two', 'three'), 'mymod', array('a', null, 3));
// The above is identical to calling:
$PAGE->requires->string_for_js('one', 'mymod', 'a'); $PAGE->requires->string_for_js('two', 'mymod'); $PAGE->requires->string_for_js('three', 'mymod', 3);
- Parameters
-
array | $identifiers | An array of desired strings |
string | $component | The module to load for |
mixed | $a | This can either be a single variable that gets passed as extra information for every string or it can be an array of mixed data where the key for the data matches that of the identifier it is meant for. |