var Modes = { modes: [], features: {}, setModes:function(json){ this.modes = json.map(function(m){ return new Mode(m); }); this.updateModePanel(); }, setFeatures:function(features){ this.features = features; this.updateModePanel(); }, findByModulation:function(modulation){ matches = this.modes.filter(function(m) { return m.modulation === modulation; }); if (matches.length) return matches[0] }, updateModePanel:function() { var available = this.modes.filter(function(m){ return m.isAvailable(); }); var normalModes = available.filter(function(m){ return !m.digimode; }); var digiModes = available.filter(function(m){ return m.digimode; }); var index = 0; var arrayLength = normalModes.length; var chunks = []; for (index = 0; index < arrayLength; index += 5) { chunks.push(normalModes.slice(index, index + 5)); } var html = [] html.push.apply(html, chunks.map(function(chunk){ return $( '
' + chunk.map(function(m){ return '
' + m.name + '
'; }).join('') + '
'); })); html.push($( '
' + '
DIG
' + '' + '
' )); $("#openwebrx-panel-receiver").find(".openwebrx-modes").html(html); } } var Mode = function(json){ this.modulation = json.modulation; this.name = json.name; this.digimode = json.digimode; this.requirements = json.requirements; }; Mode.prototype.isAvailable = function(){ return this.requirements.map(function(r){ return Modes.features[r]; }).reduce(function(a, b){ return a && b; }, true); }