convert to APF style mixins

This commit is contained in:
Fabian Jakobs 2010-04-22 13:41:32 +02:00
commit 1b37c1c6f2
7 changed files with 46 additions and 45 deletions

View file

@ -44,7 +44,7 @@ ace.BackgroundTokenizer = function(tokenizer) {
(function(){ (function(){
ace.mixin(this, ace.MEventEmitter); ace.implement(this, ace.MEventEmitter);
this.setTokenizer = function(tokenizer) { this.setTokenizer = function(tokenizer) {
this.tokenizer = tokenizer; this.tokenizer = tokenizer;

View file

@ -15,7 +15,7 @@ ace.Document = function(text, mode) {
(function() { (function() {
ace.mixin(ace.Document.prototype, ace.MEventEmitter); ace.implement(this, ace.MEventEmitter);
this._split = function(text) { this._split = function(text) {
return text.split(/\r\n|\r|\n/); return text.split(/\r\n|\r|\n/);

View file

@ -1,38 +1,41 @@
ace.provide("ace.MEventEmitter"); ace.provide("ace.MEventEmitter");
ace.MEventEmitter.$initEvents = function() { ace.MEventEmitter = function() {
this._eventRegistry = {};
}; this.$initEvents = function() {
this._eventRegistry = {};
ace.MEventEmitter.$dispatchEvent = function(eventName, e) { };
var listeners = this._eventRegistry[eventName];
if (!listeners || !listeners.length) return; this.$dispatchEvent = function(eventName, e) {
var listeners = this._eventRegistry[eventName];
var e = e || {}; if (!listeners || !listeners.length) return;
e.type = eventName;
var e = e || {};
for (var i=0; i<listeners.length; i++) { e.type = eventName;
listeners[i](e);
} for (var i=0; i<listeners.length; i++) {
}; listeners[i](e);
}
ace.MEventEmitter.addEventListener = function(eventName, callback) { };
var listeners = this._eventRegistry[eventName];
if (!listeners) { this.addEventListener = function(eventName, callback) {
var listeners = this._eventRegistry[eventName] = []; var listeners = this._eventRegistry[eventName];
} if (!listeners) {
if (ace.arrayIndexOf(listeners, callback) == -1) { var listeners = this._eventRegistry[eventName] = [];
listeners.push(callback); }
} if (ace.arrayIndexOf(listeners, callback) == -1) {
}; listeners.push(callback);
}
ace.MEventEmitter.removeEventListener = function(eventName, callback) { };
var listeners = this._eventRegistry[eventName];
if (!listeners) { this.removeEventListener = function(eventName, callback) {
return; var listeners = this._eventRegistry[eventName];
} if (!listeners) {
var index = ace.arrayIndexOf(listeners, callback); return;
if (index !== -1) { }
listeners.splice(index, 1); var index = ace.arrayIndexOf(listeners, callback);
} if (index !== -1) {
listeners.splice(index, 1);
}
};
}; };

View file

@ -19,7 +19,7 @@ ace.ScrollBar = function(parent) {
(function() { (function() {
ace.mixin(ace.ScrollBar.prototype, ace.MEventEmitter); ace.implement(this, ace.MEventEmitter);
this.onScroll = function() { this.onScroll = function() {
this.$dispatchEvent("scroll", {data: this.element.scrollTop}); this.$dispatchEvent("scroll", {data: this.element.scrollTop});

View file

@ -14,7 +14,7 @@ ace.Selection = function(doc) {
(function() { (function() {
ace.mixin(ace.Selection.prototype, ace.MEventEmitter); ace.implement(this, ace.MEventEmitter);
this.updateCursor = function() { this.updateCursor = function() {
this.$dispatchEvent("changeCursor", { data: this.getCursor() }); this.$dispatchEvent("changeCursor", { data: this.getCursor() });

View file

@ -21,10 +21,8 @@ ace.inherits = function(ctor, superCtor) {
ctor.prototype.constructor = ctor; ctor.prototype.constructor = ctor;
}; };
ace.mixin = function(obj, mixin) { ace.implement = function(proto, mixin) {
for (var key in mixin) { mixin.call(proto);
obj[key] = mixin[key];
}
}; };
ace.addListener = function(elem, type, callback) { ace.addListener = function(elem, type, callback) {
@ -81,7 +79,7 @@ ace.preventDefault = function(e) {
ace.hasCssClass = function(el, name) { ace.hasCssClass = function(el, name) {
var classes = el.className.split(/\s*/g); var classes = el.className.split(/\s*/g);
return ace.arrayIndexOf(classes, name) !== -1; return ace.arrayIndexOf(classes, name) !== -1;
}; };

View file

@ -1,7 +1,7 @@
var EventEmitter = function() { var EventEmitter = function() {
this.$initEvents(); this.$initEvents();
}; };
ace.mixin(EventEmitter.prototype, ace.MEventEmitter); ace.implement(EventEmitter.prototype, ace.MEventEmitter);
var EventEmitterTest = new TestCase("EventEmitterTest", { var EventEmitterTest = new TestCase("EventEmitterTest", {
"test: dispatch event with no data" : function() { "test: dispatch event with no data" : function() {