forked from dmachi/dojox_application
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Controller.js
75 lines (70 loc) · 2.02 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
75
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;
},
bind: function(evented, event, handler){
// summary:
// Bind event on dojo/Evented instance, document, domNode or window.
// Save event signal in controller instance. If no parameter is provided
// automatically bind all events registered in controller events property.
//
// evented: Object
// dojo/Evented instance, document, domNode or window
// event: String
// event
// handler: Function
// event handler
if(arguments.length == 0){
if(this.events){
for(var item in this.events){
if(item.charAt(0) !== "_"){//skip the private properties
this.bind(this.app, item, lang.hitch(this, this.events[item]));
}
}
}
}else{
var signal = on(evented, event, handler);
this._boundEvents.push({
"event": event,
"evented": evented,
"signal": signal
});
}
return this;
},
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);
return this;
}
});
});