Permalink
Browse files

Simplify code, jQuery style by using shorter annotations

  • Loading branch information...
1 parent 32375c5 commit 530439491d6bf9f8a33a4f78a4c8284f0555fe46 @mohamedmansour committed Jan 22, 2011
Showing with 22 additions and 14 deletions.
  1. +7 −0 js/functions.js
  2. +14 −14 js/options.js
  3. +1 −0 options.html
View
@@ -0,0 +1,7 @@
+/**
+ * Short form for getting elements by id.
+ * @param {string} id The id.
+ */
+function $(id) {
+ return document.getElementById(id);
+}
View
@@ -9,8 +9,8 @@ window.addEventListener('load', onLoad, false);
*/
function onLoad() {
onRestore();
- document.getElementById('button-save').addEventListener('click', onSave, false);
- document.getElementById('button-close').addEventListener('click', onClose, false);
+ $('button-save').addEventListener('click', onSave, false);
+ $('button-close').addEventListener('click', onClose, false);
}
/**
@@ -25,19 +25,19 @@ function onClose() {
*/
function onSave() {
// Save settings.
- bkg.settings.scheme = document.getElementById('scheme').value;
- bkg.settings.host = document.getElementById('host').value;
- bkg.settings.port = parseInt(document.getElementById('port').value);
- bkg.settings.opt_out = document.getElementById('opt_out').checked;
- bkg.settings.autostart = document.getElementById('autostart').checked;
+ bkg.settings.scheme = $('scheme').value;
+ bkg.settings.host = $('host').value;
+ bkg.settings.port = parseInt($('port').value);
+ bkg.settings.opt_out = $('opt_out').checked;
+ bkg.settings.autostart = $('autostart').checked;
// Check if the status of the proxy server is online, if so, refresh it.
if (bkg.proxy_status) {
bkg.setProxyEnabled(true);
}
// Update status to let user know options were saved.
- var info = document.getElementById('info-message');
+ var info = $('info-message');
info.style.display = 'inline';
info.style.opacity = 1;
setTimeout(function() {
@@ -50,10 +50,10 @@ function onSave() {
*/
function onRestore() {
// Restore settings.
- document.getElementById('version').innerHTML = ' (v' + bkg.settings.version + ')';
- document.getElementById('opt_out').checked = bkg.settings.opt_out;
- document.getElementById('host').value = bkg.settings.host;
- document.getElementById('port').value = bkg.settings.port;
- document.getElementById('scheme').value = bkg.settings.scheme;
- document.getElementById('autostart').checked = bkg.settings.autostart;
+ $('version').innerHTML = ' (v' + bkg.settings.version + ')';
+ $('opt_out').checked = bkg.settings.opt_out;
+ $('host').value = bkg.settings.host;
+ $('port').value = bkg.settings.port;
+ $('scheme').value = bkg.settings.scheme;
+ $('autostart').checked = bkg.settings.autostart;
}
View
@@ -3,6 +3,7 @@
<head>
<title>Proxy Anywhere</title>
<link rel="stylesheet" type="text/css" href="/css/options.css">
+ <script type="text/javascript" src="/js/functions.js"></script>
<script type="text/javascript" src="/js/options.js"></script>
</head>
<body>

0 comments on commit 5304394

Please sign in to comment.