-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswitch-height-width.plugin.js
44 lines (36 loc) · 1.19 KB
/
switch-height-width.plugin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
* Switch Height & Width
* v.1.0.3, 2022-03-24
*
* https://github.com/ogmaresca/easydiffusion-plugins
*/
"use strict";
(function() {
/** @type {HTMLSelectElement} */
const widthElem = document.getElementById('width');
/** @type {HTMLSelectElement} */
const heightElem = document.getElementById('height');
const switchButton = createElement(
'button',
{ id: `switch-width-height` },
);
switchButton.style.cursor = 'pointer';
switchButton.style.background = 'transparent';
switchButton.style.padding = '2px 10px 2px 0';
switchButton.addEventListener('click', () => {
const width = widthElem.value;
const height = heightElem.value;
widthElem.value = height;
heightElem.value = width;
// Save the new values on reloads
widthElem.dispatchEvent(new Event('change'));
heightElem.dispatchEvent(new Event('change'));
});
const switchButtonIcon = createElement(
'i',
undefined,
['fa-solid', 'fa-right-left'],
);
switchButton.appendChild(switchButtonIcon);
heightElem.insertAdjacentElement('beforebegin', switchButton);
})();