diff options
author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2014-02-28 13:47:09 -0800 |
---|---|---|
committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2014-02-28 13:47:09 -0800 |
commit | 1522c50e3ea420281bcc33b2bed7b4f297a4ba96 (patch) | |
tree | 5ee0bb7b26a666883f2b83ec88f489623d63231e /options.js | |
parent | 493fcd8f5cee5a5ed7ebee4c4b94594465da09d5 (diff) | |
download | tempo-1522c50e3ea420281bcc33b2bed7b4f297a4ba96.tar.gz tempo-1522c50e3ea420281bcc33b2bed7b4f297a4ba96.tar.xz |
Improve timeformat code.
Diffstat (limited to 'options.js')
-rw-r--r-- | options.js | 33 |
1 files changed, 14 insertions, 19 deletions
@@ -2,9 +2,12 @@ // Distributed under the terms of the GNU General Public License v2. // See http://www.gnu.org/licenses/gpl-2.0.txt for the full license text. -function save_options() { - var select = document.getElementById('timeformat'); - var timeformat = select.children[select.selectedIndex].value; +function saveOptions() { + var timeformat = 24; + if(document.getElementById('t12').checked) { + var timeformat = 12; + } + localStorage['timeformat'] = timeformat; var status = document.getElementById('status'); @@ -13,30 +16,22 @@ function save_options() { setTimeout(function() {status.innerHTML = ' '}, 1000); } -function restore_options() { +function restoreOptions() { var timeformat = localStorage['timeformat']; if(!timeformat) { - timeformat = '24'; + timeformat = 24; } - var select = document.getElementById('timeformat'); - - for(var i = 0; i < select.children.length; i++) { - var child = select.children[i]; + var option = document.getElementById('t' + timeformat); - if(child.value == timeformat) { - child.selected = 'true'; - - break; - } - } + option.checked = true; } -function start_options() { - restore_options(); +function startOptions() { + restoreOptions(); - document.querySelector('#save').addEventListener('click', save_options); + document.querySelector('#save').addEventListener('click', saveOptions); } -window.onload = start_options; +window.onload = startOptions; |