Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
e588fb8f
Commit
e588fb8f
authored
Sep 24, 2014
by
polesye
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
TNL-272: Fix double loading of cms-modules.js.
parent
0130a837
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
34 deletions
+73
-34
common/djangoapps/pipeline_js/templates/xmodule.js
+22
-13
common/djangoapps/terrain/ui_helpers.py
+51
-21
No files found.
common/djangoapps/pipeline_js/templates/xmodule.js
View file @
e588fb8f
...
...
@@ -19,19 +19,28 @@ define(["jquery", "underscore", "mathjax", "codemirror", "tinymce",
'define'
:
define
};
var
urls
=
$
{
urls
};
var
head
=
$
(
"head"
);
var
deferred
=
$
.
Deferred
();
var
numResources
=
urls
.
length
;
$
.
each
(
urls
,
function
(
i
,
url
)
{
head
.
append
(
$
(
"<script/>"
,
{
src
:
url
}));
// Wait for all the scripts to execute.
require
([
url
],
function
()
{
if
(
i
===
numResources
-
1
)
{
deferred
.
resolve
();
/**
* Loads all modules one-by-one in exact order.
* The module should be used until we'll use RequireJS for XModules.
* @param {Array} modules A list of urls.
* @return {jQuery Promise}
**/
var
requireQueue
=
function
(
modules
)
{
var
deferred
=
$
.
Deferred
();
var
loadScript
=
function
(
queue
)
{
// Loads the next script if queue is not empty.
if
(
queue
.
length
)
{
require
([
queue
.
shift
()],
function
()
{
loadScript
(
queue
);
});
}
else
{
deferred
.
resolve
();
}
});
});
};
return
deferred
.
promise
();
loadScript
(
modules
.
concat
());
return
deferred
.
promise
();
};
return
requireQueue
(
$
{
urls
});
});
common/djangoapps/terrain/ui_helpers.py
View file @
e588fb8f
...
...
@@ -57,7 +57,13 @@ REQUIREJS_WAIT = {
re
.
compile
(
r'^\s*Files & Uploads'
):
[
'js/base'
,
'jquery.ui'
,
'coffee/src/main'
,
'underscore'
,
'js/views/assets'
,
'js/views/asset'
]
],
# Pages
re
.
compile
(
'^Pages
\
|'
):
[
'js/models/explicit_url'
,
'coffee/src/views/tabs'
,
'xmodule'
,
'coffee/src/main'
,
'xblock/cms.runtime.v1'
],
}
...
...
@@ -147,24 +153,7 @@ class RequireJSError(Exception):
pass
@world.absorb
def
wait_for_requirejs
(
dependencies
=
None
):
"""
If requirejs is loaded on the page, this function will pause
Selenium until require is finished loading the given dependencies.
If requirejs is not loaded on the page, this function will return
immediately.
:param dependencies: a list of strings that identify resources that
we should wait for requirejs to load. By default, requirejs will only
wait for jquery.
"""
if
not
dependencies
:
dependencies
=
[
"jquery"
]
# stick jquery at the front
if
dependencies
[
0
]
!=
"jquery"
:
dependencies
.
insert
(
0
,
"jquery"
)
def
load_requrejs_modules
(
dependencies
,
callback
=
"callback(true);"
):
javascript
=
"""
var callback = arguments[arguments.length - 1];
if(window.require) {{
...
...
@@ -175,16 +164,17 @@ def wait_for_requirejs(dependencies=None):
addEventListener("beforeunload", unloadHandler);
addEventListener("unload", unloadHandler);
require({deps}, function($) {{
var modules = arguments;
setTimeout(function() {{
removeEventListener("beforeunload", unloadHandler);
removeEventListener("unload", unloadHandler);
callback(true);
{callback}
}}, 50);
}});
}} else {{
callback(false);
}}
"""
.
format
(
deps
=
json
.
dumps
(
dependencies
))
"""
.
format
(
deps
=
json
.
dumps
(
dependencies
)
,
callback
=
callback
)
for
_
in
range
(
5
):
# 5 attempts max
try
:
result
=
world
.
browser
.
driver
.
execute_async_script
(
dedent
(
javascript
))
...
...
@@ -217,6 +207,46 @@ def wait_for_requirejs(dependencies=None):
return
result
def
wait_for_xmodules_to_load
():
"""
If requirejs is loaded on the page, this function will pause
Selenium until require is finished loading all xmodules.
If requirejs is not loaded on the page, this function will return
immediately.
"""
callback
=
"""
if (modules[0] && modules[0].done) {{
modules[0].done(function () {{callback(true)}});
}}
"""
return
load_requrejs_modules
([
"xmodule"
],
callback
)
@world.absorb
def
wait_for_requirejs
(
dependencies
=
None
):
"""
If requirejs is loaded on the page, this function will pause
Selenium until require is finished loading the given dependencies.
If requirejs is not loaded on the page, this function will return
immediately.
:param dependencies: a list of strings that identify resources that
we should wait for requirejs to load. By default, requirejs will only
wait for jquery.
"""
if
not
dependencies
:
dependencies
=
[
"jquery"
]
# stick jquery at the front
if
dependencies
[
0
]
!=
"jquery"
:
dependencies
.
insert
(
0
,
"jquery"
)
result
=
load_requrejs_modules
(
dependencies
)
if
result
and
"xmodule"
in
dependencies
:
result
=
wait_for_xmodules_to_load
()
return
result
@world.absorb
def
wait_for_ajax_complete
():
"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment