function wrapLineNumberDiv(place) {
return function(node) {
- var container = document.createElement("DIV"),
- nums = document.createElement("DIV"),
- scroller = document.createElement("DIV");
+ var container = document.createElement("div"),
+ nums = document.createElement("div"),
+ scroller = document.createElement("div");
container.style.position = "relative";
nums.style.position = "absolute";
nums.style.height = "100%";
var win = frame.contentWindow, doc = win.document,
nums = frame.nextSibling, scroller = nums.firstChild;
- var nextNum = 1, barWidth = null;
- function sizeBar() {
- for (var root = frame; root.parentNode; root = root.parentNode);
- if (root != document || !win.Editor) {
- clearInterval(sizeInterval);
- return;
- }
-
- if (nums.offsetWidth != barWidth) {
- barWidth = nums.offsetWidth;
- nums.style.left = "-" + (frame.parentNode.style.marginLeft = barWidth + "px");
- }
- }
+ var nextNum = 1;
+
function update() {
var diff = 20 + Math.max(doc.body.offsetHeight, frame.offsetHeight) - scroller.offsetHeight;
for (var n = Math.ceil(diff / 10); n > 0; n--) {
- var div = document.createElement("DIV");
+ var div = document.createElement("div");
div.appendChild(document.createTextNode(nextNum++));
scroller.appendChild(div);
}
nums.scrollTop = doc.body.scrollTop || doc.documentElement.scrollTop || 0;
}
- sizeBar();
+
update();
win.addEventHandler(win, "scroll", update);
- win.addEventHandler(win, "resize", update);
- var sizeInterval = setInterval(sizeBar, 500);
+ win.addEventHandler(win, "resize", update);
}
function CodeMirror(place, options) {
this.options = options = options || {};
setDefaults(options, CodeMirrorConfig);
- var frame = this.frame = document.createElement("IFRAME");
+ var frame = this.frame = document.createElement("iframe");
if (options.iframeClass) frame.className = options.iframeClass;
frame.frameBorder = 0;
frame.src = "javascript:false;";
var node = place;
place = function(n){node.appendChild(n);};
}
-
if (options.lineNumbers) place = wrapLineNumberDiv(place);
place(frame);
getCode: function() {return this.editor.getCode();},
setCode: function(code) {this.editor.importCode(code);},
- selection: function() {this.focusIfIE(); return this.editor.selectedText();},
+ selection: function() {return this.editor.selectedText();},
reindent: function() {this.editor.reindent();},
- reindentSelection: function() {this.focusIfIE(); this.editor.reindentSelection(null);},
+ reindentSelection: function() {this.editor.reindentSelection(null);},
- focusIfIE: function() {
- // in IE, a lot of selection-related functionality only works when the frame is focused
- if (this.win.select.ie_selection) this.focus();
- },
focus: function() {
this.win.focus();
if (this.editor.selectionSnapshot) // IE hack
setParser: function(name) {this.editor.setParser(name);},
- cursorPosition: function(start) {this.focusIfIE(); return this.editor.cursorPosition(start);},
+ cursorPosition: function(start) {
+ if (this.win.select.ie_selection) this.focus();
+ return this.editor.cursorPosition(start);
+ },
firstLine: function() {return this.editor.firstLine();},
lastLine: function() {return this.editor.lastLine();},
nextLine: function(line) {return this.editor.nextLine(line);},