From 4491bf33fdba6048cac9e99179d6627442163217 Mon Sep 17 00:00:00 2001
From: Andrew Nicols <andrew@nicols.co.uk>
Date: Thu, 10 Oct 2013 12:18:47 +0800
Subject: [PATCH 2/2] Use new rollup system

---
 lib/outputrequirementslib.php | 127 +++++++++++++-----------------------------
 theme/yui_combo.php           |  47 ++++++++++++++++
 2 files changed, 86 insertions(+), 88 deletions(-)

diff --git a/lib/outputrequirementslib.php b/lib/outputrequirementslib.php
index 02428a1..1741646 100644
--- a/lib/outputrequirementslib.php
+++ b/lib/outputrequirementslib.php
@@ -188,13 +188,7 @@ class page_requirements_manager {
         // Enable combo loader? This significantly helps with caching and performance!
         $this->yui3loader->combine = !empty($CFG->yuicomboloading);
 
-        if (empty($CFG->cachejs)) {
-            $jsrev = -1;
-        } else if (empty($CFG->jsrev)) {
-            $jsrev = 1;
-        } else {
-            $jsrev = $CFG->jsrev;
-        }
+        $jsrev = $this->get_jsrev();
 
         // Set up JS YUI loader helper object.
         $this->YUI_config->base         = $this->yui3loader->base;
@@ -276,7 +270,7 @@ class page_requirements_manager {
             'themerev'            => theme_get_revision(),
             'slasharguments'      => (int)(!empty($CFG->slasharguments)),
             'theme'               => $page->theme->name,
-            'jsrev'               => ((empty($CFG->cachejs) or empty($CFG->jsrev)) ? -1 : $CFG->jsrev),
+            'jsrev'               => $this->get_jsrev(),
             'svgicons'            => $page->theme->use_svg_icons()
         );
         if ($CFG->debugdeveloper) {
@@ -319,6 +313,25 @@ class page_requirements_manager {
     }
 
     /**
+     * Determine the correct JS Revision to use for this load.
+     *
+     * @return int the jsrev to use.
+     */
+    protected function get_jsrev() {
+        global $CFG;
+
+        if (empty($CFG->cachejs)) {
+            $jsrev = -1;
+        } else if (empty($CFG->jsrev)) {
+            $jsrev = 1;
+        } else {
+            $jsrev = $CFG->jsrev;
+        }
+
+        return $jsrev;
+    }
+
+    /**
      * Ensure that the specified JavaScript file is linked to from this page.
      *
      * NOTE: This function is to be used in RARE CASES ONLY, please store your JS in module.js file
@@ -627,11 +640,7 @@ class page_requirements_manager {
                 }
             }
             if (substr($url, -3) === '.js') {
-                if (empty($CFG->cachejs) or !isset($CFG->jsrev)) {
-                    $jsrev = -1;
-                } else {
-                    $jsrev = (int)$CFG->jsrev;
-                }
+                $jsrev = $this->get_jsrev();
                 if (empty($CFG->slasharguments)) {
                     return new moodle_url($CFG->httpswwwroot.'/lib/javascript.php', array('rev'=>$jsrev, 'jsfile'=>$url));
                 } else {
@@ -1226,87 +1235,29 @@ class page_requirements_manager {
     protected function get_yui3lib_headcode($page) {
         global $CFG;
 
-        /*
-         * Created via http://yuilibrary.com/yui/configurator/ so that it emulates
-         * original SimpleYUI + all loaders:
-         *
-            "use": [
-                "yui",
-                "oop",
-                "dom",
-                "event-custom-base",
-                "event-base",
-                "pluginhost",
-                "node",
-                "event-delegate",
-                "io-base",
-                "json-parse",
-                "transition",
-                "selector-css3",
-                "dom-style-ie",
-                "querystring-stringify-simple"
-            ]
-         */
-
-
-        $requiremodules = array(
-            // Include everything from original SimpleYUI.
-            'yui',
-            'yui-base',
-            'get',
-            'features',
-            'loader-base',
-            'loader-rollup',
-            'loader-yui3',
-            'oop',
-            'event-custom-base',
-            'dom-core',
-            'dom-base',
-            'color-base',
-            'dom-style',
-            'selector-native',
-            'selector',
-            'node-core',
-            'node-base',
-            'event-base',
-            'event-base-ie',
-            'pluginhost-base',
-            'pluginhost-config',
-            'event-delegate',
-            'node-event-delegate',
-            'node-pluginhost',
-            'dom-screen',
-            'node-screen',
-            'node-style',
-            'querystring-stringify-simple',
-            'io-base',
-            'json-parse',
-            'transition',
-            'selector-css2',
-            'selector-css3',
-            'dom-style-ie',
-            // Some extras we use everywhere.
-            'escape',
-        );
-
         $code = '';
 
-        // Note 1: strlen(implode('&amp;', $modules)) + combo script URL should be kept under 2048 bytes.
-        // Note 2: There are some bogus @version@ in YUI 3.13.0 - always use local files to emulate SimpleYUI.
+        $jsrev = $this->get_jsrev();
+        $baserollups = array(
+            'rollup/' . $CFG->yui3version . '/simpleyui-min.js',
+        );
+        $moodlerollups = array(
+            'rollup/' . $jsrev . '/mcore-min.js',
+        );
 
         if ($this->yui3loader->combine) {
             if (!empty($page->theme->yuicssmodules)) {
+                $code .= '<script type="text/javascript" src="'.$this->yui3loader->local_comboBase
+                        . implode('&amp;', $baserollups) . '"></script>';
+                $code .= '<script type="text/javascript" src="'.$this->yui3loader->local_comboBase
+                        . implode('&amp;', $moodlerollups) . '"></script>';
+
                 $modules = array();
                 foreach ($page->theme->yuicssmodules as $module) {
                     $modules[] = "$CFG->yui3version/$module/$module-min.css";
                 }
                 $code .= '<link rel="stylesheet" type="text/css" href="'.$this->yui3loader->comboBase.implode('&amp;', $modules).'" />';
             }
-            $modules = array();
-            foreach ($requiremodules as $module) {
-                $modules[] = "$CFG->yui3version/$module/$module-min.js";
-            }
-            $code .= '<script type="text/javascript" src="'.$this->yui3loader->local_comboBase.implode('&amp;', $modules).'"></script>';
 
         } else {
             if (!empty($page->theme->yuicssmodules)) {
@@ -1314,8 +1265,11 @@ class page_requirements_manager {
                     $code .= '<link rel="stylesheet" type="text/css" href="'.$this->yui3loader->base.$module.'/'.$module.'-min.css" />';
                 }
             }
-            foreach ($requiremodules as $module) {
-                $code .= '<script type="text/javascript" src="'.$this->yui3loader->local_base.$module.'/'.$module.'-min.js';
+            foreach ($baserollups as $rollup) {
+                $code .= '<script type="text/javascript" src="'.$this->yui3loader->local_comboBase.$rollup.'"></script>';
+            }
+            foreach ($moodlerollups as $rollup) {
+                $code .= '<script type="text/javascript" src="'.$this->yui3loader->local_comboBase.$rollup.'"></script>';
             }
         }
 
@@ -1328,9 +1282,6 @@ class page_requirements_manager {
             $code = str_replace('-min.js', '-debug.js', $code);
         }
 
-        // Emulate SimpleYUI for now.
-        $code .= '<script type="text/javascript">var Y = YUI().use(\'*\');</script>';
-
         return $code;
     }
 
diff --git a/theme/yui_combo.php b/theme/yui_combo.php
index f9c528b..eca295a 100644
--- a/theme/yui_combo.php
+++ b/theme/yui_combo.php
@@ -133,6 +133,48 @@ while (count($parts)) {
 
                 // Some extras we use everywhere.
                 'escape',
+
+                'attribute-core',
+                'event-custom-complex',
+                'base-core',
+                'attribute-base',
+                'attribute-extras',
+                'attribute-observable',
+                'base-observable',
+                'base-base',
+                'base-pluginhost',
+                'base-build',
+                'event-synthetic',
+
+                'attribute-complex',
+                'event-mouseenter',
+                'event-key',
+                'event-outside',
+                'event-autohide',
+                'event-focus',
+                'classnamemanager',
+                'widget-base',
+                'widget-htmlparser',
+                'widget-skin',
+                'widget-uievents',
+                'widget-stdmod',
+                'widget-position',
+                'widget-position-align',
+                'widget-stack',
+                'widget-position-constrain',
+                'overlay',
+
+
+                'widget-autohide',
+                'button-core',
+                'button-plugin',
+                'widget-buttons',
+                'widget-modality',
+                'panel',
+                'yui-throttle',
+                'dd-ddm-base',
+                'dd-drag',
+                'dd-plugin',
             );
 
             // We need to add these new parts to the beginning of the $parts list, not the end.
@@ -140,6 +182,7 @@ while (count($parts)) {
             foreach ($yuimodules as $module) {
                 $newparts[] = $revision . '/' . $module . '/' . $module . $filesuffix;
             }
+            $newparts[] = 'yuiuseall/yuiuseall';
             $parts = array_merge($newparts, $parts);
         }
 
@@ -147,6 +190,7 @@ while (count($parts)) {
         if (strpos($rollupname, 'mcore') !== false) {
             $yuimodules = array(
                 'core/tooltip/tooltip',
+                'core/dock/dock-loader',
                 'core/notification/notification-dialogue',
             );
 
@@ -217,6 +261,9 @@ while (count($parts)) {
     } else if ($version == 'gallery') {
         $contentfile = "$CFG->libdir/yui/$part";
 
+    } else if ($version == 'yuiuseall') {
+        $filecontent = "var Y = YUI().use('*');";
+
     } else {
         if ($version != $CFG->yui3version) {
             $content .= "\n// Wrong yui version $part!\n";
-- 
1.8.1.2

