MDL-66550 theme: Wrap JS calls in pendingJS

This commit is contained in:
Andrew Nicols 2019-09-12 14:19:11 +08:00
parent bb6315f281
commit 5034f0a12b
18 changed files with 69 additions and 25 deletions

View File

@ -57,8 +57,10 @@ class fragment_requirements_manager extends page_requirements_manager {
$output = '';
// First include must be to a module with no dependencies, this prevents multiple requests.
$prefix = "require(['core/first'], function() {\n";
$prefix = 'M.util.js_pending("core/first");';
$prefix .= "require(['core/first'], function() {\n";
$suffix = "\n});";
$suffix .= 'M.util.js_complete("core/first");';
$output .= html_writer::script($prefix . implode(";\n", $this->amdjscode) . $suffix);
return $output;
}

View File

@ -1038,7 +1038,9 @@ class page_requirements_manager {
$component = clean_param($component, PARAM_COMPONENT);
$module = clean_param($module, PARAM_ALPHANUMEXT);
$modname = "{$component}/{$module}";
$functioncode = [];
if ($func !== null) {
$func = clean_param($func, PARAM_ALPHANUMEXT);
@ -1057,12 +1059,14 @@ class page_requirements_manager {
}
}
$js = 'require(["' . $component . '/' . $module . '"], function(amd) { amd.' . $func . '(' . $strparams . '); });';
} else {
$js = 'require(["' . $component . '/' . $module . '"]);';
$functioncode[] = "amd.{$func}({$strparams});";
}
$functioncode[] = "M.util.js_complete('{$modname}');";
$initcode = implode(' ', $functioncode);
$js = "M.util.js_pending('{$modname}'); require(['{$modname}'], function(amd) {{$initcode}});";
$this->js_amd_inline($js);
}
@ -1384,8 +1388,10 @@ class page_requirements_manager {
}
// First include must be to a module with no dependencies, this prevents multiple requests.
$prefix = "require(['core/first'], function() {\n";
$suffix = "\n});";
$prefix = 'M.util.js_pending("core/first");';
$prefix .= "require(['core/first'], function() {\n";
$suffix = 'M.util.js_complete("core/first");';
$suffix .= "\n});";
$output .= html_writer::script($prefix . implode(";\n", $this->amdjscode) . $suffix);
return $output;
}

View File

@ -125,8 +125,13 @@ class core_outputrequirementslib_testcase extends advanced_testcase {
$html = $page->requires->get_end_code();
$this->assertContains('require(["theme_foobar/lightbox"]);', $html);
$this->assertContains('require(["theme_foobar/demo_one"], function(amd) { amd.init(); });', $html);
$this->assertContains('require(["theme_foobar/demo_two"], function(amd) { amd.init("foo", "baz", [42,"xyz"]); });', $html);
$modname = 'theme_foobar/lightbox';
$this->assertContains("M.util.js_pending('{$modname}'); require(['{$modname}'], function(amd) {M.util.js_complete('{$modname}');});", $html);
$modname = 'theme_foobar/demo_one';
$this->assertContains("M.util.js_pending('{$modname}'); require(['{$modname}'], function(amd) {amd.init(); M.util.js_complete('{$modname}');});", $html);
$modname = 'theme_foobar/demo_two';
$this->assertContains("M.util.js_pending('{$modname}'); require(['{$modname}'], function(amd) {amd.init(\"foo\", \"baz\", [42,\"xyz\"]); M.util.js_complete('{$modname}');});", $html);
}
}

View File

