forked from mycolorway/simditor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodule.js
149 lines (119 loc) · 3.99 KB
/
module.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
(function() {
var Module, Plugin, Widget,
__slice = [].slice,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
Module = (function() {
function Module() {}
Module.extend = function(obj) {
var key, val, _ref;
if (!((obj != null) && typeof obj === 'object')) {
return;
}
for (key in obj) {
val = obj[key];
if (key !== 'included' && key !== 'extended') {
this[key] = val;
}
}
return (_ref = obj.extended) != null ? _ref.call(this) : void 0;
};
Module.include = function(obj) {
var key, val, _ref;
if (!((obj != null) && typeof obj === 'object')) {
return;
}
for (key in obj) {
val = obj[key];
if (key !== 'included' && key !== 'extended') {
this.prototype[key] = val;
}
}
return (_ref = obj.included) != null ? _ref.call(this) : void 0;
};
Module.prototype.on = function() {
var args, _ref;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
return (_ref = $(this)).on.apply(_ref, args);
};
Module.prototype.one = function() {
var args, _ref;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
return (_ref = $(this)).one.apply(_ref, args);
};
Module.prototype.off = function() {
var args, _ref;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
return (_ref = $(this)).off.apply(_ref, args);
};
Module.prototype.trigger = function() {
var args, _ref;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
return (_ref = $(this)).trigger.apply(_ref, args);
};
Module.prototype.triggerHandler = function() {
var args, _ref;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
return (_ref = $(this)).triggerHandler.apply(_ref, args);
};
return Module;
})();
Widget = (function(_super) {
__extends(Widget, _super);
Widget.connect = function(cls) {
if (typeof cls !== 'function') {
return;
}
if (!cls.className) {
throw new Error('Widget.connect: lack of class property "className"');
return;
}
this.prototype._connectedClasses.push(cls);
if (cls.className) {
return this[cls.className] = cls;
}
};
Widget.prototype._connectedClasses = [];
Widget.prototype._init = function() {};
Widget.prototype.opts = {};
function Widget(opts) {
var cls, instance, instances, name, _i, _len;
this.opts = $.extend({}, this.opts, opts);
instances = (function() {
var _i, _len, _ref, _results;
_ref = this._connectedClasses;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
cls = _ref[_i];
name = cls.className.charAt(0).toLowerCase() + cls.className.slice(1);
_results.push(this[name] = new cls(this));
}
return _results;
}).call(this);
this._init();
for (_i = 0, _len = instances.length; _i < _len; _i++) {
instance = instances[_i];
if (typeof instance._init === "function") {
instance._init();
}
}
this.trigger('pluginconnected');
}
Widget.prototype.destroy = function() {};
return Widget;
})(Module);
Plugin = (function(_super) {
__extends(Plugin, _super);
Plugin.className = 'Plugin';
Plugin.prototype.opts = {};
function Plugin(widget) {
this.widget = widget;
this.opts = $.extend({}, this.opts, this.widget.opts);
}
Plugin.prototype._init = function() {};
return Plugin;
})(Module);
window.Module = Module;
window.Widget = Widget;
window.Plugin = Plugin;
}).call(this);