/** * Ensure that the specified JavaScript function is called from an inline script * from page footer. * * @param string $function the name of the JavaScritp function to with init code, * usually something like 'M.mod_mymodule.init' * @param array $extraarguments and array of arguments to be passed to the function. * The first argument is always the YUI3 Y instance with all required dependencies * already loaded. * @param bool $ondomready wait for dom ready (helps with some IE problems when modifying DOM) * @param array $module JS module specification array */ public function js_init_call($function, array $extraarguments = null, $ondomready = false, array $module = null) { $jscode = js_writer::function_call_with_Y($function, $extraarguments); if (!$module) { // Detect module automatically. if (preg_match('/M\\.([a-z0-9]+_[^\\.]+)/', $function, $matches)) { $module = $this->find_module($matches[1]); } } $this->js_init_code($jscode, $ondomready, $module); }
/** * Renders a custom menu object (located in outputcomponents.php) * * The custom menu this method produces makes use of the YUI3 menunav widget * and requires very specific html elements and classes. * * @staticvar int $menucount * @param custom_menu $menu * @return string */ protected function render_custom_menu(custom_menu $menu) { static $menucount = 0; // If the menu has no children return an empty string if (!$menu->has_children()) { return ''; } // Increment the menu count. This is used for ID's that get worked with // in JavaScript as is essential $menucount++; // Initialise this custom menu (the custom menu object is contained in javascript-static $jscode = js_writer::function_call_with_Y('M.core_custom_menu.init', array('custom_menu_'.$menucount)); $jscode = "(function(){{$jscode}})"; $this->page->requires->yui_module('node-menunav', $jscode); // Build the root nodes as required by YUI $content = html_writer::start_tag('div', array('id'=>'custom_menu_'.$menucount, 'class'=>'yui3-menu yui3-menu-horizontal javascript-disabled custom-menu')); $content .= html_writer::start_tag('div', array('class'=>'yui3-menu-content')); $content .= html_writer::start_tag('ul'); // Render each child foreach ($menu->get_children() as $item) { $content .= $this->render_custom_menu_item($item); } // Close the open tags $content .= html_writer::end_tag('ul'); $content .= html_writer::end_tag('div'); $content .= html_writer::end_tag('div'); // Return the custom menu return $content; }