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;
|
||||||
|
|
||||||
|
|
|
||||||
327
src/Editor.js
327
src/Editor.js
|
|
@ -1,3 +1,7 @@
|
||||||
|
if (!window.ace) ace = {};
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
|
||||||
var keys = {
|
var keys = {
|
||||||
UP: 38,
|
UP: 38,
|
||||||
RIGHT: 39,
|
RIGHT: 39,
|
||||||
|
|
@ -13,9 +17,9 @@ var keys = {
|
||||||
A: 65
|
A: 65
|
||||||
}
|
}
|
||||||
|
|
||||||
function KeyBinding(element, host)
|
var KeyBinding = function(element, host)
|
||||||
{
|
{
|
||||||
lib.addListener(element, "keydown", function(e)
|
ace.addListener(element, "keydown", function(e)
|
||||||
{
|
{
|
||||||
var key = e.keyCode;
|
var key = e.keyCode;
|
||||||
|
|
||||||
|
|
@ -25,7 +29,7 @@ function KeyBinding(element, host)
|
||||||
if (e.metaKey)
|
if (e.metaKey)
|
||||||
{
|
{
|
||||||
host.selectAll();
|
host.selectAll();
|
||||||
return lib.stopEvent(e);
|
return ace.stopEvent(e);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -35,7 +39,7 @@ function KeyBinding(element, host)
|
||||||
} else {
|
} else {
|
||||||
host.navigateUp();
|
host.navigateUp();
|
||||||
}
|
}
|
||||||
return lib.stopEvent(e);
|
return ace.stopEvent(e);
|
||||||
|
|
||||||
case keys.DOWN:
|
case keys.DOWN:
|
||||||
if (e.shiftKey) {
|
if (e.shiftKey) {
|
||||||
|
|
@ -43,7 +47,7 @@ function KeyBinding(element, host)
|
||||||
} else {
|
} else {
|
||||||
host.navigateDown();
|
host.navigateDown();
|
||||||
}
|
}
|
||||||
return lib.stopEvent(e);
|
return ace.stopEvent(e);
|
||||||
|
|
||||||
case keys.LEFT:
|
case keys.LEFT:
|
||||||
if (e.metaKey && e.shiftKey) {
|
if (e.metaKey && e.shiftKey) {
|
||||||
|
|
@ -55,7 +59,7 @@ function KeyBinding(element, host)
|
||||||
} else {
|
} else {
|
||||||
host.navigateLeft();
|
host.navigateLeft();
|
||||||
}
|
}
|
||||||
return lib.stopEvent(e);
|
return ace.stopEvent(e);
|
||||||
|
|
||||||
case keys.RIGHT:
|
case keys.RIGHT:
|
||||||
if (e.metaKey && e.shiftKey) {
|
if (e.metaKey && e.shiftKey) {
|
||||||
|
|
@ -67,7 +71,7 @@ function KeyBinding(element, host)
|
||||||
} else {
|
} else {
|
||||||
host.navigateRight();
|
host.navigateRight();
|
||||||
}
|
}
|
||||||
return lib.stopEvent(e);
|
return ace.stopEvent(e);
|
||||||
|
|
||||||
case keys.PAGEDOWN:
|
case keys.PAGEDOWN:
|
||||||
if (e.shiftKey) {
|
if (e.shiftKey) {
|
||||||
|
|
@ -75,7 +79,7 @@ function KeyBinding(element, host)
|
||||||
} else {
|
} else {
|
||||||
host.scrollPageDown();
|
host.scrollPageDown();
|
||||||
}
|
}
|
||||||
return lib.stopEvent(e);
|
return ace.stopEvent(e);
|
||||||
|
|
||||||
case keys.PAGEUP:
|
case keys.PAGEUP:
|
||||||
if (e.shiftKey) {
|
if (e.shiftKey) {
|
||||||
|
|
@ -83,7 +87,7 @@ function KeyBinding(element, host)
|
||||||
} else {
|
} else {
|
||||||
host.scrollPageUp();
|
host.scrollPageUp();
|
||||||
}
|
}
|
||||||
return lib.stopEvent(e);
|
return ace.stopEvent(e);
|
||||||
|
|
||||||
case keys.POS1:
|
case keys.POS1:
|
||||||
if (e.shiftKey) {
|
if (e.shiftKey) {
|
||||||
|
|
@ -91,7 +95,7 @@ function KeyBinding(element, host)
|
||||||
} else {
|
} else {
|
||||||
host.navigateLineStart();
|
host.navigateLineStart();
|
||||||
}
|
}
|
||||||
return lib.stopEvent(e);
|
return ace.stopEvent(e);
|
||||||
|
|
||||||
case keys.END:
|
case keys.END:
|
||||||
if (e.shiftKey) {
|
if (e.shiftKey) {
|
||||||
|
|
@ -99,43 +103,43 @@ function KeyBinding(element, host)
|
||||||
} else {
|
} else {
|
||||||
host.navigateLineEnd();
|
host.navigateLineEnd();
|
||||||
}
|
}
|
||||||
return lib.stopEvent(e);
|
return ace.stopEvent(e);
|
||||||
|
|
||||||
case keys.DELETE:
|
case keys.DELETE:
|
||||||
host.removeRight();
|
host.removeRight();
|
||||||
return lib.stopEvent(e);
|
return ace.stopEvent(e);
|
||||||
|
|
||||||
case keys.BACKSPACE:
|
case keys.BACKSPACE:
|
||||||
host.removeLeft();
|
host.removeLeft();
|
||||||
return lib.stopEvent(e);
|
return ace.stopEvent(e);
|
||||||
|
|
||||||
case keys.TAB:
|
case keys.TAB:
|
||||||
host.onTextInput(" ");
|
host.onTextInput(" ");
|
||||||
return lib.stopEvent(e);
|
return ace.stopEvent(e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
function Editor(doc, renderer)
|
ace.Editor = function(doc, renderer)
|
||||||
{
|
{
|
||||||
var container = renderer.getContainerElement();
|
var container = renderer.getContainerElement();
|
||||||
this.renderer = renderer;
|
this.renderer = renderer;
|
||||||
|
|
||||||
this.textInput = new TextInput(container, this);
|
this.textInput = new ace.TextInput(container, this);
|
||||||
new KeyBinding(container, this);
|
new KeyBinding(container, this);
|
||||||
|
|
||||||
lib.addListener(container, "mousedown", lib.bind(this.onMouseDown, this));
|
ace.addListener(container, "mousedown", ace.bind(this.onMouseDown, this));
|
||||||
lib.addListener(container, "dblclick", lib.bind(this.onMouseDoubleClick, this));
|
ace.addListener(container, "dblclick", ace.bind(this.onMouseDoubleClick, this));
|
||||||
lib.addMouseWheelListener(container, lib.bind(this.onMouseWheel, this));
|
ace.addMouseWheelListener(container, ace.bind(this.onMouseWheel, this));
|
||||||
lib.addTripleClickListener(container, lib.bind(this.selectCurrentLine, this));
|
ace.addTripleClickListener(container, ace.bind(this.selectCurrentLine, this));
|
||||||
|
|
||||||
this.doc = doc;
|
this.doc = doc;
|
||||||
doc.addChangeListener(lib.bind(this.onDocumentChange, this));
|
doc.addChangeListener(ace.bind(this.onDocumentChange, this));
|
||||||
renderer.setDocument(doc);
|
renderer.setDocument(doc);
|
||||||
|
|
||||||
this.tokenizer = new BackgroundTokenizer(
|
this.tokenizer = new ace.BackgroundTokenizer(
|
||||||
new Tokenizer(XML.RULES),
|
new ace.Tokenizer(ace.XML.RULES),
|
||||||
lib.bind(this.onTokenizerUpdate, this)
|
ace.bind(this.onTokenizerUpdate, this)
|
||||||
);
|
);
|
||||||
|
|
||||||
this.tokenizer.setLines(doc.lines);
|
this.tokenizer.setLines(doc.lines);
|
||||||
|
|
@ -151,40 +155,38 @@ function Editor(doc, renderer)
|
||||||
this.selection = null;
|
this.selection = null;
|
||||||
|
|
||||||
this.renderer.draw();
|
this.renderer.draw();
|
||||||
}
|
};
|
||||||
|
|
||||||
Editor.prototype =
|
ace.Editor.prototype.resize = function() {
|
||||||
{
|
|
||||||
resize : function() {
|
|
||||||
this.renderer.draw();
|
this.renderer.draw();
|
||||||
},
|
};
|
||||||
|
|
||||||
updateCursor : function() {
|
ace.Editor.prototype.updateCursor = function() {
|
||||||
this.renderer.updateCursor(this.cursor);
|
this.renderer.updateCursor(this.cursor);
|
||||||
},
|
};
|
||||||
|
|
||||||
onFocus : function() {
|
ace.Editor.prototype.onFocus = function() {
|
||||||
this.renderer.showCursor();
|
this.renderer.showCursor();
|
||||||
this.renderer.visualizeFocus();
|
this.renderer.visualizeFocus();
|
||||||
},
|
};
|
||||||
|
|
||||||
onBlur : function() {
|
ace.Editor.prototype.onBlur = function() {
|
||||||
this.renderer.hideCursor();
|
this.renderer.hideCursor();
|
||||||
this.renderer.visualizeBlur();
|
this.renderer.visualizeBlur();
|
||||||
},
|
};
|
||||||
|
|
||||||
onDocumentChange : function(startRow, endRow)
|
ace.Editor.prototype.onDocumentChange = function(startRow, endRow)
|
||||||
{
|
{
|
||||||
this.tokenizer.start(startRow);
|
this.tokenizer.start(startRow);
|
||||||
this.renderer.updateLines(startRow, endRow);
|
this.renderer.updateLines(startRow, endRow);
|
||||||
},
|
};
|
||||||
|
|
||||||
onTokenizerUpdate : function(startRow, endRow) {
|
ace.Editor.prototype.onTokenizerUpdate = function(startRow, endRow) {
|
||||||
this.renderer.updateLines(startRow, endRow);
|
this.renderer.updateLines(startRow, endRow);
|
||||||
},
|
};
|
||||||
|
|
||||||
onMouseDown : function(e)
|
ace.Editor.prototype.onMouseDown = function(e)
|
||||||
{
|
{
|
||||||
this.textInput.focus();
|
this.textInput.focus();
|
||||||
|
|
||||||
var pos = this.renderer.screenToTextCoordinates(e.pageX, e.pageY);
|
var pos = this.renderer.screenToTextCoordinates(e.pageX, e.pageY);
|
||||||
|
|
@ -216,14 +218,14 @@ function Editor(doc, renderer)
|
||||||
_self.renderer.scrollCursorIntoView();
|
_self.renderer.scrollCursorIntoView();
|
||||||
};
|
};
|
||||||
|
|
||||||
lib.capture(this.container, onMouseSelection, onMouseSelectionEnd);
|
ace.capture(this.container, onMouseSelection, onMouseSelectionEnd);
|
||||||
var timerId = setInterval(onSelectionInterval, 20 );
|
var timerId = setInterval(onSelectionInterval, 20 );
|
||||||
|
|
||||||
return lib.preventDefault(e);
|
return ace.preventDefault(e);
|
||||||
},
|
};
|
||||||
|
|
||||||
onMouseDoubleClick : function(e)
|
ace.Editor.prototype.onMouseDoubleClick = function(e)
|
||||||
{
|
{
|
||||||
var line = this.doc.getLine(this.cursor.row);
|
var line = this.doc.getLine(this.cursor.row);
|
||||||
var column = this.cursor.column;
|
var column = this.cursor.column;
|
||||||
|
|
||||||
|
|
@ -259,36 +261,36 @@ function Editor(doc, renderer)
|
||||||
this._moveSelection(function() {
|
this._moveSelection(function() {
|
||||||
this.moveCursorTo(this.cursor.row, end);
|
this.moveCursorTo(this.cursor.row, end);
|
||||||
});
|
});
|
||||||
},
|
};
|
||||||
|
|
||||||
onMouseWheel : function(e)
|
ace.Editor.prototype.onMouseWheel = function(e)
|
||||||
{
|
{
|
||||||
var delta = e.wheel;
|
var delta = e.wheel;
|
||||||
this.renderer.scrollToY(this.renderer.getScrollTop() - (delta * 15));
|
this.renderer.scrollToY(this.renderer.getScrollTop() - (delta * 15));
|
||||||
return lib.preventDefault(e);
|
return ace.preventDefault(e);
|
||||||
},
|
};
|
||||||
|
|
||||||
getCopyText : function()
|
ace.Editor.prototype.getCopyText = function()
|
||||||
{
|
{
|
||||||
if (this.hasSelection()) {
|
if (this.hasSelection()) {
|
||||||
return this.doc.getTextRange(this.getSelectionRange());
|
return this.doc.getTextRange(this.getSelectionRange());
|
||||||
} else {
|
} else {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
|
|
||||||
onCut : function()
|
ace.Editor.prototype.onCut = function()
|
||||||
{
|
{
|
||||||
if (this.hasSelection())
|
if (this.hasSelection())
|
||||||
{
|
{
|
||||||
this.cursor = this.doc.remove(this.getSelectionRange());
|
this.cursor = this.doc.remove(this.getSelectionRange());
|
||||||
this.clearSelection();
|
this.clearSelection();
|
||||||
this.renderer.updateCursor(this.cursor);
|
this.renderer.updateCursor(this.cursor);
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
|
|
||||||
onTextInput: function(text)
|
ace.Editor.prototype.onTextInput = function(text)
|
||||||
{
|
{
|
||||||
if (this.hasSelection())
|
if (this.hasSelection())
|
||||||
{
|
{
|
||||||
this.cursor = this.doc.replace(this.getSelectionRange(), text);
|
this.cursor = this.doc.replace(this.getSelectionRange(), text);
|
||||||
|
|
@ -298,10 +300,10 @@ function Editor(doc, renderer)
|
||||||
}
|
}
|
||||||
this.renderer.updateCursor(this.cursor);
|
this.renderer.updateCursor(this.cursor);
|
||||||
this.renderer.scrollCursorIntoView();
|
this.renderer.scrollCursorIntoView();
|
||||||
},
|
};
|
||||||
|
|
||||||
removeRight : function()
|
ace.Editor.prototype.removeRight = function()
|
||||||
{
|
{
|
||||||
if (this.hasSelection())
|
if (this.hasSelection())
|
||||||
{
|
{
|
||||||
this.cursor = this.doc.remove(this.getSelectionRange());
|
this.cursor = this.doc.remove(this.getSelectionRange());
|
||||||
|
|
@ -322,10 +324,10 @@ function Editor(doc, renderer)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.renderer.scrollCursorIntoView();
|
this.renderer.scrollCursorIntoView();
|
||||||
},
|
};
|
||||||
|
|
||||||
removeLeft : function()
|
ace.Editor.prototype.removeLeft = function()
|
||||||
{
|
{
|
||||||
if (this.hasSelection())
|
if (this.hasSelection())
|
||||||
{
|
{
|
||||||
this.cursor = this.doc.remove(this.getSelectionRange());
|
this.cursor = this.doc.remove(this.getSelectionRange());
|
||||||
|
|
@ -351,66 +353,66 @@ function Editor(doc, renderer)
|
||||||
|
|
||||||
this.renderer.updateCursor(this.cursor);
|
this.renderer.updateCursor(this.cursor);
|
||||||
this.renderer.scrollCursorIntoView();
|
this.renderer.scrollCursorIntoView();
|
||||||
},
|
},
|
||||||
|
|
||||||
onCompositionStart : function()
|
ace.Editor.prototype.onCompositionStart = function()
|
||||||
{
|
{
|
||||||
this.renderer.showComposition(this.cursor);
|
this.renderer.showComposition(this.cursor);
|
||||||
this.onTextInput(" ");
|
this.onTextInput(" ");
|
||||||
},
|
};
|
||||||
|
|
||||||
onCompositionUpdate : function(text) {
|
ace.Editor.prototype.onCompositionUpdate = function(text) {
|
||||||
this.renderer.setCompositionText(text);
|
this.renderer.setCompositionText(text);
|
||||||
},
|
};
|
||||||
|
|
||||||
onCompositionEnd : function() {
|
ace.Editor.prototype.onCompositionEnd = function() {
|
||||||
this.renderer.hideComposition();
|
this.renderer.hideComposition();
|
||||||
this.removeLeft();
|
this.removeLeft();
|
||||||
},
|
};
|
||||||
|
|
||||||
getFirstVisibleRow : function() {
|
ace.Editor.prototype.getFirstVisibleRow = function() {
|
||||||
return this.renderer.getFirstVisibleRow();
|
return this.renderer.getFirstVisibleRow();
|
||||||
},
|
};
|
||||||
|
|
||||||
getLastVisibleRow : function() {
|
ace.Editor.prototype.getLastVisibleRow = function() {
|
||||||
return this.renderer.getLastVisibleRow();
|
return this.renderer.getLastVisibleRow();
|
||||||
},
|
};
|
||||||
|
|
||||||
getPageDownRow : function() {
|
ace.Editor.prototype.getPageDownRow = function() {
|
||||||
return this.renderer.getLastVisibleRow() - 1;
|
return this.renderer.getLastVisibleRow() - 1;
|
||||||
},
|
};
|
||||||
|
|
||||||
getPageUpRow : function()
|
ace.Editor.prototype.getPageUpRow = function()
|
||||||
{
|
{
|
||||||
var firstRow = this.renderer.getFirstVisibleRow();
|
var firstRow = this.renderer.getFirstVisibleRow();
|
||||||
var lastRow = this.renderer.getLastVisibleRow();
|
var lastRow = this.renderer.getLastVisibleRow();
|
||||||
|
|
||||||
return firstRow - (lastRow-firstRow) + 1;
|
return firstRow - (lastRow-firstRow) + 1;
|
||||||
},
|
};
|
||||||
|
|
||||||
scrollPageDown : function() {
|
ace.Editor.prototype.scrollPageDown = function() {
|
||||||
this.renderer.scrollToRow(this.getPageDownRow());
|
this.renderer.scrollToRow(this.getPageDownRow());
|
||||||
},
|
};
|
||||||
|
|
||||||
scrollPageUp : function() {
|
ace.Editor.prototype.scrollPageUp = function() {
|
||||||
this.renderer.scrollToRow(this.getPageUpRow());
|
this.renderer.scrollToRow(this.getPageUpRow());
|
||||||
},
|
};
|
||||||
|
|
||||||
navigateUp : function()
|
ace.Editor.prototype.navigateUp = function()
|
||||||
{
|
{
|
||||||
this.clearSelection();
|
this.clearSelection();
|
||||||
this.moveCursorUp();
|
this.moveCursorUp();
|
||||||
this.renderer.scrollCursorIntoView();
|
this.renderer.scrollCursorIntoView();
|
||||||
},
|
};
|
||||||
|
|
||||||
navigateDown : function() {
|
ace.Editor.prototype.navigateDown = function() {
|
||||||
this.clearSelection();
|
this.clearSelection();
|
||||||
this.moveCursorDown();
|
this.moveCursorDown();
|
||||||
this.renderer.scrollCursorIntoView();
|
this.renderer.scrollCursorIntoView();
|
||||||
},
|
};
|
||||||
|
|
||||||
navigateLeft : function()
|
ace.Editor.prototype.navigateLeft = function()
|
||||||
{
|
{
|
||||||
if (this.hasSelection()) {
|
if (this.hasSelection()) {
|
||||||
var selectionStart = this.getSelectionRange().start;
|
var selectionStart = this.getSelectionRange().start;
|
||||||
this.moveCursorTo(selectionStart.row, selectionStart.column);
|
this.moveCursorTo(selectionStart.row, selectionStart.column);
|
||||||
|
|
@ -420,10 +422,10 @@ function Editor(doc, renderer)
|
||||||
this.clearSelection();
|
this.clearSelection();
|
||||||
|
|
||||||
this.renderer.scrollCursorIntoView();
|
this.renderer.scrollCursorIntoView();
|
||||||
},
|
};
|
||||||
|
|
||||||
navigateRight : function()
|
ace.Editor.prototype.navigateRight = function()
|
||||||
{
|
{
|
||||||
if (this.hasSelection()) {
|
if (this.hasSelection()) {
|
||||||
var selectionEnd = this.getSelectionRange().end;
|
var selectionEnd = this.getSelectionRange().end;
|
||||||
this.moveCursorTo(selectionEnd.row, selectionEnd.column);
|
this.moveCursorTo(selectionEnd.row, selectionEnd.column);
|
||||||
|
|
@ -433,32 +435,32 @@ function Editor(doc, renderer)
|
||||||
this.clearSelection();
|
this.clearSelection();
|
||||||
|
|
||||||
this.renderer.scrollCursorIntoView();
|
this.renderer.scrollCursorIntoView();
|
||||||
},
|
},
|
||||||
|
|
||||||
navigateLineStart : function()
|
ace.Editor.prototype.navigateLineStart = function()
|
||||||
{
|
{
|
||||||
this.clearSelection();
|
this.clearSelection();
|
||||||
this.moveCursorLineStart();
|
this.moveCursorLineStart();
|
||||||
this.renderer.scrollCursorIntoView();
|
this.renderer.scrollCursorIntoView();
|
||||||
},
|
};
|
||||||
|
|
||||||
navigateLineEnd : function()
|
ace.Editor.prototype.navigateLineEnd = function()
|
||||||
{
|
{
|
||||||
this.clearSelection();
|
this.clearSelection();
|
||||||
this.moveCursorLineEnd();
|
this.moveCursorLineEnd();
|
||||||
this.renderer.scrollCursorIntoView();
|
this.renderer.scrollCursorIntoView();
|
||||||
},
|
};
|
||||||
|
|
||||||
moveCursorUp : function() {
|
ace.Editor.prototype.moveCursorUp = function() {
|
||||||
this.moveCursorBy(-1, 0);
|
this.moveCursorBy(-1, 0);
|
||||||
},
|
};
|
||||||
|
|
||||||
moveCursorDown : function() {
|
ace.Editor.prototype.moveCursorDown = function() {
|
||||||
this.moveCursorBy(1, 0);
|
this.moveCursorBy(1, 0);
|
||||||
},
|
};
|
||||||
|
|
||||||
moveCursorLeft : function()
|
ace.Editor.prototype.moveCursorLeft = function()
|
||||||
{
|
{
|
||||||
if (this.cursor.column == 0) {
|
if (this.cursor.column == 0) {
|
||||||
if (this.cursor.row > 0) {
|
if (this.cursor.row > 0) {
|
||||||
this.moveCursorTo(this.cursor.row-1, this.doc.getLine(this.cursor.row-1).length);
|
this.moveCursorTo(this.cursor.row-1, this.doc.getLine(this.cursor.row-1).length);
|
||||||
|
|
@ -466,10 +468,10 @@ function Editor(doc, renderer)
|
||||||
} else {
|
} else {
|
||||||
this.moveCursorBy(0, -1);
|
this.moveCursorBy(0, -1);
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
|
|
||||||
moveCursorRight : function()
|
ace.Editor.prototype.moveCursorRight = function()
|
||||||
{
|
{
|
||||||
if (this.cursor.column == this.doc.getLine(this.cursor.row).length) {
|
if (this.cursor.column == this.doc.getLine(this.cursor.row).length) {
|
||||||
if (this.cursor.row < this.doc.getLength()-1) {
|
if (this.cursor.row < this.doc.getLength()-1) {
|
||||||
this.moveCursorTo(this.cursor.row+1, 0);
|
this.moveCursorTo(this.cursor.row+1, 0);
|
||||||
|
|
@ -478,25 +480,25 @@ function Editor(doc, renderer)
|
||||||
this.moveCursorBy(0, 1);
|
this.moveCursorBy(0, 1);
|
||||||
}
|
}
|
||||||
this.renderer.scrollCursorIntoView();
|
this.renderer.scrollCursorIntoView();
|
||||||
},
|
};
|
||||||
|
|
||||||
moveCursorLineStart : function()
|
ace.Editor.prototype.moveCursorLineStart = function()
|
||||||
{
|
{
|
||||||
this.moveCursorTo(this.cursor.row, 0);
|
this.moveCursorTo(this.cursor.row, 0);
|
||||||
this.renderer.scrollCursorIntoView();
|
this.renderer.scrollCursorIntoView();
|
||||||
},
|
};
|
||||||
|
|
||||||
moveCursorLineEnd : function() {
|
ace.Editor.prototype.moveCursorLineEnd = function() {
|
||||||
this.moveCursorTo(this.cursor.row, this.doc.getLine(this.cursor.row).length);
|
this.moveCursorTo(this.cursor.row, this.doc.getLine(this.cursor.row).length);
|
||||||
this.renderer.scrollCursorIntoView();
|
this.renderer.scrollCursorIntoView();
|
||||||
},
|
};
|
||||||
|
|
||||||
moveCursorBy : function(rows, chars) {
|
ace.Editor.prototype.moveCursorBy = function(rows, chars) {
|
||||||
this.moveCursorTo(this.cursor.row+rows, this.cursor.column+chars);
|
this.moveCursorTo(this.cursor.row+rows, this.cursor.column+chars);
|
||||||
},
|
};
|
||||||
|
|
||||||
moveCursorTo : function(row, column)
|
ace.Editor.prototype.moveCursorTo = function(row, column)
|
||||||
{
|
{
|
||||||
if (row >= this.doc.getLength()) {
|
if (row >= this.doc.getLength()) {
|
||||||
this.cursor.row = this.doc.getLength()-1;
|
this.cursor.row = this.doc.getLength()-1;
|
||||||
this.cursor.column = this.doc.getLine(this.cursor.row).length;
|
this.cursor.column = this.doc.getLine(this.cursor.row).length;
|
||||||
|
|
@ -508,14 +510,14 @@ function Editor(doc, renderer)
|
||||||
this.cursor.column = Math.min(this.doc.getLine(this.cursor.row).length, Math.max(0, column));
|
this.cursor.column = Math.min(this.doc.getLine(this.cursor.row).length, Math.max(0, column));
|
||||||
}
|
}
|
||||||
this.updateCursor();
|
this.updateCursor();
|
||||||
},
|
};
|
||||||
|
|
||||||
hasSelection : function() {
|
ace.Editor.prototype.hasSelection = function() {
|
||||||
return !!this.selectionLead;
|
return !!this.selectionLead;
|
||||||
},
|
};
|
||||||
|
|
||||||
setSelectionAnchor : function(row, column)
|
ace.Editor.prototype.setSelectionAnchor = function(row, column)
|
||||||
{
|
{
|
||||||
this.clearSelection();
|
this.clearSelection();
|
||||||
|
|
||||||
this.selectionAnchor = {
|
this.selectionAnchor = {
|
||||||
|
|
@ -524,10 +526,10 @@ function Editor(doc, renderer)
|
||||||
};
|
};
|
||||||
|
|
||||||
this.selectionLead = null;
|
this.selectionLead = null;
|
||||||
},
|
};
|
||||||
|
|
||||||
getSelectionRange : function()
|
ace.Editor.prototype.getSelectionRange = function()
|
||||||
{
|
{
|
||||||
var anchor = this.selectionAnchor;
|
var anchor = this.selectionAnchor;
|
||||||
var lead = this.selectionLead;
|
var lead = this.selectionLead;
|
||||||
|
|
||||||
|
|
@ -546,10 +548,10 @@ function Editor(doc, renderer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
|
|
||||||
clearSelection : function()
|
ace.Editor.prototype.clearSelection = function()
|
||||||
{
|
{
|
||||||
this.selectionLead = null;
|
this.selectionLead = null;
|
||||||
this.selectionAnchor = null;
|
this.selectionAnchor = null;
|
||||||
|
|
||||||
|
|
@ -557,20 +559,20 @@ function Editor(doc, renderer)
|
||||||
this.renderer.removeMarker(this.selection);
|
this.renderer.removeMarker(this.selection);
|
||||||
this.selection = null;
|
this.selection = null;
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
|
|
||||||
selectAll : function()
|
ace.Editor.prototype.selectAll = function()
|
||||||
{
|
{
|
||||||
var lastRow = this.doc.getLength()-1;
|
var lastRow = this.doc.getLength()-1;
|
||||||
this.setSelectionAnchor(lastRow, this.doc.getLine(lastRow).length);
|
this.setSelectionAnchor(lastRow, this.doc.getLine(lastRow).length);
|
||||||
|
|
||||||
this._moveSelection(function() {
|
this._moveSelection(function() {
|
||||||
this.moveCursorTo(0, 0);
|
this.moveCursorTo(0, 0);
|
||||||
});
|
});
|
||||||
},
|
};
|
||||||
|
|
||||||
_moveSelection : function(mover)
|
ace.Editor.prototype._moveSelection = function(mover)
|
||||||
{
|
{
|
||||||
if (!this.selectionAnchor) {
|
if (!this.selectionAnchor) {
|
||||||
this.selectionAnchor = {
|
this.selectionAnchor = {
|
||||||
row: this.cursor.row,
|
row: this.cursor.row,
|
||||||
|
|
@ -590,34 +592,34 @@ function Editor(doc, renderer)
|
||||||
}
|
}
|
||||||
this.selection = this.renderer.addMarker(this.getSelectionRange(), "selection");
|
this.selection = this.renderer.addMarker(this.getSelectionRange(), "selection");
|
||||||
this.renderer.scrollCursorIntoView();
|
this.renderer.scrollCursorIntoView();
|
||||||
},
|
};
|
||||||
|
|
||||||
selectUp : function() {
|
ace.Editor.prototype.selectUp = function() {
|
||||||
this._moveSelection(this.moveCursorUp);
|
this._moveSelection(this.moveCursorUp);
|
||||||
},
|
};
|
||||||
|
|
||||||
selectDown : function() {
|
ace.Editor.prototype.selectDown = function() {
|
||||||
this._moveSelection(this.moveCursorDown);
|
this._moveSelection(this.moveCursorDown);
|
||||||
},
|
};
|
||||||
|
|
||||||
selectRight : function() {
|
ace.Editor.prototype.selectRight = function() {
|
||||||
this._moveSelection(this.moveCursorRight);
|
this._moveSelection(this.moveCursorRight);
|
||||||
},
|
};
|
||||||
|
|
||||||
selectLeft : function() {
|
ace.Editor.prototype.selectLeft = function() {
|
||||||
this._moveSelection(this.moveCursorLeft);
|
this._moveSelection(this.moveCursorLeft);
|
||||||
},
|
};
|
||||||
|
|
||||||
selectLineStart : function() {
|
ace.Editor.prototype.selectLineStart = function() {
|
||||||
this._moveSelection(this.moveCursorLineStart);
|
this._moveSelection(this.moveCursorLineStart);
|
||||||
},
|
};
|
||||||
|
|
||||||
selectLineEnd : function() {
|
ace.Editor.prototype.selectLineEnd = function() {
|
||||||
this._moveSelection(this.moveCursorLineEnd);
|
this._moveSelection(this.moveCursorLineEnd);
|
||||||
},
|
};
|
||||||
|
|
||||||
selectPageDown : function()
|
ace.Editor.prototype.selectPageDown = function()
|
||||||
{
|
{
|
||||||
var visibleRows = this.getLastVisibleRow() - this.getFirstVisibleRow();
|
var visibleRows = this.getLastVisibleRow() - this.getFirstVisibleRow();
|
||||||
var row = this.getPageDownRow() + Math.round(visibleRows / 2);
|
var row = this.getPageDownRow() + Math.round(visibleRows / 2);
|
||||||
|
|
||||||
|
|
@ -626,10 +628,10 @@ function Editor(doc, renderer)
|
||||||
this._moveSelection(function() {
|
this._moveSelection(function() {
|
||||||
this.moveCursorTo(row, this.cursor.column);
|
this.moveCursorTo(row, this.cursor.column);
|
||||||
});
|
});
|
||||||
},
|
};
|
||||||
|
|
||||||
selectPageUp : function()
|
ace.Editor.prototype.selectPageUp = function()
|
||||||
{
|
{
|
||||||
var visibleRows = this.getLastVisibleRow() - this.getFirstVisibleRow();
|
var visibleRows = this.getLastVisibleRow() - this.getFirstVisibleRow();
|
||||||
var row = this.getPageUpRow() + Math.round(visibleRows / 2);
|
var row = this.getPageUpRow() + Math.round(visibleRows / 2);
|
||||||
|
|
||||||
|
|
@ -638,13 +640,14 @@ function Editor(doc, renderer)
|
||||||
this._moveSelection(function() {
|
this._moveSelection(function() {
|
||||||
this.moveCursorTo(row, this.cursor.column);
|
this.moveCursorTo(row, this.cursor.column);
|
||||||
});
|
});
|
||||||
},
|
};
|
||||||
|
|
||||||
selectCurrentLine : function()
|
ace.Editor.prototype.selectCurrentLine = function()
|
||||||
{
|
{
|
||||||
this.setSelectionAnchor(this.cursor.row, 0);
|
this.setSelectionAnchor(this.cursor.row, 0);
|
||||||
this._moveSelection(function() {
|
this._moveSelection(function() {
|
||||||
this.moveCursorTo(this.cursor.row+1, 0);
|
this.moveCursorTo(this.cursor.row+1, 0);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
})();
|
||||||
|
|
@ -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,25 +8,23 @@ function TextDocument(text)
|
||||||
this.listeners = [];
|
this.listeners = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
TextDocument.prototype =
|
ace.TextDocument.prototype._split = function(text) {
|
||||||
{
|
|
||||||
_split : function(text) {
|
|
||||||
return text.split(/[\n\r]/)
|
return text.split(/[\n\r]/)
|
||||||
},
|
};
|
||||||
|
|
||||||
addChangeListener : function(listener) {
|
ace.TextDocument.prototype.addChangeListener = function(listener) {
|
||||||
this.listeners.push(listener);
|
this.listeners.push(listener);
|
||||||
},
|
};
|
||||||
|
|
||||||
fireChangeEvent : function(firstRow, lastRow)
|
ace.TextDocument.prototype.fireChangeEvent = function(firstRow, lastRow)
|
||||||
{
|
{
|
||||||
for (var i=0; i < this.listeners.length; i++) {
|
for (var i=0; i < this.listeners.length; i++) {
|
||||||
this.listeners[i](firstRow, lastRow);
|
this.listeners[i](firstRow, lastRow);
|
||||||
};
|
};
|
||||||
},
|
};
|
||||||
|
|
||||||
getWidth : function()
|
ace.TextDocument.prototype.getWidth = function()
|
||||||
{
|
{
|
||||||
if (this.modified)
|
if (this.modified)
|
||||||
{
|
{
|
||||||
this.modified = false;
|
this.modified = false;
|
||||||
|
|
@ -37,13 +37,13 @@ TextDocument.prototype =
|
||||||
this.width = longestLine;
|
this.width = longestLine;
|
||||||
}
|
}
|
||||||
return this.width;
|
return this.width;
|
||||||
},
|
};
|
||||||
|
|
||||||
getLine : function(row) {
|
ace.TextDocument.prototype.getLine = function(row) {
|
||||||
return this.lines[row] || "";
|
return this.lines[row] || "";
|
||||||
},
|
};
|
||||||
|
|
||||||
keywords : {
|
ace.TextDocument.prototype.keywords = {
|
||||||
"break" : 1,
|
"break" : 1,
|
||||||
"case" : 1,
|
"case" : 1,
|
||||||
"catch" : 1,
|
"catch" : 1,
|
||||||
|
|
@ -67,10 +67,10 @@ TextDocument.prototype =
|
||||||
"var" : 1,
|
"var" : 1,
|
||||||
"while" : 1,
|
"while" : 1,
|
||||||
"with" : 1
|
"with" : 1
|
||||||
},
|
};
|
||||||
|
|
||||||
getLineTokens : function(row)
|
ace.TextDocument.prototype.getLineTokens = function(row)
|
||||||
{
|
{
|
||||||
var tokens = [];
|
var tokens = [];
|
||||||
|
|
||||||
var re = /(?:(\s+)|("[^"]*")|('[^']*')|([\[\]\(\)\{\}])|([a-zA-Z_][a-zA-Z0-9_]*)|(\/\/.*)|(.))/g
|
var re = /(?:(\s+)|("[^"]*")|('[^']*')|([\[\]\(\)\{\}])|([a-zA-Z_][a-zA-Z0-9_]*)|(\/\/.*)|(.))/g
|
||||||
|
|
@ -97,14 +97,14 @@ TextDocument.prototype =
|
||||||
};
|
};
|
||||||
|
|
||||||
return tokens;
|
return tokens;
|
||||||
},
|
};
|
||||||
|
|
||||||
getLength : function() {
|
ace.TextDocument.prototype.getLength = function() {
|
||||||
return this.lines.length;
|
return this.lines.length;
|
||||||
},
|
};
|
||||||
|
|
||||||
getTextRange : function(range)
|
ace.TextDocument.prototype.getTextRange = function(range)
|
||||||
{
|
{
|
||||||
if (range.start.row == range.end.row) {
|
if (range.start.row == range.end.row) {
|
||||||
return this.lines[range.start.row].substring(range.start.column, range.end.column);
|
return this.lines[range.start.row].substring(range.start.column, range.end.column);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -115,20 +115,20 @@ TextDocument.prototype =
|
||||||
|
|
||||||
return lines.join("\n");
|
return lines.join("\n");
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
|
|
||||||
insert : function(position, text)
|
ace.TextDocument.prototype.insert = function(position, text)
|
||||||
{
|
{
|
||||||
var end = this._insert(position, text);
|
var end = this._insert(position, text);
|
||||||
this.fireChangeEvent(
|
this.fireChangeEvent(
|
||||||
position.row,
|
position.row,
|
||||||
position.row == end.row ? position.row : undefined
|
position.row == end.row ? position.row : undefined
|
||||||
);
|
);
|
||||||
return end;
|
return end;
|
||||||
},
|
};
|
||||||
|
|
||||||
_insert : function(position, text)
|
ace.TextDocument.prototype._insert = function(position, text)
|
||||||
{
|
{
|
||||||
this.modified = true;
|
this.modified = true;
|
||||||
|
|
||||||
var newLines = this._split(text);
|
var newLines = this._split(text);
|
||||||
|
|
@ -173,10 +173,10 @@ TextDocument.prototype =
|
||||||
column: newLines[newLines.length-1].length
|
column: newLines[newLines.length-1].length
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
|
|
||||||
remove : function(range)
|
ace.TextDocument.prototype.remove = function(range)
|
||||||
{
|
{
|
||||||
var end = this._remove(range);
|
var end = this._remove(range);
|
||||||
|
|
||||||
this.fireChangeEvent(
|
this.fireChangeEvent(
|
||||||
|
|
@ -184,10 +184,10 @@ TextDocument.prototype =
|
||||||
range.end.row == range.start.row ? range.start.row : undefined
|
range.end.row == range.start.row ? range.start.row : undefined
|
||||||
);
|
);
|
||||||
return end;
|
return end;
|
||||||
},
|
};
|
||||||
|
|
||||||
_remove : function(range)
|
ace.TextDocument.prototype._remove = function(range)
|
||||||
{
|
{
|
||||||
this.modified = true;
|
this.modified = true;
|
||||||
|
|
||||||
var firstRow = range.start.row;
|
var firstRow = range.start.row;
|
||||||
|
|
@ -200,10 +200,10 @@ TextDocument.prototype =
|
||||||
this.lines.splice(firstRow, lastRow-firstRow+1, row);
|
this.lines.splice(firstRow, lastRow-firstRow+1, row);
|
||||||
|
|
||||||
return range.start;
|
return range.start;
|
||||||
},
|
};
|
||||||
|
|
||||||
replace : function(range, text)
|
ace.TextDocument.prototype.replace = function(range, text)
|
||||||
{
|
{
|
||||||
this._remove(range);
|
this._remove(range);
|
||||||
if (text) {
|
if (text) {
|
||||||
var end = this._insert(range.start, text);
|
var end = this._insert(range.start, text);
|
||||||
|
|
@ -218,5 +218,4 @@ TextDocument.prototype =
|
||||||
);
|
);
|
||||||
|
|
||||||
return end;
|
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