# This patch file was generated by NetBeans IDE
# This patch can be applied using context Tools: Apply Diff Patch action on respective folder.
# It uses platform neutral UTF-8 encoding.
# Above lines and this line are ignored by the patching process.
Index: moodle/lib/outputrequirementslib.php
--- moodle/lib/outputrequirementslib.php Base (1.40)
+++ moodle/lib/outputrequirementslib.php Locally Modified (Based On 1.40)
@@ -150,12 +150,27 @@
         $this->M_yui_loader->filter       = ($this->yui3loader->filter == YUI_DEBUG) ? 'debug' : '';
         $this->M_yui_loader->insertBefore = 'firstthemesheet';
         $this->M_yui_loader->modules      = array();
-        if (empty($CFG->useexternalyui) || true) {
-            $this->M_yui_loader->groups = array(
+        $this->M_yui_loader->groups       = array(
+            'moodle' => array(
+                'name' => 'moodle',
+                'base' => $CFG->httpswwwroot . '/theme/yui_combo.php?moodle/',
+                'comboBase' => $CFG->httpswwwroot . '/theme/yui_combo.php?',
+                'combine' => $this->yui3loader->combine,
+                'filter' => '',
+                'ext' => false,
+                'root' => 'moodle/',
+                'patterns' => array(
+                    'moodle-' => array(
+                        'group' => 'moodle',
+                        'configFn' => '@MOODLECONFIGFN@'
+                    ),
+                    'root' => 'moodle'
+                )
+            ),
                 'local' => array(
                     'name' => 'gallery',
                     'base' => $CFG->wwwroot.'/lib/yui/gallery/',
-                    'comboBase' => $this->yui3loader->comboBase,
+                'comboBase' => $CFG->httpswwwroot . '/theme/yui_combo.php?',
                     'combine' => $this->yui3loader->combine,
                     'filter' => $this->M_yui_loader->filter,
                     'ext' => false,
@@ -166,10 +181,9 @@
                             'configFn' => '@GALLERYCONFIGFN@',
                         ),
                         'root' => 'gallery'
-                    ),
                 )
+            )
             );
-        }
         $this->add_yui2_modules(); // adds loading info for all YUI2 modules
         $this->js_module($this->find_module('core_filepicker'));
         $this->js_module($this->find_module('core_dock'));
