From 836a5f2cbd10e335c7d099223e0b6d72d18d2351 Mon Sep 17 00:00:00 2001 From: Christopher Wall Date: Sun, 13 May 2012 20:47:12 +0100 Subject: [PATCH 1/5] Added "use seconds" --- index.html | 2 +- js/ui.js | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index 7d7878d..8606ba6 100644 --- a/index.html +++ b/index.html @@ -42,7 +42,7 @@

options

timer

-

+

session

diff --git a/js/ui.js b/js/ui.js index dfe8103..79eba96 100644 --- a/js/ui.js +++ b/js/ui.js @@ -35,6 +35,21 @@ var ui = (function() { if (hours > 0) {s = hours + ":" + s;} return s; } + function seconds_time(time) { + if(time < 0) return "DNF"; + + time = Math.round(time / (1000)); + var s=""; + var secs = time % 60; + var mins = ((time - secs) / 60) % 60; + var hours = (time - secs - 60 * mins) / 3600; + s = secs + if (secs < 10 && (mins > 0 || hours > 0)) {s = "0" + s;} + if (mins > 0 || hours > 0) {s = mins + ":" + s;} + if (mins < 20 && hours > 0) {s = "0" + s;} + if (hours > 0) {s = hours + ":" + s;} + return s; + } function solve_time(solve) { var out = ""; @@ -228,7 +243,12 @@ var ui = (function() { }, update_running: function(time) { + if(config['hide_milli']) + {t(timer_label, seconds_time(time));} + else + { t(timer_label, human_time(time)); + } }, on_stop: function() { @@ -336,6 +356,11 @@ var ui = (function() { update_stats(); t(timer_label, human_time(timer.get_time())); } + $('hide_milli').onchange = function() { + config['hide_milli'] = $('hide_milli').checked; + update_stats(); + t(timer_label, human_time(timer.get_time())); + } $('save_btn').onclick = session.save; $('load_btn').onclick = function() { session.load(); }; $('auto_save').onchange = function() { config['auto_save'] = $('auto_save').checked; }; @@ -372,6 +397,7 @@ var ui = (function() { } $('use_milli').checked = config['use_milli']; + $('hide_milli').checked = config['hide_milli']; window.onbeforeunload = on_close; window.onblur = function() { timer_label.style.color="gray"; }; From dd36dba30b3c9e6090f3412038dcca2df0e8f5c1 Mon Sep 17 00:00:00 2001 From: Christopher Wall Date: Sun, 13 May 2012 20:54:28 +0100 Subject: [PATCH 2/5] bn --- js/ui.js | 414 ------------------------------------------------------- 1 file changed, 414 deletions(-) delete mode 100644 js/ui.js diff --git a/js/ui.js b/js/ui.js deleted file mode 100644 index 79eba96..0000000 --- a/js/ui.js +++ /dev/null @@ -1,414 +0,0 @@ -"use strict"; -function load_external(url) { - var file = document.createElement('script'); - file.type = "text/javascript"; - file.src = url; - document.getElementsByTagName("head")[0].appendChild(file); -} - -function $(id) { return document.getElementById(id); } -function t(e, t) { e.innerHTML = t; } - -var ui = (function() { - function toggle(e) { e.style.display = (e.style.display === "none") ? "inline" : "none"; } - function is_visible(e) { return e.style.display !== "none"; } - - var timer_label, times_label, scramble_label, stats_label, options_label, to_hide; - var config; - - function human_time(time) { - if(time < 0) return "DNF"; - - time = Math.round(time / (config['use_milli'] ? 1 : 10)); - var bits = time % (config['use_milli'] ? 1000 : 100); - time = (time - bits) / (config['use_milli'] ? 1000 : 100); - var secs = time % 60; - var mins = ((time - secs) / 60) % 60; - var hours = (time - secs - 60 * mins) / 3600; - var s = "" + bits; - if (bits < 10) {s = "0" + s;} - if (bits < 100 && config['use_milli']) {s = "0" + s;} - s = secs + "." + s; - if (secs < 10 && (mins > 0 || hours > 0)) {s = "0" + s;} - if (mins > 0 || hours > 0) {s = mins + ":" + s;} - if (mins < 20 && hours > 0) {s = "0" + s;} - if (hours > 0) {s = hours + ":" + s;} - return s; - } - function seconds_time(time) { - if(time < 0) return "DNF"; - - time = Math.round(time / (1000)); - var s=""; - var secs = time % 60; - var mins = ((time - secs) / 60) % 60; - var hours = (time - secs - 60 * mins) / 3600; - s = secs - if (secs < 10 && (mins > 0 || hours > 0)) {s = "0" + s;} - if (mins > 0 || hours > 0) {s = mins + ":" + s;} - if (mins < 20 && hours > 0) {s = "0" + s;} - if (hours > 0) {s = hours + ":" + s;} - return s; - } - - function solve_time(solve) { - var out = ""; - if(solve['DNF']) - out += "DNF("; - - out += human_time(solve['time']); - out += solve['plus_two'] ? "+" : ""; - - if(solve['DNF']) - out += ")"; - return out; - } - - function on_inspection(inspection_time) { - timer_label.style.color = "red"; - if(inspection_time > 0) { - t(timer_label, inspection_time); - } - else if(inspection_time > -2) { - t(timer_label, "+2"); - } - else { - t(timer_label, "DNF"); - } - } - - function next_scramble() - { - t(scramble_label, scramble_manager.next()); - } - - function update_stats() { - t($('s_t'), session.length()); - t($('c_a_5'), human_time(session.current_average(5))); - t($('c_a_12'), human_time(session.current_average(12))); - t($('c_a_100'), human_time(session.current_average(100))); - t($('b_a_5'), human_time(session.best_average(5, false)['avg'])); - t($('b_a_12'), human_time(session.best_average(12, false)['avg'])); - t($('b_a_100'), human_time(session.best_average(100, false)['avg'])); - t($('s_a'), human_time(session.session_average())); - t($('s_m'), human_time(session.session_mean())); - t(times_label, to_times_list(null, null, null, null)); - times_label.scrollTop = times_label.scrollHeight; - } - - function to_times_list(highlight_index, length, paren_i, paren_j) { - if(session.length() < 1) return " " - if(highlight_index === null) - highlight_index = length = paren_i = paren_j = -1; - - var out = ""; - for(var i = 0; i < session.length(); ++i) { - if(i != 0) out += ", "; - if(i === highlight_index) out += ""; - if(i === paren_i || i === paren_j) out += "("; - - var time_str = solve_time(session.solves()[i]); - if(highlight_index === -1 || (i < highlight_index || i > highlight_index+length)) { - out += ""; - out += time_str; - out += ""; - } - else { - out += time_str; - } - - if(i === paren_i || i === paren_j) out += ")"; - if(i === highlight_index + length) out += ""; - } - return out; - } - - function populate_scramblers_menu() { - var menu = $('scramble_menu'); - for(var i = 0; i < scramble_manager.scramblers.length; i++) { - menu.options[i] = new Option(scramble_manager.get_name(i)); - } - menu.options[scramble_manager.current_index()].selected = true; - } - - function centre(el) { - el.style.marginLeft = (el.offsetWidth / -2) + "px"; - el.style.marginTop = (el.offsetHeight / -2) + "px"; - } - - function toggle_options_popup() { - if(timer.is_running()) return; - toggle($('options_popup')); - toggle($('gray_out')); - centre($('options_popup')); - } - - function toggle_solve_popup(index) { - if(timer.is_running()) return; - if(index !== null) { - $('solve_popup_index').innerHTML = index + 1; - $('solve_popup_time').innerHTML = solve_time(session.solves()[index]); - $('solve_popup_scramble').innerHTML = session.solves()[index]['scramble']; - $('solve_popup_p2').onclick = function() { - session.toggle_plus_two(index); - $('solve_popup_time').innerHTML = solve_time(session.solves()[index]); - }; - $('solve_popup_dnf').onclick = function() { - session.toggle_dnf(index); - $('solve_popup_time').innerHTML = solve_time(session.solves()[index]); - }; - $('solve_popup_del').onclick = function() { - session.del(index); - toggle_popup(); - }; - } - toggle($('solve_popup')); - toggle($('gray_out')); - centre($('solve_popup')); - } - - function toggle_avg_popup(index, end) { - if(index !== null) { - var out = ""; - for(var i = index; i < end+1; i++) - { - out += solve_time(session.solves()[i]) + " "; - out += session.solves()[i]['scramble'] + "
"; - } - $('avg_popup_list').innerHTML = out; - $('avg_popup_header').innerHTML = "solves " + (index+1) + " - " + (end+1); - } - toggle($('avg_popup')); - toggle($('gray_out')); - centre($('avg_popup')); - } - - function toggle_popup() { - if(is_visible($('options_popup'))) toggle($('options_popup')); - else if(is_visible($('solve_popup'))) { - toggle($('solve_popup')); - } - else if(is_visible($('avg_popup'))) - toggle($('avg_popup')); - toggle($('gray_out')); - } - - function highlight(start, length, paren_i, paren_j) { - if(timer.is_running()) return; - if(paren_i === null || paren_j === null) paren_i = paren_j = -1; - t(times_label, to_times_list(start, length - 1, paren_i, paren_j)); - } - - function highlight_current(length, paren_i, paren_j) { - if(timer.is_running()) return; - if(paren_i === null || paren_j === null) paren_i = paren_j = -1; - highlight(session.length() - length, length, paren_i, paren_j); - } - - function spacebar_down(ev) { - timer.trigger_down(ev); - } - - function spacebar_up(ev) { - timer.trigger_up(ev); - } - - function esc_up(ev) { - if(is_visible($('gray_out'))) { - toggle_popup(); - } - else { - if(timer.is_running()) timer.trigger_down(); - ui.reset(); - } - } - - function on_close() { - if(config['auto_save']) - session.save(); - localStorage.setItem("ui.config", JSON.stringify(config)); - } - - return { - update_stats: update_stats, - - on_inspection: on_inspection, - - on_running: function() { - timer_label.style.color = "black"; - for(var i = 0; i < to_hide.length; i++) - { - to_hide[i].className = to_hide[i].className + " disabled"; - } - }, - - update_running: function(time) { - if(config['hide_milli']) - {t(timer_label, seconds_time(time));} - else - { - t(timer_label, human_time(time)); - } - }, - - on_stop: function() { - t(timer_label, human_time(timer.get_time())); - for(var i = 0; i < to_hide.length; i++) - { - to_hide[i].className = to_hide[i].className.replace("disabled", ""); - } - next_scramble(); - }, - - toggle_solve_popup: toggle_solve_popup, - toggle_avg_popup: toggle_avg_popup, - - reset: function() { - timer.reset(); - next_scramble(); - t(timer_label, "0.00"); - t(times_label, " "); - update_stats(); - }, - - load_plugin: function() { - var url = $('plugin_url').value; - load_external(url); - $('plugin_url').value = ""; - }, - - plugin_loaded: function(name) { - t($('info'), "loaded " + name); - populate_scramblers_menu(); - setTimeout(function() { - t($('info'), ""); - }, 1000); - }, - - init: function() { - timer_label = $('timer_label'); - scramble_label = $('scramble_label'); - stats_label = $('stats_label'); - times_label = $('times_label'); - options_label = $('options_label'); - to_hide = document.getElementsByClassName("hide_running"); - - $('p2').onclick = function() { - if(timer.is_running()) return; - session.toggle_plus_two(null); - t(timer_label, solve_time(session.last())); - }; - $('dnf').onclick = function() { - if(timer.is_running()) return; - session.toggle_dnf(null); - t(timer_label, solve_time(session.last())); - }; - - $('c_a_5').onclick = function() { - if(timer.is_running()) return; - highlight_current(5, null, null); - }; - $('b_a_5').onclick = function() { - if(timer.is_running()) return; - var a = session.best_average(5, true); - highlight(a['index'], 5, a['best_single_index'], a['worst_single_index']); - }; - $('c_a_12').onclick = function() { - if(timer.is_running()) return; - highlight_current(12, null, null); - }; - $('b_a_12').onclick = function() { - if(timer.is_running()) return; - var a = session.best_average(12, true); - highlight(a['index'], 12, a['best_single_index'], a['worst_single_index']); - }; - $('s_a').onclick = function() { - if(timer.is_running()) return; - highlight_current(session.length(), null, null); - }; - $('s_m').onclick = function() { - if(timer.is_running()) return; - highlight_current(session.length(), null, null); - }; - - $('toggle_stats').onclick = function() { - if(timer.is_running()) return; - toggle($('stats_link')); - if(is_visible($('stats_link'))) - $('toggle_stats').innerHTML = "hide stats"; - else - $('toggle_stats').innerHTML = "show stats"; - }; - - $('options_label').onclick = toggle_options_popup; - $('close_options').onclick = toggle_options_popup; - $('gray_out').onclick = toggle_popup; - $('scramble_menu').onchange = function(s) { - scramble_manager.set($('scramble_menu').selectedIndex); - next_scramble(); - }; - $('use_inspection').onchange = function() { - timer.toggle_inspection(); - config['use_inspection'] = $('use_inspection').checked; - } - $('use_milli').onchange = function() { - config['use_milli'] = $('use_milli').checked; - update_stats(); - t(timer_label, human_time(timer.get_time())); - } - $('hide_milli').onchange = function() { - config['hide_milli'] = $('hide_milli').checked; - update_stats(); - t(timer_label, human_time(timer.get_time())); - } - $('save_btn').onclick = session.save; - $('load_btn').onclick = function() { session.load(); }; - $('auto_save').onchange = function() { config['auto_save'] = $('auto_save').checked; }; - - $('solve_popup_close').onclick = toggle_popup; - - scramble_manager.add_default(); - populate_scramblers_menu(); - - ui.reset(); - - shortcuts.init(); - shortcuts.add_key_down(shortcuts.space, {'func': spacebar_down}); - shortcuts.add_key_up(shortcuts.space, {'func': spacebar_up}); - shortcuts.add_key_up(shortcuts.esc, {'func': esc_up}); - - shortcuts.add_key_up('3'.charCodeAt(), {'shift': true, 'func': function() { scramble_manager.set($('scramble_menu').selectedIndex = 0); next_scramble(); }}); - shortcuts.add_key_up('4'.charCodeAt(), {'shift': true, 'func': function() { scramble_manager.set($('scramble_menu').selectedIndex = 1); next_scramble(); }}); - shortcuts.add_key_up('5'.charCodeAt(), {'shift': true, 'func': function() { scramble_manager.set($('scramble_menu').selectedIndex = 2); next_scramble(); }}); - shortcuts.add_key_up('D'.charCodeAt(), {'shift': true, 'func': function(){ session.del(null); }}); - - if(localStorage) - config = JSON.parse(localStorage.getItem("ui.config")); - if(config == null) - config = {}; - - if(config['auto_save']) { - $('auto_save').checked = true; - session.load(); - } - if(config['use_inspection']) { - $('use_inspection').checked = true; - timer.toggle_inspection(); - } - - $('use_milli').checked = config['use_milli']; - $('hide_milli').checked = config['hide_milli']; - - window.onbeforeunload = on_close; - window.onblur = function() { timer_label.style.color="gray"; }; - window.onfocus = function() { timer_label.style.color="black"; }; - window.onresize= function() { - centre($('options_popup')); - centre($('solve_popup')); - centre($('avg_popup')); - } - } - }; -})(); -window['ui'] = ui; -window.onload = ui.init; From 0ff3106aaf61aa20dc7ddf09bfed9665870106e3 Mon Sep 17 00:00:00 2001 From: Christopher Wall Date: Sun, 13 May 2012 20:55:40 +0100 Subject: [PATCH 3/5] n --- js/ui.js | 414 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 414 insertions(+) create mode 100644 js/ui.js diff --git a/js/ui.js b/js/ui.js new file mode 100644 index 0000000..79eba96 --- /dev/null +++ b/js/ui.js @@ -0,0 +1,414 @@ +"use strict"; +function load_external(url) { + var file = document.createElement('script'); + file.type = "text/javascript"; + file.src = url; + document.getElementsByTagName("head")[0].appendChild(file); +} + +function $(id) { return document.getElementById(id); } +function t(e, t) { e.innerHTML = t; } + +var ui = (function() { + function toggle(e) { e.style.display = (e.style.display === "none") ? "inline" : "none"; } + function is_visible(e) { return e.style.display !== "none"; } + + var timer_label, times_label, scramble_label, stats_label, options_label, to_hide; + var config; + + function human_time(time) { + if(time < 0) return "DNF"; + + time = Math.round(time / (config['use_milli'] ? 1 : 10)); + var bits = time % (config['use_milli'] ? 1000 : 100); + time = (time - bits) / (config['use_milli'] ? 1000 : 100); + var secs = time % 60; + var mins = ((time - secs) / 60) % 60; + var hours = (time - secs - 60 * mins) / 3600; + var s = "" + bits; + if (bits < 10) {s = "0" + s;} + if (bits < 100 && config['use_milli']) {s = "0" + s;} + s = secs + "." + s; + if (secs < 10 && (mins > 0 || hours > 0)) {s = "0" + s;} + if (mins > 0 || hours > 0) {s = mins + ":" + s;} + if (mins < 20 && hours > 0) {s = "0" + s;} + if (hours > 0) {s = hours + ":" + s;} + return s; + } + function seconds_time(time) { + if(time < 0) return "DNF"; + + time = Math.round(time / (1000)); + var s=""; + var secs = time % 60; + var mins = ((time - secs) / 60) % 60; + var hours = (time - secs - 60 * mins) / 3600; + s = secs + if (secs < 10 && (mins > 0 || hours > 0)) {s = "0" + s;} + if (mins > 0 || hours > 0) {s = mins + ":" + s;} + if (mins < 20 && hours > 0) {s = "0" + s;} + if (hours > 0) {s = hours + ":" + s;} + return s; + } + + function solve_time(solve) { + var out = ""; + if(solve['DNF']) + out += "DNF("; + + out += human_time(solve['time']); + out += solve['plus_two'] ? "+" : ""; + + if(solve['DNF']) + out += ")"; + return out; + } + + function on_inspection(inspection_time) { + timer_label.style.color = "red"; + if(inspection_time > 0) { + t(timer_label, inspection_time); + } + else if(inspection_time > -2) { + t(timer_label, "+2"); + } + else { + t(timer_label, "DNF"); + } + } + + function next_scramble() + { + t(scramble_label, scramble_manager.next()); + } + + function update_stats() { + t($('s_t'), session.length()); + t($('c_a_5'), human_time(session.current_average(5))); + t($('c_a_12'), human_time(session.current_average(12))); + t($('c_a_100'), human_time(session.current_average(100))); + t($('b_a_5'), human_time(session.best_average(5, false)['avg'])); + t($('b_a_12'), human_time(session.best_average(12, false)['avg'])); + t($('b_a_100'), human_time(session.best_average(100, false)['avg'])); + t($('s_a'), human_time(session.session_average())); + t($('s_m'), human_time(session.session_mean())); + t(times_label, to_times_list(null, null, null, null)); + times_label.scrollTop = times_label.scrollHeight; + } + + function to_times_list(highlight_index, length, paren_i, paren_j) { + if(session.length() < 1) return " " + if(highlight_index === null) + highlight_index = length = paren_i = paren_j = -1; + + var out = ""; + for(var i = 0; i < session.length(); ++i) { + if(i != 0) out += ", "; + if(i === highlight_index) out += ""; + if(i === paren_i || i === paren_j) out += "("; + + var time_str = solve_time(session.solves()[i]); + if(highlight_index === -1 || (i < highlight_index || i > highlight_index+length)) { + out += ""; + out += time_str; + out += ""; + } + else { + out += time_str; + } + + if(i === paren_i || i === paren_j) out += ")"; + if(i === highlight_index + length) out += ""; + } + return out; + } + + function populate_scramblers_menu() { + var menu = $('scramble_menu'); + for(var i = 0; i < scramble_manager.scramblers.length; i++) { + menu.options[i] = new Option(scramble_manager.get_name(i)); + } + menu.options[scramble_manager.current_index()].selected = true; + } + + function centre(el) { + el.style.marginLeft = (el.offsetWidth / -2) + "px"; + el.style.marginTop = (el.offsetHeight / -2) + "px"; + } + + function toggle_options_popup() { + if(timer.is_running()) return; + toggle($('options_popup')); + toggle($('gray_out')); + centre($('options_popup')); + } + + function toggle_solve_popup(index) { + if(timer.is_running()) return; + if(index !== null) { + $('solve_popup_index').innerHTML = index + 1; + $('solve_popup_time').innerHTML = solve_time(session.solves()[index]); + $('solve_popup_scramble').innerHTML = session.solves()[index]['scramble']; + $('solve_popup_p2').onclick = function() { + session.toggle_plus_two(index); + $('solve_popup_time').innerHTML = solve_time(session.solves()[index]); + }; + $('solve_popup_dnf').onclick = function() { + session.toggle_dnf(index); + $('solve_popup_time').innerHTML = solve_time(session.solves()[index]); + }; + $('solve_popup_del').onclick = function() { + session.del(index); + toggle_popup(); + }; + } + toggle($('solve_popup')); + toggle($('gray_out')); + centre($('solve_popup')); + } + + function toggle_avg_popup(index, end) { + if(index !== null) { + var out = ""; + for(var i = index; i < end+1; i++) + { + out += solve_time(session.solves()[i]) + " "; + out += session.solves()[i]['scramble'] + "
"; + } + $('avg_popup_list').innerHTML = out; + $('avg_popup_header').innerHTML = "solves " + (index+1) + " - " + (end+1); + } + toggle($('avg_popup')); + toggle($('gray_out')); + centre($('avg_popup')); + } + + function toggle_popup() { + if(is_visible($('options_popup'))) toggle($('options_popup')); + else if(is_visible($('solve_popup'))) { + toggle($('solve_popup')); + } + else if(is_visible($('avg_popup'))) + toggle($('avg_popup')); + toggle($('gray_out')); + } + + function highlight(start, length, paren_i, paren_j) { + if(timer.is_running()) return; + if(paren_i === null || paren_j === null) paren_i = paren_j = -1; + t(times_label, to_times_list(start, length - 1, paren_i, paren_j)); + } + + function highlight_current(length, paren_i, paren_j) { + if(timer.is_running()) return; + if(paren_i === null || paren_j === null) paren_i = paren_j = -1; + highlight(session.length() - length, length, paren_i, paren_j); + } + + function spacebar_down(ev) { + timer.trigger_down(ev); + } + + function spacebar_up(ev) { + timer.trigger_up(ev); + } + + function esc_up(ev) { + if(is_visible($('gray_out'))) { + toggle_popup(); + } + else { + if(timer.is_running()) timer.trigger_down(); + ui.reset(); + } + } + + function on_close() { + if(config['auto_save']) + session.save(); + localStorage.setItem("ui.config", JSON.stringify(config)); + } + + return { + update_stats: update_stats, + + on_inspection: on_inspection, + + on_running: function() { + timer_label.style.color = "black"; + for(var i = 0; i < to_hide.length; i++) + { + to_hide[i].className = to_hide[i].className + " disabled"; + } + }, + + update_running: function(time) { + if(config['hide_milli']) + {t(timer_label, seconds_time(time));} + else + { + t(timer_label, human_time(time)); + } + }, + + on_stop: function() { + t(timer_label, human_time(timer.get_time())); + for(var i = 0; i < to_hide.length; i++) + { + to_hide[i].className = to_hide[i].className.replace("disabled", ""); + } + next_scramble(); + }, + + toggle_solve_popup: toggle_solve_popup, + toggle_avg_popup: toggle_avg_popup, + + reset: function() { + timer.reset(); + next_scramble(); + t(timer_label, "0.00"); + t(times_label, " "); + update_stats(); + }, + + load_plugin: function() { + var url = $('plugin_url').value; + load_external(url); + $('plugin_url').value = ""; + }, + + plugin_loaded: function(name) { + t($('info'), "loaded " + name); + populate_scramblers_menu(); + setTimeout(function() { + t($('info'), ""); + }, 1000); + }, + + init: function() { + timer_label = $('timer_label'); + scramble_label = $('scramble_label'); + stats_label = $('stats_label'); + times_label = $('times_label'); + options_label = $('options_label'); + to_hide = document.getElementsByClassName("hide_running"); + + $('p2').onclick = function() { + if(timer.is_running()) return; + session.toggle_plus_two(null); + t(timer_label, solve_time(session.last())); + }; + $('dnf').onclick = function() { + if(timer.is_running()) return; + session.toggle_dnf(null); + t(timer_label, solve_time(session.last())); + }; + + $('c_a_5').onclick = function() { + if(timer.is_running()) return; + highlight_current(5, null, null); + }; + $('b_a_5').onclick = function() { + if(timer.is_running()) return; + var a = session.best_average(5, true); + highlight(a['index'], 5, a['best_single_index'], a['worst_single_index']); + }; + $('c_a_12').onclick = function() { + if(timer.is_running()) return; + highlight_current(12, null, null); + }; + $('b_a_12').onclick = function() { + if(timer.is_running()) return; + var a = session.best_average(12, true); + highlight(a['index'], 12, a['best_single_index'], a['worst_single_index']); + }; + $('s_a').onclick = function() { + if(timer.is_running()) return; + highlight_current(session.length(), null, null); + }; + $('s_m').onclick = function() { + if(timer.is_running()) return; + highlight_current(session.length(), null, null); + }; + + $('toggle_stats').onclick = function() { + if(timer.is_running()) return; + toggle($('stats_link')); + if(is_visible($('stats_link'))) + $('toggle_stats').innerHTML = "hide stats"; + else + $('toggle_stats').innerHTML = "show stats"; + }; + + $('options_label').onclick = toggle_options_popup; + $('close_options').onclick = toggle_options_popup; + $('gray_out').onclick = toggle_popup; + $('scramble_menu').onchange = function(s) { + scramble_manager.set($('scramble_menu').selectedIndex); + next_scramble(); + }; + $('use_inspection').onchange = function() { + timer.toggle_inspection(); + config['use_inspection'] = $('use_inspection').checked; + } + $('use_milli').onchange = function() { + config['use_milli'] = $('use_milli').checked; + update_stats(); + t(timer_label, human_time(timer.get_time())); + } + $('hide_milli').onchange = function() { + config['hide_milli'] = $('hide_milli').checked; + update_stats(); + t(timer_label, human_time(timer.get_time())); + } + $('save_btn').onclick = session.save; + $('load_btn').onclick = function() { session.load(); }; + $('auto_save').onchange = function() { config['auto_save'] = $('auto_save').checked; }; + + $('solve_popup_close').onclick = toggle_popup; + + scramble_manager.add_default(); + populate_scramblers_menu(); + + ui.reset(); + + shortcuts.init(); + shortcuts.add_key_down(shortcuts.space, {'func': spacebar_down}); + shortcuts.add_key_up(shortcuts.space, {'func': spacebar_up}); + shortcuts.add_key_up(shortcuts.esc, {'func': esc_up}); + + shortcuts.add_key_up('3'.charCodeAt(), {'shift': true, 'func': function() { scramble_manager.set($('scramble_menu').selectedIndex = 0); next_scramble(); }}); + shortcuts.add_key_up('4'.charCodeAt(), {'shift': true, 'func': function() { scramble_manager.set($('scramble_menu').selectedIndex = 1); next_scramble(); }}); + shortcuts.add_key_up('5'.charCodeAt(), {'shift': true, 'func': function() { scramble_manager.set($('scramble_menu').selectedIndex = 2); next_scramble(); }}); + shortcuts.add_key_up('D'.charCodeAt(), {'shift': true, 'func': function(){ session.del(null); }}); + + if(localStorage) + config = JSON.parse(localStorage.getItem("ui.config")); + if(config == null) + config = {}; + + if(config['auto_save']) { + $('auto_save').checked = true; + session.load(); + } + if(config['use_inspection']) { + $('use_inspection').checked = true; + timer.toggle_inspection(); + } + + $('use_milli').checked = config['use_milli']; + $('hide_milli').checked = config['hide_milli']; + + window.onbeforeunload = on_close; + window.onblur = function() { timer_label.style.color="gray"; }; + window.onfocus = function() { timer_label.style.color="black"; }; + window.onresize= function() { + centre($('options_popup')); + centre($('solve_popup')); + centre($('avg_popup')); + } + } + }; +})(); +window['ui'] = ui; +window.onload = ui.init; From 54b88f8b62ae5d048834cf9c03b83dc13995eee7 Mon Sep 17 00:00:00 2001 From: Christopher Wall Date: Sun, 13 May 2012 20:59:29 +0100 Subject: [PATCH 4/5] pre merge --- js/ui.js | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/js/ui.js b/js/ui.js index 79eba96..dfe8103 100644 --- a/js/ui.js +++ b/js/ui.js @@ -35,21 +35,6 @@ var ui = (function() { if (hours > 0) {s = hours + ":" + s;} return s; } - function seconds_time(time) { - if(time < 0) return "DNF"; - - time = Math.round(time / (1000)); - var s=""; - var secs = time % 60; - var mins = ((time - secs) / 60) % 60; - var hours = (time - secs - 60 * mins) / 3600; - s = secs - if (secs < 10 && (mins > 0 || hours > 0)) {s = "0" + s;} - if (mins > 0 || hours > 0) {s = mins + ":" + s;} - if (mins < 20 && hours > 0) {s = "0" + s;} - if (hours > 0) {s = hours + ":" + s;} - return s; - } function solve_time(solve) { var out = ""; @@ -243,12 +228,7 @@ var ui = (function() { }, update_running: function(time) { - if(config['hide_milli']) - {t(timer_label, seconds_time(time));} - else - { t(timer_label, human_time(time)); - } }, on_stop: function() { @@ -356,11 +336,6 @@ var ui = (function() { update_stats(); t(timer_label, human_time(timer.get_time())); } - $('hide_milli').onchange = function() { - config['hide_milli'] = $('hide_milli').checked; - update_stats(); - t(timer_label, human_time(timer.get_time())); - } $('save_btn').onclick = session.save; $('load_btn').onclick = function() { session.load(); }; $('auto_save').onchange = function() { config['auto_save'] = $('auto_save').checked; }; @@ -397,7 +372,6 @@ var ui = (function() { } $('use_milli').checked = config['use_milli']; - $('hide_milli').checked = config['hide_milli']; window.onbeforeunload = on_close; window.onblur = function() { timer_label.style.color="gray"; }; From a13e8a8bec97c8020092908078405d0de995f0f1 Mon Sep 17 00:00:00 2001 From: Christopher Wall Date: Sun, 13 May 2012 21:22:09 +0100 Subject: [PATCH 5/5] Added "Use seconds" in single format. --- js/ui.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/js/ui.js b/js/ui.js index 27961b2..a212e7f 100644 --- a/js/ui.js +++ b/js/ui.js @@ -16,19 +16,26 @@ var ui = (function() { var timer_label, times_label, scramble_label, stats_label, options_label, to_hide; var config; - function human_time(time) { + function human_time(time,running) { if(time < 0) return "DNF"; - + if(config['hide_milli']&&running) + { + time = Math.floor(time/ 1000); + var bits = 0; + } + else + { time = Math.round(time / (config['use_milli'] ? 1 : 10)); var bits = time % (config['use_milli'] ? 1000 : 100); time = (time - bits) / (config['use_milli'] ? 1000 : 100); + } var secs = time % 60; var mins = ((time - secs) / 60) % 60; var hours = (time - secs - 60 * mins) / 3600; var s = "" + bits; if(bits < 10) { s = "0" + s; } if(bits < 100 && config['use_milli']) { s = "0" + s; } - s = secs + "." + s; + if(config['hide_milli']&&running){s = secs;}else{s = secs + "." + s;} if(secs < 10 && (mins > 0 || hours > 0)) { s = "0" + s; } if(mins > 0 || hours > 0) { s = mins + ":" + s; } if(mins < 20 && hours > 0) { s = "0" + s; } @@ -252,7 +259,7 @@ var ui = (function() { }, update_running: function(time) { - t(timer_label, human_time(time)); + t(timer_label, human_time(time,true)); }, on_stop: function() { @@ -357,7 +364,11 @@ var ui = (function() { $('use_milli').onchange = function() { config['use_milli'] = $('use_milli').checked; update_stats(); - t(timer_label, human_time(timer.get_time())); + t(timer_label, human_time(timer.get_time(),false)); + } + $('hide_milli').onchange = function() { + config['hide_milli'] = $('hide_milli').checked; + t(timer_label, human_time(timer.get_time(),false)); } $('save_btn').onclick = session.save; $('load_btn').onclick = function() { session.load(); }; @@ -440,6 +451,7 @@ var ui = (function() { } $('use_milli').checked = config['use_milli']; + $('hide_milli').checked = config['hide_milli']; load_user_styles();