forked from maccman/holla
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsuperapp.js
More file actions
72 lines (57 loc) · 1.4 KB
/
Copy pathsuperapp.js
File metadata and controls
72 lines (57 loc) · 1.4 KB
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
//= require <superclass>
//= require <superevent>
var SuperApp = new SuperClass;
SuperApp.include(SuperEvent);
SuperApp.include({
init: function(){
this.states = {};
this.current = new SuperApp.State;
},
add: function(name){
var state = new SuperApp.State(this, name);
this.states[name] = state;
return state;
},
find: function(name){
return(this.states[name]);
},
change: function(){
var args = jQuery.makeArray(arguments);
var name = args.shift();
var previous = this.current;
var state = this.states[name];
if ( !state ) throw "Unknown state: " + name;
state.runSetup();
previous.beforeExit();
state.beforeEnter.apply(state, args);
this.current = state;
state.afterEnter();
previous.afterExit();
this.trigger("change", name, state);
}
});
SuperApp.State = new SuperClass;
SuperApp.State.include(SuperEvent);
SuperApp.State.include({
init: function(app, name){
this.app = app;
this.name = name;
jQuery(this.proxy(function(){
this.load();
}));
},
runSetup: function(){
if ( !this.hasSetup ) {
this.hasSetup = true;
this.setup();
}
},
delay: function(func, timeout){
setTimeout(this.proxy(func, timeout || 0));
}
});
SuperApp.State.fn.setupEvents([
"beforeEnter", "afterEnter",
"beforeExit", "afterExit",
"load", "setup"
]);