Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-39246 JavaScript: store the time the page starts loading.

This helps synchronise time on the client side with time on the server.
If you wait until a js_init_call runs, you might have had to wait an
unknown number of seconds while all the JS loads. Therefore, we capture
the current time as soon as possible in <head>.

This is a bit like adding .jsenabled to <body> as soon as possible, to
reduce visual flicker.
  • Loading branch information...
commit 15dedb11683acb004b6cc3e602607f8493e0f60b 1 parent cf5a329
@timhunt timhunt authored
Showing with 13 additions and 4 deletions.
  1. +13 −4 lib/outputrequirementslib.php
View
17 lib/outputrequirementslib.php
@@ -131,7 +131,7 @@ class page_requirements_manager {
protected $yui3loader;
/**
- * @var stdClass default YUI loader configuration
+ * @var YUI_config default YUI loader configuration
*/
protected $YUI_config;
@@ -1313,16 +1313,25 @@ public function get_head_code(moodle_page $page, core_renderer $renderer) {
$output = '';
+ // Set up the M namespace.
+ $js = "var M = {}; M.yui = {};\n";
+
+ // Capture the time now ASAP during page load. This minimises the lag when
+ // we try to relate times on the server to times in the browser.
+ // An example of where this is used is the quiz countdown timer.
+ $js .= "M.pageloadstarttime = new Date();\n";
+
+ // Add a subset of Moodle configuration to the M namespace.
+ $js .= js_writer::set_variable('M.cfg', $this->M_cfg, false);
+
// Set up global YUI3 loader object - this should contain all code needed by plugins.
// Note: in JavaScript just use "YUI().use('overlay', function(Y) { .... });",
// this needs to be done before including any other script.
- $js = "var M = {}; M.yui = {};\n";
$js .= $this->YUI_config->get_config_functions();
$js .= js_writer::set_variable('YUI_config', $this->YUI_config, false) . "\n";
$js .= "M.yui.loader = {modules: {}};\n"; // Backwards compatibility only, not used any more.
- $js .= js_writer::set_variable('M.cfg', $this->M_cfg, false);
-
$js = $this->YUI_config->update_header_js($js);
+
$output .= html_writer::script($js);
// YUI3 JS and CSS need to be loaded in the header but after the YUI_config has been created.
Please sign in to comment.
Something went wrong with that request. Please try again.