pardus-options-library 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +323 -0
- package/eslint.config.js +38 -0
- package/package.json +32 -0
- package/src/classes/abstract/abstract-button.js +116 -0
- package/src/classes/abstract/abstract-toggle-button.js +145 -0
- package/src/classes/contents-area.js +22 -0
- package/src/classes/description-element.js +80 -0
- package/src/classes/disableable-html-element.js +48 -0
- package/src/classes/html-element.js +189 -0
- package/src/classes/info-element.js +56 -0
- package/src/classes/options/abstract-array-option.js +38 -0
- package/src/classes/options/abstract-option.js +189 -0
- package/src/classes/options/boolean-option.js +24 -0
- package/src/classes/options/grouped-options.js +61 -0
- package/src/classes/options/key-down-disable-button.js +20 -0
- package/src/classes/options/key-down-option.js +178 -0
- package/src/classes/options/key-down-set-key-button.js +18 -0
- package/src/classes/options/numeric-option.js +40 -0
- package/src/classes/options/select-option.js +74 -0
- package/src/classes/options/text-area-option.js +39 -0
- package/src/classes/options-box.js +200 -0
- package/src/classes/options-content.js +178 -0
- package/src/classes/options-group.js +114 -0
- package/src/classes/pardus-options-utility.js +139 -0
- package/src/classes/pardus-options.js +144 -0
- package/src/classes/save-button-row/load-button.js +21 -0
- package/src/classes/save-button-row/preset-label.js +95 -0
- package/src/classes/save-button-row/preset-row.js +106 -0
- package/src/classes/save-button-row/presets.js +57 -0
- package/src/classes/save-button-row/reset-button.js +21 -0
- package/src/classes/save-button-row/save-button-row.js +69 -0
- package/src/classes/save-button-row/save-button.js +21 -0
- package/src/classes/tabs/sub-tab.js +66 -0
- package/src/classes/tabs/tab-content.js +149 -0
- package/src/classes/tabs/tab-label.js +45 -0
- package/src/classes/tabs/tab.js +66 -0
- package/src/classes/tabs/tabs-element.js +25 -0
- package/src/classes/tabs/tabs-row.js +44 -0
- package/src/classes/tip-box.js +69 -0
- package/src/classes/version-row.js +14 -0
- package/src/index.js +13 -0
- package/webpack.config.cjs +16 -0
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import HtmlElement from './html-element.js';
|
|
2
|
+
import PardusOptionsUtility from './pardus-options-utility.js';
|
|
3
|
+
import OptionsBox from './options-box.js';
|
|
4
|
+
|
|
5
|
+
export default class OptionsContent extends HtmlElement {
|
|
6
|
+
constructor({
|
|
7
|
+
id,
|
|
8
|
+
content = null,
|
|
9
|
+
saveFunction = PardusOptionsUtility.defaultSaveFunction,
|
|
10
|
+
getFunction = PardusOptionsUtility.defaultGetFunction,
|
|
11
|
+
refresh = true,
|
|
12
|
+
active = true,
|
|
13
|
+
}) {
|
|
14
|
+
super(id);
|
|
15
|
+
this.content = content;
|
|
16
|
+
this.saveFunction = saveFunction;
|
|
17
|
+
this.getFunction = getFunction;
|
|
18
|
+
this.leftBoxes = [];
|
|
19
|
+
this.rightBoxes = [];
|
|
20
|
+
this.topBoxes = [];
|
|
21
|
+
this.bottomBoxes = [];
|
|
22
|
+
this.refresh = refresh;
|
|
23
|
+
this.active = active;
|
|
24
|
+
this.addAfterRefreshHook((opts) => {
|
|
25
|
+
if (opts.maintainRefreshStatus) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
this.refresh = true;
|
|
29
|
+
});
|
|
30
|
+
this.addAfterRefreshHook(() => {
|
|
31
|
+
for (const box of this.topBoxes) {
|
|
32
|
+
box.afterRefreshElement();
|
|
33
|
+
}
|
|
34
|
+
for (const box of this.leftBoxes) {
|
|
35
|
+
box.afterRefreshElement();
|
|
36
|
+
}
|
|
37
|
+
for (const box of this.rightBoxes) {
|
|
38
|
+
box.afterRefreshElement();
|
|
39
|
+
}
|
|
40
|
+
for (const box of this.bottomBoxes) {
|
|
41
|
+
box.afterRefreshElement();
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
addBox({
|
|
47
|
+
top = false,
|
|
48
|
+
bottom = false,
|
|
49
|
+
...args
|
|
50
|
+
}) {
|
|
51
|
+
let newBox = null;
|
|
52
|
+
if (top) {
|
|
53
|
+
newBox = this.addBoxTop(args);
|
|
54
|
+
} else if (bottom) {
|
|
55
|
+
newBox = this.addBoxBottom(args);
|
|
56
|
+
} else if (this.leftBoxes.length <= this.rightBoxes.length) {
|
|
57
|
+
newBox = this.addBoxLeft(args);
|
|
58
|
+
} else {
|
|
59
|
+
newBox = this.addBoxRight(args);
|
|
60
|
+
}
|
|
61
|
+
return newBox;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
addBoxBottom({
|
|
65
|
+
refresh = this.refresh,
|
|
66
|
+
...args
|
|
67
|
+
}) {
|
|
68
|
+
const newBox = new OptionsBox({
|
|
69
|
+
id: `${this.id}-bottom-box-${this.bottomBoxes.length}`,
|
|
70
|
+
refresh,
|
|
71
|
+
...args,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
this.bottomBoxes.push(newBox);
|
|
75
|
+
|
|
76
|
+
if (refresh) {
|
|
77
|
+
this.refreshElement();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return newBox;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
addBoxTop({
|
|
84
|
+
refresh = this.refresh,
|
|
85
|
+
...args
|
|
86
|
+
}) {
|
|
87
|
+
const newBox = new OptionsBox({
|
|
88
|
+
id: `${this.id}-top-box-${this.topBoxes.length}`,
|
|
89
|
+
refresh,
|
|
90
|
+
...args,
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
this.topBoxes.push(newBox);
|
|
94
|
+
|
|
95
|
+
if (refresh) {
|
|
96
|
+
this.refreshElement();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return newBox;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
addBoxLeft({
|
|
103
|
+
refresh = this.refresh,
|
|
104
|
+
...args
|
|
105
|
+
}) {
|
|
106
|
+
const newBox = new OptionsBox({
|
|
107
|
+
id: `${this.id}-left-box-${this.leftBoxes.length}`,
|
|
108
|
+
refresh,
|
|
109
|
+
...args,
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
this.leftBoxes.push(newBox);
|
|
113
|
+
|
|
114
|
+
if (refresh) {
|
|
115
|
+
this.refreshElement();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return newBox;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
addBoxRight({
|
|
122
|
+
refresh = this.refresh,
|
|
123
|
+
...args
|
|
124
|
+
}) {
|
|
125
|
+
const newBox = new OptionsBox({
|
|
126
|
+
id: `${this.id}-right-box-${this.rightBoxes.length}`,
|
|
127
|
+
refresh,
|
|
128
|
+
...args,
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
this.rightBoxes.push(newBox);
|
|
132
|
+
|
|
133
|
+
if (refresh) {
|
|
134
|
+
this.refreshElement();
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return newBox;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
addPremiumBox(args) {
|
|
141
|
+
return this.addBox({
|
|
142
|
+
premium: true,
|
|
143
|
+
...args,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
addPremiumBoxLeft(args) {
|
|
148
|
+
return this.addBoxLeft({
|
|
149
|
+
premium: true,
|
|
150
|
+
...args,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
addPremiumBoxRight(args) {
|
|
155
|
+
return this.addBoxRight({
|
|
156
|
+
premium: true,
|
|
157
|
+
...args,
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
toString() {
|
|
162
|
+
if (this.content !== null) {
|
|
163
|
+
return this.content;
|
|
164
|
+
}
|
|
165
|
+
const hidden = this.active ? '' : 'hidden';
|
|
166
|
+
return `<tr id="${this.id}" ${hidden}><td><table width="100%" align="center"><tbody><tr><td id="${this.id}-top" colspan="3" valign="top">${this.topBoxes.join('<br><br>')}${(this.topBoxes.length > 0) ? '<br><br>' : ''}</td></tr><tr><td id="${this.id}-left" width="350" valign="top">${this.leftBoxes.join('<br><br>')}</td><td width="40"></td><td id="${this.id}-right" width="350" valign="top">${this.rightBoxes.join('<br><br>')}</td></tr><tr><td id="${this.id}-bottom" colspan="3" valign="top">${(this.bottomBoxes.length > 0) ? '<br><br>' : ''}${this.bottomBoxes.join('<br><br>')}</td></tr></tbody></table></td></tr>`;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
setActive() {
|
|
170
|
+
this.active = true;
|
|
171
|
+
this.getElement().removeAttribute('hidden');
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
setInactive() {
|
|
175
|
+
this.active = false;
|
|
176
|
+
this.getElement().setAttribute('hidden', '');
|
|
177
|
+
}
|
|
178
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import DisableableHtmlElement from './disableable-html-element.js';
|
|
2
|
+
import PardusOptionsUtility from './pardus-options-utility.js';
|
|
3
|
+
import BooleanOption from './options/boolean-option.js';
|
|
4
|
+
import TextAreaOption from './options/text-area-option.js';
|
|
5
|
+
import NumericOption from './options/numeric-option.js';
|
|
6
|
+
import KeyDownOption from './options/key-down-option.js';
|
|
7
|
+
import SelectOption from './options/select-option.js';
|
|
8
|
+
import GroupedOptions from './options/grouped-options.js';
|
|
9
|
+
|
|
10
|
+
export default class OptionsGroup extends DisableableHtmlElement {
|
|
11
|
+
constructor({
|
|
12
|
+
id,
|
|
13
|
+
premium = false,
|
|
14
|
+
saveFunction = PardusOptionsUtility.defaultSaveFunction,
|
|
15
|
+
getFunction = PardusOptionsUtility.defaultGetFunction,
|
|
16
|
+
disabled = false,
|
|
17
|
+
}) {
|
|
18
|
+
super({
|
|
19
|
+
id,
|
|
20
|
+
disabled,
|
|
21
|
+
});
|
|
22
|
+
this.premium = premium;
|
|
23
|
+
this.saveFunction = saveFunction;
|
|
24
|
+
this.getFunction = getFunction;
|
|
25
|
+
this.options = [];
|
|
26
|
+
this.disabled = disabled;
|
|
27
|
+
this.addAfterRefreshHook(() => {
|
|
28
|
+
for (const option of this.options) {
|
|
29
|
+
option.afterRefreshElement();
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
setDisabled(disabled = false) {
|
|
35
|
+
this.disabled = disabled;
|
|
36
|
+
for (const option of this.options) {
|
|
37
|
+
option.setDisabled(disabled);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
addBooleanOption(args) {
|
|
42
|
+
const newOption = new BooleanOption({
|
|
43
|
+
id: `${this.id}-option-${this.options.length}`,
|
|
44
|
+
disabled: this.disabled,
|
|
45
|
+
...args,
|
|
46
|
+
});
|
|
47
|
+
this.options.push(newOption);
|
|
48
|
+
return newOption;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
addTextAreaOption(args) {
|
|
52
|
+
const newOption = new TextAreaOption({
|
|
53
|
+
id: `${this.id}-option-${this.options.length}`,
|
|
54
|
+
disabled: this.disabled,
|
|
55
|
+
...args,
|
|
56
|
+
});
|
|
57
|
+
this.options.push(newOption);
|
|
58
|
+
return newOption;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
addNumericOption(args) {
|
|
62
|
+
const newOption = new NumericOption({
|
|
63
|
+
id: `${this.id}-option-${this.options.length}`,
|
|
64
|
+
disabled: this.disabled,
|
|
65
|
+
...args,
|
|
66
|
+
});
|
|
67
|
+
this.options.push(newOption);
|
|
68
|
+
return newOption;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
addKeyDownOption(args) {
|
|
72
|
+
const newOption = new KeyDownOption({
|
|
73
|
+
id: `${this.id}-option-${this.options.length}`,
|
|
74
|
+
disabled: this.disabled,
|
|
75
|
+
...args,
|
|
76
|
+
});
|
|
77
|
+
this.options.push(newOption);
|
|
78
|
+
return newOption;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
addSelectOption(args) {
|
|
82
|
+
const newOption = new SelectOption({
|
|
83
|
+
id: `${this.id}-option-${this.options.length}`,
|
|
84
|
+
disabled: this.disabled,
|
|
85
|
+
...args,
|
|
86
|
+
});
|
|
87
|
+
this.options.push(newOption);
|
|
88
|
+
return newOption;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
addGroupedOption({
|
|
92
|
+
description,
|
|
93
|
+
saveFunction = this.saveFunction,
|
|
94
|
+
getFunction = this.getFunction,
|
|
95
|
+
}) {
|
|
96
|
+
const newOption = new GroupedOptions({
|
|
97
|
+
id: `${this.id}-option-${this.options.length}`,
|
|
98
|
+
disabled: this.disabled,
|
|
99
|
+
description,
|
|
100
|
+
saveFunction,
|
|
101
|
+
getFunction,
|
|
102
|
+
});
|
|
103
|
+
this.options.push(newOption);
|
|
104
|
+
return newOption;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
toString() {
|
|
108
|
+
// If no options have been defined, then don't add any elements
|
|
109
|
+
if (this.options.length === 0) {
|
|
110
|
+
return `<tr id="${this.id}" style="display: none;"><td><table width="100%"><tbody></tbody></table></td></tr>`;
|
|
111
|
+
}
|
|
112
|
+
return `<tr id="${this.id}"><td><table width="100%"><tbody>${this.options.join('')}</tbody></table></td></tr>`;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module PardusOptionsUtility
|
|
3
|
+
*/
|
|
4
|
+
export default class PardusOptionsUtility {
|
|
5
|
+
/**
|
|
6
|
+
* @ignore
|
|
7
|
+
*/
|
|
8
|
+
static defaultSaveFunction(key, value) {
|
|
9
|
+
return GM_setValue(key, value);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @ignore
|
|
14
|
+
*/
|
|
15
|
+
static defaultGetFunction(key, defaultValue = null) {
|
|
16
|
+
return GM_getValue(key, defaultValue);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @ignore
|
|
21
|
+
*/
|
|
22
|
+
static defaultDeleteFunction(key) {
|
|
23
|
+
return GM_deleteValue(key);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Returns the active universe
|
|
28
|
+
* @returns {string} One of 'orion', 'artemis', or 'pegasus'
|
|
29
|
+
* @throws Will throw an error if no universe could be determined.
|
|
30
|
+
*/
|
|
31
|
+
static getUniverse() {
|
|
32
|
+
switch (document.location.hostname) {
|
|
33
|
+
case 'orion.pardus.at':
|
|
34
|
+
return 'orion';
|
|
35
|
+
case 'artemis.pardus.at':
|
|
36
|
+
return 'artemis';
|
|
37
|
+
case 'pegasus.pardus.at':
|
|
38
|
+
return 'pegasus';
|
|
39
|
+
default:
|
|
40
|
+
throw new Error('Unable to determine universe');
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Returns the universe-specific name of a variable
|
|
46
|
+
* @ignore
|
|
47
|
+
*/
|
|
48
|
+
static getVariableName(variableName) {
|
|
49
|
+
return `${this.getUniverse()}_${variableName}`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Returns the universe-specific value of a variable
|
|
54
|
+
* @param {string} variableName The name of the universe-specific variable to retrieve
|
|
55
|
+
* @param {*} [defaultValue=null] A default value to return if the universe-specific variable has never been set.
|
|
56
|
+
* @returns {*} Value of the universe-specific value, or if not set, the default value.
|
|
57
|
+
*/
|
|
58
|
+
static getVariableValue(variableName, defaultValue = null) {
|
|
59
|
+
return this.defaultGetFunction(this.getVariableName(variableName), defaultValue);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Sets the universe-specific value of a variable
|
|
64
|
+
* @param {string} variableName The name of the universe-specific variable to set
|
|
65
|
+
* @param {*} value The value to set for the universe-specific variable.
|
|
66
|
+
*/
|
|
67
|
+
static setVariableValue(variableName, value) {
|
|
68
|
+
return this.defaultSaveFunction(this.getVariableName(variableName), value);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Deletes the universe-specific value of a variable
|
|
73
|
+
* @param {string} variableName The name of the universe-specific variable to delete
|
|
74
|
+
*/
|
|
75
|
+
static deleteVariableValue(variableName) {
|
|
76
|
+
return this.defaultDeleteFunction(this.getVariableName(variableName));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @ignore
|
|
81
|
+
*/
|
|
82
|
+
static setActiveTab(id) {
|
|
83
|
+
window.localStorage.setItem('pardusOptionsOpenTab', id);
|
|
84
|
+
window.dispatchEvent(new window.Event('storage'));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Returns a path to the user's image pack to use as a base for relative image URLs
|
|
89
|
+
* @returns {string} Path to the user's iamge pack
|
|
90
|
+
*/
|
|
91
|
+
static getImagePackUrl() {
|
|
92
|
+
const defaultImagePackUrl = '//static.pardus.at/img/std/';
|
|
93
|
+
const imagePackUrl = String(document.querySelector('body').style.backgroundImage).replace(/url\("*|"*\)|[a-z0-9]+\.gif/g, '');
|
|
94
|
+
|
|
95
|
+
return imagePackUrl !== '' ? imagePackUrl : defaultImagePackUrl;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @ignore
|
|
100
|
+
*/
|
|
101
|
+
static addGlobalListeners() {
|
|
102
|
+
EventTarget.prototype.addPardusKeyDownListener = function addPardusKeyDownListener(pardusVariable, defaultValue, listener, options = false) {
|
|
103
|
+
const pardusVariableKey = PardusOptionsUtility.getVariableValue(pardusVariable, defaultValue);
|
|
104
|
+
|
|
105
|
+
if (!pardusVariableKey) {
|
|
106
|
+
throw new Error(`No Pardus variable ${pardusVariable} defined!`);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (Object.hasOwn(pardusVariableKey, 'disabled')) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (!this.pardusListeners) {
|
|
114
|
+
this.pardusListeners = [];
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Prevent duplicates from being added
|
|
118
|
+
if (this.pardusListeners.includes(`${pardusVariableKey.code}${pardusVariable}`)) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
this.pardusListeners.push(`${pardusVariableKey.code}${pardusVariable}`);
|
|
123
|
+
|
|
124
|
+
const eventListener = (event) => {
|
|
125
|
+
if (event.isComposing || event.keyCode === 229 || event.repeat) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (event.keyCode !== pardusVariableKey.code) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
listener(event);
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
this.addEventListener('keydown', eventListener, options);
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import PardusOptionsUtility from './pardus-options-utility.js';
|
|
2
|
+
import TipBox from './tip-box.js';
|
|
3
|
+
import TabsElement from './tabs/tabs-element.js';
|
|
4
|
+
import ContentsArea from './contents-area.js';
|
|
5
|
+
import Tab from './tabs/tab.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @module PardusOptions
|
|
9
|
+
*/
|
|
10
|
+
export default class PardusOptions {
|
|
11
|
+
/**
|
|
12
|
+
* @ignore
|
|
13
|
+
*/
|
|
14
|
+
static init() {
|
|
15
|
+
if (document.getElementById('options-area')) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Get the normal Pardus options
|
|
20
|
+
const defaultPardusOptionsContent = document.getElementsByTagName('table')[2];
|
|
21
|
+
|
|
22
|
+
// Identify the containing HTML element to house all the options HTML
|
|
23
|
+
const pardusMainElement = defaultPardusOptionsContent.parentNode;
|
|
24
|
+
|
|
25
|
+
// Give the Pardus options an appropriate id, and remove it from the DOM
|
|
26
|
+
defaultPardusOptionsContent.setAttribute('id', 'options-content-pardus-default');
|
|
27
|
+
defaultPardusOptionsContent.setAttribute('class', 'tabstyle');
|
|
28
|
+
defaultPardusOptionsContent.remove();
|
|
29
|
+
|
|
30
|
+
// Add this object to the DOM within the main containing element
|
|
31
|
+
pardusMainElement.appendChild(this.getPardusOptionsElement());
|
|
32
|
+
|
|
33
|
+
const defaultTipBox = this.createDefaultTipBox();
|
|
34
|
+
pardusMainElement.appendChild(defaultTipBox.toElement());
|
|
35
|
+
|
|
36
|
+
// Add the Pardus options back in
|
|
37
|
+
this.addTab({
|
|
38
|
+
id: 'pardus-default',
|
|
39
|
+
heading: 'Pardus Options',
|
|
40
|
+
content: defaultPardusOptionsContent.outerHTML,
|
|
41
|
+
refresh: false,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// Set the Pardus options tab to be active by default
|
|
45
|
+
PardusOptionsUtility.setActiveTab('pardus-default');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @deprecated Get the version of the Pardus Options Library running
|
|
50
|
+
*/
|
|
51
|
+
static version() {
|
|
52
|
+
return 1.6;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @ignore
|
|
57
|
+
*/
|
|
58
|
+
static createDefaultTipBox() {
|
|
59
|
+
return new TipBox({
|
|
60
|
+
id: 'options-default-tip-box',
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @ignore
|
|
66
|
+
*/
|
|
67
|
+
static getDefaultTipBox() {
|
|
68
|
+
const defaultTipBox = this.createDefaultTipBox();
|
|
69
|
+
defaultTipBox.refreshElement();
|
|
70
|
+
return defaultTipBox;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @ignore
|
|
75
|
+
*/
|
|
76
|
+
static getTabsElement() {
|
|
77
|
+
return new TabsElement({
|
|
78
|
+
id: 'options-tabs',
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* @ignore
|
|
84
|
+
*/
|
|
85
|
+
static getContentElement() {
|
|
86
|
+
return new ContentsArea({
|
|
87
|
+
id: 'options-content',
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* @ignore
|
|
93
|
+
*/
|
|
94
|
+
static getPardusOptionsElement() {
|
|
95
|
+
const template = document.createElement('template');
|
|
96
|
+
template.innerHTML = `<table id="options-area" cellspacing="0" cellpadding="0" border="0"><tbody><tr cellspacing="0" cellpadding="0" border="0"><td>${this.getTabsElement()}</td></tr>${this.getContentElement()}</tbody></table>`;
|
|
97
|
+
return template.content.firstChild;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Add a tab on the Options page on Pardus to show your options
|
|
102
|
+
* @param {Object} params An object containing parameter values
|
|
103
|
+
* @param {string} params.id A namespace identifier to identify the tab from other tabs. Must be globally unique.
|
|
104
|
+
* @param {string} params.heading Text to display in the tab
|
|
105
|
+
* @param {string} params.content HTML to embed within the tab.
|
|
106
|
+
* @returns {TabContent} Tab
|
|
107
|
+
*/
|
|
108
|
+
static addTab({
|
|
109
|
+
id,
|
|
110
|
+
heading,
|
|
111
|
+
content = null,
|
|
112
|
+
saveFunction = PardusOptionsUtility.defaultSaveFunction,
|
|
113
|
+
getFunction = PardusOptionsUtility.defaultGetFunction,
|
|
114
|
+
refresh = true,
|
|
115
|
+
defaultLabel,
|
|
116
|
+
}) {
|
|
117
|
+
const newTab = new Tab({
|
|
118
|
+
id,
|
|
119
|
+
heading,
|
|
120
|
+
content,
|
|
121
|
+
saveFunction,
|
|
122
|
+
getFunction,
|
|
123
|
+
refresh,
|
|
124
|
+
defaultLabel,
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
// Check for id uniqueness
|
|
128
|
+
if (document.getElementById(newTab.id)) {
|
|
129
|
+
throw new Error(`Tab '${newTab.id}' already exists!`);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
this.getTabsElement().addLabel({
|
|
133
|
+
label: newTab.getLabel(),
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
this.getContentElement().addContent({
|
|
137
|
+
content: newTab.getContent(),
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
newTab.addListeners();
|
|
141
|
+
|
|
142
|
+
return newTab.getContent();
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import AbstractButton from '../abstract/abstract-button.js';
|
|
2
|
+
|
|
3
|
+
export default class LoadButton extends AbstractButton {
|
|
4
|
+
constructor({
|
|
5
|
+
id,
|
|
6
|
+
premium = false,
|
|
7
|
+
disabled = false,
|
|
8
|
+
}) {
|
|
9
|
+
super({
|
|
10
|
+
id,
|
|
11
|
+
premium,
|
|
12
|
+
disabled,
|
|
13
|
+
actionText: 'Load',
|
|
14
|
+
actionPerformedText: 'Loaded',
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
displayLoaded() {
|
|
19
|
+
this.displayClicked();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import DisableableHtmlElement from '../disableable-html-element.js';
|
|
2
|
+
import PardusOptionsUtility from '../pardus-options-utility.js';
|
|
3
|
+
|
|
4
|
+
export default class PresetLabel extends DisableableHtmlElement {
|
|
5
|
+
constructor({
|
|
6
|
+
id,
|
|
7
|
+
disabled = false,
|
|
8
|
+
defaultValue = '',
|
|
9
|
+
}) {
|
|
10
|
+
super({
|
|
11
|
+
id,
|
|
12
|
+
disabled,
|
|
13
|
+
});
|
|
14
|
+
this.defaultValue = defaultValue;
|
|
15
|
+
this.styleExtra = '';
|
|
16
|
+
this.colour = '#D0D1D9';
|
|
17
|
+
this.backgroundColour = '#00001C';
|
|
18
|
+
|
|
19
|
+
if (this.disabled) {
|
|
20
|
+
this.colour = '#B5B5B5';
|
|
21
|
+
this.backgroundColour = '#CCCCCC';
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
this.style = `color: ${this.colour};background-color: ${this.backgroundColour};${this.styleExtra}`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
toString() {
|
|
28
|
+
return `<input id="${this.id}" type="text" value="${this.getValue()}" style="${this.style}" ${this.disabled ? 'disabled' : ''}></input>`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
save() {
|
|
32
|
+
PardusOptionsUtility.defaultSaveFunction(`${PardusOptionsUtility.getVariableName(this.id)}`, this.getCurrentValue());
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
hasValue() {
|
|
36
|
+
if (!PardusOptionsUtility.defaultGetFunction(`${PardusOptionsUtility.getVariableName(this.id)}`, false)) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Disables the input element
|
|
45
|
+
* @function AbstractOption#disable
|
|
46
|
+
*/
|
|
47
|
+
disable() {
|
|
48
|
+
this.setDisabled(true);
|
|
49
|
+
if (this.getInputElement()) {
|
|
50
|
+
this.getInputElement().removeAttribute('disabled');
|
|
51
|
+
this.getInputElement().setAttribute('style', this.style);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Enables the input element
|
|
57
|
+
* @function AbstractOption#enable
|
|
58
|
+
*/
|
|
59
|
+
enable() {
|
|
60
|
+
this.setDisabled(false);
|
|
61
|
+
if (this.getInputElement()) {
|
|
62
|
+
this.getInputElement().removeAttribute('disabled');
|
|
63
|
+
this.getInputElement().setAttribute('style', this.style);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
setDisabled(disabled = false) {
|
|
68
|
+
this.disabled = disabled;
|
|
69
|
+
if (this.disabled) {
|
|
70
|
+
this.colour = '#B5B5B5';
|
|
71
|
+
this.backgroundColour = '#CCCCCC';
|
|
72
|
+
} else {
|
|
73
|
+
this.colour = '#D0D1D9';
|
|
74
|
+
this.backgroundColour = '#00001C';
|
|
75
|
+
}
|
|
76
|
+
this.style = `color: ${this.colour};background-color: ${this.backgroundColour};${this.styleExtra}`;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Gets the input element for the option
|
|
81
|
+
* @function PresetLabel#getInputElement
|
|
82
|
+
* @returns {object} Input element
|
|
83
|
+
*/
|
|
84
|
+
getInputElement() {
|
|
85
|
+
return document.getElementById(this.id);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
getCurrentValue() {
|
|
89
|
+
return this.getInputElement().value;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
getValue() {
|
|
93
|
+
return PardusOptionsUtility.defaultGetFunction(`${PardusOptionsUtility.getVariableName(this.id)}`, this.defaultValue);
|
|
94
|
+
}
|
|
95
|
+
}
|