Skip to content

Commit 7a094e0

Browse files
reworded logic for settings switches
1 parent 3a03e48 commit 7a094e0

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

js/app.js

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -442,10 +442,19 @@ $(window).ready(function() {
442442

443443
// settings page
444444

445-
if(offline.get('opt_daylight')) $('#sw_daylight').removeClass('off').addClass('on');
446-
447-
// offline and mobile
448-
$('#sw_layers_clouds, #sw_offline, #sw_station, #sw_imperial, #sw_haxis_hours, #sw_daylight, #sw_hide_receivers').click(function() {
445+
// list of all switches
446+
var opts = [
447+
"#sw_layers_clouds",
448+
"#sw_offline",
449+
"#sw_station",
450+
"#sw_imperial",
451+
"#sw_haxis_hours",
452+
"#sw_daylight",
453+
"#sw_hide_receivers"
454+
];
455+
456+
// applies functionality when switches are toggled
457+
$(opts.join(',')).click(function() {
449458
var e = $(this);
450459
var name = e.attr('id').replace('sw', 'opt');
451460
var on;
@@ -493,12 +502,12 @@ $(window).ready(function() {
493502
});
494503

495504
// set the switch, based on the remembered choice
496-
if(offline.get('opt_offline')) $('#sw_offline').removeClass('off').addClass('on');
497-
if(offline.get('opt_station')) $('#sw_station').removeClass('off').addClass('on');
498-
if(offline.get('opt_imperial')) $('#sw_imperial').removeClass('off').addClass('on');
499-
if(offline.get('opt_haxis_hours')) $('#sw_haxis_hours').removeClass('off').addClass('on');
500-
if(offline.get('opt_hide_receivers')) $('#sw_hide_receivers').removeClass('off').addClass('on');
501-
if(offline.get('opt_layers_clouds')) $('#sw_layers_clouds').removeClass('off').addClass('on');
505+
for(var k in opts) {
506+
var switch_id = opts[k];
507+
var opt_name = switch_id.replace("#sw_", "opt_");
508+
509+
if(offline.get(opt_name)) $(switch_id).removeClass('off').addClass('on');
510+
}
502511

503512
// force re-cache
504513
$('#sw_cache').click(function() {

0 commit comments

Comments
 (0)