better CSS class handling
This commit is contained in:
parent
99ad78d13c
commit
09a09e8ac2
5 changed files with 34 additions and 9 deletions
|
|
@ -4,7 +4,7 @@ ace.ScrollBar = function(parent) {
|
|||
this.$initEvents();
|
||||
|
||||
this.element = document.createElement("div");
|
||||
this.element.className = "scrollbar";
|
||||
this.element.className = "sb";
|
||||
|
||||
this.inner = document.createElement("div");
|
||||
this.element.appendChild(this.inner);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ ace.provide("ace.VirtualRenderer");
|
|||
|
||||
ace.VirtualRenderer = function(container) {
|
||||
this.container = container;
|
||||
this.container.className += " editor";
|
||||
ace.addCssClass(this.container, "editor");
|
||||
|
||||
this.scroller = document.createElement("div");
|
||||
this.scroller.className = "scroller";
|
||||
|
|
@ -233,11 +233,11 @@ ace.VirtualRenderer.prototype.screenToTextCoordinates = function(pageX, pageY) {
|
|||
};
|
||||
|
||||
ace.VirtualRenderer.prototype.visualizeFocus = function() {
|
||||
//this.container.className = "editor focus";
|
||||
ace.addCssClass(this.container, "focus");
|
||||
};
|
||||
|
||||
ace.VirtualRenderer.prototype.visualizeBlur = function() {
|
||||
//this.container.className = "editor";
|
||||
ace.removeCssClass(this.container, "focus");
|
||||
};
|
||||
|
||||
ace.VirtualRenderer.prototype.showComposition = function(position) {
|
||||
|
|
|
|||
25
src/ace.js
25
src/ace.js
|
|
@ -78,6 +78,31 @@ ace.preventDefault = function(e) {
|
|||
e.returnValue = false;
|
||||
};
|
||||
|
||||
|
||||
ace.hasCssClass = function(el, name) {
|
||||
var classes = el.className.split(/\s*/g);
|
||||
return ace.arrayIndexOf(classes, name) !== -1;
|
||||
};
|
||||
|
||||
|
||||
ace.addCssClass = function(el, name) {
|
||||
if (!ace.hasCssClass(el, name)) {
|
||||
el.className += " " + name;
|
||||
}
|
||||
};
|
||||
|
||||
ace.removeCssClass = function(el, name) {
|
||||
var classes = el.className.split(/\s+/g);
|
||||
while (true) {
|
||||
var index = ace.arrayIndexOf(classes, name);
|
||||
if (index == -1) {
|
||||
break;
|
||||
}
|
||||
classes.splice(index, 1);
|
||||
}
|
||||
el.className = classes.join(" ");
|
||||
};
|
||||
|
||||
ace.getInnerWidth = function(element) {
|
||||
return (parseInt(ace.computedStyle(element, "paddingLeft"))
|
||||
+ parseInt(ace.computedStyle(element, "paddingRight")) + element.clientWidth);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue