1 /** vim: et:ts=4:sw=4:sts=4 |
1 /** vim: et:ts=4:sw=4:sts=4 |
2 * @license RequireJS 2.1.20 Copyright (c) 2010-2015, The Dojo Foundation All Rights Reserved. |
2 * @license RequireJS 2.2.0 Copyright jQuery Foundation and other contributors. |
3 * Available via the MIT or new BSD license. |
3 * Released under MIT license, http://github.com/requirejs/requirejs/LICENSE |
4 * see: http://github.com/jrburke/requirejs for details |
|
5 */ |
4 */ |
6 //Not using strict: uneven strict support in browsers, #392, and causes |
5 //Not using strict: uneven strict support in browsers, #392, and causes |
7 //problems with requirejs.exec()/transpiler plugins that may not be strict. |
6 //problems with requirejs.exec()/transpiler plugins that may not be strict. |
8 /*jslint regexp: true, nomen: true, sloppy: true */ |
7 /*jslint regexp: true, nomen: true, sloppy: true */ |
9 /*global window, navigator, document, importScripts, setTimeout, opera */ |
8 /*global window, navigator, document, importScripts, setTimeout, opera */ |
10 |
9 |
11 var requirejs, require, define; |
10 var requirejs, require, define; |
12 (function (global) { |
11 (function (global) { |
13 var req, s, head, baseElement, dataMain, src, |
12 var req, s, head, baseElement, dataMain, src, |
14 interactiveScript, currentlyAddingScript, mainScript, subPath, |
13 interactiveScript, currentlyAddingScript, mainScript, subPath, |
15 version = '2.1.20', |
14 version = '2.2.0', |
16 commentRegExp = /(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg, |
15 commentRegExp = /(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg, |
17 cjsRequireRegExp = /[^.]\s*require\s*\(\s*["']([^'"\s]+)["']\s*\)/g, |
16 cjsRequireRegExp = /[^.]\s*require\s*\(\s*["']([^'"\s]+)["']\s*\)/g, |
18 jsSuffixRegExp = /\.js$/, |
17 jsSuffixRegExp = /\.js$/, |
19 currDirRegExp = /^\.\//, |
18 currDirRegExp = /^\.\//, |
20 op = Object.prototype, |
19 op = Object.prototype, |
21 ostring = op.toString, |
20 ostring = op.toString, |
22 hasOwn = op.hasOwnProperty, |
21 hasOwn = op.hasOwnProperty, |
23 ap = Array.prototype, |
|
24 isBrowser = !!(typeof window !== 'undefined' && typeof navigator !== 'undefined' && window.document), |
22 isBrowser = !!(typeof window !== 'undefined' && typeof navigator !== 'undefined' && window.document), |
25 isWebWorker = !isBrowser && typeof importScripts !== 'undefined', |
23 isWebWorker = !isBrowser && typeof importScripts !== 'undefined', |
26 //PS3 indicates loaded and complete, but need to wait for complete |
24 //PS3 indicates loaded and complete, but need to wait for complete |
27 //specifically. Sequence is 'loading', 'loaded', execution, |
25 //specifically. Sequence is 'loading', 'loaded', execution, |
28 // then 'complete'. The UA check is unfortunate, but not sure how |
26 // then 'complete'. The UA check is unfortunate, but not sure how |
1650 } |
1666 } |
1651 } |
1667 } |
1652 |
1668 |
1653 //Join the path parts together, then figure out if baseUrl is needed. |
1669 //Join the path parts together, then figure out if baseUrl is needed. |
1654 url = syms.join('/'); |
1670 url = syms.join('/'); |
1655 url += (ext || (/^data\:|\?/.test(url) || skipExt ? '' : '.js')); |
1671 url += (ext || (/^data\:|^blob\:|\?/.test(url) || skipExt ? '' : '.js')); |
1656 url = (url.charAt(0) === '/' || url.match(/^[\w\+\.\-]+:/) ? '' : config.baseUrl) + url; |
1672 url = (url.charAt(0) === '/' || url.match(/^[\w\+\.\-]+:/) ? '' : config.baseUrl) + url; |
1657 } |
1673 } |
1658 |
1674 |
1659 return config.urlArgs ? url + |
1675 return config.urlArgs && !/^blob\:/.test(url) ? |
1660 ((url.indexOf('?') === -1 ? '?' : '&') + |
1676 url + config.urlArgs(moduleName, url) : url; |
1661 config.urlArgs) : url; |
|
1662 }, |
1677 }, |
1663 |
1678 |
1664 //Delegates to req.load. Broken out as a separate function to |
1679 //Delegates to req.load. Broken out as a separate function to |
1665 //allow overriding in the optimizer. |
1680 //allow overriding in the optimizer. |
1666 load: function (id, url) { |
1681 load: function (id, url) { |
1704 * Callback for script errors. |
1719 * Callback for script errors. |
1705 */ |
1720 */ |
1706 onScriptError: function (evt) { |
1721 onScriptError: function (evt) { |
1707 var data = getScriptData(evt); |
1722 var data = getScriptData(evt); |
1708 if (!hasPathFallback(data.id)) { |
1723 if (!hasPathFallback(data.id)) { |
1709 return onError(makeError('scripterror', 'Script error for: ' + data.id, evt, [data.id])); |
1724 var parents = []; |
|
1725 eachProp(registry, function(value, key) { |
|
1726 if (key.indexOf('_@r') !== 0) { |
|
1727 each(value.depMaps, function(depMap) { |
|
1728 if (depMap.id === data.id) { |
|
1729 parents.push(key); |
|
1730 return true; |
|
1731 } |
|
1732 }); |
|
1733 } |
|
1734 }); |
|
1735 return onError(makeError('scripterror', 'Script error for "' + data.id + |
|
1736 (parents.length ? |
|
1737 '", needed by: ' + parents.join(', ') : |
|
1738 '"'), evt, [data.id])); |
1710 } |
1739 } |
1711 } |
1740 } |
1712 }; |
1741 }; |
1713 |
1742 |
1714 context.require = context.makeRequire(); |
1743 context.require = context.makeRequire(); |
1863 var config = (context && context.config) || {}, |
1892 var config = (context && context.config) || {}, |
1864 node; |
1893 node; |
1865 if (isBrowser) { |
1894 if (isBrowser) { |
1866 //In the browser so use a script tag |
1895 //In the browser so use a script tag |
1867 node = req.createNode(config, moduleName, url); |
1896 node = req.createNode(config, moduleName, url); |
1868 if (config.onNodeCreated) { |
|
1869 config.onNodeCreated(node, config, moduleName, url); |
|
1870 } |
|
1871 |
1897 |
1872 node.setAttribute('data-requirecontext', context.contextName); |
1898 node.setAttribute('data-requirecontext', context.contextName); |
1873 node.setAttribute('data-requiremodule', moduleName); |
1899 node.setAttribute('data-requiremodule', moduleName); |
1874 |
1900 |
1875 //Set up load listener. Test attachEvent first because IE9 has |
1901 //Set up load listener. Test attachEvent first because IE9 has |
1881 //UNFORTUNATELY Opera implements attachEvent but does not follow the script |
1907 //UNFORTUNATELY Opera implements attachEvent but does not follow the script |
1882 //script execution mode. |
1908 //script execution mode. |
1883 if (node.attachEvent && |
1909 if (node.attachEvent && |
1884 //Check if node.attachEvent is artificially added by custom script or |
1910 //Check if node.attachEvent is artificially added by custom script or |
1885 //natively supported by browser |
1911 //natively supported by browser |
1886 //read https://github.com/jrburke/requirejs/issues/187 |
1912 //read https://github.com/requirejs/requirejs/issues/187 |
1887 //if we can NOT find [native code] then it must NOT natively supported. |
1913 //if we can NOT find [native code] then it must NOT natively supported. |
1888 //in IE8, node.attachEvent does not have toString() |
1914 //in IE8, node.attachEvent does not have toString() |
1889 //Note the test for "[native code" with no closing brace, see: |
1915 //Note the test for "[native code" with no closing brace, see: |
1890 //https://github.com/jrburke/requirejs/issues/273 |
1916 //https://github.com/requirejs/requirejs/issues/273 |
1891 !(node.attachEvent.toString && node.attachEvent.toString().indexOf('[native code') < 0) && |
1917 !(node.attachEvent.toString && node.attachEvent.toString().indexOf('[native code') < 0) && |
1892 !isOpera) { |
1918 !isOpera) { |
1893 //Probably IE. IE (at least 6-8) do not fire |
1919 //Probably IE. IE (at least 6-8) do not fire |
1894 //script onload right after executing the script, so |
1920 //script onload right after executing the script, so |
1895 //we cannot tie the anonymous define call to a name. |
1921 //we cannot tie the anonymous define call to a name. |
1913 node.addEventListener('load', context.onScriptLoad, false); |
1939 node.addEventListener('load', context.onScriptLoad, false); |
1914 node.addEventListener('error', context.onScriptError, false); |
1940 node.addEventListener('error', context.onScriptError, false); |
1915 } |
1941 } |
1916 node.src = url; |
1942 node.src = url; |
1917 |
1943 |
|
1944 //Calling onNodeCreated after all properties on the node have been |
|
1945 //set, but before it is placed in the DOM. |
|
1946 if (config.onNodeCreated) { |
|
1947 config.onNodeCreated(node, config, moduleName, url); |
|
1948 } |
|
1949 |
1918 //For some cache cases in IE 6-8, the script executes before the end |
1950 //For some cache cases in IE 6-8, the script executes before the end |
1919 //of the appendChild execution, so to tie an anonymous define |
1951 //of the appendChild execution, so to tie an anonymous define |
1920 //call to the module name (which is stored on the node), hold on |
1952 //call to the module name (which is stored on the node), hold on |
1921 //to a reference to this node, but clear after the DOM insertion. |
1953 //to a reference to this node, but clear after the DOM insertion. |
1922 currentlyAddingScript = node; |
1954 currentlyAddingScript = node; |
1931 } else if (isWebWorker) { |
1963 } else if (isWebWorker) { |
1932 try { |
1964 try { |
1933 //In a web worker, use importScripts. This is not a very |
1965 //In a web worker, use importScripts. This is not a very |
1934 //efficient use of importScripts, importScripts will block until |
1966 //efficient use of importScripts, importScripts will block until |
1935 //its script is downloaded and evaluated. However, if web workers |
1967 //its script is downloaded and evaluated. However, if web workers |
1936 //are in play, the expectation that a build has been done so that |
1968 //are in play, the expectation is that a build has been done so |
1937 //only one script needs to be loaded anyway. This may need to be |
1969 //that only one script needs to be loaded anyway. This may need |
1938 //reevaluated if other use cases become common. |
1970 //to be reevaluated if other use cases become common. |
|
1971 |
|
1972 // Post a task to the event loop to work around a bug in WebKit |
|
1973 // where the worker gets garbage-collected after calling |
|
1974 // importScripts(): https://webkit.org/b/153317 |
|
1975 setTimeout(function() {}, 0); |
1939 importScripts(url); |
1976 importScripts(url); |
1940 |
1977 |
1941 //Account for anonymous modules |
1978 //Account for anonymous modules |
1942 context.completeLoad(moduleName); |
1979 context.completeLoad(moduleName); |
1943 } catch (e) { |
1980 } catch (e) { |
1979 dataMain = script.getAttribute('data-main'); |
2016 dataMain = script.getAttribute('data-main'); |
1980 if (dataMain) { |
2017 if (dataMain) { |
1981 //Preserve dataMain in case it is a path (i.e. contains '?') |
2018 //Preserve dataMain in case it is a path (i.e. contains '?') |
1982 mainScript = dataMain; |
2019 mainScript = dataMain; |
1983 |
2020 |
1984 //Set final baseUrl if there is not already an explicit one. |
2021 //Set final baseUrl if there is not already an explicit one, |
1985 if (!cfg.baseUrl) { |
2022 //but only do so if the data-main value is not a loader plugin |
|
2023 //module ID. |
|
2024 if (!cfg.baseUrl && mainScript.indexOf('!') === -1) { |
1986 //Pull off the directory of data-main for use as the |
2025 //Pull off the directory of data-main for use as the |
1987 //baseUrl. |
2026 //baseUrl. |
1988 src = mainScript.split('/'); |
2027 src = mainScript.split('/'); |
1989 mainScript = src.pop(); |
2028 mainScript = src.pop(); |
1990 subPath = src.length ? src.join('/') + '/' : './'; |
2029 subPath = src.length ? src.join('/') + '/' : './'; |
2041 //look for require calls, and pull them into the dependencies, |
2080 //look for require calls, and pull them into the dependencies, |
2042 //but only if there are function args. |
2081 //but only if there are function args. |
2043 if (callback.length) { |
2082 if (callback.length) { |
2044 callback |
2083 callback |
2045 .toString() |
2084 .toString() |
2046 .replace(commentRegExp, '') |
2085 .replace(commentRegExp, commentReplace) |
2047 .replace(cjsRequireRegExp, function (match, dep) { |
2086 .replace(cjsRequireRegExp, function (match, dep) { |
2048 deps.push(dep); |
2087 deps.push(dep); |
2049 }); |
2088 }); |
2050 |
2089 |
2051 //May be a CommonJS thing even without require calls, but still |
2090 //May be a CommonJS thing even without require calls, but still |