-
Notifications
You must be signed in to change notification settings - Fork 0
/
clickfocus.js
32 lines (30 loc) · 862 Bytes
/
clickfocus.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
(function() {
var focus_e=null;
var entity_clicked=false;
var init_first_entity=true;
Crafty.c("ClickFocus", {
init: function() {
this.requires("Mouse");
this.bind("Click", function() {
if(focus_e) {
focus_e.trigger("Blur");
}
focus_e=this;
focus_e.trigger("Focus");
entity_clicked=true;
});
if(init_first_entity) {
init_first_entity=false;
Crafty.addEvent(this, Crafty.stage.elem, "click", function() {
if(!entity_clicked) {
if(focus_e) {
focus_e.trigger("Blur")
}
focus_e=null;
}
entity_clicked=false;
});
}
}
});
})();