|
3 | 3 |
|
4 | 4 | (function(mod) { |
5 | 5 | if (typeof exports == "object" && typeof module == "object") // CommonJS |
6 | | - mod(require("../../lib/codemirror")); |
| 6 | + mod(require("../../lib/codemirror"), "cjs"); |
7 | 7 | else if (typeof define == "function" && define.amd) // AMD |
8 | | - define(["../../lib/codemirror"], mod); |
| 8 | + define(["../../lib/codemirror"], function(CM) { mod(CM, "amd"); }); |
9 | 9 | else // Plain browser env |
10 | | - mod(CodeMirror); |
11 | | -})(function(CodeMirror) { |
| 10 | + mod(CodeMirror, "plain"); |
| 11 | +})(function(CodeMirror, env) { |
12 | 12 | if (!CodeMirror.modeURL) CodeMirror.modeURL = "../mode/%N/%N.js"; |
13 | 13 |
|
14 | 14 | var loading = {}; |
|
35 | 35 | if (CodeMirror.modes.hasOwnProperty(mode)) return ensureDeps(mode, cont); |
36 | 36 | if (loading.hasOwnProperty(mode)) return loading[mode].push(cont); |
37 | 37 |
|
38 | | - var script = document.createElement("script"); |
39 | | - script.src = CodeMirror.modeURL.replace(/%N/g, mode); |
40 | | - var others = document.getElementsByTagName("script")[0]; |
41 | | - others.parentNode.insertBefore(script, others); |
42 | | - var list = loading[mode] = [cont]; |
43 | | - var count = 0, poll = setInterval(function() { |
44 | | - if (++count > 100) return clearInterval(poll); |
45 | | - if (CodeMirror.modes.hasOwnProperty(mode)) { |
46 | | - clearInterval(poll); |
47 | | - loading[mode] = null; |
| 38 | + var file = CodeMirror.modeURL.replace(/%N/g, mode); |
| 39 | + if (env == "plain") { |
| 40 | + var script = document.createElement("script"); |
| 41 | + script.src = file; |
| 42 | + var others = document.getElementsByTagName("script")[0]; |
| 43 | + var list = loading[mode] = [cont]; |
| 44 | + CodeMirror.on(script, "load", function() { |
48 | 45 | ensureDeps(mode, function() { |
49 | 46 | for (var i = 0; i < list.length; ++i) list[i](); |
50 | 47 | }); |
51 | | - } |
52 | | - }, 200); |
| 48 | + }); |
| 49 | + others.parentNode.insertBefore(script, others); |
| 50 | + } else if (env == "cjs") { |
| 51 | + require(file); |
| 52 | + cont(); |
| 53 | + } else if (env == "amd") { |
| 54 | + requirejs([file], cont); |
| 55 | + } |
53 | 56 | }; |
54 | 57 |
|
55 | 58 | CodeMirror.autoLoadMode = function(instance, mode) { |
|
0 commit comments