Skip to content

Commit fddf581

Browse files
committed
first step
1 parent 6521b69 commit fddf581

File tree

3 files changed

+117
-0
lines changed

3 files changed

+117
-0
lines changed

Class.js

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/* Simple JavaScript Inheritance
2+
* By John Resig http://ejohn.org/
3+
* MIT Licensed.
4+
*/
5+
// Inspired by base2 and Prototype
6+
(function(){
7+
var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
8+
9+
// The base Class implementation (does nothing)
10+
this.Class = function(){};
11+
12+
// Create a new Class that inherits from this class
13+
Class.extend = function(prop) {
14+
var _super = this.prototype;
15+
16+
// Instantiate a base class (but only create the instance,
17+
// don't run the init constructor)
18+
initializing = true;
19+
var prototype = new this();
20+
initializing = false;
21+
22+
// Copy the properties over onto the new prototype
23+
for (var name in prop) {
24+
// Check if we're overwriting an existing function
25+
prototype[name] = typeof prop[name] == "function" &&
26+
typeof _super[name] == "function" && fnTest.test(prop[name]) ?
27+
(function(name, fn){
28+
return function() {
29+
var tmp = this._super;
30+
31+
// Add a new ._super() method that is the same method
32+
// but on the super-class
33+
this._super = _super[name];
34+
35+
// The method only need to be bound temporarily, so we
36+
// remove it when we're done executing
37+
var ret = fn.apply(this, arguments);
38+
this._super = tmp;
39+
40+
return ret;
41+
};
42+
})(name, prop[name]) :
43+
prop[name];
44+
}
45+
46+
// The dummy class constructor
47+
function Class() {
48+
// All construction is actually done in the init method
49+
if ( !initializing && this.init )
50+
this.init.apply(this, arguments);
51+
}
52+
53+
// Populate our constructed prototype object
54+
Class.prototype = prototype;
55+
56+
// Enforce the constructor to be what we expect
57+
Class.prototype.constructor = Class;
58+
59+
// And make this class extendable
60+
Class.extend = arguments.callee;
61+
62+
return Class;
63+
};
64+
})();
65+

Event.js

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
var Event = Class.extend({
2+
3+
listen: function(object, eventName, callback)
4+
{
5+
var context = this;
6+
var callbackWithContext = function(event) {
7+
callback.call(context, event);
8+
}
9+
if (object instanceof TwengaObject) {
10+
object._addListener(eventName, callbackWithContext);
11+
} else if(object instanceof Element) {
12+
object.addEventListener(eventName, function(event){
13+
event.source = this;
14+
event.name = eventName;
15+
callbackWithContext(event);
16+
}, false);
17+
}
18+
},
19+
20+
_addListener: function(eventName, callback)
21+
{
22+
if (this._aEventsListeners == undefined) {
23+
this._aEventsListeners = new Object();
24+
}
25+
if (this._aEventsListeners[eventName] == undefined) {
26+
this._aEventsListeners[eventName] = new Array();
27+
}
28+
this._aEventsListeners[eventName].push(callback);
29+
},
30+
31+
notify: function(eventName, event)
32+
{
33+
event = event || {};
34+
event.source = this;
35+
event.name = eventName;
36+
if (this._aEventsListeners[eventName] != undefined) {
37+
for (i in this._aEventsListeners[eventName]) {
38+
this._aEventsListeners[eventName][i](event);
39+
}
40+
}
41+
}
42+
43+
});

Fluent.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Array.prototype.extend = function()
2+
{
3+
var oCurrentObj = {};
4+
for(var i = 0; i < this.length; i++)
5+
{
6+
oCurrentObj = this[i].extend(oCurrentObj);
7+
}
8+
return oCurrentObj;
9+
}

0 commit comments

Comments
 (0)