-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevent-synthetic.js
117 lines (93 loc) · 3.14 KB
/
event-synthetic.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
/**
Backward compatibility shim for Y.Event.define.
@module eventx
@submodule eventx-synthetic
@for Y.Event
**/
var nodeMap = Y.Node._instances,
DOMEvent = Y.Event.DOMEvent,
NOOP = function () {};
function SynthSubscription() {
DOMEvent.Subscription.apply(this, arguments);
}
Y.extend(SynthSubscription, DOMEvent.Subscription, {
notify: function (args) {
if (args[0] && args[0].type) {
args[0].type = this.details.domType;
}
return DOMEvent.Subscription.prototype.notify.apply(this, arguments);
},
// To mock the notifier object from current synth infrastructure
fire: function () {
this.notify(arguments);
}
});
Y.Event.SyntheticEvent = new Y.CustomEvent({
parseSignature: function (target, args, details) {
var extras;
if (this.processArgs) {
extras = this.processArgs(args, details.delegate);
if (extras) {
Y.mix(details, extras, true);
}
}
},
on: function (el, sub) {
var details = sub.details,
node = Y.one(el),
method = (details.delegate && this._oldDelegate) ?
'_oldDelegate' : '_oldOn';
details.nodeYuid = node._yuid;
if (this[method]) {
// Pass the filter even to _oldOn() because it's harmless, since
// the signature is expecting only three args. Also, it should
// allow some synths to remove their delegate config, since it
// only relayed to on() anyway.
this[method](node, sub, sub, details.filter);
}
},
// Extract the filter only. Delegation logic is mostly deferred to
// the forking to event._oldDelegate() from event.on()
delegate: function (target, args, details) {
details.filter = args.splice(2, 1)[0];
if (!args[2]) {
args[2] = this.thisObjFn;
}
},
detach: function (target, sub) {
var node;
if (this._oldDetach) {
// TODO: better default? I'd rather not store the Node instance
node = nodeMap[sub.details.nodeYuid] || Y;
this._oldDetach(node, sub, sub);
}
},
thisObjFn: function (e) {
return (e && e.get && e.get('currentTarget')) ||
nodeMap[this.details.nodeYuid]; // default to container?
},
Subscription: SynthSubscription,
// No actual DOM sub is added directly by SyntheticEvent
_addDOMSub : NOOP,
_removeDOMSub: NOOP
}, DOMEvent);
Y.Event.define = function (type, config, force) {
if (force || !Y.Event.DOM_EVENTS[type]) {
config = Y.merge(config);
if (config.detach) {
config._oldDetach = config.detach;
// Don't override the SyntheticEvent's detach
delete config.detach;
}
if (config.on) {
config._oldOn = config.on;
delete config.on;
}
if (config.delegate) {
config._oldDelegate = config.delegate;
delete config.delegate;
}
Y.Event.DOM_EVENTS[type] =
new Y.CustomEvent(config, Y.Event.SyntheticEvent);
}
};