Merge branch 'MDL-63714-35' of git://github.com/andrewnicols/moodle into MOODLE_35_STABLE
This commit is contained in:
Vendored
+1
@@ -0,0 +1 @@
|
||||
define(["jquery"],function(a){var b=function(b){var c=a.Deferred();return b=b||{},M.util.js_pending(b),c.then(function(){return M.util.js_complete(b)})["catch"](),c};return b.prototype.constructor=b,b});
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -0,0 +1,52 @@
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* A helper to manage pendingJS checks.
|
||||
*
|
||||
* @module core/pending
|
||||
* @package core
|
||||
* @copyright 2018 Andrew Nicols <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @since 3.6
|
||||
*/
|
||||
define(['jquery'], function($) {
|
||||
|
||||
/**
|
||||
* Request a new pendingPromise to be resolved.
|
||||
*
|
||||
* When the action you are performing is complete, simply call resolve on the returned Promise.
|
||||
*
|
||||
* @param {Object} pendingKey An optional key value to use
|
||||
* @return {Promise}
|
||||
*/
|
||||
var request = function(pendingKey) {
|
||||
var pendingPromise = $.Deferred();
|
||||
|
||||
pendingKey = pendingKey || {};
|
||||
M.util.js_pending(pendingKey);
|
||||
|
||||
pendingPromise.then(function() {
|
||||
return M.util.js_complete(pendingKey);
|
||||
})
|
||||
.catch();
|
||||
|
||||
return pendingPromise;
|
||||
};
|
||||
|
||||
request.prototype.constructor = request;
|
||||
|
||||
return request;
|
||||
});
|
||||
+25
-17
@@ -23,22 +23,25 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @since 2.9
|
||||
*/
|
||||
define(['core/mustache',
|
||||
'jquery',
|
||||
'core/ajax',
|
||||
'core/str',
|
||||
'core/notification',
|
||||
'core/url',
|
||||
'core/config',
|
||||
'core/localstorage',
|
||||
'core/icon_system',
|
||||
'core/event',
|
||||
'core/yui',
|
||||
'core/log',
|
||||
'core/truncate',
|
||||
'core/user_date'
|
||||
],
|
||||
function(mustache, $, ajax, str, notification, coreurl, config, storage, IconSystem, event, Y, Log, Truncate, UserDate) {
|
||||
define([
|
||||
'core/mustache',
|
||||
'jquery',
|
||||
'core/ajax',
|
||||
'core/str',
|
||||
'core/notification',
|
||||
'core/url',
|
||||
'core/config',
|
||||
'core/localstorage',
|
||||
'core/icon_system',
|
||||
'core/event',
|
||||
'core/yui',
|
||||
'core/log',
|
||||
'core/truncate',
|
||||
'core/user_date',
|
||||
'core/pending',
|
||||
],
|
||||
function(mustache, $, ajax, str, notification, coreurl, config, storage, IconSystem, event, Y, Log, Truncate, UserDate,
|
||||
Pending) {
|
||||
|
||||
// Module variables.
|
||||
/** @var {Number} uniqInstances Count of times this constructor has been called. */
|
||||
@@ -509,6 +512,7 @@ define(['core/mustache',
|
||||
this.currentThemeName = themeName;
|
||||
var iconTemplate = iconSystem.getTemplateName();
|
||||
|
||||
var pendingPromise = new Pending('core/templates:doRender');
|
||||
return this.getTemplate(iconTemplate).then(function() {
|
||||
this.addHelpers(context, themeName);
|
||||
var result = mustache.render(templateSource, context, this.partialHelper.bind(this));
|
||||
@@ -553,7 +557,11 @@ define(['core/mustache',
|
||||
}
|
||||
|
||||
return $.Deferred().resolve(html, js).promise();
|
||||
}.bind(this));
|
||||
}.bind(this))
|
||||
.then(function(html, js) {
|
||||
pendingPromise.resolve();
|
||||
return $.Deferred().resolve(html, js).promise();
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
+21
-12
@@ -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.
|
||||
*
|
||||
* @param String uniqid - required, unregisters this identifier
|
||||
* @return boolean - True if there is any pending js.
|
||||
* This function must be matched with an identical call to M.util.js_pending.
|
||||
*
|
||||
* @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;
|
||||
|
||||
Reference in New Issue
Block a user