LaravelTest
66 строк · 2.5 Кб
1// CodeMirror, copyright (c) by Marijn Haverbeke and others
2// Distributed under an MIT license: https://codemirror.net/LICENSE
3
4(function(mod) {5if (typeof exports == "object" && typeof module == "object") // CommonJS6mod(require("../../lib/codemirror"), "cjs");7else if (typeof define == "function" && define.amd) // AMD8define(["../../lib/codemirror"], function(CM) { mod(CM, "amd"); });9else // Plain browser env10mod(CodeMirror, "plain");11})(function(CodeMirror, env) {12if (!CodeMirror.modeURL) CodeMirror.modeURL = "../mode/%N/%N.js";13
14var loading = {};15function splitCallback(cont, n) {16var countDown = n;17return function() { if (--countDown == 0) cont(); };18}19function ensureDeps(mode, cont, options) {20var modeObj = CodeMirror.modes[mode], deps = modeObj && modeObj.dependencies;21if (!deps) return cont();22var missing = [];23for (var i = 0; i < deps.length; ++i) {24if (!CodeMirror.modes.hasOwnProperty(deps[i]))25missing.push(deps[i]);26}27if (!missing.length) return cont();28var split = splitCallback(cont, missing.length);29for (var i = 0; i < missing.length; ++i)30CodeMirror.requireMode(missing[i], split, options);31}32
33CodeMirror.requireMode = function(mode, cont, options) {34if (typeof mode != "string") mode = mode.name;35if (CodeMirror.modes.hasOwnProperty(mode)) return ensureDeps(mode, cont, options);36if (loading.hasOwnProperty(mode)) return loading[mode].push(cont);37
38var file = options && options.path ? options.path(mode) : CodeMirror.modeURL.replace(/%N/g, mode);39if (options && options.loadMode) {40options.loadMode(file, function() { ensureDeps(mode, cont, options) })41} else if (env == "plain") {42var script = document.createElement("script");43script.src = file;44var others = document.getElementsByTagName("script")[0];45var list = loading[mode] = [cont];46CodeMirror.on(script, "load", function() {47ensureDeps(mode, function() {48for (var i = 0; i < list.length; ++i) list[i]();49}, options);50});51others.parentNode.insertBefore(script, others);52} else if (env == "cjs") {53require(file);54cont();55} else if (env == "amd") {56requirejs([file], cont);57}58};59
60CodeMirror.autoLoadMode = function(instance, mode, options) {61if (!CodeMirror.modes.hasOwnProperty(mode))62CodeMirror.requireMode(mode, function() {63instance.setOption("mode", instance.getOption("mode"));64}, options);65};66});67