/
popup.js
90 lines (84 loc) · 2.11 KB
/
popup.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
$(function() {
var ideKey = "XDEBUG_ECLIPSE";
// Check if localStorage is available and get the ideKey out of it if any
if (localStorage && localStorage["xdebugIdeKey"])
{
ideKey = localStorage["xdebugIdeKey"];
}
// Request the current state from the active tab
chrome.tabs.query({ active: true, windowId: chrome.windows.WINDOW_ID_CURRENT }, function(tabs)
{
chrome.tabs.sendMessage(
tabs[0].id,
{
cmd: "getStatus",
idekey: ideKey
},
function(response)
{
// Highlight the correct option
$('a[data-status="' + response.status + '"]').addClass("active");
}
);
});
// Attach handler when user clicks on
$("a").on("click", function(eventObject) {
var newStatus = $(this).data("status");
// Set the new state on the active tab
chrome.tabs.query({ active: true, windowId: chrome.windows.WINDOW_ID_CURRENT }, function(tabs)
{
chrome.tabs.sendMessage(
tabs[0].id,
{
cmd: "setStatus",
status: newStatus,
idekey: ideKey
},
function(response)
{
// Make the backgroundpage update the icon and close the popup
chrome.runtime.getBackgroundPage(function(backgroundPage) {
backgroundPage.updateIcon(response.status, tabs[0].id);
window.close();
});
}
);
});
});
// Shortcuts
key("d", function() { $("#action-debug").click(); });
key("p", function() { $("#action-profile").click(); });
key("t", function() { $("#action-trace").click(); });
key("s", function() { $("#action-disable").click(); });
key("space,enter", function() { $("a:focus").click(); });
key("down,right", function()
{
var current = $(".action:focus");
if (current.length === 0)
{
$(".action:first").focus();
}
else
{
current.parent().next().find("a").focus();
}
});
key("up,left", function()
{
var current = $(".action:focus");
if (current.length === 0)
{
$(".action:last").focus();
}
else
{
current.parent().prev().find("a").focus();
}
});
// Bit of a hack to prevent Chrome from focussing the first option automaticly
$("a").on("focus", function()
{
$(this).blur();
$("a").off("focus");
});
});