-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintents-repo.js
47 lines (40 loc) · 1.29 KB
/
intents-repo.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
(function() {
function _getIntentRegistrations() {
if (localStorage.intentHandlers) {
return JSON.parse(localStorage.intentHandlers);
}
return {};
}
function _setIntentRegistrations(ob) {
localStorage.intentHandlers = JSON.stringify(ob);
}
var chan = Channel.build({window: window.parent, origin: "*", scope: "intents_channel"});
chan.bind("registerIntentHandler", function(trans, data) {
var intentsOb = _getIntentRegistrations();
if (!intentsOb[data.intent]) {
intentsOb[data.intent] = {};
}
if (!intentsOb[data.intent][data.filter]) {
intentsOb[data.intent][data.filter] = {};
}
intentsOb[data.intent][data.filter][data.url] = data;
_setIntentRegistrations(intentsOb);
});
chan.bind("isIntentHandlerRegistered", function(trans, data) {
var intentsOb = _getIntentRegistrations();
try {
return !!intentsOb[data.intent][data.filter][data.url];
} catch(ex) {
return false;
}
});
chan.bind("unregisterIntentandler", function(trans, data) {
var intentsOb = _getIntentRegistrations();
try {
delete localStorage.intentHandlers[data.intent][data.filter][data.url];
} catch (ex) {
return; // nothing to do.
}
_setIntentRegistrations(intentsOb);
});
})();