forked from stsquad/emacs_chrome
-
Notifications
You must be signed in to change notification settings - Fork 1
/
options.js
66 lines (56 loc) · 1.9 KB
/
options.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
/*
* options.js
*
* This is the JavaScript for the extension options page
*
* This file is part of emacs_chrome (http://github.com/stsquad/emacs_chrome)
* and licensed under the GPLv3. See the COPYING file for details
*/
// Snarfed from AdThwart, not sure why checkboxes are so trixy
function loadCheckbox(id, config) {
document.getElementById(id).checked = typeof localStorage[config] == "undefined" ? false : localStorage[config] == "true";
}
function saveCheckbox(id, config) {
localStorage[config] = document.getElementById(id).checked;
}
// Saves options to localStorage
function save_options() {
localStorage["edit_server_port"] = document.getElementById("port").value;
saveCheckbox("dblclick", "enable_dblclick");
saveCheckbox("keyshort", "enable_keys");
// Update status to let user know options were saved.
var status = document.getElementById("status");
status.innerHTML = "Options Saved.";
setTimeout(function() {
status.innerHTML = "";
}, 750);
}
// Restores select box state to saved value from localStorage.
function restore_options() {
var port = localStorage["edit_server_port"];
if (!port) {
port = 9292;
}
document.getElementById("port").value = port;
loadCheckbox("dblclick", "enable_dblclick");
loadCheckbox("keyshort", "enable_keys");
}
/* Message handling multiplexer */
function localMessageHandler(msg, port) {
// What was the bidding?
var cmd = msg.msg;
if (cmd == "test_result") {
var status = document.getElementById("server_status");
status.innerHTML = msg.text;
} else {
console.log("localMessageHandler: un-handled message:"+cmd);
}
}
// Test for the presence of an Edit Server
function test_server() {
var port = chrome.extension.connect();
var status = document.getElementById("server_status");
status.innerHTML = "testing...";
port.onMessage.addListener(localMessageHandler);
port.postMessage({msg: "test"});
}