-
Notifications
You must be signed in to change notification settings - Fork 0
/
doon.js
61 lines (51 loc) · 1.47 KB
/
doon.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
/**
* Do On - Super light weight event driven containers.
*
* @version 1.0.2
* @author Christian Blanquera <cblanquera@openovate.com>
* @website https://github.com/cblanquera/doon
* @license MIT
*/
jQuery.fn.extend({
doon: function() {
return this.each(function() {
jQuery('*[data-do]', this).add(this)
.each(function() {
var trigger = jQuery(this);
var actions = trigger.attr('data-do');
if(!actions || trigger.data('doon')) {
return;
}
actions = actions.split('|');
trigger.data('doon', true);
var event = trigger.attr('data-on');
var target = this;
if (trigger.data('doon-target')) {
target = jQuery(trigger.data('doon-target'));
}
//trigger init
actions.forEach(function(action) {
jQuery(window).trigger(action+'-init', [target]);
});
if(!event) {
return;
}
jQuery.each(event.split('|'), function(i, event) {
jQuery(target).on(event, function(e) {
actions.some(function(action) {
//mod the custom event type
e.type = action + '-' + event;
//pass it along
jQuery(window).trigger(e, [target]);
return e.return === false
});
//so you can stop a form
if (e.return === false) {
return false;
}
});
});
});
});
}
});