Commit 2a204f7f by Andy Armstrong

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
...@@ -142,8 +142,12 @@ ...@@ -142,8 +142,12 @@
// Django i18n catalog globals // Django i18n catalog globals
"interpolate", "interpolate",
"gettext", "gettext",
"ngettext",
// Miscellaneous globals // 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 = [ ...@@ -1252,6 +1252,13 @@ base_vendor_js = [
'js/vendor/url.min.js', 'js/vendor/url.min.js',
'common/js/vendor/underscore.js', 'common/js/vendor/underscore.js',
'js/vendor/underscore.string.min.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/vendor/requirejs/require.js',
'js/RequireJS-namespace-undefine.js', 'js/RequireJS-namespace-undefine.js',
'js/vendor/URI.min.js', 'js/vendor/URI.min.js',
......
...@@ -70,7 +70,11 @@ ...@@ -70,7 +70,11 @@
'logger': 'empty:', 'logger': 'empty:',
'utility': 'empty:', 'utility': 'empty:',
'URI': '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 @@ ...@@ -4,13 +4,23 @@
// into the optimized files. Therefore load these libraries through script tags and explicitly define them. // 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. // Note that when the optimizer executes this code, window will not be defined.
if (window) { if (window) {
var defineDependency = function (globalVariable, name, noShim) { var defineDependency = function (globalName, name, noShim) {
if (window[globalVariable]) { 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) { if (noShim) {
define(name, {}); define(name, {});
} }
else { else {
define(name, [], function() {return window[globalVariable];}); define(name, [], function() { return globalValue; });
} }
} }
else { else {
...@@ -30,6 +40,10 @@ ...@@ -30,6 +40,10 @@
defineDependency("URI", "URI"); defineDependency("URI", "URI");
defineDependency("Backbone", "backbone"); 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 // utility.js adds two functions to the window object, but does not return anything
defineDependency("isExternal", "utility", true); defineDependency("isExternal", "utility", true);
} }
...@@ -84,9 +98,6 @@ ...@@ -84,9 +98,6 @@
// end of files needed by OVA // end of files needed by OVA
}, },
shim: { shim: {
"gettext": {
exports: "gettext"
},
"annotator_1.2.9": { "annotator_1.2.9": {
deps: ["jquery"], deps: ["jquery"],
exports: "Annotator" exports: "Annotator"
...@@ -94,9 +105,6 @@ ...@@ -94,9 +105,6 @@
"date": { "date": {
exports: "Date" exports: "Date"
}, },
"jquery": {
exports: "$"
},
"jquery.cookie": { "jquery.cookie": {
deps: ["jquery"], deps: ["jquery"],
exports: "jQuery.fn.cookie" exports: "jQuery.fn.cookie"
...@@ -117,13 +125,6 @@ ...@@ -117,13 +125,6 @@
deps: ["jquery", "tinymce"], deps: ["jquery", "tinymce"],
exports: "jQuery.fn.tinymce" exports: "jQuery.fn.tinymce"
}, },
"underscore": {
exports: "_"
},
"backbone": {
deps: ["underscore", "jquery"],
exports: "Backbone"
},
"backbone.paginator": { "backbone.paginator": {
deps: ["backbone"], deps: ["backbone"],
exports: "Backbone.Paginator" exports: "Backbone.Paginator"
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"dependencies": { "dependencies": {
"coffee-script": "1.6.1", "coffee-script": "1.6.1",
"edx-pattern-library": "0.10.4", "edx-pattern-library": "0.10.4",
"edx-ui-toolkit": "~0.8.0", "edx-ui-toolkit": "0.9.0",
"requirejs": "~2.1.22", "requirejs": "~2.1.22",
"uglify-js": "2.4.24", "uglify-js": "2.4.24",
"underscore": "~1.8.3" "underscore": "~1.8.3"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment