From 3945e54eddd02091126221836221760f477e4263 Mon Sep 17 00:00:00 2001 From: Mia <49593536+mia-pi-git@users.noreply.github.com> Date: Mon, 23 Oct 2023 16:39:59 -0500 Subject: [PATCH 1/3] Overhaul the format selector to be more easily used --- js/client-mainmenu.js | 53 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 5 deletions(-) diff --git a/js/client-mainmenu.js b/js/client-mainmenu.js index d83c7f88c4..a334f9cfa1 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, "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] += '';
+ 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 += ' ';
}
- html += '';
- this.$el.html(html);
+ return html;
+ },
+ update: function () {
+ var $formatEl = this.$el.find('span[name=formats]');
+ $formatEl.empty();
+ $formatEl.html(this.renderFormats());
+ },
+ updateOpen: function (ev) {
+ var section = $(ev.currentTarget).attr('section');
+ this.open[section] = !this.open[section];
+ Storage.prefs('openformats', this.open);
+ },
+ updateSearch: function (event) {
+ this.search = $(event.currentTarget).val();
+ this.update();
},
selectFormat: function (format) {
if (this.onselect) {
From ee23625a53495f98a4f9014560477f59f16ee344 Mon Sep 17 00:00:00 2001
From: Mia <49593536+mia-pi-git@users.noreply.github.com>
Date: Mon, 23 Oct 2023 17:36:46 -0500
Subject: [PATCH 2/3] Update js/client-mainmenu.js
Co-authored-by: Kris Johnson <11083252+KrisXV@users.noreply.github.com>
---
js/client-mainmenu.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/js/client-mainmenu.js b/js/client-mainmenu.js
index a334f9cfa1..8d3db29c6d 100644
--- a/js/client-mainmenu.js
+++ b/js/client-mainmenu.js
@@ -1235,8 +1235,8 @@
// 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, "Randomized Format Spotlight": true, "RoA Spotlight": true,
+ "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 = "";
From 34e6193f192acc50f6ade3296e28d72d4de9c19f Mon Sep 17 00:00:00 2001
From: Mia <49593536+mia-pi-git@users.noreply.github.com>
Date: Mon, 23 Oct 2023 19:53:46 -0500
Subject: [PATCH 3/3] Lower search pop open limit
---
js/client-mainmenu.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/js/client-mainmenu.js b/js/client-mainmenu.js
index 8d3db29c6d..fa95111cc7 100644
--- a/js/client-mainmenu.js
+++ b/js/client-mainmenu.js
@@ -1281,7 +1281,7 @@
if (!bufs[curBuf]) {
bufs[curBuf] = '';
}
- var open = (this.open[curSection] || this.search && this.search.length >= 3) ? ' open' : '';
+ var open = (this.open[curSection] || toID(this.search)) ? ' open' : '';
bufs[curBuf] += '';
bufs[curBuf] += BattleLog.escapeHTML(curSection) + '
';