/* CodeMirror main module * * Implements the CodeMirror constructor and prototype, which take care * of initializing the editor frame, and providing the outside interface. */ // The CodeMirrorConfig object is used to specify a default // configuration. If you specify such an object before loading this // file, the values you put into it will override the defaults given // below. You can also assign to it after loading. var CodeMirrorConfig = window.CodeMirrorConfig || {}; var CodeMirror = (function(){ function setDefaults(object, defaults) { for (var option in defaults) { if (!object.hasOwnProperty(option)) object[option] = defaults[option]; } } function forEach(array, action) { for (var i = 0; i < array.length; i++) action(array[i]); } // These default options can be overridden by passing a set of // options to a specific CodeMirror constructor. See manual.html for // their meaning. setDefaults(CodeMirrorConfig, { stylesheet: "", path: "", parserfile: [], basefiles: ["util.js", "stringstream.js", "select.js", "undo.js", "editor.js", "tokenize.js"], iframeClass: null, passDelay: 200, passTime: 50, lineNumberDelay: 200, lineNumberTime: 50, continuousScanning: false, saveFunction: null, onChange: null, undoDepth: 50, undoDelay: 800, disableSpellcheck: true, textWrapping: true, readOnly: false, width: "", height: "300px", autoMatchParens: false, parserConfig: null, tabMode: "indent", // or "spaces", "default", "shift" reindentOnLoad: false, activeTokens: null, cursorActivity: null, lineNumbers: false, indentUnit: 2 }); function addLineNumberDiv(container) { var nums = document.createElement("DIV"), scroller = document.createElement("DIV"); nums.style.position = "absolute"; nums.style.height = "100%"; if (nums.style.setExpression) { try {nums.style.setExpression("height", "this.previousSibling.offsetHeight + 'px'");} catch(e) {} // Seems to throw 'Not Implemented' on some IE8 versions } nums.style.top = "0px"; nums.style.overflow = "hidden"; container.appendChild(nums); scroller.className = "CodeMirror-line-numbers"; nums.appendChild(scroller); return nums; } function CodeMirror(place, options) { // Backward compatibility for deprecated options. if (options.dumbTabs) options.tabMode = "spaces"; else if (options.normalTab) options.tabMode = "default"; // Use passed options, if any, to override defaults. this.options = options = options || {}; setDefaults(options, CodeMirrorConfig); var frame = this.frame = document.createElement("IFRAME"); if (options.iframeClass) frame.className = options.iframeClass; frame.frameBorder = 0; frame.src = "javascript:false;"; frame.style.border = "0"; frame.style.width = '100%'; frame.style.height = '100%'; // display: block occasionally suppresses some Firefox bugs, so we // always add it, redundant as it sounds. frame.style.display = "block"; var div = this.wrapping = document.createElement("DIV"); div.style.position = "relative"; div.className = "CodeMirror-wrapping"; div.style.width = options.width; div.style.height = options.height; if (place.appendChild) place.appendChild(div); else place(div); div.appendChild(frame); if (options.lineNumbers) this.lineNumbers = addLineNumberDiv(div); // Link back to this object, so that the editor can fetch options // and add a reference to itself. frame.CodeMirror = this; this.win = frame.contentWindow; if (typeof options.parserfile == "string") options.parserfile = [options.parserfile]; if (typeof options.stylesheet == "string") options.stylesheet = [options.stylesheet]; var html = [""]; // Hack to work around a bunch of IE8-specific problems. html.push(""); forEach(options.stylesheet, function(file) { html.push(""); }); forEach(options.basefiles.concat(options.parserfile), function(file) { html.push("