Skip to content

Commit

Permalink
Add a button to allow using the format selector in chat pages
Browse files Browse the repository at this point in the history
  • Loading branch information
mia-pi-git committed Sep 25, 2023
1 parent 239ec41 commit 1af066f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
21 changes: 18 additions & 3 deletions js/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -877,16 +877,19 @@ function toId() {
serializeForm: function (form, checkboxOnOff) {
// querySelector dates back to IE8 so we can use it
// fortunate, because form serialization is a HUGE MESS in older browsers
var elements = form.querySelectorAll('input[name], select[name], textarea[name], keygen[name]');
var elements = form.querySelectorAll('input[name], select[name], textarea[name], keygen[name], button[value]');
var out = [];
window.elements = elements;
for (var i = 0; i < elements.length; i++) {
var element = elements[i];
if ($(element).attr('type') === 'submit') continue;
if (element.type === 'checkbox' && !element.value && checkboxOnOff) {
out.push([element.name, element.checked ? 'on' : 'off']);
} else if (!['checkbox', 'radio'].includes(element.type) || element.checked) {
out.push([element.name, element.value]);
}
}
window.out = out;
return out;
},
submitSend: function (e) {
Expand Down Expand Up @@ -2110,12 +2113,15 @@ function toId() {
},
dispatchClickButton: function (e) {
var target = e.currentTarget;
if (target.name) {
var type = $(target).attr('type');
if (type === 'submit') type = null;
if (target.name || type) {
app.dismissingSource = app.dismissPopups();
app.dispatchingButton = target;
e.preventDefault();
e.stopImmediatePropagation();
this[target.name](target.value, target);
if (target.name && this[target.name]) this[target.name](target.value, target);
if (type && this[type]) this[type](target.value, target);
delete app.dismissingSource;
delete app.dispatchingButton;
}
Expand Down Expand Up @@ -2143,6 +2149,15 @@ function toId() {
//
},

/**
* Used for <formatselect>, does format popup and caches value in button value
*/
selectformat: function (value, target) {
app.addPopup(FormatPopup, {format: 'gen9randombattle', sourceEl: target, selectType: 'watch', onselect: function (newFormat) {
target.value = newFormat;
}});
},

// layout

bestWidth: 659,
Expand Down
12 changes: 12 additions & 0 deletions src/battle-log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@ export class BattleLog {
username: 0,
spotify: 0,
youtube: 0,
formatselect: 0,
twitch: 0,
});

Expand All @@ -780,6 +781,7 @@ export class BattleLog {
'psicon::pokemon': 0,
'psicon::item': 0,
'psicon::type': 0,
'selectformat::type': 0,
'psicon::category': 0,
'username::name': 0,
'form::data-submitsend': 0,
Expand Down Expand Up @@ -913,6 +915,16 @@ export class BattleLog {
'frameborder', '0', 'allow', 'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture', 'allowfullscreen', 'allowfullscreen',
],
};
} else if (tagName === 'formatselect') {
return {
tagName: 'button',
attribs: [
'type', 'selectformat',
'class', "select formatselect",
'value', getAttrib('value') || "gen9randombattle",
'name', getAttrib('name') || '',
],
}
} else if (tagName === 'psicon') {
// <psicon> is a custom element which supports a set of mutually incompatible attributes:
// <psicon pokemon> and <psicon item>
Expand Down

0 comments on commit 1af066f

Please sign in to comment.