5
if (typeof exports == "object" && typeof module == "object")
6
mod(require("../../lib/codemirror"), "cjs");
7
else if (typeof define == "function" && define.amd)
8
define(["../../lib/codemirror"], function(CM) { mod(CM, "amd"); });
10
mod(CodeMirror, "plain");
11
})(function(CodeMirror, env) {
12
if (!CodeMirror.modeURL) CodeMirror.modeURL = "../mode/%N/%N.js";
15
function splitCallback(cont, n) {
17
return function() { if (--countDown == 0) cont(); };
19
function ensureDeps(mode, cont, options) {
20
var modeObj = CodeMirror.modes[mode], deps = modeObj && modeObj.dependencies;
21
if (!deps) return cont();
23
for (var i = 0; i < deps.length; ++i) {
24
if (!CodeMirror.modes.hasOwnProperty(deps[i]))
25
missing.push(deps[i]);
27
if (!missing.length) return cont();
28
var split = splitCallback(cont, missing.length);
29
for (var i = 0; i < missing.length; ++i)
30
CodeMirror.requireMode(missing[i], split, options);
33
CodeMirror.requireMode = function(mode, cont, options) {
34
if (typeof mode != "string") mode = mode.name;
35
if (CodeMirror.modes.hasOwnProperty(mode)) return ensureDeps(mode, cont, options);
36
if (loading.hasOwnProperty(mode)) return loading[mode].push(cont);
38
var file = options && options.path ? options.path(mode) : CodeMirror.modeURL.replace(/%N/g, mode);
39
if (options && options.loadMode) {
40
options.loadMode(file, function() { ensureDeps(mode, cont, options) })
41
} else if (env == "plain") {
42
var script = document.createElement("script");
44
var others = document.getElementsByTagName("script")[0];
45
var list = loading[mode] = [cont];
46
CodeMirror.on(script, "load", function() {
47
ensureDeps(mode, function() {
48
for (var i = 0; i < list.length; ++i) list[i]();
51
others.parentNode.insertBefore(script, others);
52
} else if (env == "cjs") {
55
} else if (env == "amd") {
56
requirejs([file], cont);
60
CodeMirror.autoLoadMode = function(instance, mode, options) {
61
if (!CodeMirror.modes.hasOwnProperty(mode))
62
CodeMirror.requireMode(mode, function() {
63
instance.setOption("mode", instance.getOption("mode"));