mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 14:27:22 +01:00
0a4047ab31
Unfortunately the babel minify-mangle plugin seems to be abandoned and in certain circumstances can be very buggy. The only safe options are to disable it, or to switch to a different minification library. Not minifying our javascript is not ideal, so this commit updates the javascript tasks to use a rollup, combined with babel, and terser. Babel still converts code from ES/UMD/AMD to AMD modules with the relevant browser support, whilst terser minifies the code. The rollup bundler handles tracking and creation of sourcemaps, and supports better parallelisation of the tasks. Since the upgrade to Node LTS/Gallium requires an upgrade to @babel/core and eslint, which change the built files anyway, this seems like the ideal time to make this change.
13 lines
3.1 KiB
JavaScript
13 lines
3.1 KiB
JavaScript
/**
|
|
* Standard Ajax wrapper for Moodle. It calls the central Ajax script,
|
|
* which can call any existing webservice using the current session.
|
|
* In addition, it can batch multiple requests and return multiple responses.
|
|
*
|
|
* @module core/ajax
|
|
* @copyright 2015 Damyon Wiese <damyon@moodle.com>
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
* @since 2.9
|
|
*/
|
|
define("core/ajax",["jquery","core/config","core/log","core/url"],(function($,config,Log,URL){var unloading=!1,requestSuccess=function(responses){var request,response,nosessionupdate,exception=null,i=0;if(responses.error)for(;i<this.length;i++)(request=this[i]).deferred.reject(responses);else{for(i=0;i<this.length;i++){if(request=this[i],void 0===(response=responses[i])){exception=new Error("missing response");break}if(!1!==response.error){exception=response.exception,nosessionupdate=this[i].nosessionupdate;break}request.deferred.resolve(response.data)}null!==exception&&("servicerequireslogin"!==exception.errorcode||nosessionupdate?this.forEach((function(request){request.deferred.reject(exception)})):window.location=URL.relativeUrl("/login/index.php"))}},requestFail=function(jqXHR,textStatus,exception){var i=0;for(i=0;i<this.length;i++){var request=this[i];unloading?(Log.error("Page unloaded."),Log.error(exception)):request.deferred.reject(exception)}};return{call:function(requests,async,loginrequired,nosessionupdate,timeout,cachekey){$(window).bind("beforeunload",(function(){unloading=!0}));var i,ajaxRequestData=[],promises=[],methodInfo=[],requestInfo="";for(void 0===loginrequired&&(loginrequired=!0),void 0===async&&(async=!0),void 0===timeout&&(timeout=0),void 0===cachekey||(cachekey=parseInt(cachekey))<=0?cachekey=null:cachekey||(cachekey=null),void 0===nosessionupdate&&(nosessionupdate=!1),i=0;i<requests.length;i++){var request=requests[i];ajaxRequestData.push({index:i,methodname:request.methodname,args:request.args}),request.nosessionupdate=nosessionupdate,request.deferred=$.Deferred(),promises.push(request.deferred.promise()),void 0!==request.done&&request.deferred.done(request.done),void 0!==request.fail&&request.deferred.fail(request.fail),request.index=i,methodInfo.push(request.methodname)}requestInfo=methodInfo.length<=5?methodInfo.sort().join():methodInfo.length+"-method-calls",ajaxRequestData=JSON.stringify(ajaxRequestData);var settings={type:"POST",context:requests,dataType:"json",processData:!1,async:async,contentType:"application/json",timeout:timeout},script="service.php",url=config.wwwroot+"/lib/ajax/";if(loginrequired?url+=script+"?sesskey="+config.sesskey+"&info="+requestInfo:(url+=(script="service-nologin.php")+"?info="+requestInfo,cachekey&&(url+="&cachekey="+cachekey,settings.type="GET")),nosessionupdate&&(url+="&nosessionupdate=true"),"POST"===settings.type)settings.data=ajaxRequestData;else{var urlUseGet=url+"&args="+encodeURIComponent(ajaxRequestData);urlUseGet.length>2e3?(settings.type="POST",settings.data=ajaxRequestData):url=urlUseGet}return async?$.ajax(url,settings).done(requestSuccess).fail(requestFail):(settings.success=requestSuccess,settings.error=requestFail,$.ajax(url,settings)),promises}}}));
|
|
|
|
//# sourceMappingURL=ajax.min.js.map
|