From 4cfc2fa980fcd17eca4a2235410e43ce2fdb3935 Mon Sep 17 00:00:00 2001 From: Michael Fairchild <mfairchild365@gmail.com> Date: Tue, 16 Feb 2016 08:37:20 -0600 Subject: [PATCH] Restore the admin interface JS RequireJS was not being loaded/configured correctly for the admin interface because it is not in the framework --- plugins/unl_theme/start.php | 41 ++++++++----------- .../views/default/elgg/require_config.js.php | 36 +++++++++------- 2 files changed, 39 insertions(+), 38 deletions(-) diff --git a/plugins/unl_theme/start.php b/plugins/unl_theme/start.php index bb3e39ce..0d8e4a06 100755 --- a/plugins/unl_theme/start.php +++ b/plugins/unl_theme/start.php @@ -51,30 +51,25 @@ function unl_theme_init() { // 'src' => "{$bower}fuelux/dist/js/fuelux.js", // )); - /** - * Elgg has its own requireJS, and expects a different baseURL than the UNL framework. Reset back to the framework. - */ - - $base_url = elgg_get_site_url(); - - //Add paths stuff to the requirejs config - _elgg_services()->amdConfig->removePath('languages/en'); - _elgg_services()->amdConfig->addPath('languages/en', $base_url.'js/languages'); - _elgg_services()->amdConfig->addPath('elgg/reportedcontent', $base_url.'mod/reportedcontent/views/default/elgg/reportedcontent'); - _elgg_services()->amdConfig->addPath('unl_theme/js', $base_url.'mod/unl_theme/views/default/js/unl_theme/js'); - _elgg_services()->amdConfig->addPath('bootstrap', $base_url.'mod/unl_theme/vendors/bower_components/bootstrap/dist/js/bootstrap'); - _elgg_services()->amdConfig->addPath('moment', $base_url.'mod/unl_theme/vendors/bower_components/moment/moment'); - - - - //Reset the base_url - //_elgg_services()->amdConfig->setBaseUrl('//unlcms.unl.edu/wdn/templates_4.1/scripts/compressed/'); - - //Tell elgg not to load its own version of require - elgg_unregister_js('require'); - elgg_unregister_js('jquery-ui'); - if (elgg_get_context() != "admin") { + /** + * Elgg has its own requireJS, and expects a different baseURL than the UNL framework. Reset back to the framework. + * Only do this for the main interface, the admin interface requires requirejs. + */ + $base_url = elgg_get_site_url(); + + //Add paths stuff to the requirejs config + _elgg_services()->amdConfig->removePath('languages/en'); + _elgg_services()->amdConfig->addPath('languages/en', $base_url.'js/languages'); + _elgg_services()->amdConfig->addPath('elgg/reportedcontent', $base_url.'mod/reportedcontent/views/default/elgg/reportedcontent'); + _elgg_services()->amdConfig->addPath('unl_theme/js', $base_url.'mod/unl_theme/views/default/js/unl_theme/js'); + _elgg_services()->amdConfig->addPath('bootstrap', $base_url.'mod/unl_theme/vendors/bower_components/bootstrap/dist/js/bootstrap'); + _elgg_services()->amdConfig->addPath('moment', $base_url.'mod/unl_theme/vendors/bower_components/moment/moment'); + + //Tell elgg not to load its own version of require + elgg_unregister_js('require'); + elgg_unregister_js('jquery-ui'); + //elgg_load_js("agency"); elgg_load_js('respond'); elgg_load_js("bootstrap"); diff --git a/plugins/unl_theme/views/default/elgg/require_config.js.php b/plugins/unl_theme/views/default/elgg/require_config.js.php index 3719ce4f..ee1ca283 100644 --- a/plugins/unl_theme/views/default/elgg/require_config.js.php +++ b/plugins/unl_theme/views/default/elgg/require_config.js.php @@ -9,23 +9,29 @@ unset($amdConfig['deps']); ?> // <script> +var elgg_require_config = <?php echo json_encode($amdConfig, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); ?>; +<?php unset($amdConfig['baseUrl']); ?> +var unl_require_config = <?php echo json_encode($amdConfig, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); ?>; + //load jquery-ui ourselves from the framework and override the global $ variable. -require(['jquery', 'jqueryui'], function($) { - window.$ = $; -}); -<?php -/** - * Elgg ships with is own baseUrl, which conflicts with the framework baseUrl. - * So, we need to - * 1) remove Elgg's base url (in favor of the framework's) - * 2) define absolute paths to elgg's modules (see start.php) - */ -unset($amdConfig['baseUrl']); -?> +if (typeof WDN !== 'undefined') { + require(['jquery', 'jqueryui'], function($) { + window.$ = $; + }); -//Merge the framework require config with elgg's require config (prefer UNL's settings) -require.config(<?php echo json_encode($amdConfig, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); ?>); + <?php + /** + * Elgg ships with is own baseUrl, which conflicts with the framework baseUrl. + * So, we need to + * 1) remove Elgg's base url (in favor of the framework's) + * 2) define absolute paths to elgg's modules (see start.php) + */ + + ?> + require.config(unl_require_config); +} else { + require = elgg_require_config; +} -<?php // Note we don't process the require() queue yet because it may require('elgg') // and we have to load that synchronously a little later -- GitLab