introduce "ace" namespace and unify OO style
This commit is contained in:
parent
72b556efaa
commit
84ec636d7d
16 changed files with 835 additions and 813 deletions
|
|
@ -40,7 +40,8 @@
|
||||||
|
|
||||||
<script type="text/javascript" charset="utf-8">
|
<script type="text/javascript" charset="utf-8">
|
||||||
|
|
||||||
var editor = new Editor(new TextDocument("Juhu Kinners"), new VirtualRenderer("container"));
|
var container = document.getElementById("container");
|
||||||
|
var editor = new ace.Editor(new ace.TextDocument("Juhu Kinners"), new ace.VirtualRenderer(container));
|
||||||
|
|
||||||
window.onresize = function() {
|
window.onresize = function() {
|
||||||
editor.resize();
|
editor.resize();
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ button.onclick = function()
|
||||||
console.log("update", firstLine, lastLine);
|
console.log("update", firstLine, lastLine);
|
||||||
};
|
};
|
||||||
|
|
||||||
var tokenizer = new BackgroundTokenizer(new Tokenizer(JavaScript.RULES), onUpdate, onComplete);
|
var tokenizer = new ace.BackgroundTokenizer(new ace.Tokenizer(ace.JavaScript.RULES), onUpdate, onComplete);
|
||||||
tokenizer.setLines(text.value.split(/[\n\r]/));
|
tokenizer.setLines(text.value.split(/[\n\r]/));
|
||||||
tokenizer.start();
|
tokenizer.start();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,11 +14,11 @@
|
||||||
Juhu Kinners
|
Juhu Kinners
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="../src/lib.js" type="text/javascript" charset="utf-8"></script>
|
<script src="../src/ace.js" type="text/javascript" charset="utf-8"></script>
|
||||||
<script type="text/javascript" charset="utf-8">
|
<script type="text/javascript" charset="utf-8">
|
||||||
|
|
||||||
var el = document.getElementById("juhu");
|
var el = document.getElementById("juhu");
|
||||||
lib.addTripleClickListener(el, function() {
|
ace.addTripleClickListener(el, function() {
|
||||||
console.log("triple");
|
console.log("triple");
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
function BackgroundTokenizer(tokenizer, onUpdate, onComplete)
|
if (!window.ace) ace = {};
|
||||||
|
|
||||||
|
ace.BackgroundTokenizer = function(tokenizer, onUpdate, onComplete)
|
||||||
{
|
{
|
||||||
this.running = false;
|
this.running = false;
|
||||||
this.textLines = [];
|
this.textLines = [];
|
||||||
|
|
@ -47,7 +49,7 @@ function BackgroundTokenizer(tokenizer, onUpdate, onComplete)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
BackgroundTokenizer.prototype.setLines = function(textLines)
|
ace.BackgroundTokenizer.prototype.setLines = function(textLines)
|
||||||
{
|
{
|
||||||
this.textLines = textLines;
|
this.textLines = textLines;
|
||||||
this.lines = [];
|
this.lines = [];
|
||||||
|
|
@ -55,7 +57,7 @@ BackgroundTokenizer.prototype.setLines = function(textLines)
|
||||||
this.stop();
|
this.stop();
|
||||||
};
|
};
|
||||||
|
|
||||||
BackgroundTokenizer.prototype.start = function(startRow)
|
ace.BackgroundTokenizer.prototype.start = function(startRow)
|
||||||
{
|
{
|
||||||
this.currentLine = Math.min(startRow || 0, this.currentLine, this.textLines.length);
|
this.currentLine = Math.min(startRow || 0, this.currentLine, this.textLines.length);
|
||||||
this.lines.splice(startRow, this.lines.length);
|
this.lines.splice(startRow, this.lines.length);
|
||||||
|
|
@ -67,11 +69,11 @@ BackgroundTokenizer.prototype.start = function(startRow)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
BackgroundTokenizer.prototype.stop = function() {
|
ace.BackgroundTokenizer.prototype.stop = function() {
|
||||||
this.running = false;
|
this.running = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
BackgroundTokenizer.prototype.getTokens = function(row)
|
ace.BackgroundTokenizer.prototype.getTokens = function(row)
|
||||||
{
|
{
|
||||||
if (this.lines[row]) {
|
if (this.lines[row]) {
|
||||||
return this.lines[row].tokens;
|
return this.lines[row].tokens;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
function CursorLayer(parentEl)
|
if (!window.ace) ace = {};
|
||||||
|
|
||||||
|
ace.CursorLayer = function(parentEl)
|
||||||
{
|
{
|
||||||
this.element = document.createElement("div");
|
this.element = document.createElement("div");
|
||||||
this.element.className = "layer cursor-layer";
|
this.element.className = "layer cursor-layer";
|
||||||
|
|
@ -10,7 +12,7 @@ function CursorLayer(parentEl)
|
||||||
this.isVisible = false;
|
this.isVisible = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CursorLayer.prototype.setCursor = function(position)
|
ace.CursorLayer.prototype.setCursor = function(position)
|
||||||
{
|
{
|
||||||
this.position = {
|
this.position = {
|
||||||
row: position.row,
|
row: position.row,
|
||||||
|
|
@ -18,7 +20,7 @@ CursorLayer.prototype.setCursor = function(position)
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
CursorLayer.prototype.hideCursor = function()
|
ace.CursorLayer.prototype.hideCursor = function()
|
||||||
{
|
{
|
||||||
this.isVisible = false;
|
this.isVisible = false;
|
||||||
if (this.cursor.parentNode) {
|
if (this.cursor.parentNode) {
|
||||||
|
|
@ -27,7 +29,7 @@ CursorLayer.prototype.hideCursor = function()
|
||||||
clearInterval(this.blinkId);
|
clearInterval(this.blinkId);
|
||||||
};
|
};
|
||||||
|
|
||||||
CursorLayer.prototype.showCursor = function()
|
ace.CursorLayer.prototype.showCursor = function()
|
||||||
{
|
{
|
||||||
this.isVisible = true;
|
this.isVisible = true;
|
||||||
this.element.appendChild(this.cursor);
|
this.element.appendChild(this.cursor);
|
||||||
|
|
@ -43,11 +45,11 @@ CursorLayer.prototype.showCursor = function()
|
||||||
}, 1000);
|
}, 1000);
|
||||||
};
|
};
|
||||||
|
|
||||||
CursorLayer.prototype.getPixelPosition = function() {
|
ace.CursorLayer.prototype.getPixelPosition = function() {
|
||||||
return this.pixelPos || {left: 0, top:0};
|
return this.pixelPos || {left: 0, top:0};
|
||||||
}
|
}
|
||||||
|
|
||||||
CursorLayer.prototype.update = function(config)
|
ace.CursorLayer.prototype.update = function(config)
|
||||||
{
|
{
|
||||||
if (!this.position) return;
|
if (!this.position) return;
|
||||||
|
|
||||||
|
|
|
||||||
973
src/Editor.js
973
src/Editor.js
File diff suppressed because it is too large
Load diff
|
|
@ -1,11 +1,13 @@
|
||||||
function GutterLayer(parentEl)
|
if (!window.ace) ace = {};
|
||||||
|
|
||||||
|
ace.GutterLayer = function(parentEl)
|
||||||
{
|
{
|
||||||
this.element = document.createElement("div");
|
this.element = document.createElement("div");
|
||||||
this.element.className = "layer gutter-layer";
|
this.element.className = "layer gutter-layer";
|
||||||
parentEl.appendChild(this.element);
|
parentEl.appendChild(this.element);
|
||||||
}
|
}
|
||||||
|
|
||||||
GutterLayer.prototype.update = function(config)
|
ace.GutterLayer.prototype.update = function(config)
|
||||||
{
|
{
|
||||||
var html = [];
|
var html = [];
|
||||||
for (var i=config.firstRow; i<=config.lastRow; i++)
|
for (var i=config.firstRow; i<=config.lastRow; i++)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
|
if (!window.ace) ace = {};
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
window.JavaScript = {};
|
ace.JavaScript = {};
|
||||||
|
|
||||||
var keywords = {
|
var keywords = {
|
||||||
"break" : 1,
|
"break" : 1,
|
||||||
|
|
@ -31,7 +33,7 @@ var keywords = {
|
||||||
// regexp must not have capturing parentheses
|
// regexp must not have capturing parentheses
|
||||||
// regexps are ordered -> the first match is used
|
// regexps are ordered -> the first match is used
|
||||||
|
|
||||||
JavaScript.RULES = {
|
ace.JavaScript.RULES = {
|
||||||
start :
|
start :
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
function MarkerLayer(parentEl)
|
if (!window.ace) ace = {};
|
||||||
|
|
||||||
|
ace.MarkerLayer = function(parentEl)
|
||||||
{
|
{
|
||||||
this.element = document.createElement("div");
|
this.element = document.createElement("div");
|
||||||
this.element.className = "layer marker-layer";
|
this.element.className = "layer marker-layer";
|
||||||
|
|
@ -8,7 +10,7 @@ function MarkerLayer(parentEl)
|
||||||
this._markerId = 1;
|
this._markerId = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
MarkerLayer.prototype.addMarker = function(range, clazz)
|
ace.MarkerLayer.prototype.addMarker = function(range, clazz)
|
||||||
{
|
{
|
||||||
var id = this._markerId++;
|
var id = this._markerId++;
|
||||||
this.markers[id] = {
|
this.markers[id] = {
|
||||||
|
|
@ -21,7 +23,7 @@ MarkerLayer.prototype.addMarker = function(range, clazz)
|
||||||
return id;
|
return id;
|
||||||
};
|
};
|
||||||
|
|
||||||
MarkerLayer.prototype.removeMarker = function(markerId)
|
ace.MarkerLayer.prototype.removeMarker = function(markerId)
|
||||||
{
|
{
|
||||||
var marker = this.markers[markerId];
|
var marker = this.markers[markerId];
|
||||||
if (marker) {
|
if (marker) {
|
||||||
|
|
@ -30,7 +32,7 @@ MarkerLayer.prototype.removeMarker = function(markerId)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
MarkerLayer.prototype.update = function(config)
|
ace.MarkerLayer.prototype.update = function(config)
|
||||||
{
|
{
|
||||||
var config = config || this.config;
|
var config = config || this.config;
|
||||||
if (!config) return;
|
if (!config) return;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
function TextDocument(text)
|
if (!window.ace) ace = {};
|
||||||
|
|
||||||
|
ace.TextDocument = function(text)
|
||||||
{
|
{
|
||||||
this.lines = this._split(text);
|
this.lines = this._split(text);
|
||||||
this.modified = true;
|
this.modified = true;
|
||||||
|
|
@ -6,217 +8,214 @@ function TextDocument(text)
|
||||||
this.listeners = [];
|
this.listeners = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
TextDocument.prototype =
|
ace.TextDocument.prototype._split = function(text) {
|
||||||
|
return text.split(/[\n\r]/)
|
||||||
|
};
|
||||||
|
|
||||||
|
ace.TextDocument.prototype.addChangeListener = function(listener) {
|
||||||
|
this.listeners.push(listener);
|
||||||
|
};
|
||||||
|
|
||||||
|
ace.TextDocument.prototype.fireChangeEvent = function(firstRow, lastRow)
|
||||||
{
|
{
|
||||||
_split : function(text) {
|
for (var i=0; i < this.listeners.length; i++) {
|
||||||
return text.split(/[\n\r]/)
|
this.listeners[i](firstRow, lastRow);
|
||||||
},
|
};
|
||||||
|
};
|
||||||
|
|
||||||
addChangeListener : function(listener) {
|
ace.TextDocument.prototype.getWidth = function()
|
||||||
this.listeners.push(listener);
|
{
|
||||||
},
|
if (this.modified)
|
||||||
|
|
||||||
fireChangeEvent : function(firstRow, lastRow)
|
|
||||||
{
|
{
|
||||||
for (var i=0; i < this.listeners.length; i++) {
|
this.modified = false;
|
||||||
this.listeners[i](firstRow, lastRow);
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
getWidth : function()
|
var lines = this.lines;
|
||||||
{
|
var longestLine = 0;
|
||||||
if (this.modified)
|
for (var i=0; i < lines.length; i++) {
|
||||||
{
|
longestLine = Math.max(longestLine, lines[i].length);
|
||||||
this.modified = false;
|
|
||||||
|
|
||||||
var lines = this.lines;
|
|
||||||
var longestLine = 0;
|
|
||||||
for (var i=0; i < lines.length; i++) {
|
|
||||||
longestLine = Math.max(longestLine, lines[i].length);
|
|
||||||
}
|
|
||||||
this.width = longestLine;
|
|
||||||
}
|
}
|
||||||
return this.width;
|
this.width = longestLine;
|
||||||
},
|
|
||||||
|
|
||||||
getLine : function(row) {
|
|
||||||
return this.lines[row] || "";
|
|
||||||
},
|
|
||||||
|
|
||||||
keywords : {
|
|
||||||
"break" : 1,
|
|
||||||
"case" : 1,
|
|
||||||
"catch" : 1,
|
|
||||||
"continue" : 1,
|
|
||||||
"default" : 1,
|
|
||||||
"delete" : 1,
|
|
||||||
"do" : 1,
|
|
||||||
"else" : 1,
|
|
||||||
"finally" : 1,
|
|
||||||
"for" : 1,
|
|
||||||
"function" : 1,
|
|
||||||
"if" : 1,
|
|
||||||
"in" : 1,
|
|
||||||
"instanceof" : 1,
|
|
||||||
"new" : 1,
|
|
||||||
"return" : 1,
|
|
||||||
"switch" : 1,
|
|
||||||
"throw" : 1,
|
|
||||||
"try" : 1,
|
|
||||||
"typeof" : 1,
|
|
||||||
"var" : 1,
|
|
||||||
"while" : 1,
|
|
||||||
"with" : 1
|
|
||||||
},
|
|
||||||
|
|
||||||
getLineTokens : function(row)
|
|
||||||
{
|
|
||||||
var tokens = [];
|
|
||||||
|
|
||||||
var re = /(?:(\s+)|("[^"]*")|('[^']*')|([\[\]\(\)\{\}])|([a-zA-Z_][a-zA-Z0-9_]*)|(\/\/.*)|(.))/g
|
|
||||||
re.lastIndex = 0;
|
|
||||||
|
|
||||||
var match;
|
|
||||||
var line = this.getLine(row);
|
|
||||||
while (match = re.exec(line))
|
|
||||||
{
|
|
||||||
var token = {
|
|
||||||
type: "text",
|
|
||||||
value: match[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
if (match[2] || match[3]) {
|
|
||||||
token.type = "string";
|
|
||||||
} else if (match[5] && this.keywords[match[5]]) {
|
|
||||||
token.type = "keyword";
|
|
||||||
} else if (match[6]) {
|
|
||||||
token.type = "comment";
|
|
||||||
}
|
|
||||||
|
|
||||||
tokens.push(token);
|
|
||||||
};
|
|
||||||
|
|
||||||
return tokens;
|
|
||||||
},
|
|
||||||
|
|
||||||
getLength : function() {
|
|
||||||
return this.lines.length;
|
|
||||||
},
|
|
||||||
|
|
||||||
getTextRange : function(range)
|
|
||||||
{
|
|
||||||
if (range.start.row == range.end.row) {
|
|
||||||
return this.lines[range.start.row].substring(range.start.column, range.end.column);
|
|
||||||
} else {
|
|
||||||
var lines = [];
|
|
||||||
lines.push(this.lines[range.start.row].substring(range.start.column));
|
|
||||||
lines.push.apply(lines, this.lines.slice(range.start.row+1, range.end.row));
|
|
||||||
lines.push(this.lines[range.end.row].substring(0, range.end.column));
|
|
||||||
|
|
||||||
return lines.join("\n");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
insert : function(position, text)
|
|
||||||
{
|
|
||||||
var end = this._insert(position, text);
|
|
||||||
this.fireChangeEvent(
|
|
||||||
position.row,
|
|
||||||
position.row == end.row ? position.row : undefined
|
|
||||||
);
|
|
||||||
return end;
|
|
||||||
},
|
|
||||||
|
|
||||||
_insert : function(position, text)
|
|
||||||
{
|
|
||||||
this.modified = true;
|
|
||||||
|
|
||||||
var newLines = this._split(text);
|
|
||||||
|
|
||||||
if (text == "\n")
|
|
||||||
{
|
|
||||||
var line = this.lines[position.row] || "";
|
|
||||||
this.lines[position.row] = line.substring(0, position.column);
|
|
||||||
this.lines.splice(position.row+1, 0, line.substring(position.column));
|
|
||||||
|
|
||||||
return {
|
|
||||||
row: position.row + 1,
|
|
||||||
column: 0
|
|
||||||
};
|
|
||||||
}
|
|
||||||
else if (newLines.length == 1)
|
|
||||||
{
|
|
||||||
var line = this.lines[position.row] || "";
|
|
||||||
this.lines[position.row] = line.substring(0, position.column) + text + line.substring(position.column);
|
|
||||||
|
|
||||||
return {
|
|
||||||
row: position.row,
|
|
||||||
column: position.column+text.length
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var line = this.lines[position.row] || "";
|
|
||||||
|
|
||||||
this.lines[position.row] = line.substring(0, position.column) + newLines[0];
|
|
||||||
this.lines[position.row+1] = newLines[newLines.length-1] + line.substring(position.column);
|
|
||||||
|
|
||||||
if (newLines.length > 2)
|
|
||||||
{
|
|
||||||
var args = [position.row + 1, 0]
|
|
||||||
args.push.apply(args, newLines.slice(1, -1));
|
|
||||||
this.lines.splice.apply(this.lines, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
row: position.row + newLines.length - 1,
|
|
||||||
column: newLines[newLines.length-1].length
|
|
||||||
};
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
remove : function(range)
|
|
||||||
{
|
|
||||||
var end = this._remove(range);
|
|
||||||
|
|
||||||
this.fireChangeEvent(
|
|
||||||
range.start.row,
|
|
||||||
range.end.row == range.start.row ? range.start.row : undefined
|
|
||||||
);
|
|
||||||
return end;
|
|
||||||
},
|
|
||||||
|
|
||||||
_remove : function(range)
|
|
||||||
{
|
|
||||||
this.modified = true;
|
|
||||||
|
|
||||||
var firstRow = range.start.row;
|
|
||||||
var lastRow = range.end.row;
|
|
||||||
|
|
||||||
var row =
|
|
||||||
this.lines[firstRow].substring(0, range.start.column) +
|
|
||||||
this.lines[lastRow].substring(range.end.column);
|
|
||||||
|
|
||||||
this.lines.splice(firstRow, lastRow-firstRow+1, row);
|
|
||||||
|
|
||||||
return range.start;
|
|
||||||
},
|
|
||||||
|
|
||||||
replace : function(range, text)
|
|
||||||
{
|
|
||||||
this._remove(range);
|
|
||||||
if (text) {
|
|
||||||
var end = this._insert(range.start, text);
|
|
||||||
} else {
|
|
||||||
end = range.start;
|
|
||||||
}
|
|
||||||
|
|
||||||
var lastRemoved = range.end.column == 0 ? range.end.column-1 : range.end.column;
|
|
||||||
this.fireChangeEvent(
|
|
||||||
range.start.row,
|
|
||||||
lastRemoved == end.row ? lastRemoved : undefined
|
|
||||||
);
|
|
||||||
|
|
||||||
return end;
|
|
||||||
}
|
}
|
||||||
|
return this.width;
|
||||||
|
};
|
||||||
|
|
||||||
|
ace.TextDocument.prototype.getLine = function(row) {
|
||||||
|
return this.lines[row] || "";
|
||||||
|
};
|
||||||
|
|
||||||
|
ace.TextDocument.prototype.keywords = {
|
||||||
|
"break" : 1,
|
||||||
|
"case" : 1,
|
||||||
|
"catch" : 1,
|
||||||
|
"continue" : 1,
|
||||||
|
"default" : 1,
|
||||||
|
"delete" : 1,
|
||||||
|
"do" : 1,
|
||||||
|
"else" : 1,
|
||||||
|
"finally" : 1,
|
||||||
|
"for" : 1,
|
||||||
|
"function" : 1,
|
||||||
|
"if" : 1,
|
||||||
|
"in" : 1,
|
||||||
|
"instanceof" : 1,
|
||||||
|
"new" : 1,
|
||||||
|
"return" : 1,
|
||||||
|
"switch" : 1,
|
||||||
|
"throw" : 1,
|
||||||
|
"try" : 1,
|
||||||
|
"typeof" : 1,
|
||||||
|
"var" : 1,
|
||||||
|
"while" : 1,
|
||||||
|
"with" : 1
|
||||||
|
};
|
||||||
|
|
||||||
|
ace.TextDocument.prototype.getLineTokens = function(row)
|
||||||
|
{
|
||||||
|
var tokens = [];
|
||||||
|
|
||||||
|
var re = /(?:(\s+)|("[^"]*")|('[^']*')|([\[\]\(\)\{\}])|([a-zA-Z_][a-zA-Z0-9_]*)|(\/\/.*)|(.))/g
|
||||||
|
re.lastIndex = 0;
|
||||||
|
|
||||||
|
var match;
|
||||||
|
var line = this.getLine(row);
|
||||||
|
while (match = re.exec(line))
|
||||||
|
{
|
||||||
|
var token = {
|
||||||
|
type: "text",
|
||||||
|
value: match[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
if (match[2] || match[3]) {
|
||||||
|
token.type = "string";
|
||||||
|
} else if (match[5] && this.keywords[match[5]]) {
|
||||||
|
token.type = "keyword";
|
||||||
|
} else if (match[6]) {
|
||||||
|
token.type = "comment";
|
||||||
|
}
|
||||||
|
|
||||||
|
tokens.push(token);
|
||||||
|
};
|
||||||
|
|
||||||
|
return tokens;
|
||||||
|
};
|
||||||
|
|
||||||
|
ace.TextDocument.prototype.getLength = function() {
|
||||||
|
return this.lines.length;
|
||||||
|
};
|
||||||
|
|
||||||
|
ace.TextDocument.prototype.getTextRange = function(range)
|
||||||
|
{
|
||||||
|
if (range.start.row == range.end.row) {
|
||||||
|
return this.lines[range.start.row].substring(range.start.column, range.end.column);
|
||||||
|
} else {
|
||||||
|
var lines = [];
|
||||||
|
lines.push(this.lines[range.start.row].substring(range.start.column));
|
||||||
|
lines.push.apply(lines, this.lines.slice(range.start.row+1, range.end.row));
|
||||||
|
lines.push(this.lines[range.end.row].substring(0, range.end.column));
|
||||||
|
|
||||||
|
return lines.join("\n");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ace.TextDocument.prototype.insert = function(position, text)
|
||||||
|
{
|
||||||
|
var end = this._insert(position, text);
|
||||||
|
this.fireChangeEvent(
|
||||||
|
position.row,
|
||||||
|
position.row == end.row ? position.row : undefined
|
||||||
|
);
|
||||||
|
return end;
|
||||||
|
};
|
||||||
|
|
||||||
|
ace.TextDocument.prototype._insert = function(position, text)
|
||||||
|
{
|
||||||
|
this.modified = true;
|
||||||
|
|
||||||
|
var newLines = this._split(text);
|
||||||
|
|
||||||
|
if (text == "\n")
|
||||||
|
{
|
||||||
|
var line = this.lines[position.row] || "";
|
||||||
|
this.lines[position.row] = line.substring(0, position.column);
|
||||||
|
this.lines.splice(position.row+1, 0, line.substring(position.column));
|
||||||
|
|
||||||
|
return {
|
||||||
|
row: position.row + 1,
|
||||||
|
column: 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else if (newLines.length == 1)
|
||||||
|
{
|
||||||
|
var line = this.lines[position.row] || "";
|
||||||
|
this.lines[position.row] = line.substring(0, position.column) + text + line.substring(position.column);
|
||||||
|
|
||||||
|
return {
|
||||||
|
row: position.row,
|
||||||
|
column: position.column+text.length
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var line = this.lines[position.row] || "";
|
||||||
|
|
||||||
|
this.lines[position.row] = line.substring(0, position.column) + newLines[0];
|
||||||
|
this.lines[position.row+1] = newLines[newLines.length-1] + line.substring(position.column);
|
||||||
|
|
||||||
|
if (newLines.length > 2)
|
||||||
|
{
|
||||||
|
var args = [position.row + 1, 0]
|
||||||
|
args.push.apply(args, newLines.slice(1, -1));
|
||||||
|
this.lines.splice.apply(this.lines, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
row: position.row + newLines.length - 1,
|
||||||
|
column: newLines[newLines.length-1].length
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ace.TextDocument.prototype.remove = function(range)
|
||||||
|
{
|
||||||
|
var end = this._remove(range);
|
||||||
|
|
||||||
|
this.fireChangeEvent(
|
||||||
|
range.start.row,
|
||||||
|
range.end.row == range.start.row ? range.start.row : undefined
|
||||||
|
);
|
||||||
|
return end;
|
||||||
|
};
|
||||||
|
|
||||||
|
ace.TextDocument.prototype._remove = function(range)
|
||||||
|
{
|
||||||
|
this.modified = true;
|
||||||
|
|
||||||
|
var firstRow = range.start.row;
|
||||||
|
var lastRow = range.end.row;
|
||||||
|
|
||||||
|
var row =
|
||||||
|
this.lines[firstRow].substring(0, range.start.column) +
|
||||||
|
this.lines[lastRow].substring(range.end.column);
|
||||||
|
|
||||||
|
this.lines.splice(firstRow, lastRow-firstRow+1, row);
|
||||||
|
|
||||||
|
return range.start;
|
||||||
|
};
|
||||||
|
|
||||||
|
ace.TextDocument.prototype.replace = function(range, text)
|
||||||
|
{
|
||||||
|
this._remove(range);
|
||||||
|
if (text) {
|
||||||
|
var end = this._insert(range.start, text);
|
||||||
|
} else {
|
||||||
|
end = range.start;
|
||||||
|
}
|
||||||
|
|
||||||
|
var lastRemoved = range.end.column == 0 ? range.end.column-1 : range.end.column;
|
||||||
|
this.fireChangeEvent(
|
||||||
|
range.start.row,
|
||||||
|
lastRemoved == end.row ? lastRemoved : undefined
|
||||||
|
);
|
||||||
|
|
||||||
|
return end;
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
function TextInput(parentNode, host) {
|
if (!window.ace) ace = {};
|
||||||
|
|
||||||
|
ace.TextInput = function(parentNode, host) {
|
||||||
|
|
||||||
var text = document.createElement("textarea");
|
var text = document.createElement("textarea");
|
||||||
var style = text.style;
|
var style = text.style;
|
||||||
|
|
@ -51,23 +53,23 @@ function TextInput(parentNode, host) {
|
||||||
text.select();
|
text.select();
|
||||||
}
|
}
|
||||||
|
|
||||||
lib.addListener(text, "keypress", onTextInput, false);
|
ace.addListener(text, "keypress", onTextInput, false);
|
||||||
lib.addListener(text, "textInput", onTextInput, false);
|
ace.addListener(text, "textInput", onTextInput, false);
|
||||||
lib.addListener(text, "paste", onTextInput, false);
|
ace.addListener(text, "paste", onTextInput, false);
|
||||||
lib.addListener(text, "propertychange", onTextInput, false);
|
ace.addListener(text, "propertychange", onTextInput, false);
|
||||||
|
|
||||||
lib.addListener(text, "copy", onCopy, false);
|
ace.addListener(text, "copy", onCopy, false);
|
||||||
lib.addListener(text, "cut", onCut, false);
|
ace.addListener(text, "cut", onCut, false);
|
||||||
|
|
||||||
lib.addListener(text, "compositionstart", onCompositionStart, false);
|
ace.addListener(text, "compositionstart", onCompositionStart, false);
|
||||||
lib.addListener(text, "compositionupdate", onCompositionUpdate, false);
|
ace.addListener(text, "compositionupdate", onCompositionUpdate, false);
|
||||||
lib.addListener(text, "compositionend", onCompositionEnd, false);
|
ace.addListener(text, "compositionend", onCompositionEnd, false);
|
||||||
|
|
||||||
lib.addListener(text, "blur", function() {
|
ace.addListener(text, "blur", function() {
|
||||||
host.onBlur();
|
host.onBlur();
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
lib.addListener(text, "focus", function() {
|
ace.addListener(text, "focus", function() {
|
||||||
host.onFocus();
|
host.onFocus();
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
function TextLayer(parentEl)
|
if (!window.ace) ace = {};
|
||||||
|
|
||||||
|
ace.TextLayer = function(parentEl)
|
||||||
{
|
{
|
||||||
this.element = document.createElement("div");
|
this.element = document.createElement("div");
|
||||||
this.element.className = "layer text-layer";
|
this.element.className = "layer text-layer";
|
||||||
|
|
@ -7,19 +9,19 @@ function TextLayer(parentEl)
|
||||||
this._measureSizes();
|
this._measureSizes();
|
||||||
}
|
}
|
||||||
|
|
||||||
TextLayer.prototype.setTokenizer = function(tokenizer) {
|
ace.TextLayer.prototype.setTokenizer = function(tokenizer) {
|
||||||
this.tokenizer = tokenizer;
|
this.tokenizer = tokenizer;
|
||||||
};
|
};
|
||||||
|
|
||||||
TextLayer.prototype.getLineHeight = function() {
|
ace.TextLayer.prototype.getLineHeight = function() {
|
||||||
return this.lineHeight;
|
return this.lineHeight;
|
||||||
};
|
};
|
||||||
|
|
||||||
TextLayer.prototype.getCharacterWidth = function() {
|
ace.TextLayer.prototype.getCharacterWidth = function() {
|
||||||
return this.characterWidth;
|
return this.characterWidth;
|
||||||
};
|
};
|
||||||
|
|
||||||
TextLayer.prototype._measureSizes = function()
|
ace.TextLayer.prototype._measureSizes = function()
|
||||||
{
|
{
|
||||||
var measureNode = document.createElement("div");
|
var measureNode = document.createElement("div");
|
||||||
var style = measureNode.style;
|
var style = measureNode.style;
|
||||||
|
|
@ -41,7 +43,7 @@ TextLayer.prototype._measureSizes = function()
|
||||||
this.element.removeChild(measureNode);
|
this.element.removeChild(measureNode);
|
||||||
};
|
};
|
||||||
|
|
||||||
TextLayer.prototype.updateLines = function(layerConfig, firstRow, lastRow)
|
ace.TextLayer.prototype.updateLines = function(layerConfig, firstRow, lastRow)
|
||||||
{
|
{
|
||||||
var first = Math.max(firstRow, layerConfig.firstRow);
|
var first = Math.max(firstRow, layerConfig.firstRow);
|
||||||
var last = Math.min(lastRow, layerConfig.lastRow);
|
var last = Math.min(lastRow, layerConfig.lastRow);
|
||||||
|
|
@ -58,7 +60,7 @@ TextLayer.prototype.updateLines = function(layerConfig, firstRow, lastRow)
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
TextLayer.prototype.update = function(config)
|
ace.TextLayer.prototype.update = function(config)
|
||||||
{
|
{
|
||||||
var html = [];
|
var html = [];
|
||||||
for (var i=config.firstRow; i<=config.lastRow; i++)
|
for (var i=config.firstRow; i<=config.lastRow; i++)
|
||||||
|
|
@ -76,7 +78,7 @@ TextLayer.prototype.update = function(config)
|
||||||
this.element.innerHTML = html.join("");
|
this.element.innerHTML = html.join("");
|
||||||
};
|
};
|
||||||
|
|
||||||
TextLayer.prototype.renderLine = function(stringBuilder, row)
|
ace.TextLayer.prototype.renderLine = function(stringBuilder, row)
|
||||||
{
|
{
|
||||||
var tokens = this.tokenizer.getTokens(row);
|
var tokens = this.tokenizer.getTokens(row);
|
||||||
for (var i=0; i < tokens.length; i++)
|
for (var i=0; i < tokens.length; i++)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
|
if (!window.ace) ace = {};
|
||||||
|
|
||||||
function Tokenizer(rules)
|
ace.Tokenizer = function(rules)
|
||||||
{
|
{
|
||||||
this.rules = rules;
|
this.rules = rules;
|
||||||
|
|
||||||
|
|
@ -17,7 +18,7 @@ function Tokenizer(rules)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Tokenizer.prototype.getLineTokens = function(line, startState)
|
ace.Tokenizer.prototype.getLineTokens = function(line, startState)
|
||||||
{
|
{
|
||||||
var currentState = startState;
|
var currentState = startState;
|
||||||
var state = this.rules[currentState];
|
var state = this.rules[currentState];
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
function VirtualRenderer(containerId)
|
if (!window.ace) ace = {};
|
||||||
|
|
||||||
|
ace.VirtualRenderer = function(container)
|
||||||
{
|
{
|
||||||
this.container = document.getElementById(containerId);
|
this.container = container;
|
||||||
this.container.className += "editor";
|
this.container.className += "editor";
|
||||||
|
|
||||||
this.scroller = document.createElement("div");
|
this.scroller = document.createElement("div");
|
||||||
|
|
@ -11,16 +13,16 @@ function VirtualRenderer(containerId)
|
||||||
this.gutter.className = "gutter";
|
this.gutter.className = "gutter";
|
||||||
this.container.appendChild(this.gutter);
|
this.container.appendChild(this.gutter);
|
||||||
|
|
||||||
this.gutterLayer = new GutterLayer(this.gutter);
|
this.gutterLayer = new ace.GutterLayer(this.gutter);
|
||||||
this.markerLayer = new MarkerLayer(this.scroller);
|
this.markerLayer = new ace.MarkerLayer(this.scroller);
|
||||||
|
|
||||||
var textLayer = this.textLayer = new TextLayer(this.scroller);
|
var textLayer = this.textLayer = new ace.TextLayer(this.scroller);
|
||||||
this.canvas = textLayer.element;
|
this.canvas = textLayer.element;
|
||||||
|
|
||||||
this.characterWidth = textLayer.getCharacterWidth();
|
this.characterWidth = textLayer.getCharacterWidth();
|
||||||
this.lineHeight = textLayer.getLineHeight();
|
this.lineHeight = textLayer.getLineHeight();
|
||||||
|
|
||||||
this.cursorLayer = new CursorLayer(this.scroller);
|
this.cursorLayer = new ace.CursorLayer(this.scroller);
|
||||||
|
|
||||||
this.layers = [this.markerLayer, textLayer, this.cursorLayer];
|
this.layers = [this.markerLayer, textLayer, this.cursorLayer];
|
||||||
|
|
||||||
|
|
@ -32,29 +34,29 @@ function VirtualRenderer(containerId)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
VirtualRenderer.prototype.setDocument = function(doc)
|
ace.VirtualRenderer.prototype.setDocument = function(doc)
|
||||||
{
|
{
|
||||||
this.lines = doc.lines;
|
this.lines = doc.lines;
|
||||||
this.doc = doc;
|
this.doc = doc;
|
||||||
};
|
};
|
||||||
|
|
||||||
VirtualRenderer.prototype.setTokenizer = function(tokenizer) {
|
ace.VirtualRenderer.prototype.setTokenizer = function(tokenizer) {
|
||||||
this.textLayer.setTokenizer(tokenizer);
|
this.textLayer.setTokenizer(tokenizer);
|
||||||
};
|
};
|
||||||
|
|
||||||
VirtualRenderer.prototype.getContainerElement = function() {
|
ace.VirtualRenderer.prototype.getContainerElement = function() {
|
||||||
return this.container;
|
return this.container;
|
||||||
};
|
};
|
||||||
|
|
||||||
VirtualRenderer.prototype.getFirstVisibleRow = function() {
|
ace.VirtualRenderer.prototype.getFirstVisibleRow = function() {
|
||||||
return this.layerConfig.firstRow || 0;
|
return this.layerConfig.firstRow || 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
VirtualRenderer.prototype.getLastVisibleRow = function() {
|
ace.VirtualRenderer.prototype.getLastVisibleRow = function() {
|
||||||
return this.layerConfig.lastRow || 0;
|
return this.layerConfig.lastRow || 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
VirtualRenderer.prototype.updateLines = function(firstRow, lastRow)
|
ace.VirtualRenderer.prototype.updateLines = function(firstRow, lastRow)
|
||||||
{
|
{
|
||||||
var layerConfig = this.layerConfig;
|
var layerConfig = this.layerConfig;
|
||||||
|
|
||||||
|
|
@ -74,7 +76,7 @@ VirtualRenderer.prototype.updateLines = function(firstRow, lastRow)
|
||||||
this.textLayer.updateLines(layerConfig, firstRow, lastRow);
|
this.textLayer.updateLines(layerConfig, firstRow, lastRow);
|
||||||
};
|
};
|
||||||
|
|
||||||
VirtualRenderer.prototype.draw = function()
|
ace.VirtualRenderer.prototype.draw = function()
|
||||||
{
|
{
|
||||||
var lines = this.lines;
|
var lines = this.lines;
|
||||||
|
|
||||||
|
|
@ -115,29 +117,29 @@ VirtualRenderer.prototype.draw = function()
|
||||||
this.gutterLayer.update(layerConfig);
|
this.gutterLayer.update(layerConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
VirtualRenderer.prototype.addMarker = function(range, clazz) {
|
ace.VirtualRenderer.prototype.addMarker = function(range, clazz) {
|
||||||
return this.markerLayer.addMarker(range, clazz);
|
return this.markerLayer.addMarker(range, clazz);
|
||||||
};
|
};
|
||||||
|
|
||||||
VirtualRenderer.prototype.removeMarker = function(markerId) {
|
ace.VirtualRenderer.prototype.removeMarker = function(markerId) {
|
||||||
this.markerLayer.removeMarker(markerId);
|
this.markerLayer.removeMarker(markerId);
|
||||||
};
|
};
|
||||||
|
|
||||||
VirtualRenderer.prototype.updateCursor = function(position)
|
ace.VirtualRenderer.prototype.updateCursor = function(position)
|
||||||
{
|
{
|
||||||
this.cursorLayer.setCursor(position);
|
this.cursorLayer.setCursor(position);
|
||||||
this.cursorLayer.update(this.layerConfig);
|
this.cursorLayer.update(this.layerConfig);
|
||||||
};
|
};
|
||||||
|
|
||||||
VirtualRenderer.prototype.hideCursor = function() {
|
ace.VirtualRenderer.prototype.hideCursor = function() {
|
||||||
this.cursorLayer.hideCursor();
|
this.cursorLayer.hideCursor();
|
||||||
};
|
};
|
||||||
|
|
||||||
VirtualRenderer.prototype.showCursor = function() {
|
ace.VirtualRenderer.prototype.showCursor = function() {
|
||||||
this.cursorLayer.showCursor();
|
this.cursorLayer.showCursor();
|
||||||
};
|
};
|
||||||
|
|
||||||
VirtualRenderer.prototype.scrollCursorIntoView = function()
|
ace.VirtualRenderer.prototype.scrollCursorIntoView = function()
|
||||||
{
|
{
|
||||||
var pos = this.cursorLayer.getPixelPosition();
|
var pos = this.cursorLayer.getPixelPosition();
|
||||||
|
|
||||||
|
|
@ -161,15 +163,15 @@ VirtualRenderer.prototype.scrollCursorIntoView = function()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
VirtualRenderer.prototype.getScrollTop = function() {
|
ace.VirtualRenderer.prototype.getScrollTop = function() {
|
||||||
return this.scrollTop;
|
return this.scrollTop;
|
||||||
};
|
};
|
||||||
|
|
||||||
VirtualRenderer.prototype.scrollToRow = function(row) {
|
ace.VirtualRenderer.prototype.scrollToRow = function(row) {
|
||||||
this.scrollToY(row*this.lineHeight);
|
this.scrollToY(row*this.lineHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
VirtualRenderer.prototype.scrollToY = function(scrollTop)
|
ace.VirtualRenderer.prototype.scrollToY = function(scrollTop)
|
||||||
{
|
{
|
||||||
var maxHeight = this.lines.length * this.lineHeight - this.scroller.clientHeight;
|
var maxHeight = this.lines.length * this.lineHeight - this.scroller.clientHeight;
|
||||||
var scrollTop = Math.max(0, Math.min(maxHeight, scrollTop));
|
var scrollTop = Math.max(0, Math.min(maxHeight, scrollTop));
|
||||||
|
|
@ -180,7 +182,7 @@ VirtualRenderer.prototype.scrollToY = function(scrollTop)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
VirtualRenderer.prototype.screenToTextCoordinates = function(pageX, pageY)
|
ace.VirtualRenderer.prototype.screenToTextCoordinates = function(pageX, pageY)
|
||||||
{
|
{
|
||||||
var canvasPos = this.scroller.getBoundingClientRect();
|
var canvasPos = this.scroller.getBoundingClientRect();
|
||||||
|
|
||||||
|
|
@ -193,19 +195,19 @@ VirtualRenderer.prototype.screenToTextCoordinates = function(pageX, pageY)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
VirtualRenderer.prototype.visualizeFocus = function() {
|
ace.VirtualRenderer.prototype.visualizeFocus = function() {
|
||||||
this.container.className = "editor focus";
|
this.container.className = "editor focus";
|
||||||
};
|
};
|
||||||
|
|
||||||
VirtualRenderer.prototype.visualizeBlur = function() {
|
ace.VirtualRenderer.prototype.visualizeBlur = function() {
|
||||||
this.container.className = "editor";
|
this.container.className = "editor";
|
||||||
};
|
};
|
||||||
|
|
||||||
VirtualRenderer.prototype.showComposition = function(position) {
|
ace.VirtualRenderer.prototype.showComposition = function(position) {
|
||||||
};
|
};
|
||||||
|
|
||||||
VirtualRenderer.prototype.setCompositionText = function(text) {
|
ace.VirtualRenderer.prototype.setCompositionText = function(text) {
|
||||||
};
|
};
|
||||||
|
|
||||||
VirtualRenderer.prototype.hideComposition = function() {
|
ace.VirtualRenderer.prototype.hideComposition = function() {
|
||||||
};
|
};
|
||||||
|
|
@ -1,11 +1,13 @@
|
||||||
|
if (!window.ace) ace = {};
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
window.XML = {};
|
ace.XML = {};
|
||||||
|
|
||||||
// regexp must not have capturing parentheses
|
// regexp must not have capturing parentheses
|
||||||
// regexps are ordered -> the first match is used
|
// regexps are ordered -> the first match is used
|
||||||
|
|
||||||
XML.RULES = {
|
ace.XML.RULES = {
|
||||||
start :
|
start :
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
|
|
|
||||||
62
src/lib.js
62
src/lib.js
|
|
@ -1,8 +1,8 @@
|
||||||
|
if (!window.ace) ace = {};
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
window.lib = {};
|
ace.addListener = function(elem, type, callback) {
|
||||||
|
|
||||||
lib.addListener = function(elem, type, callback) {
|
|
||||||
if (elem.addEventListener) {
|
if (elem.addEventListener) {
|
||||||
return elem.addEventListener(type, callback, false);
|
return elem.addEventListener(type, callback, false);
|
||||||
}
|
}
|
||||||
|
|
@ -15,7 +15,7 @@ lib.addListener = function(elem, type, callback) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lib.removeListener = function(elem, type, callback) {
|
ace.removeListener = function(elem, type, callback) {
|
||||||
if (elem.removeEventListener) {
|
if (elem.removeEventListener) {
|
||||||
return elem.removeEventListener(type, callback, false);
|
return elem.removeEventListener(type, callback, false);
|
||||||
}
|
}
|
||||||
|
|
@ -24,7 +24,7 @@ lib.removeListener = function(elem, type, callback) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lib.setText = function(elem, text) {
|
ace.setText = function(elem, text) {
|
||||||
if (elem.innerText !== undefined) {
|
if (elem.innerText !== undefined) {
|
||||||
elem.innerText = text;
|
elem.innerText = text;
|
||||||
}
|
}
|
||||||
|
|
@ -33,20 +33,20 @@ lib.setText = function(elem, text) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lib.stopEvent = function(e) {
|
ace.stopEvent = function(e) {
|
||||||
lib.stopPropagation(e);
|
ace.stopPropagation(e);
|
||||||
lib.preventDefault(e);
|
ace.preventDefault(e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
lib.stopPropagation = function(e) {
|
ace.stopPropagation = function(e) {
|
||||||
if (e.stopPropagation)
|
if (e.stopPropagation)
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
else
|
else
|
||||||
e.cancelBubble = true;
|
e.cancelBubble = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
lib.preventDefault = function(e)
|
ace.preventDefault = function(e)
|
||||||
{
|
{
|
||||||
if (e.preventDefault)
|
if (e.preventDefault)
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
@ -54,7 +54,7 @@ lib.preventDefault = function(e)
|
||||||
e.returnValue = false;
|
e.returnValue = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
lib.inherits = function(ctor, superCtor) {
|
ace.inherits = function(ctor, superCtor) {
|
||||||
var tempCtor = function(){};
|
var tempCtor = function(){};
|
||||||
tempCtor.prototype = superCtor.prototype;
|
tempCtor.prototype = superCtor.prototype;
|
||||||
ctor.super_ = superCtor.prototype;
|
ctor.super_ = superCtor.prototype;
|
||||||
|
|
@ -62,25 +62,25 @@ lib.inherits = function(ctor, superCtor) {
|
||||||
ctor.prototype.constructor = ctor;
|
ctor.prototype.constructor = ctor;
|
||||||
};
|
};
|
||||||
|
|
||||||
lib.getInnerWidth = function(element)
|
ace.getInnerWidth = function(element)
|
||||||
{
|
{
|
||||||
return (
|
return (
|
||||||
parseInt(lib.computedStyle(element, "paddingLeft")) +
|
parseInt(ace.computedStyle(element, "paddingLeft")) +
|
||||||
parseInt(lib.computedStyle(element, "paddingRight")) +
|
parseInt(ace.computedStyle(element, "paddingRight")) +
|
||||||
element.clientWidth
|
element.clientWidth
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
lib.getInnerHeight = function(element)
|
ace.getInnerHeight = function(element)
|
||||||
{
|
{
|
||||||
return (
|
return (
|
||||||
parseInt(lib.computedStyle(element, "paddingTop")) +
|
parseInt(ace.computedStyle(element, "paddingTop")) +
|
||||||
parseInt(lib.computedStyle(element, "paddingBottom")) +
|
parseInt(ace.computedStyle(element, "paddingBottom")) +
|
||||||
element.clientHeight
|
element.clientHeight
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
lib.computedStyle = function(element, style)
|
ace.computedStyle = function(element, style)
|
||||||
{
|
{
|
||||||
if (window.getComputedStyle) {
|
if (window.getComputedStyle) {
|
||||||
return (window.getComputedStyle(element, null))[style];
|
return (window.getComputedStyle(element, null))[style];
|
||||||
|
|
@ -89,7 +89,7 @@ lib.computedStyle = function(element, style)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lib.scrollbarHeight = function() {
|
ace.scrollbarHeight = function() {
|
||||||
var el = document.createElement("div");
|
var el = document.createElement("div");
|
||||||
var style = el.style;
|
var style = el.style;
|
||||||
|
|
||||||
|
|
@ -105,13 +105,13 @@ lib.scrollbarHeight = function() {
|
||||||
return height;
|
return height;
|
||||||
}
|
}
|
||||||
|
|
||||||
lib.bind = function(fcn, context) {
|
ace.bind = function(fcn, context) {
|
||||||
return function() {
|
return function() {
|
||||||
return fcn.apply(context, arguments);
|
return fcn.apply(context, arguments);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lib.capture = function(el, eventHandler, releaseCaptureHandler)
|
ace.capture = function(el, eventHandler, releaseCaptureHandler)
|
||||||
{
|
{
|
||||||
function onMouseMove(e)
|
function onMouseMove(e)
|
||||||
{
|
{
|
||||||
|
|
@ -134,17 +134,17 @@ lib.capture = function(el, eventHandler, releaseCaptureHandler)
|
||||||
document.addEventListener("mouseup", onMouseUp, true);
|
document.addEventListener("mouseup", onMouseUp, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
lib.addMouseWheelListener = function(el, callback)
|
ace.addMouseWheelListener = function(el, callback)
|
||||||
{
|
{
|
||||||
var listener = function(e) {
|
var listener = function(e) {
|
||||||
e.wheel = (e.wheelDelta) ? e.wheelDelta / 120 : -(e.detail || 0) / 3;
|
e.wheel = (e.wheelDelta) ? e.wheelDelta / 120 : -(e.detail || 0) / 3;
|
||||||
callback(e);
|
callback(e);
|
||||||
}
|
}
|
||||||
lib.addListener(el, "DOMMouseScroll", listener);
|
ace.addListener(el, "DOMMouseScroll", listener);
|
||||||
lib.addListener(el, "mousewheel", listener);
|
ace.addListener(el, "mousewheel", listener);
|
||||||
};
|
};
|
||||||
|
|
||||||
lib.autoremoveListener = function(el, type, callback, timeout)
|
ace.autoremoveListener = function(el, type, callback, timeout)
|
||||||
{
|
{
|
||||||
var listener = function(e)
|
var listener = function(e)
|
||||||
{
|
{
|
||||||
|
|
@ -154,18 +154,18 @@ lib.autoremoveListener = function(el, type, callback, timeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
var remove = function() {
|
var remove = function() {
|
||||||
lib.removeListener(el, type, listener);
|
ace.removeListener(el, type, listener);
|
||||||
};
|
};
|
||||||
|
|
||||||
lib.addListener(el, type, listener);
|
ace.addListener(el, type, listener);
|
||||||
var timeoutId = setTimeout(remove, timeout);
|
var timeoutId = setTimeout(remove, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
lib.addTripleClickListener = function(el, callback)
|
ace.addTripleClickListener = function(el, callback)
|
||||||
{
|
{
|
||||||
lib.addListener(el, "mousedown", function() {
|
ace.addListener(el, "mousedown", function() {
|
||||||
lib.autoremoveListener(el, "mousedown", function() {
|
ace.autoremoveListener(el, "mousedown", function() {
|
||||||
lib.autoremoveListener(el, "mousedown", callback, 300);
|
ace.autoremoveListener(el, "mousedown", callback, 300);
|
||||||
}, 300);
|
}, 300);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue