Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/wp-file-.../lib/codemirr.../lib
File: codemirror.js
// CodeMirror, copyright (c) by Marijn Haverbeke and others
[0] Fix | Delete
// Distributed under an MIT license: http://codemirror.net/LICENSE
[1] Fix | Delete
[2] Fix | Delete
// This is CodeMirror (http://codemirror.net), a code editor
[3] Fix | Delete
// implemented in JavaScript on top of the browser's DOM.
[4] Fix | Delete
//
[5] Fix | Delete
// You can find some technical background for some of the code below
[6] Fix | Delete
// at http://marijnhaverbeke.nl/blog/#cm-internals .
[7] Fix | Delete
[8] Fix | Delete
(function(mod) {
[9] Fix | Delete
if (typeof exports == "object" && typeof module == "object") // CommonJS
[10] Fix | Delete
module.exports = mod();
[11] Fix | Delete
else if (typeof define == "function" && define.amd) // AMD
[12] Fix | Delete
return define([], mod);
[13] Fix | Delete
else // Plain browser env
[14] Fix | Delete
(this || window).CodeMirror = mod();
[15] Fix | Delete
})(function() {
[16] Fix | Delete
"use strict";
[17] Fix | Delete
[18] Fix | Delete
// BROWSER SNIFFING
[19] Fix | Delete
[20] Fix | Delete
// Kludges for bugs and behavior differences that can't be feature
[21] Fix | Delete
// detected are enabled based on userAgent etc sniffing.
[22] Fix | Delete
var userAgent = navigator.userAgent;
[23] Fix | Delete
var platform = navigator.platform;
[24] Fix | Delete
[25] Fix | Delete
var gecko = /gecko\/\d/i.test(userAgent);
[26] Fix | Delete
var ie_upto10 = /MSIE \d/.test(userAgent);
[27] Fix | Delete
var ie_11up = /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(userAgent);
[28] Fix | Delete
var ie = ie_upto10 || ie_11up;
[29] Fix | Delete
var ie_version = ie && (ie_upto10 ? document.documentMode || 6 : ie_11up[1]);
[30] Fix | Delete
var webkit = /WebKit\//.test(userAgent);
[31] Fix | Delete
var qtwebkit = webkit && /Qt\/\d+\.\d+/.test(userAgent);
[32] Fix | Delete
var chrome = /Chrome\//.test(userAgent);
[33] Fix | Delete
var presto = /Opera\//.test(userAgent);
[34] Fix | Delete
var safari = /Apple Computer/.test(navigator.vendor);
[35] Fix | Delete
var mac_geMountainLion = /Mac OS X 1\d\D([8-9]|\d\d)\D/.test(userAgent);
[36] Fix | Delete
var phantom = /PhantomJS/.test(userAgent);
[37] Fix | Delete
[38] Fix | Delete
var ios = /AppleWebKit/.test(userAgent) && /Mobile\/\w+/.test(userAgent);
[39] Fix | Delete
// This is woefully incomplete. Suggestions for alternative methods welcome.
[40] Fix | Delete
var mobile = ios || /Android|webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(userAgent);
[41] Fix | Delete
var mac = ios || /Mac/.test(platform);
[42] Fix | Delete
var chromeOS = /\bCrOS\b/.test(userAgent);
[43] Fix | Delete
var windows = /win/i.test(platform);
[44] Fix | Delete
[45] Fix | Delete
var presto_version = presto && userAgent.match(/Version\/(\d*\.\d*)/);
[46] Fix | Delete
if (presto_version) presto_version = Number(presto_version[1]);
[47] Fix | Delete
if (presto_version && presto_version >= 15) { presto = false; webkit = true; }
[48] Fix | Delete
// Some browsers use the wrong event properties to signal cmd/ctrl on OS X
[49] Fix | Delete
var flipCtrlCmd = mac && (qtwebkit || presto && (presto_version == null || presto_version < 12.11));
[50] Fix | Delete
var captureRightClick = gecko || (ie && ie_version >= 9);
[51] Fix | Delete
[52] Fix | Delete
// Optimize some code when these features are not used.
[53] Fix | Delete
var sawReadOnlySpans = false, sawCollapsedSpans = false;
[54] Fix | Delete
[55] Fix | Delete
// EDITOR CONSTRUCTOR
[56] Fix | Delete
[57] Fix | Delete
// A CodeMirror instance represents an editor. This is the object
[58] Fix | Delete
// that user code is usually dealing with.
[59] Fix | Delete
[60] Fix | Delete
function CodeMirror(place, options) {
[61] Fix | Delete
if (!(this instanceof CodeMirror)) return new CodeMirror(place, options);
[62] Fix | Delete
[63] Fix | Delete
this.options = options = options ? copyObj(options) : {};
[64] Fix | Delete
// Determine effective options based on given values and defaults.
[65] Fix | Delete
copyObj(defaults, options, false);
[66] Fix | Delete
setGuttersForLineNumbers(options);
[67] Fix | Delete
[68] Fix | Delete
var doc = options.value;
[69] Fix | Delete
if (typeof doc == "string") doc = new Doc(doc, options.mode, null, options.lineSeparator);
[70] Fix | Delete
this.doc = doc;
[71] Fix | Delete
[72] Fix | Delete
var input = new CodeMirror.inputStyles[options.inputStyle](this);
[73] Fix | Delete
var display = this.display = new Display(place, doc, input);
[74] Fix | Delete
display.wrapper.CodeMirror = this;
[75] Fix | Delete
updateGutters(this);
[76] Fix | Delete
themeChanged(this);
[77] Fix | Delete
if (options.lineWrapping)
[78] Fix | Delete
this.display.wrapper.className += " CodeMirror-wrap";
[79] Fix | Delete
if (options.autofocus && !mobile) display.input.focus();
[80] Fix | Delete
initScrollbars(this);
[81] Fix | Delete
[82] Fix | Delete
this.state = {
[83] Fix | Delete
keyMaps: [], // stores maps added by addKeyMap
[84] Fix | Delete
overlays: [], // highlighting overlays, as added by addOverlay
[85] Fix | Delete
modeGen: 0, // bumped when mode/overlay changes, used to invalidate highlighting info
[86] Fix | Delete
overwrite: false,
[87] Fix | Delete
delayingBlurEvent: false,
[88] Fix | Delete
focused: false,
[89] Fix | Delete
suppressEdits: false, // used to disable editing during key handlers when in readOnly mode
[90] Fix | Delete
pasteIncoming: false, cutIncoming: false, // help recognize paste/cut edits in input.poll
[91] Fix | Delete
selectingText: false,
[92] Fix | Delete
draggingText: false,
[93] Fix | Delete
highlight: new Delayed(), // stores highlight worker timeout
[94] Fix | Delete
keySeq: null, // Unfinished key sequence
[95] Fix | Delete
specialChars: null
[96] Fix | Delete
};
[97] Fix | Delete
[98] Fix | Delete
var cm = this;
[99] Fix | Delete
[100] Fix | Delete
// Override magic textarea content restore that IE sometimes does
[101] Fix | Delete
// on our hidden textarea on reload
[102] Fix | Delete
if (ie && ie_version < 11) setTimeout(function() { cm.display.input.reset(true); }, 20);
[103] Fix | Delete
[104] Fix | Delete
registerEventHandlers(this);
[105] Fix | Delete
ensureGlobalHandlers();
[106] Fix | Delete
[107] Fix | Delete
startOperation(this);
[108] Fix | Delete
this.curOp.forceUpdate = true;
[109] Fix | Delete
attachDoc(this, doc);
[110] Fix | Delete
[111] Fix | Delete
if ((options.autofocus && !mobile) || cm.hasFocus())
[112] Fix | Delete
setTimeout(bind(onFocus, this), 20);
[113] Fix | Delete
else
[114] Fix | Delete
onBlur(this);
[115] Fix | Delete
[116] Fix | Delete
for (var opt in optionHandlers) if (optionHandlers.hasOwnProperty(opt))
[117] Fix | Delete
optionHandlers[opt](this, options[opt], Init);
[118] Fix | Delete
maybeUpdateLineNumberWidth(this);
[119] Fix | Delete
if (options.finishInit) options.finishInit(this);
[120] Fix | Delete
for (var i = 0; i < initHooks.length; ++i) initHooks[i](this);
[121] Fix | Delete
endOperation(this);
[122] Fix | Delete
// Suppress optimizelegibility in Webkit, since it breaks text
[123] Fix | Delete
// measuring on line wrapping boundaries.
[124] Fix | Delete
if (webkit && options.lineWrapping &&
[125] Fix | Delete
getComputedStyle(display.lineDiv).textRendering == "optimizelegibility")
[126] Fix | Delete
display.lineDiv.style.textRendering = "auto";
[127] Fix | Delete
}
[128] Fix | Delete
[129] Fix | Delete
// DISPLAY CONSTRUCTOR
[130] Fix | Delete
[131] Fix | Delete
// The display handles the DOM integration, both for input reading
[132] Fix | Delete
// and content drawing. It holds references to DOM nodes and
[133] Fix | Delete
// display-related state.
[134] Fix | Delete
[135] Fix | Delete
function Display(place, doc, input) {
[136] Fix | Delete
var d = this;
[137] Fix | Delete
this.input = input;
[138] Fix | Delete
[139] Fix | Delete
// Covers bottom-right square when both scrollbars are present.
[140] Fix | Delete
d.scrollbarFiller = elt("div", null, "CodeMirror-scrollbar-filler");
[141] Fix | Delete
d.scrollbarFiller.setAttribute("cm-not-content", "true");
[142] Fix | Delete
// Covers bottom of gutter when coverGutterNextToScrollbar is on
[143] Fix | Delete
// and h scrollbar is present.
[144] Fix | Delete
d.gutterFiller = elt("div", null, "CodeMirror-gutter-filler");
[145] Fix | Delete
d.gutterFiller.setAttribute("cm-not-content", "true");
[146] Fix | Delete
// Will contain the actual code, positioned to cover the viewport.
[147] Fix | Delete
d.lineDiv = elt("div", null, "CodeMirror-code");
[148] Fix | Delete
// Elements are added to these to represent selection and cursors.
[149] Fix | Delete
d.selectionDiv = elt("div", null, null, "position: relative; z-index: 1");
[150] Fix | Delete
d.cursorDiv = elt("div", null, "CodeMirror-cursors");
[151] Fix | Delete
// A visibility: hidden element used to find the size of things.
[152] Fix | Delete
d.measure = elt("div", null, "CodeMirror-measure");
[153] Fix | Delete
// When lines outside of the viewport are measured, they are drawn in this.
[154] Fix | Delete
d.lineMeasure = elt("div", null, "CodeMirror-measure");
[155] Fix | Delete
// Wraps everything that needs to exist inside the vertically-padded coordinate system
[156] Fix | Delete
d.lineSpace = elt("div", [d.measure, d.lineMeasure, d.selectionDiv, d.cursorDiv, d.lineDiv],
[157] Fix | Delete
null, "position: relative; outline: none");
[158] Fix | Delete
// Moved around its parent to cover visible view.
[159] Fix | Delete
d.mover = elt("div", [elt("div", [d.lineSpace], "CodeMirror-lines")], null, "position: relative");
[160] Fix | Delete
// Set to the height of the document, allowing scrolling.
[161] Fix | Delete
d.sizer = elt("div", [d.mover], "CodeMirror-sizer");
[162] Fix | Delete
d.sizerWidth = null;
[163] Fix | Delete
// Behavior of elts with overflow: auto and padding is
[164] Fix | Delete
// inconsistent across browsers. This is used to ensure the
[165] Fix | Delete
// scrollable area is big enough.
[166] Fix | Delete
d.heightForcer = elt("div", null, null, "position: absolute; height: " + scrollerGap + "px; width: 1px;");
[167] Fix | Delete
// Will contain the gutters, if any.
[168] Fix | Delete
d.gutters = elt("div", null, "CodeMirror-gutters");
[169] Fix | Delete
d.lineGutter = null;
[170] Fix | Delete
// Actual scrollable element.
[171] Fix | Delete
d.scroller = elt("div", [d.sizer, d.heightForcer, d.gutters], "CodeMirror-scroll");
[172] Fix | Delete
d.scroller.setAttribute("tabIndex", "-1");
[173] Fix | Delete
// The element in which the editor lives.
[174] Fix | Delete
d.wrapper = elt("div", [d.scrollbarFiller, d.gutterFiller, d.scroller], "CodeMirror");
[175] Fix | Delete
[176] Fix | Delete
// Work around IE7 z-index bug (not perfect, hence IE7 not really being supported)
[177] Fix | Delete
if (ie && ie_version < 8) { d.gutters.style.zIndex = -1; d.scroller.style.paddingRight = 0; }
[178] Fix | Delete
if (!webkit && !(gecko && mobile)) d.scroller.draggable = true;
[179] Fix | Delete
[180] Fix | Delete
if (place) {
[181] Fix | Delete
if (place.appendChild) place.appendChild(d.wrapper);
[182] Fix | Delete
else place(d.wrapper);
[183] Fix | Delete
}
[184] Fix | Delete
[185] Fix | Delete
// Current rendered range (may be bigger than the view window).
[186] Fix | Delete
d.viewFrom = d.viewTo = doc.first;
[187] Fix | Delete
d.reportedViewFrom = d.reportedViewTo = doc.first;
[188] Fix | Delete
// Information about the rendered lines.
[189] Fix | Delete
d.view = [];
[190] Fix | Delete
d.renderedView = null;
[191] Fix | Delete
// Holds info about a single rendered line when it was rendered
[192] Fix | Delete
// for measurement, while not in view.
[193] Fix | Delete
d.externalMeasured = null;
[194] Fix | Delete
// Empty space (in pixels) above the view
[195] Fix | Delete
d.viewOffset = 0;
[196] Fix | Delete
d.lastWrapHeight = d.lastWrapWidth = 0;
[197] Fix | Delete
d.updateLineNumbers = null;
[198] Fix | Delete
[199] Fix | Delete
d.nativeBarWidth = d.barHeight = d.barWidth = 0;
[200] Fix | Delete
d.scrollbarsClipped = false;
[201] Fix | Delete
[202] Fix | Delete
// Used to only resize the line number gutter when necessary (when
[203] Fix | Delete
// the amount of lines crosses a boundary that makes its width change)
[204] Fix | Delete
d.lineNumWidth = d.lineNumInnerWidth = d.lineNumChars = null;
[205] Fix | Delete
// Set to true when a non-horizontal-scrolling line widget is
[206] Fix | Delete
// added. As an optimization, line widget aligning is skipped when
[207] Fix | Delete
// this is false.
[208] Fix | Delete
d.alignWidgets = false;
[209] Fix | Delete
[210] Fix | Delete
d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null;
[211] Fix | Delete
[212] Fix | Delete
// Tracks the maximum line length so that the horizontal scrollbar
[213] Fix | Delete
// can be kept static when scrolling.
[214] Fix | Delete
d.maxLine = null;
[215] Fix | Delete
d.maxLineLength = 0;
[216] Fix | Delete
d.maxLineChanged = false;
[217] Fix | Delete
[218] Fix | Delete
// Used for measuring wheel scrolling granularity
[219] Fix | Delete
d.wheelDX = d.wheelDY = d.wheelStartX = d.wheelStartY = null;
[220] Fix | Delete
[221] Fix | Delete
// True when shift is held down.
[222] Fix | Delete
d.shift = false;
[223] Fix | Delete
[224] Fix | Delete
// Used to track whether anything happened since the context menu
[225] Fix | Delete
// was opened.
[226] Fix | Delete
d.selForContextMenu = null;
[227] Fix | Delete
[228] Fix | Delete
d.activeTouch = null;
[229] Fix | Delete
[230] Fix | Delete
input.init(d);
[231] Fix | Delete
}
[232] Fix | Delete
[233] Fix | Delete
// STATE UPDATES
[234] Fix | Delete
[235] Fix | Delete
// Used to get the editor into a consistent state again when options change.
[236] Fix | Delete
[237] Fix | Delete
function loadMode(cm) {
[238] Fix | Delete
cm.doc.mode = CodeMirror.getMode(cm.options, cm.doc.modeOption);
[239] Fix | Delete
resetModeState(cm);
[240] Fix | Delete
}
[241] Fix | Delete
[242] Fix | Delete
function resetModeState(cm) {
[243] Fix | Delete
cm.doc.iter(function(line) {
[244] Fix | Delete
if (line.stateAfter) line.stateAfter = null;
[245] Fix | Delete
if (line.styles) line.styles = null;
[246] Fix | Delete
});
[247] Fix | Delete
cm.doc.frontier = cm.doc.first;
[248] Fix | Delete
startWorker(cm, 100);
[249] Fix | Delete
cm.state.modeGen++;
[250] Fix | Delete
if (cm.curOp) regChange(cm);
[251] Fix | Delete
}
[252] Fix | Delete
[253] Fix | Delete
function wrappingChanged(cm) {
[254] Fix | Delete
if (cm.options.lineWrapping) {
[255] Fix | Delete
addClass(cm.display.wrapper, "CodeMirror-wrap");
[256] Fix | Delete
cm.display.sizer.style.minWidth = "";
[257] Fix | Delete
cm.display.sizerWidth = null;
[258] Fix | Delete
} else {
[259] Fix | Delete
rmClass(cm.display.wrapper, "CodeMirror-wrap");
[260] Fix | Delete
findMaxLine(cm);
[261] Fix | Delete
}
[262] Fix | Delete
estimateLineHeights(cm);
[263] Fix | Delete
regChange(cm);
[264] Fix | Delete
clearCaches(cm);
[265] Fix | Delete
setTimeout(function(){updateScrollbars(cm);}, 100);
[266] Fix | Delete
}
[267] Fix | Delete
[268] Fix | Delete
// Returns a function that estimates the height of a line, to use as
[269] Fix | Delete
// first approximation until the line becomes visible (and is thus
[270] Fix | Delete
// properly measurable).
[271] Fix | Delete
function estimateHeight(cm) {
[272] Fix | Delete
var th = textHeight(cm.display), wrapping = cm.options.lineWrapping;
[273] Fix | Delete
var perLine = wrapping && Math.max(5, cm.display.scroller.clientWidth / charWidth(cm.display) - 3);
[274] Fix | Delete
return function(line) {
[275] Fix | Delete
if (lineIsHidden(cm.doc, line)) return 0;
[276] Fix | Delete
[277] Fix | Delete
var widgetsHeight = 0;
[278] Fix | Delete
if (line.widgets) for (var i = 0; i < line.widgets.length; i++) {
[279] Fix | Delete
if (line.widgets[i].height) widgetsHeight += line.widgets[i].height;
[280] Fix | Delete
}
[281] Fix | Delete
[282] Fix | Delete
if (wrapping)
[283] Fix | Delete
return widgetsHeight + (Math.ceil(line.text.length / perLine) || 1) * th;
[284] Fix | Delete
else
[285] Fix | Delete
return widgetsHeight + th;
[286] Fix | Delete
};
[287] Fix | Delete
}
[288] Fix | Delete
[289] Fix | Delete
function estimateLineHeights(cm) {
[290] Fix | Delete
var doc = cm.doc, est = estimateHeight(cm);
[291] Fix | Delete
doc.iter(function(line) {
[292] Fix | Delete
var estHeight = est(line);
[293] Fix | Delete
if (estHeight != line.height) updateLineHeight(line, estHeight);
[294] Fix | Delete
});
[295] Fix | Delete
}
[296] Fix | Delete
[297] Fix | Delete
function themeChanged(cm) {
[298] Fix | Delete
cm.display.wrapper.className = cm.display.wrapper.className.replace(/\s*cm-s-\S+/g, "") +
[299] Fix | Delete
cm.options.theme.replace(/(^|\s)\s*/g, " cm-s-");
[300] Fix | Delete
clearCaches(cm);
[301] Fix | Delete
}
[302] Fix | Delete
[303] Fix | Delete
function guttersChanged(cm) {
[304] Fix | Delete
updateGutters(cm);
[305] Fix | Delete
regChange(cm);
[306] Fix | Delete
setTimeout(function(){alignHorizontally(cm);}, 20);
[307] Fix | Delete
}
[308] Fix | Delete
[309] Fix | Delete
// Rebuild the gutter elements, ensure the margin to the left of the
[310] Fix | Delete
// code matches their width.
[311] Fix | Delete
function updateGutters(cm) {
[312] Fix | Delete
var gutters = cm.display.gutters, specs = cm.options.gutters;
[313] Fix | Delete
removeChildren(gutters);
[314] Fix | Delete
for (var i = 0; i < specs.length; ++i) {
[315] Fix | Delete
var gutterClass = specs[i];
[316] Fix | Delete
var gElt = gutters.appendChild(elt("div", null, "CodeMirror-gutter " + gutterClass));
[317] Fix | Delete
if (gutterClass == "CodeMirror-linenumbers") {
[318] Fix | Delete
cm.display.lineGutter = gElt;
[319] Fix | Delete
gElt.style.width = (cm.display.lineNumWidth || 1) + "px";
[320] Fix | Delete
}
[321] Fix | Delete
}
[322] Fix | Delete
gutters.style.display = i ? "" : "none";
[323] Fix | Delete
updateGutterSpace(cm);
[324] Fix | Delete
}
[325] Fix | Delete
[326] Fix | Delete
function updateGutterSpace(cm) {
[327] Fix | Delete
var width = cm.display.gutters.offsetWidth;
[328] Fix | Delete
cm.display.sizer.style.marginLeft = width + "px";
[329] Fix | Delete
}
[330] Fix | Delete
[331] Fix | Delete
// Compute the character length of a line, taking into account
[332] Fix | Delete
// collapsed ranges (see markText) that might hide parts, and join
[333] Fix | Delete
// other lines onto it.
[334] Fix | Delete
function lineLength(line) {
[335] Fix | Delete
if (line.height == 0) return 0;
[336] Fix | Delete
var len = line.text.length, merged, cur = line;
[337] Fix | Delete
while (merged = collapsedSpanAtStart(cur)) {
[338] Fix | Delete
var found = merged.find(0, true);
[339] Fix | Delete
cur = found.from.line;
[340] Fix | Delete
len += found.from.ch - found.to.ch;
[341] Fix | Delete
}
[342] Fix | Delete
cur = line;
[343] Fix | Delete
while (merged = collapsedSpanAtEnd(cur)) {
[344] Fix | Delete
var found = merged.find(0, true);
[345] Fix | Delete
len -= cur.text.length - found.from.ch;
[346] Fix | Delete
cur = found.to.line;
[347] Fix | Delete
len += cur.text.length - found.to.ch;
[348] Fix | Delete
}
[349] Fix | Delete
return len;
[350] Fix | Delete
}
[351] Fix | Delete
[352] Fix | Delete
// Find the longest line in the document.
[353] Fix | Delete
function findMaxLine(cm) {
[354] Fix | Delete
var d = cm.display, doc = cm.doc;
[355] Fix | Delete
d.maxLine = getLine(doc, doc.first);
[356] Fix | Delete
d.maxLineLength = lineLength(d.maxLine);
[357] Fix | Delete
d.maxLineChanged = true;
[358] Fix | Delete
doc.iter(function(line) {
[359] Fix | Delete
var len = lineLength(line);
[360] Fix | Delete
if (len > d.maxLineLength) {
[361] Fix | Delete
d.maxLineLength = len;
[362] Fix | Delete
d.maxLine = line;
[363] Fix | Delete
}
[364] Fix | Delete
});
[365] Fix | Delete
}
[366] Fix | Delete
[367] Fix | Delete
// Make sure the gutters options contains the element
[368] Fix | Delete
// "CodeMirror-linenumbers" when the lineNumbers option is true.
[369] Fix | Delete
function setGuttersForLineNumbers(options) {
[370] Fix | Delete
var found = indexOf(options.gutters, "CodeMirror-linenumbers");
[371] Fix | Delete
if (found == -1 && options.lineNumbers) {
[372] Fix | Delete
options.gutters = options.gutters.concat(["CodeMirror-linenumbers"]);
[373] Fix | Delete
} else if (found > -1 && !options.lineNumbers) {
[374] Fix | Delete
options.gutters = options.gutters.slice(0);
[375] Fix | Delete
options.gutters.splice(found, 1);
[376] Fix | Delete
}
[377] Fix | Delete
}
[378] Fix | Delete
[379] Fix | Delete
// SCROLLBARS
[380] Fix | Delete
[381] Fix | Delete
// Prepare DOM reads needed to update the scrollbars. Done in one
[382] Fix | Delete
// shot to minimize update/measure roundtrips.
[383] Fix | Delete
function measureForScrollbars(cm) {
[384] Fix | Delete
var d = cm.display, gutterW = d.gutters.offsetWidth;
[385] Fix | Delete
var docH = Math.round(cm.doc.height + paddingVert(cm.display));
[386] Fix | Delete
return {
[387] Fix | Delete
clientHeight: d.scroller.clientHeight,
[388] Fix | Delete
viewHeight: d.wrapper.clientHeight,
[389] Fix | Delete
scrollWidth: d.scroller.scrollWidth, clientWidth: d.scroller.clientWidth,
[390] Fix | Delete
viewWidth: d.wrapper.clientWidth,
[391] Fix | Delete
barLeft: cm.options.fixedGutter ? gutterW : 0,
[392] Fix | Delete
docHeight: docH,
[393] Fix | Delete
scrollHeight: docH + scrollGap(cm) + d.barHeight,
[394] Fix | Delete
nativeBarWidth: d.nativeBarWidth,
[395] Fix | Delete
gutterWidth: gutterW
[396] Fix | Delete
};
[397] Fix | Delete
}
[398] Fix | Delete
[399] Fix | Delete
function NativeScrollbars(place, scroll, cm) {
[400] Fix | Delete
this.cm = cm;
[401] Fix | Delete
var vert = this.vert = elt("div", [elt("div", null, null, "min-width: 1px")], "CodeMirror-vscrollbar");
[402] Fix | Delete
var horiz = this.horiz = elt("div", [elt("div", null, null, "height: 100%; min-height: 1px")], "CodeMirror-hscrollbar");
[403] Fix | Delete
place(vert); place(horiz);
[404] Fix | Delete
[405] Fix | Delete
on(vert, "scroll", function() {
[406] Fix | Delete
if (vert.clientHeight) scroll(vert.scrollTop, "vertical");
[407] Fix | Delete
});
[408] Fix | Delete
on(horiz, "scroll", function() {
[409] Fix | Delete
if (horiz.clientWidth) scroll(horiz.scrollLeft, "horizontal");
[410] Fix | Delete
});
[411] Fix | Delete
[412] Fix | Delete
this.checkedZeroWidth = false;
[413] Fix | Delete
// Need to set a minimum width to see the scrollbar on IE7 (but must not set it on IE8).
[414] Fix | Delete
if (ie && ie_version < 8) this.horiz.style.minHeight = this.vert.style.minWidth = "18px";
[415] Fix | Delete
}
[416] Fix | Delete
[417] Fix | Delete
NativeScrollbars.prototype = copyObj({
[418] Fix | Delete
update: function(measure) {
[419] Fix | Delete
var needsH = measure.scrollWidth > measure.clientWidth + 1;
[420] Fix | Delete
var needsV = measure.scrollHeight > measure.clientHeight + 1;
[421] Fix | Delete
var sWidth = measure.nativeBarWidth;
[422] Fix | Delete
[423] Fix | Delete
if (needsV) {
[424] Fix | Delete
this.vert.style.display = "block";
[425] Fix | Delete
this.vert.style.bottom = needsH ? sWidth + "px" : "0";
[426] Fix | Delete
var totalHeight = measure.viewHeight - (needsH ? sWidth : 0);
[427] Fix | Delete
// A bug in IE8 can cause this value to be negative, so guard it.
[428] Fix | Delete
this.vert.firstChild.style.height =
[429] Fix | Delete
Math.max(0, measure.scrollHeight - measure.clientHeight + totalHeight) + "px";
[430] Fix | Delete
} else {
[431] Fix | Delete
this.vert.style.display = "";
[432] Fix | Delete
this.vert.firstChild.style.height = "0";
[433] Fix | Delete
}
[434] Fix | Delete
[435] Fix | Delete
if (needsH) {
[436] Fix | Delete
this.horiz.style.display = "block";
[437] Fix | Delete
this.horiz.style.right = needsV ? sWidth + "px" : "0";
[438] Fix | Delete
this.horiz.style.left = measure.barLeft + "px";
[439] Fix | Delete
var totalWidth = measure.viewWidth - measure.barLeft - (needsV ? sWidth : 0);
[440] Fix | Delete
this.horiz.firstChild.style.width =
[441] Fix | Delete
(measure.scrollWidth - measure.clientWidth + totalWidth) + "px";
[442] Fix | Delete
} else {
[443] Fix | Delete
this.horiz.style.display = "";
[444] Fix | Delete
this.horiz.firstChild.style.width = "0";
[445] Fix | Delete
}
[446] Fix | Delete
[447] Fix | Delete
if (!this.checkedZeroWidth && measure.clientHeight > 0) {
[448] Fix | Delete
if (sWidth == 0) this.zeroWidthHack();
[449] Fix | Delete
this.checkedZeroWidth = true;
[450] Fix | Delete
}
[451] Fix | Delete
[452] Fix | Delete
return {right: needsV ? sWidth : 0, bottom: needsH ? sWidth : 0};
[453] Fix | Delete
},
[454] Fix | Delete
setScrollLeft: function(pos) {
[455] Fix | Delete
if (this.horiz.scrollLeft != pos) this.horiz.scrollLeft = pos;
[456] Fix | Delete
if (this.disableHoriz) this.enableZeroWidthBar(this.horiz, this.disableHoriz);
[457] Fix | Delete
},
[458] Fix | Delete
setScrollTop: function(pos) {
[459] Fix | Delete
if (this.vert.scrollTop != pos) this.vert.scrollTop = pos;
[460] Fix | Delete
if (this.disableVert) this.enableZeroWidthBar(this.vert, this.disableVert);
[461] Fix | Delete
},
[462] Fix | Delete
zeroWidthHack: function() {
[463] Fix | Delete
var w = mac && !mac_geMountainLion ? "12px" : "18px";
[464] Fix | Delete
this.horiz.style.height = this.vert.style.width = w;
[465] Fix | Delete
this.horiz.style.pointerEvents = this.vert.style.pointerEvents = "none";
[466] Fix | Delete
this.disableHoriz = new Delayed;
[467] Fix | Delete
this.disableVert = new Delayed;
[468] Fix | Delete
},
[469] Fix | Delete
enableZeroWidthBar: function(bar, delay) {
[470] Fix | Delete
bar.style.pointerEvents = "auto";
[471] Fix | Delete
function maybeDisable() {
[472] Fix | Delete
// To find out whether the scrollbar is still visible, we
[473] Fix | Delete
// check whether the element under the pixel in the bottom
[474] Fix | Delete
// left corner of the scrollbar box is the scrollbar box
[475] Fix | Delete
// itself (when the bar is still visible) or its filler child
[476] Fix | Delete
// (when the bar is hidden). If it is still visible, we keep
[477] Fix | Delete
// it enabled, if it's hidden, we disable pointer events.
[478] Fix | Delete
var box = bar.getBoundingClientRect();
[479] Fix | Delete
var elt = document.elementFromPoint(box.left + 1, box.bottom - 1);
[480] Fix | Delete
if (elt != bar) bar.style.pointerEvents = "none";
[481] Fix | Delete
else delay.set(1000, maybeDisable);
[482] Fix | Delete
}
[483] Fix | Delete
delay.set(1000, maybeDisable);
[484] Fix | Delete
},
[485] Fix | Delete
clear: function() {
[486] Fix | Delete
var parent = this.horiz.parentNode;
[487] Fix | Delete
parent.removeChild(this.horiz);
[488] Fix | Delete
parent.removeChild(this.vert);
[489] Fix | Delete
}
[490] Fix | Delete
}, NativeScrollbars.prototype);
[491] Fix | Delete
[492] Fix | Delete
function NullScrollbars() {}
[493] Fix | Delete
[494] Fix | Delete
NullScrollbars.prototype = copyObj({
[495] Fix | Delete
update: function() { return {bottom: 0, right: 0}; },
[496] Fix | Delete
setScrollLeft: function() {},
[497] Fix | Delete
setScrollTop: function() {},
[498] Fix | Delete
clear: function() {}
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function