MCPcopy Create free account
hub / github.com/ronreiter/interactive-tutorials / CodeMirror

Function CodeMirror

static/js/codemirror/codemirror.js:42–90  ·  view source on GitHub ↗
(place, options)

Source from the content-addressed store, hash-verified

40 // CONSTRUCTOR
41
42 function CodeMirror(place, options) {
43 if (!(this instanceof CodeMirror)) return new CodeMirror(place, options);
44
45 this.options = options = options || {};
46 // Determine effective options based on given values and defaults.
47 for (var opt in defaults) if (!options.hasOwnProperty(opt) && defaults.hasOwnProperty(opt))
48 options[opt] = defaults[opt];
49 setGuttersForLineNumbers(options);
50
51 var docStart = typeof options.value == "string" ? 0 : options.value.first;
52 var display = this.display = makeDisplay(place, docStart);
53 display.wrapper.CodeMirror = this;
54 updateGutters(this);
55 if (options.autofocus && !mobile) focusInput(this);
56
57 this.state = {keyMaps: [],
58 overlays: [],
59 modeGen: 0,
60 overwrite: false, focused: false,
61 suppressEdits: false, pasteIncoming: false,
62 draggingText: false,
63 highlight: new Delayed()};
64
65 themeChanged(this);
66 if (options.lineWrapping)
67 this.display.wrapper.className += " CodeMirror-wrap";
68
69 var doc = options.value;
70 if (typeof doc == "string") doc = new Doc(options.value, options.mode);
71 operation(this, attachDoc)(this, doc);
72
73 // Override magic textarea content restore that IE sometimes does
74 // on our hidden textarea on reload
75 if (ie) setTimeout(bind(resetInput, this, true), 20);
76
77 registerEventHandlers(this);
78 // IE throws unspecified error in certain cases, when
79 // trying to access activeElement before onload
80 var hasFocus; try { hasFocus = (document.activeElement == display.input); } catch(e) { }
81 if (hasFocus || (options.autofocus && !mobile)) setTimeout(bind(onFocus, this), 20);
82 else onBlur(this);
83
84 operation(this, function() {
85 for (var opt in optionHandlers)
86 if (optionHandlers.propertyIsEnumerable(opt))
87 optionHandlers[opt](this, options[opt], Init);
88 for (var i = 0; i < initHooks.length; ++i) initHooks[i](this);
89 })();
90 }
91
92 // DISPLAY CONSTRUCTOR
93

Callers 1

codemirror.jsFile · 0.85

Calls 9

setGuttersForLineNumbersFunction · 0.85
makeDisplayFunction · 0.85
updateGuttersFunction · 0.85
focusInputFunction · 0.85
themeChangedFunction · 0.85
operationFunction · 0.85
bindFunction · 0.85
registerEventHandlersFunction · 0.85
onBlurFunction · 0.70

Tested by

no test coverage detected