mirror of
https://github.com/smogon/pokemon-showdown-client.git
synced 2026-10-25 03:31:07 -05:00
Add a button to allow using the format selector in chat pages (#2155)
This commit is contained in:
19
js/client.js
19
js/client.js
@@ -877,10 +877,11 @@ 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 = [];
|
||||
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) {
|
||||
@@ -2113,12 +2114,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;
|
||||
}
|
||||
@@ -2146,6 +2150,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,
|
||||
|
||||
@@ -759,6 +759,7 @@ export class BattleLog {
|
||||
username: 0,
|
||||
spotify: 0,
|
||||
youtube: 0,
|
||||
formatselect: 0,
|
||||
twitch: 0,
|
||||
});
|
||||
|
||||
@@ -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,
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user