@ -1,2 +1,2 @@
define ("theme_boost/aria",["jquery","core/pending"],function(a,b){return{init:function init(){var c=!1,d=function(){c=!0},e=function(){var a=c;c=!1;return a};a("[data-toggle=\"dropdown\"]").keydown(function(b){var c=b.which||b.keyCode,e;if(38==c){d()}if(27==c){e=a(b.target).attr("aria-expanded");b.preventDefault();if("false"==e){a(b.target).click()}}if(32==c||13==c){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;if(c){d=a(c).find("[role=\"menuitem\"]")}if(d&&0<d.length){if(e()){g=d[d.length-1]}else{g=d[0]}}if(g){f(g)}});a(".dropdown [role=\"menu\"] [role=\"menuitem\"]").keypress(function(b){var c=String.fromCharCode(b.which||b.keyCode),d=a(b.target).closest("[role=\"menu\"]"),e=0,g=!1,h,j;if(!d){return}g=a(d).find("[role=\"menuitem\"]");if(!g){return}c=c.toLowerCase();for(e=0;e<g.length;e++){h=a(g[e]);j=h.text().trim().toLowerCase();if(0==j.indexOf(c)){f(h);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){return}h=a(e).find("[role=\"menuitem\"]");if(!h){return}if(40==c){for(g=0;g<h.length-1;g++){if(h[g]==b.target){d=h[g+1];break}}if(!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}}if(!d){d=h[h.length-1]}}else if(36==c){d=h[0]}else if(35==c){d=h[h.length-1]}if(d){b.preventDefault();f(d)}});a(".dropdown").on("hidden.bs.dropdown",function(b){var c=a(b.target).find("[data-toggle=\"dropdown\"]");if(c){f(c)}});a(function(){window.setTimeout(function(b){var c=a("[role=\"alert\"][data-aria-autofocus=\"true\"]");if(0<c.length){a(c[0]).attr("tabindex","0");a(c[0]).focus()}b.resolve()},300,new b("core/aria:delayed-focus"))})}}});
define ("theme_boost/aria",["jquery","core/pending"],function(a,b){return{init:function init(){var c=!1,d=function(){c=!0},e=function(){var a=c;c=!1;return a};a("[data-toggle=\"dropdown\"]").keydown(function(b){var c=b.which||b.keyCode,e;if(38==c){d()}if(27==c){e=a(b.target).attr("aria-expanded");b.preventDefault();if("false"==e){a(b.target).click()}}if(32==c||13==c){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;if(c){d=a(c).find("[role=\"menuitem\"]")}if(d&&0<d.length){if(e()){g=d[d.length-1]}else{g=d[0]}}if(g){f(g)}});a(".dropdown [role=\"menu\"] [role=\"menuitem\"]").keypress(function(b){var c=String.fromCharCode(b.which||b.keyCode),d=a(b.target).closest("[role=\"menu\"]"),e=0,g=!1,h,j;if(!d){return}g=a(d).find("[role=\"menuitem\"]");if(!g){return}c=c.toLowerCase();for(e=0;e<g.length;e++){h=a(g[e]);j=h.text().trim().toLowerCase();if(0==j.indexOf(c)){f(h);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){return}h=a(e).find("[role=\"menuitem\"]");if(!h){return}if(40==c){for(g=0;g<h.length-1;g++){if(h[g]==b.target){d=h[g+1];break}}if(!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}}if(!d){d=h[h.length-1]}}else if(36==c){d=h[0]}else if(35==c){d=h[h.length-1]}if(d){b.preventDefault();f(d)}});a(".dropdown").on("hidden.bs.dropdown",function(b){var c=a(b.target).find("[data-toggle=\"dropdown\"]");if(c){f(c)}});var g=new b("core/aria:delayed-focus");a(function(){window.setTimeout(function(b){var c=a("[role=\"alert\"][data-aria-autofocus=\"true\"]");if(0<c.length){a(c[0]).attr("tabindex","0");a(c[0]).focus()}b.resolve()},300,g)})}}});
//# sourceMappingURL=aria.min.js.map

File diff suppressed because one or more lines are too long

View File

@ -1,2 +1,2 @@
define ("theme_boost/loader",["jquery","./tether","core/event"],function(a,b,c){window.jQuery=a;window.Tether=b;require(["theme_boost/aria","theme_boost/pending","theme_boost/util","theme_boost/alert","theme_boost/button","theme_boost/carousel","theme_boost/collapse","theme_boost/dropdown","theme_boost/modal","theme_boost/scrollspy","theme_boost/tab","theme_boost/tooltip","theme_boost/popover"],function(b){a("body").popover({trigger:"focus",selector:"[data-toggle=popover][data-trigger!=hover]"});a("html").popover({container:"body",selector:"[data-toggle=popover][data-trigger=hover]",trigger:"hover",delay:{hide:500}});a.fn.dropdown.Constructor.Default.flip=!1;a("a[data-toggle=\"tab\"]").on("shown.bs.tab",function(b){var c=a(b.target).attr("href");if(history.replaceState){history.replaceState(null,null,c)}else{location.hash=c}});var d=window.location.hash;if(d){a(".nav-link[href=\""+d+"\"]").tab("show")}c.getLegacyEvents().done(function(b){a(document).on(b.FILTER_CONTENT_UPDATED,function(){a("body").popover({selector:"[data-toggle=\"popover\"]",trigger:"focus"})})});b.init()});return{}});
define ("theme_boost/loader",["jquery","./tether","core/event"],function(a,b,c){window.jQuery=a;window.Tether=b;M.util.js_pending("theme_boost/loader:children");require(["theme_boost/aria","theme_boost/pending","theme_boost/util","theme_boost/alert","theme_boost/button","theme_boost/carousel","theme_boost/collapse","theme_boost/dropdown","theme_boost/modal","theme_boost/scrollspy","theme_boost/tab","theme_boost/tooltip","theme_boost/popover"],function(b){a("body").popover({trigger:"focus",selector:"[data-toggle=popover][data-trigger!=hover]"});a("html").popover({container:"body",selector:"[data-toggle=popover][data-trigger=hover]",trigger:"hover",delay:{hide:500}});a.fn.dropdown.Constructor.Default.flip=!1;a("a[data-toggle=\"tab\"]").on("shown.bs.tab",function(b){var c=a(b.target).attr("href");if(history.replaceState){history.replaceState(null,null,c)}else{location.hash=c}});var d=window.location.hash;if(d){a(".nav-link[href=\""+d+"\"]").tab("show")}c.getLegacyEvents().done(function(b){a(document).on(b.FILTER_CONTENT_UPDATED,function(){a("body").popover({selector:"[data-toggle=\"popover\"]",trigger:"focus"})})});b.init();M.util.js_complete("theme_boost/loader:children")});return{}});
//# sourceMappingURL=loader.min.js.map

File diff suppressed because one or more lines are too long

View File

@ -186,6 +186,7 @@ define(['jquery', 'core/pending'], function($, Pending) {
});
// After page load, focus on any element with special autofocus attribute.
var delayedFocusPromise = new Pending('core/aria:delayed-focus');
$(function() {
window.setTimeout(function(pendingPromise) {
var alerts = $('[role="alert"][data-aria-autofocus="true"]');
@ -194,7 +195,7 @@ define(['jquery', 'core/pending'], function($, Pending) {
$(alerts[0]).focus();
}
pendingPromise.resolve();
}, 300, new Pending('core/aria:delayed-focus'));
}, 300, delayedFocusPromise);
});
}
};

