Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
moodle
moodle
Commits
dc39d0cf
Commit
dc39d0cf
authored
Oct 24, 2018
by
Andrew Nicols
Browse files
MDL-63714 javascript: Improve docs for pendingjs
parent
daf0b4f0
Changes
1
Hide whitespace changes
Inline
Side-by-side
lib/javascript-static.js
View file @
dc39d0cf
...
...
@@ -653,16 +653,22 @@ M.util.complete_js = [];
/**
* Register any long running javascript code with a unique identifier.
* Should be followed with a call to js_complete with a matching
* idenfitier when the code is complete. May also be called with no arguments
* to test if there is any js calls pending. This is relied on by behat so that
* it can wait for all pending updates before interacting with a page.
* @param String uniqid - optional, if provided,
* registers this identifier until js_complete is called.
* @return boolean - True if there is any pending js.
* This is used to ensure that Behat steps do not continue with interactions until the page finishes loading.
*
* All calls to M.util.js_pending _must_ be followed by a subsequent call to M.util.js_complete with the same exact
* uniqid.
*
* This function may also be called with no arguments to test if there is any js calls pending.
*
* The uniqid specified may be any Object, including Number, String, or actual Object; however please note that the
* paired js_complete function performs a strict search for the key specified. As such, if using an Object, the exact
* Object must be passed into both functions.
*
* @param {Mixed} uniqid Register long-running code against the supplied identifier
* @return {Number} Number of pending items
*/
M
.
util
.
js_pending
=
function
(
uniqid
)
{
if
(
uniqid
!==
false
)
{
if
(
typeof
uniqid
!==
'
undefined
'
)
{
M
.
util
.
pending_js
.
push
(
uniqid
);
}
...
...
@@ -690,11 +696,12 @@ YUI.add('moodle-core-io', function(Y) {
});
/**
* Unregister any long running javascript code by unique identifier.
* This function should form a matching pair with js_pending
* Unregister some long running javascript code using the unique identifier specified in M.util.js_pending.
*
* This function must be matched with an identical call to M.util.js_pending.
*
* @param
String uniqid - required, unregisters this
identifier
* @return
boolean - True if there is any pending js.
* @param
{Mixed} uniqid Register long-running code against the supplied
identifier
* @return
{Number} Number of pending items remaining after removing this item
*/
M
.
util
.
js_complete
=
function
(
uniqid
)
{
// Use the Y.Array.indexOf instead of the native because some older browsers do not support
...
...
@@ -702,6 +709,8 @@ M.util.js_complete = function(uniqid) {
var
index
=
Y
.
Array
.
indexOf
(
M
.
util
.
pending_js
,
uniqid
);
if
(
index
>=
0
)
{
M
.
util
.
complete_js
.
push
(
M
.
util
.
pending_js
.
splice
(
index
,
1
));
}
else
{
window
.
console
.
log
(
"
Unable to locate key for js_complete call
"
,
uniqid
);
}
return
M
.
util
.
pending_js
.
length
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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