Skip to content
Snippets Groups Projects
Commit 2a204f7f authored by Andy Armstrong's avatar Andy Armstrong
Browse files

Add static HtmlUtils/StringUtils into edx namespace

This is a temporary workaround for code that needs
access to these classes from the UI Toolkit but
without using RequireJS.
parent 9b128695
No related branches found
No related tags found
No related merge requests found
......@@ -142,8 +142,12 @@
// Django i18n catalog globals
"interpolate",
"gettext",
"ngettext",
// Miscellaneous globals
"JSON"
"JSON",
// edX globals
"edx"
]
}
define(['domReady!', 'jquery', 'backbone', 'underscore', 'gettext']);
define([
'edx-ui-toolkit/js/utils/string-utils',
'edx-ui-toolkit/js/utils/html-utils',
'domReady!',
'jquery',
'backbone',
'underscore',
'gettext'
],
function(StringUtils, HtmlUtils) {
'use strict';
// Install utility classes in the edX namespace to make them
// available to code that doesn't use RequireJS,
// e.g. XModules and XBlocks.
if (window) {
window.edx = window.edx || {};
window.edx.StringUtils = StringUtils;
window.edx.HtmlUtils = HtmlUtils;
}
});
......@@ -1252,6 +1252,13 @@ base_vendor_js = [
'js/vendor/url.min.js',
'common/js/vendor/underscore.js',
'js/vendor/underscore.string.min.js',
# Make some edX UI Toolkit utilities available in the global "edx" namespace
'edx-ui-toolkit/js/utils/global-loader.js',
'edx-ui-toolkit/js/utils/string-utils.js',
'edx-ui-toolkit/js/utils/html-utils.js',
# Finally load RequireJS and dependent vendor libraries
'js/vendor/requirejs/require.js',
'js/RequireJS-namespace-undefine.js',
'js/vendor/URI.min.js',
......
......@@ -70,7 +70,11 @@
'logger': 'empty:',
'utility': 'empty:',
'URI': 'empty:',
'DiscussionModuleView': 'empty:'
'DiscussionModuleView': 'empty:',
// Don't bundle UI Toolkit helpers as they are loaded into the "edx" namespace
'edx-ui-toolkit/js/utils/html-utils': 'empty:',
'edx-ui-toolkit/js/utils/string-utils': 'empty:'
},
/**
......
......@@ -4,13 +4,23 @@
// into the optimized files. Therefore load these libraries through script tags and explicitly define them.
// Note that when the optimizer executes this code, window will not be defined.
if (window) {
var defineDependency = function (globalVariable, name, noShim) {
if (window[globalVariable]) {
var defineDependency = function (globalName, name, noShim) {
var getGlobalValue = function(name) {
var globalNamePath = name.split('.'),
result = window,
i;
for (i = 0; i < globalNamePath.length; i++) {
result = result[globalNamePath[i]];
}
return result;
},
globalValue = getGlobalValue(globalName);
if (globalValue) {
if (noShim) {
define(name, {});
}
else {
define(name, [], function() {return window[globalVariable];});
define(name, [], function() { return globalValue; });
}
}
else {
......@@ -30,6 +40,10 @@
defineDependency("URI", "URI");
defineDependency("Backbone", "backbone");
// Add the UI Toolkit helper classes that have been installed in the "edx" namespace
defineDependency("edx.HtmlUtils", "edx-ui-toolkit/js/utils/html-utils");
defineDependency("edx.StringUtils", "edx-ui-toolkit/js/utils/string-utils");
// utility.js adds two functions to the window object, but does not return anything
defineDependency("isExternal", "utility", true);
}
......@@ -84,9 +98,6 @@
// end of files needed by OVA
},
shim: {
"gettext": {
exports: "gettext"
},
"annotator_1.2.9": {
deps: ["jquery"],
exports: "Annotator"
......@@ -94,9 +105,6 @@
"date": {
exports: "Date"
},
"jquery": {
exports: "$"
},
"jquery.cookie": {
deps: ["jquery"],
exports: "jQuery.fn.cookie"
......@@ -117,13 +125,6 @@
deps: ["jquery", "tinymce"],
exports: "jQuery.fn.tinymce"
},
"underscore": {
exports: "_"
},
"backbone": {
deps: ["underscore", "jquery"],
exports: "Backbone"
},
"backbone.paginator": {
deps: ["backbone"],
exports: "Backbone.Paginator"
......
......@@ -4,7 +4,7 @@
"dependencies": {
"coffee-script": "1.6.1",
"edx-pattern-library": "0.10.4",
"edx-ui-toolkit": "~0.8.0",
"edx-ui-toolkit": "0.9.0",
"requirejs": "~2.1.22",
"uglify-js": "2.4.24",
"underscore": "~1.8.3"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment