导入

    /**
* Creates the node for the load command. Only used in browser envs.
*/
req.createNode = function (config, moduleName, url) {
var node = config.xhtml ?
document.createElementNS('http://www.w3.org/1999/xhtml', 'html:script') :
document.createElement('script');
node.type = config.scriptType || 'text/javascript';
node.charset = 'utf-8';
node.async = true;
return node;
};

  

加载

/**
* Does the request to load a module for the browser case.
* Make this a separate function to allow other environments
* to override it.
*
* @param {Object} context the require context to find state.
* @param {String} moduleName the name of the module.
* @param {Object} url the URL to the module.
*/
req.load = function (context, moduleName, url) {
var config = (context && context.config) || {},
node;
if (isBrowser) {
//In the browser so use a script tag
node = req.createNode(config, moduleName, url); node.setAttribute('data-requirecontext', context.contextName);
node.setAttribute('data-requiremodule', moduleName); //Set up load listener. Test attachEvent first because IE9 has
//a subtle issue in its addEventListener and script onload firings
//that do not match the behavior of all other browsers with
//addEventListener support, which fire the onload event for a
//script right after the script execution. See:
//https://connect.microsoft.com/IE/feedback/details/648057/script-onload-event-is-not-fired-immediately-after-script-execution
//UNFORTUNATELY Opera implements attachEvent but does not follow the script
//script execution mode.
if (node.attachEvent &&
//Check if node.attachEvent is artificially added by custom script or
//natively supported by browser
//read https://github.com/jrburke/requirejs/issues/187
//if we can NOT find [native code] then it must NOT natively supported.
//in IE8, node.attachEvent does not have toString()
//Note the test for "[native code" with no closing brace, see:
//https://github.com/jrburke/requirejs/issues/273
!(node.attachEvent.toString && node.attachEvent.toString().indexOf('[native code') < 0) &&
!isOpera) {
//Probably IE. IE (at least 6-8) do not fire
//script onload right after executing the script, so
//we cannot tie the anonymous define call to a name.
//However, IE reports the script as being in 'interactive'
//readyState at the time of the define call.
useInteractive = true; node.attachEvent('onreadystatechange', context.onScriptLoad);
//It would be great to add an error handler here to catch
//404s in IE9+. However, onreadystatechange will fire before
//the error handler, so that does not help. If addEventListener
//is used, then IE will fire error before load, but we cannot
//use that pathway given the connect.microsoft.com issue
//mentioned above about not doing the 'script execute,
//then fire the script load event listener before execute
//next script' that other browsers do.
//Best hope: IE10 fixes the issues,
//and then destroys all installs of IE 6-9.
//node.attachEvent('onerror', context.onScriptError);
} else {
node.addEventListener('load', context.onScriptLoad, false);
node.addEventListener('error', context.onScriptError, false);
}
node.src = url; //For some cache cases in IE 6-8, the script executes before the end
//of the appendChild execution, so to tie an anonymous define
//call to the module name (which is stored on the node), hold on
//to a reference to this node, but clear after the DOM insertion.
currentlyAddingScript = node;
if (baseElement) {
head.insertBefore(node, baseElement);
} else {
head.appendChild(node);
}
currentlyAddingScript = null; return node;
} else if (isWebWorker) {
try {
//In a web worker, use importScripts. This is not a very
//efficient use of importScripts, importScripts will block until
//its script is downloaded and evaluated. However, if web workers
//are in play, the expectation that a build has been done so that
//only one script needs to be loaded anyway. This may need to be
//reevaluated if other use cases become common.
importScripts(url); //Account for anonymous modules
context.completeLoad(moduleName);
} catch (e) {
context.onError(makeError('importscripts',
'importScripts failed for ' +
moduleName + ' at ' + url,
e,
[moduleName]));
}
}
};

  

最新文章

  1. run VLC in root
  2. SASS学习笔记(1)
  3. __proto__和protaotype的区分
  4. paper 68 :MATLAB中取整函数(fix, floor, ceil, round)的使用
  5. 应付配置文件 Profile
  6. JavaScript高级程序设计49.pdf
  7. mini2440 uboot使用nfs方式引导内核,文件系统
  8. 更改ORACLE 用户的 expired状态
  9. redis基础的字符串类型
  10. ural1494 Monobilliards
  11. 嵌入式linux下wifi网卡的使用(四)——应用程序sub_supplicant编译
  12. laravel-Policy步骤
  13. locate中使用variant
  14. 记一次Django报错Reverse for &#39;indextwo&#39; with no arguments not found. 1 pattern(s) tried: [&#39;$index/$&#39;]
  15. 利用原生js的Dom操作实现简单的ToDoList的效果
  16. 问题1:设置了text-overflow : ellipsis未起作用
  17. Linux服务-openssh
  18. python测试开发django-25.表单提交之post注册案例
  19. 5款替代微软Visio的开源免费软件(转)
  20. 洛谷 P4248: bzoj 3238: [AHOI2013]差异

热门文章

  1. Python os模块、os.path模块常用方法
  2. ArrayList、Vector和LinkedList
  3. JavaScript动画相关
  4. C++中的sort函数和⾃定义cmp函数
  5. 确定BP神经网络中的节点数
  6. IIS7和IIS8环境下 ThinkPHP专用URL Rewrite伪静态规则
  7. Python 之并发编程之线程下
  8. 牛客网Sql
  9. 操作系统OS - 重装Windows7卡在completing installation
  10. win8.1 virtualbox 安装centos7注意事项