View File

@ -27,6 +27,7 @@ define(['jquery', './tether', 'core/event'], function(jQuery, Tether, Event) {
window.jQuery = jQuery;
window.Tether = Tether;
M.util.js_pending('theme_boost/loader:children');
require(['theme_boost/aria',
'theme_boost/pending',
@ -87,6 +88,7 @@ define(['jquery', './tether', 'core/event'], function(jQuery, Tether, Event) {
});
Aria.init();
M.util.js_complete('theme_boost/loader:children');
});

View File

@ -64,5 +64,8 @@
</body>
</html>
{{#js}}
require(['theme_boost/loader']);
M.util.js_pending('theme_boost/loader');
require(['theme_boost/loader'], function() {
M.util.js_complete('theme_boost/loader');
});
{{/js}}

View File

@ -95,8 +95,13 @@
</body>
</html>
{{#js}}
require(['theme_boost/loader']);
M.util.js_pending('theme_boost/loader');
require(['theme_boost/loader'], function() {
M.util.js_complete('theme_boost/loader');
});
M.util.js_pending('theme_boost/drawer');
require(['theme_boost/drawer'], function(mod) {
mod.init();
M.util.js_complete('theme_boost/drawer');
});
{{/js}}

View File

@ -53,5 +53,8 @@
</body>
</html>
{{#js}}
require(['theme_boost/loader']);
M.util.js_pending('theme_boost/loader');
require(['theme_boost/loader'], function() {
M.util.js_complete('theme_boost/loader');
});
{{/js}}

View File

@ -67,5 +67,8 @@
</body>
</html>
{{#js}}
require(['theme_boost/loader']);
M.util.js_pending('theme_boost/loader');
require(['theme_boost/loader'], function() {
M.util.js_complete('theme_boost/loader');
});
{{/js}}

View File

@ -73,5 +73,8 @@
</body>
</html>
{{#js}}
require(['theme_boost/loader']);
M.util.js_pending('theme_boost/loader');
require(['theme_boost/loader'], function() {
M.util.js_complete('theme_boost/loader');
});
{{/js}}

View File

@ -87,5 +87,8 @@
</body>
</html>
{{#js}}
require(['theme_boost/loader']);
M.util.js_pending('theme_boost/loader');
require(['theme_boost/loader'], function() {
M.util.js_complete('theme_boost/loader');
});
{{/js}}

View File

@ -96,6 +96,8 @@
</body>
</html>
{{#js}}
require(['theme_boost/loader']);
M.util.js_pending('theme_boost/loader');
require(['theme_boost/loader'], function() {
M.util.js_complete('theme_boost/loader');
});
{{/js}}

View File

@ -68,5 +68,8 @@
</body>
</html>
{{#js}}
require(['theme_boost/loader']);
M.util.js_pending('theme_boost/loader');
require(['theme_boost/loader'], function() {
M.util.js_complete('theme_boost/loader');
});
{{/js}}

View File

@ -106,5 +106,8 @@
</body>
</html>
{{#js}}
require(['theme_boost/loader']);
M.util.js_pending('theme_boost/loader');
require(['theme_boost/loader'], function() {
M.util.js_complete('theme_boost/loader');
});
{{/js}}