diff --git a/js/client-mainmenu.js b/js/client-mainmenu.js index d83c7f88c4..fa95111cc7 100644 --- a/js/client-mainmenu.js +++ b/js/client-mainmenu.js @@ -1224,16 +1224,42 @@ }); var FormatPopup = this.FormatPopup = this.Popup.extend({ + events: { + 'keyup input': 'updateSearch', + 'click details': 'updateOpen', + }, initialize: function (data) { - var curFormat = data.format; + this.data = data; + if (!this.open) { + // todo: maybe make this configurable? not sure since it will cache what users toggle. + // avoiding that decision for now because it requires either an ugly hack + // or an overhaul of BattleFormats. + this.open = Storage.prefs('openformats') || { + "S/V Singles": true, "S/V Doubles": true, "National Dex": true, "OM of the Month": true, + "Other Metagames": true, "Randomized Format Spotlight": true, "RoA Spotlight": true, + }; + } + if (!this.search) this.search = ""; this.onselect = data.onselect; + + var html = '

'; + html += this.renderFormats(); + html += '

'; + this.$el.html(html); + }, + renderFormats: function () { + var data = this.data; + var curFormat = data.format; var selectType = data.selectType; if (!selectType) selectType = (this.sourceEl.closest('form').data('search') ? 'search' : 'challenge'); + var bufs = []; var curBuf = 0; if (selectType === 'watch') { bufs[1] = '
  • '; } + var curSection = ''; for (var i in BattleFormats) { var format = BattleFormats[i]; @@ -1245,6 +1271,7 @@ } if (format.section && format.section !== curSection) { + if (curSection) bufs[curBuf] += '

    '; curSection = format.section; if (!app.supports['formatColumns']) { curBuf = (curSection === 'Doubles' || curSection === 'Past Generations') ? 2 : 1; @@ -1254,9 +1281,13 @@ if (!bufs[curBuf]) { bufs[curBuf] = ''; } - bufs[curBuf] += '
  • ' + BattleLog.escapeHTML(curSection) + '

  • '; + var open = (this.open[curSection] || toID(this.search)) ? ' open' : ''; + bufs[curBuf] += '

    '; + bufs[curBuf] += '

    '; + bufs[curBuf] += BattleLog.escapeHTML(curSection) + ''; } var formatName = BattleLog.escapeFormat(format.id); + if (this.search && !format.id.includes(toID(this.search))) continue; if (formatName.charAt(0) !== '[') formatName = '[Gen 6] ' + formatName; formatName = formatName.replace('[Gen 9] ', ''); formatName = formatName.replace('[Gen 9 ', '['); @@ -1264,7 +1295,6 @@ formatName = formatName.replace('[Gen 7 ', '['); bufs[curBuf] += '
  • '; } - var html = ''; for (var i = 1, l = bufs.length; i < l; i++) { html += '