Commit b7eea135 by Christina Roberts

Merge pull request #4119 from edx/christina/requirejs-promise

Wait for scripts defined in common xmodule code to execute.
parents 7a452b62 3acf394d
...@@ -32,20 +32,19 @@ main_xblock_info = { ...@@ -32,20 +32,19 @@ main_xblock_info = {
<script type='text/javascript'> <script type='text/javascript'>
require(["domReady!", "jquery", "js/models/xblock_info", "js/views/pages/container", require(["domReady!", "jquery", "js/models/xblock_info", "js/views/pages/container",
"js/collections/component_template", "xmodule", "coffee/src/main", "xblock/cms.runtime.v1"], "js/collections/component_template", "xmodule", "coffee/src/main", "xblock/cms.runtime.v1"],
function(doc, $, XBlockInfo, ContainerPage, ComponentTemplates) { function(doc, $, XBlockInfo, ContainerPage, ComponentTemplates, xmoduleLoader) {
var view, mainXBlockInfo;
var templates = new ComponentTemplates(${component_templates | n}, {parse: true}); var templates = new ComponentTemplates(${component_templates | n}, {parse: true});
var mainXBlockInfo = new XBlockInfo(${json.dumps(main_xblock_info) | n});
mainXBlockInfo = new XBlockInfo(${json.dumps(main_xblock_info) | n}); xmoduleLoader.done(function () {
var view = new ContainerPage({
view = new ContainerPage({
el: $('#content'), el: $('#content'),
model: mainXBlockInfo, model: mainXBlockInfo,
templates: templates templates: templates
}); });
view.render(); view.render();
}); });
});
</script> </script>
</%block> </%block>
......
...@@ -21,7 +21,8 @@ ...@@ -21,7 +21,8 @@
<script type='text/javascript'> <script type='text/javascript'>
require(["js/models/explicit_url", "coffee/src/views/tabs", require(["js/models/explicit_url", "coffee/src/views/tabs",
"xmodule", "coffee/src/main", "xblock/cms.runtime.v1"], "xmodule", "coffee/src/main", "xblock/cms.runtime.v1"],
function (TabsModel, TabsEditView) { function (TabsModel, TabsEditView, xmoduleLoader) {
xmoduleLoader.done(function () {
var model = new TabsModel({ var model = new TabsModel({
id: "${context_course.location}", id: "${context_course.location}",
explicit_url: "${reverse('contentstore.views.tabs_handler', kwargs={'course_key_string': context_course.id})}" explicit_url: "${reverse('contentstore.views.tabs_handler', kwargs={'course_key_string': context_course.id})}"
...@@ -33,6 +34,7 @@ ...@@ -33,6 +34,7 @@
mast: $('.wrapper-mast') mast: $('.wrapper-mast')
}); });
}); });
});
</script> </script>
</%block> </%block>
......
...@@ -21,12 +21,13 @@ from django.utils.translation import ugettext as _ ...@@ -21,12 +21,13 @@ from django.utils.translation import ugettext as _
<%block name="jsextra"> <%block name="jsextra">
<script type='text/javascript'> <script type='text/javascript'>
require(["domReady!", "jquery", "js/models/module_info", "coffee/src/views/unit", "js/collections/component_template", require(["domReady!", "jquery", "js/models/module_info", "coffee/src/views/unit", "js/collections/component_template",
"jquery.ui", "xmodule", "coffee/src/main", "xblock/cms.runtime.v1"], "xmodule", "jquery.ui", "coffee/src/main", "xblock/cms.runtime.v1"],
function(doc, $, ModuleModel, UnitEditView, ComponentTemplates) { function(doc, $, ModuleModel, UnitEditView, ComponentTemplates, xmoduleLoader) {
window.unit_location_analytics = '${unit_usage_key}'; window.unit_location_analytics = '${unit_usage_key}';
var templates = new ComponentTemplates(${component_templates | n}, {parse: true}); var templates = new ComponentTemplates(${component_templates | n}, {parse: true});
xmoduleLoader.done(function () {
new UnitEditView({ new UnitEditView({
el: $('.main-wrapper'), el: $('.main-wrapper'),
view: 'unit', view: 'unit',
...@@ -41,6 +42,7 @@ require(["domReady!", "jquery", "js/models/module_info", "coffee/src/views/unit" ...@@ -41,6 +42,7 @@ require(["domReady!", "jquery", "js/models/module_info", "coffee/src/views/unit"
$emptyEditor = $(this).find('.empty'); $emptyEditor = $(this).find('.empty');
$(this).prepend($emptyEditor); $(this).prepend($emptyEditor);
}); });
});
}); });
</script> </script>
</%block> </%block>
......
...@@ -21,8 +21,17 @@ define(["jquery", "underscore", "mathjax", "codemirror", "tinymce", ...@@ -21,8 +21,17 @@ define(["jquery", "underscore", "mathjax", "codemirror", "tinymce",
var urls = ${urls}; var urls = ${urls};
var head = $("head"); var head = $("head");
$.each(urls, function(i, url) { var deferred = $.Deferred();
var numResources = urls.length;
$.each(urls, function (i, url) {
head.append($("<script/>", {src: url})); head.append($("<script/>", {src: url}));
// Wait for all the scripts to execute.
require([url], function () {
if (i === numResources - 1) {
deferred.resolve();
}
}); });
return window.XModule; });
return deferred.promise();
}); });
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