| 92 | // DISPLAY CONSTRUCTOR |
| 93 | |
| 94 | function makeDisplay(place, docStart) { |
| 95 | var d = {}; |
| 96 | var input = d.input = elt("textarea", null, null, "position: absolute; padding: 0; width: 1px; height: 1em; outline: none;"); |
| 97 | if (webkit) input.style.width = "1000px"; |
| 98 | else input.setAttribute("wrap", "off"); |
| 99 | input.setAttribute("autocorrect", "off"); input.setAttribute("autocapitalize", "off"); |
| 100 | // Wraps and hides input textarea |
| 101 | d.inputDiv = elt("div", [input], null, "overflow: hidden; position: relative; width: 3px; height: 0px;"); |
| 102 | // The actual fake scrollbars. |
| 103 | d.scrollbarH = elt("div", [elt("div", null, null, "height: 1px")], "CodeMirror-hscrollbar"); |
| 104 | d.scrollbarV = elt("div", [elt("div", null, null, "width: 1px")], "CodeMirror-vscrollbar"); |
| 105 | d.scrollbarFiller = elt("div", null, "CodeMirror-scrollbar-filler"); |
| 106 | // DIVs containing the selection and the actual code |
| 107 | d.lineDiv = elt("div"); |
| 108 | d.selectionDiv = elt("div", null, null, "position: relative; z-index: 1"); |
| 109 | // Blinky cursor, and element used to ensure cursor fits at the end of a line |
| 110 | d.cursor = elt("div", "\u00a0", "CodeMirror-cursor"); |
| 111 | // Secondary cursor, shown when on a 'jump' in bi-directional text |
| 112 | d.otherCursor = elt("div", "\u00a0", "CodeMirror-cursor CodeMirror-secondarycursor"); |
| 113 | // Used to measure text size |
| 114 | d.measure = elt("div", null, "CodeMirror-measure"); |
| 115 | // Wraps everything that needs to exist inside the vertically-padded coordinate system |
| 116 | d.lineSpace = elt("div", [d.measure, d.selectionDiv, d.lineDiv, d.cursor, d.otherCursor], |
| 117 | null, "position: relative; outline: none"); |
| 118 | // Moved around its parent to cover visible view |
| 119 | d.mover = elt("div", [elt("div", [d.lineSpace], "CodeMirror-lines")], null, "position: relative"); |
| 120 | // Set to the height of the text, causes scrolling |
| 121 | d.sizer = elt("div", [d.mover], "CodeMirror-sizer"); |
| 122 | // D is needed because behavior of elts with overflow: auto and padding is inconsistent across browsers |
| 123 | d.heightForcer = elt("div", "\u00a0", null, "position: absolute; height: " + scrollerCutOff + "px"); |
| 124 | // Will contain the gutters, if any |
| 125 | d.gutters = elt("div", null, "CodeMirror-gutters"); |
| 126 | d.lineGutter = null; |
| 127 | // Helper element to properly size the gutter backgrounds |
| 128 | var scrollerInner = elt("div", [d.sizer, d.heightForcer, d.gutters], null, "position: relative; min-height: 100%"); |
| 129 | // Provides scrolling |
| 130 | d.scroller = elt("div", [scrollerInner], "CodeMirror-scroll"); |
| 131 | d.scroller.setAttribute("tabIndex", "-1"); |
| 132 | // The element in which the editor lives. |
| 133 | d.wrapper = elt("div", [d.inputDiv, d.scrollbarH, d.scrollbarV, |
| 134 | d.scrollbarFiller, d.scroller], "CodeMirror"); |
| 135 | // Work around IE7 z-index bug |
| 136 | if (ie_lt8) { d.gutters.style.zIndex = -1; d.scroller.style.paddingRight = 0; } |
| 137 | if (place.appendChild) place.appendChild(d.wrapper); else place(d.wrapper); |
| 138 | |
| 139 | // Needed to hide big blue blinking cursor on Mobile Safari |
| 140 | if (ios) input.style.width = "0px"; |
| 141 | if (!webkit) d.scroller.draggable = true; |
| 142 | // Needed to handle Tab key in KHTML |
| 143 | if (khtml) { d.inputDiv.style.height = "1px"; d.inputDiv.style.position = "absolute"; } |
| 144 | // Need to set a minimum width to see the scrollbar on IE7 (but must not set it on IE8). |
| 145 | else if (ie_lt8) d.scrollbarH.style.minWidth = d.scrollbarV.style.minWidth = "18px"; |
| 146 | |
| 147 | // Current visible range (may be bigger than the view window). |
| 148 | d.viewOffset = d.lastSizeC = 0; |
| 149 | d.showingFrom = d.showingTo = docStart; |
| 150 | |
| 151 | // Used to only resize the line number gutter when necessary (when |