forked from dmachi/dojox_application
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Controller.js
74 lines (67 loc) · 1.92 KB
/
Controller.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
define(["dojo/_base/lang", "dojo/_base/declare", "dojo/on"], function(lang, declare, on){
// module:
// dojox/app/Controller
// summary:
// Bind events on dojox/app application's dojo/Evented instance or document.
return declare("dojox.app.Controller", null, {
constructor: function(app, events){
// summary:
// bind events on application dojo/Evented instance.
// bind css selector events on document.
//
// app:
// dojox/app application instance.
// events:
// {event : handler}
this.events = this.events || events;
this._boundEvents = [];
this.app = app;
if(this.events){
for(var item in this.events){
if(item.charAt(0) !== "_"){//skip the private properties
this.bind(this.app.domNode, item, lang.hitch(this, this.events[item]));
}
}
}
},
bind: function(evented, event, handler){
// summary:
// Bind event on dojo/Evented instance, document, domNode or window.
// Save event signal in controller instance.
//
// evented: Object
// dojo/Evented instance, document, domNode or window
// event: String
// event
// handler: Function
// event handler
if(!handler){
console.warn("bind event '"+event+"' without callback function.");
}
var signal = on(evented, event, handler);
this._boundEvents.push({
"event": event,
"evented": evented,
"signal": signal
});
},
unbind: function(evented, event){
// summary:
// remove a binded event signal.
//
// evented: Object
// dojo/Evented instance, document, domNode or window
// event: String
// event
var len = this._boundEvents.length;
for(var i=0; i<len; i++){
if((this._boundEvents[i]['event'] == event) && (this._boundEvents[i]['evented'] == evented)){
this._boundEvents[i]['signal'].remove();
this._boundEvents.splice(i, 1);
return;
}
}
console.warn("event '"+event+"' not bind on ", evented);
}
});
});