MDL-16672 Output a standard set of config variables into JavaScript on every page.
authortjhunt <tjhunt>
Thu, 25 Sep 2008 03:11:33 +0000 (03:11 +0000)
committertjhunt <tjhunt>
Thu, 25 Sep 2008 03:11:33 +0000 (03:11 +0000)
lib/weblib.php

index 33083fbd52f7f927d80b71adeefdc8ad7ffbb494..97d31df383c70ed8fe6cfda814c2a8f97a9df583 100644 (file)
@@ -2358,6 +2358,8 @@ function print_header ($title='', $heading='', $navigation='', $focus='',
 
     $meta .= "\n".require_js('',1);
 
+    $meta .= standard_js_config();
+
 /// Set up some navigation variables
 
     if (is_newnav($navigation)){
@@ -2731,6 +2733,22 @@ function print_js_config($settings = array(), $prefix='', $return = false) {
     }
 }
 
+/**
+ * This function generates the code that defines the standard moodle_cfg object.
+ * This object has a number of fields that are values that various pieces of
+ * JavaScript code need access too. For example $CFG->wwwroot and $CFG->pixpath.
+ *
+ * @return string a <script> tag that defines the moodle_cfg object.
+ */
+function standard_js_config() {
+    global $CFG;
+    return print_js_config(array(
+        'wwwroot' => $CFG->httpswwwroot, // Yes, really.
+        'pixpath' => $CFG->pixpath,
+        'modpixpath' => $CFG->modpixpath,
+    ), 'moodle_cfg', true);
+}
+
 /**
  * Debugging aid: serve page as 'application/xhtml+xml' where possible,
  *     and substitute the XHTML strict document type.