@@ -591,14 +605,10 @@
     }
 
     /**
-     * Adds a call to make use of a YUI gallery module.
+     * Adds a call to make use of a YUI gallery module. DEPRECATED DO NOT USE!!!
      *
-     * This function adds code to the page footer that will tell a YUI instance to
-     * use the requested gallery module(s) and then call the desired function.
+     * @deprecated DO NOT USE
      *
-     * @todo Once YUI support loading skins from the gallery the if to use
-     * external yui libs should be fixed so that it calls;
-     *
      * @param string|array $modules One or more gallery modules to require
      * @param string $version
      * @param string $function
@@ -607,15 +617,35 @@
      */
     public function js_gallery_module($modules, $version, $function, array $arguments = null, $ondomready = false) {
         global $CFG;
+        debugging('This function will be removed before 2.0 is released please change it from js_gallery_module to yui_module', DEBUG_DEVELOPER);
+        $this->yui_module($modules, $function, $arguments, $version, $ondomready);
+    }
+
+    /**
+     * Creates a JavaScript function call that requires one or more modules to be loaded
+     *
+     * This function can be used to include all of the standard YUI module types within JavaScript:
+     *     - YUI3 modules    [node, event, io]
+     *     - YUI2 modules    [yui2-*]
+     *     - Moodle modules  [moodle-*]
+     *     - Gallery modules [gallery-*]
+     *
+     * @param array|string $modules One or more modules
+     * @param string $function The function to call once modules have been loaded
+     * @param array $arguments An array of arguments to pass to the function
+     * @param string $galleryversion The gallery version to use
+     * @param bool $ondomready
+     */
+    public function yui_module($modules, $function, array $arguments = null, $galleryversion = '2010.04.08-12-35', $ondomready = false) {
         if (!is_array($modules)) {
             $modules = array($modules);
         }
         if (empty($CFG->useexternalyui) || true) {
             // We need to set the M.yui.galleryversion to the correct version
-            $jscode = 'M.yui.galleryversion='.json_encode($version).';';
+            $jscode = 'M.yui.galleryversion='.json_encode($galleryversion).';';
         } else {
             // Set Y's config.gallery to the version
-            $jscode = 'Y.config.gallery='.json_encode($version).';';
+            $jscode = 'Y.config.gallery='.json_encode($galleryversion).';';
         }
         $jscode .= 'Y.use('.join(',', array_map('json_encode', $modules)).',function() {'.js_writer::function_call($function, $arguments).'})';
         if ($ondomready) {
@@ -933,10 +963,12 @@
         // set up global YUI3 loader object - this should contain all code needed by plugins
         // note: in JavaScript just use "YUI(M.yui.loader).use('overlay', function(Y) { .... });"
         // this needs to be done before including any other script
-        $js = "var M = {}; M.yui = {}; ";
-        $js .= "var galleryConfigFn = function(me) {var p = me.path,v=M.yui.galleryversion,f;if(/-(skin|core)/.test(me.name)) {me.type = 'css';var p = p.replace(/-(skin|core)/, '').replace(/\.js/, '.css').split('/'), f = p.pop().replace(/(\-(min|debug))/, '');if (/-skin/.test(me.name)) {p.splice(p.length,0,v,'assets','skins','sam', f);} else {p.splice(p.length,0,v,'assets', f);};} else {var p = p.split('/'), f = p.pop();p.splice(p.length,0,v, f);};me.path = p.join('/');}; ";
-        $js .= str_replace('"@GALLERYCONFIGFN@"', 'galleryConfigFn', js_writer::set_variable('M.yui.loader', $this->M_yui_loader, false) . "\n");
+        $js = "var M = {}; M.yui = {}; var moodleConfigFn = function(me) {var p = me.path, b = me.name.replace(/^moodle-/,'').split('-', 3), n = b.pop();if (/(skin|core)/.test(n)) {n = b.pop();me.type = 'css';};me.path = b.join('-')+'/'+n+'/'+n+'.'+me.type;}; var galleryConfigFn = function(me) {var p = me.path,v=M.yui.galleryversion,f;if(/-(skin|core)/.test(me.name)) {me.type = 'css';p = p.replace(/-(skin|core)/, '').replace(/\.js/, '.css').split('/'), f = p.pop().replace(/(\-(min|debug))/, '');if (/-skin/.test(me.name)) {p.splice(p.length,0,v,'assets','skins','sam', f);} else {p.splice(p.length,0,v,'assets', f);};} else {p = p.split('/'), f = p.pop();p.splice(p.length,0,v, f);};me.path = p.join('/');};\n";
+        $js .= js_writer::set_variable('M.yui.loader', $this->M_yui_loader, false) . "\n";
         $js .= js_writer::set_variable('M.cfg', $this->M_cfg, false);
+        $js = str_replace('"@GALLERYCONFIGFN@"', 'galleryConfigFn', $js);
+        $js = str_replace('"@MOODLECONFIGFN@"', 'moodleConfigFn', $js);
+
         $output .= html_writer::script($js);
 
         // link our main JS file, all core stuff should be there
Index: moodle/theme/yui_combo.php
--- moodle/theme/yui_combo.php Base (1.8)
+++ moodle/theme/yui_combo.php Locally Modified (Based On 1.8)
@@ -57,12 +57,20 @@
         $content .= "\n// Wrong combo resource $part!\n";
         continue;
     }
-    $version = $bits[0];
+    //debug($bits);
+    $version = array_shift($bits);
+    if ($version == 'moodle') {
+        require_once($CFG->dirroot.'/lib/moodlelib.php');
+        $frankenstyle = array_shift($bits);
+        $dir = get_component_directory($frankenstyle);
+        $contentfile = $dir.'/yui/'.join('/', $bits);
+    } else {
     if ($version != $CFG->yui3version and $version != $CFG->yui2version and $version != 'gallery') {
         $content .= "\n// Wrong yui version $part!\n";
         continue;
     }
     $contentfile = "$CFG->libdir/yui/$part";
+    }
     if (!file_exists($contentfile) or !is_file($contentfile)) {
         $content .= "\n// Combo resource $part not found!\n";
         continue;
@@ -72,7 +80,7 @@
     if ($mimetype === 'text/css') {
         if ($version == 'gallery') {
             // search for all images in gallery module CSS and serve them through the yui_image.php script
-            $filecontent = preg_replace('/([a-z_-]+)\.(png|gif)/', 'yui_image.php?file='.$version.'/'.$bits[1].'/'.$bits[2].'/$1.$2', $filecontent);
+            $filecontent = preg_replace('/([a-z_-]+)\.(png|gif)/', 'yui_image.php?file='.$version.'/'.$bits[0].'/'.$bits[1].'/$1.$2', $filecontent);
         } else {
             // search for all images in yui2 CSS and serve them through the yui_image.php script
             $filecontent = preg_replace('/([a-z_-]+)\.(png|gif)/', 'yui_image.php?file='.$version.'/$1.$2', $filecontent);
