Skip to content

Commit 60fffbe

Browse files
committed
Added kind maklesoft.cross.ApplicationEvents
0 parents  commit 60fffbe

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
enyo.kind({
2+
name: "maklesoft.cross.ApplicationEvents",
3+
kind: enyo.ApplicationEvents,
4+
events: {
5+
onSearch: ""
6+
},
7+
create: function() {
8+
this.inherited(arguments);
9+
10+
this.chromeWindowFocusChangedHandler = enyo.bind(this, this.chromeWindowFocusChangedHandler);
11+
this.windowActivatedHandler = enyo.bind(this, this.doWindowActivated);
12+
this.windowDeactivatedHandler = enyo.bind(this, this.doWindowDeactivated);
13+
this.backHandler = enyo.bind(this, this.doBack);
14+
this.openAppMenuHandler = enyo.bind(this, this.doOpenAppMenu);
15+
this.searchHandler = enyo.bind(this, this.doSearch);
16+
17+
if (typeof chrome != 'undefined' && chrome.windows) {
18+
if (this.onWindowActivated || this.onWindowDeactivated) {
19+
chrome.windows.getCurrent(enyo.bind(this, function(window) {
20+
this.chromeWindowId = window.id;
21+
chrome.windows.onFocusChanged.addListener(this.chromeWindowFocusChangedHandler);
22+
}))
23+
}
24+
} else if (typeof PhoneGap != 'undefined') {
25+
if (this.onWindowActivated) {
26+
document.addEventListener("pause", this.windowActivatedHandler, false);
27+
}
28+
if (this.onWindowDeactivated) {
29+
document.addEventListener("resume", this.windowDeactivatedHandler, false);
30+
}
31+
32+
if (this.onBack) {
33+
document.addEventListener("backbutton", this.backHandler, false);
34+
}
35+
36+
if (this.onOpenAppMenu) {
37+
document.addEventListener("menubutton", this.openAppMenuHandler, false);
38+
}
39+
40+
if (this.onSearch) {
41+
document.addEventListener("searchbutton", this.searchHandler, false);
42+
}
43+
}
44+
},
45+
chromeWindowFocusChangedHandler: function(windowId) {
46+
if (this.chromeWindowId == windowId) {
47+
this.doWindowActivated();
48+
} else {
49+
this.doWindowDeactivated();
50+
}
51+
},
52+
destroy: function() {
53+
this.inherited(arguments);
54+
if (typeof chrome != 'undefined' && chrome.windows) {
55+
chrome.windows.onFocusChanged.removeListener(this.chromeWindowFocusChangedHandler);
56+
} else if (typeof PhoneGap != 'undefined') {
57+
document.removeEventListener("pause", this.windowActivatedHandler);
58+
document.removeEventListener("resume", this.windowDeactivatedHandler);
59+
document.removeEventListener("backbutton", this.backHandler);
60+
document.removeEventListener("menubutton", this.openAppMenuHandler);
61+
document.removeEventListener("searchbutton", this.searchHandler);
62+
}
63+
}
64+
});

0 commit comments

Comments
 (0)