MDL-63714 javascript: Add new core/pending module
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;
|
||||
});
|
||||
+21
-18
@@ -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,7 +512,7 @@ define(['core/mustache',
|
||||
this.currentThemeName = themeName;
|
||||
var iconTemplate = iconSystem.getTemplateName();
|
||||
|
||||
M.util.js_pending('core/templates:doRender');
|
||||
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));
|
||||
@@ -556,7 +559,7 @@ define(['core/mustache',
|
||||
return $.Deferred().resolve(html, js).promise();
|
||||
}.bind(this))
|
||||
.then(function(html, js) {
|
||||
M.util.js_complete('core/templates:doRender');
|
||||
pendingPromise.resolve();
|
||||
return $.Deferred().resolve(html, js).promise();
|
||||
});
|
||||
};
|
||||
|
||||
Vendored
+1
-1
@@ -1 +1 @@
|
||||
define(["jquery"],function(a){return{init:function(){var b=!1,c=function(){b=!0},d=function(){var a=b;return b=!1,a};a('[data-toggle="dropdown"]').keydown(function(b){var d,e=b.which||b.keyCode;38==e&&c(),27==e&&(d=a(b.target).attr("aria-expanded"),b.preventDefault(),"false"==d&&a(b.target).click()),32!=e&&13!=e||(b.preventDefault(),a(b.target).click())});var e=function(b){M.util.pending_js("core/aria:delayed-focus");var c=function(){a(this).focus(),M.util.complete_js("core/aria:delayed-focus")}.bind(b);setTimeout(c,50)};a(".dropdown").on("shown.bs.dropdown",function(b){var c=a(b.target).find('[role="menu"]'),f=!1,g=!1;c&&(f=a(c).find('[role="menuitem"]')),f&&f.length>0&&(g=d()?f[f.length-1]:f[0]),g&&e(g)}),a('.dropdown [role="menu"] [role="menuitem"]').keypress(function(b){var c,d,f=String.fromCharCode(b.which||b.keyCode),g=a(b.target).closest('[role="menu"]'),h=0,i=!1;if(g&&(i=a(g).find('[role="menuitem"]')))for(f=f.toLowerCase(),h=0;h<i.length;h++)if(c=a(i[h]),d=c.text().trim().toLowerCase(),0==d.indexOf(f)){e(c);break}}),a('.dropdown [role="menu"] [role="menuitem"]').keydown(function(b){var c=b.which||b.keyCode,d=!1,f=a(b.target).closest('[role="menu"]'),g=0,h=!1;if(f&&(h=a(f).find('[role="menuitem"]'))){if(40==c){for(g=0;g<h.length-1;g++)if(h[g]==b.target){d=h[g+1];break}d||(d=h[0])}else if(38==c){for(g=1;g<h.length;g++)if(h[g]==b.target){d=h[g-1];break}d||(d=h[h.length-1])}else 36==c?d=h[0]:35==c&&(d=h[h.length-1]);d&&(b.preventDefault(),e(d))}}),a(".dropdown").on("hidden.bs.dropdown",function(b){var c=a(b.target).find('[data-toggle="dropdown"]');c&&e(c)}),a(function(){M.util.pending_js("core/aria:delayed-focus"),window.setTimeout(function(){var b=a('[role="alert"][data-aria-autofocus="true"]');b.length>0&&(a(b[0]).attr("tabindex","0"),a(b[0]).focus()),M.util.complete_js("core/aria:delayed-focus")},300)})}}});
|
||||
define(["jquery","core/pending"],function(a,b){return{init:function(){var c=!1,d=function(){c=!0},e=function(){var a=c;return c=!1,a};a('[data-toggle="dropdown"]').keydown(function(b){var c,e=b.which||b.keyCode;38==e&&d(),27==e&&(c=a(b.target).attr("aria-expanded"),b.preventDefault(),"false"==c&&a(b.target).click()),32!=e&&13!=e||(b.preventDefault(),a(b.target).click())});var f=function(c){var d=function(b){a(this).focus(),b.resolve()}.bind(c);setTimeout(d,50,new b("core/aria:delayed-focus"))};a(".dropdown").on("shown.bs.dropdown",function(b){var c=a(b.target).find('[role="menu"]'),d=!1,g=!1;c&&(d=a(c).find('[role="menuitem"]')),d&&d.length>0&&(g=e()?d[d.length-1]:d[0]),g&&f(g)}),a('.dropdown [role="menu"] [role="menuitem"]').keypress(function(b){var c,d,e=String.fromCharCode(b.which||b.keyCode),g=a(b.target).closest('[role="menu"]'),h=0,i=!1;if(g&&(i=a(g).find('[role="menuitem"]')))for(e=e.toLowerCase(),h=0;h<i.length;h++)if(c=a(i[h]),d=c.text().trim().toLowerCase(),0==d.indexOf(e)){f(c);break}}),a('.dropdown [role="menu"] [role="menuitem"]').keydown(function(b){var c=b.which||b.keyCode,d=!1,e=a(b.target).closest('[role="menu"]'),g=0,h=!1;if(e&&(h=a(e).find('[role="menuitem"]'))){if(40==c){for(g=0;g<h.length-1;g++)if(h[g]==b.target){d=h[g+1];break}d||(d=h[0])}else if(38==c){for(g=1;g<h.length;g++)if(h[g]==b.target){d=h[g-1];break}d||(d=h[h.length-1])}else 36==c?d=h[0]:35==c&&(d=h[h.length-1]);d&&(b.preventDefault(),f(d))}}),a(".dropdown").on("hidden.bs.dropdown",function(b){var c=a(b.target).find('[data-toggle="dropdown"]');c&&f(c)}),a(function(){window.setTimeout(function(b){var c=a('[role="alert"][data-aria-autofocus="true"]');c.length>0&&(a(c[0]).attr("tabindex","0"),a(c[0]).focus()),b.resolve()},300,new b("core/aria:delayed-focus"))})}}});
|
||||
@@ -20,7 +20,7 @@
|
||||
* @copyright 2018 Damyon Wiese <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
define(['jquery'], function($) {
|
||||
define(['jquery', 'core/pending'], function($, Pending) {
|
||||
return {
|
||||
init: function() {
|
||||
// Drop downs from bootstrap don't support keyboard accessibility by default.
|
||||
@@ -65,12 +65,11 @@ define(['jquery'], function($) {
|
||||
|
||||
// Special handling for navigation keys when menu is open.
|
||||
var shiftFocus = function(element) {
|
||||
M.util.pending_js('core/aria:delayed-focus');
|
||||
var delayedFocus = function() {
|
||||
var delayedFocus = function(pendingPromise) {
|
||||
$(this).focus();
|
||||
M.util.complete_js('core/aria:delayed-focus');
|
||||
pendingPromise.resolve();
|
||||
}.bind(element);
|
||||
setTimeout(delayedFocus, 50);
|
||||
setTimeout(delayedFocus, 50, new Pending('core/aria:delayed-focus'));
|
||||
};
|
||||
|
||||
$('.dropdown').on('shown.bs.dropdown', function(e) {
|
||||
@@ -188,15 +187,14 @@ define(['jquery'], function($) {
|
||||
|
||||
// After page load, focus on any element with special autofocus attribute.
|
||||
$(function() {
|
||||
M.util.pending_js('core/aria:delayed-focus');
|
||||
window.setTimeout(function() {
|
||||
window.setTimeout(function(pendingPromise) {
|
||||
var alerts = $('[role="alert"][data-aria-autofocus="true"]');
|
||||
if (alerts.length > 0) {
|
||||
$(alerts[0]).attr('tabindex', '0');
|
||||
$(alerts[0]).focus();
|
||||
}
|
||||
M.util.complete_js('core/aria:delayed-focus');
|
||||
}, 300);
|
||||
pendingPromise.resolve();
|
||||
}, 300, new Pending('core/aria:delayed-focus'));
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user