-
Notifications
You must be signed in to change notification settings - Fork 3
/
IncrementParameters.js
120 lines (104 loc) · 3.61 KB
/
IncrementParameters.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*** Increment Parameters ***/
// Utility to easily increment numbered parameters
// Documentation at [[en:w:User:BrandonXLF/IncrementParameters]]
// By [[en:w:User:BrandonXLF]]
$.when(mw.loader.using('oojs-ui'), $.ready).then(function() {
$(mw.util.addPortletLink('p-tb', '#', 'Increment params')).click(function(e) {
var regex = {
all: /\|(\s*[^ =|_-]?[^ =|]*?\s*)([1-9]\d*)(\s*[^ =|]*?[^ =|]?\s*)=/g,
suffix: /\|(\s*(?:header|label|data|rowclass|class)*?\s*)([1-9]\d*)(\s*[^ =|]*?[^ =|]?\s*)=/g,
infobox: /\|(\s*(?:header|label|data|rowclass|class)*?\s*)([1-9]\d*)(\s*)=/g
},
opts = new OO.ui.RadioSelectInputWidget({
value: 'all',
options: [
{
data: 'all',
label: 'Increment ALL incremental parameters.'
},
{
data: 'suffix',
label: 'Only increment header, label, data, rowclass, and class (with or without suffix).'
},
{
data: 'infobox',
label: 'Only increment header, label, data, rowclass, and class (without suffix).'
}
]
}),
increment = new OO.ui.NumberInputWidget({
min: 0,
step: 1,
value: 1
}),
min = new OO.ui.NumberInputWidget({
min: 0,
step: 1,
placeholder: '0'
}),
max = new OO.ui.NumberInputWidget({
min: 0,
step: 1,
placeholder: 'Infinity'
}),
text = new OO.ui.MultilineTextInputWidget({
rows: 10,
maxRows: 999999,
autosize: true,
placeholder: 'Input'
});
e.preventDefault();
text.$element.css({fontFamily: 'monospace, monospace'});
function IncrementParametersDialog(config) {
IncrementParametersDialog.super.call(this, config);
}
OO.inheritClass(IncrementParametersDialog, OO.ui.ProcessDialog);
IncrementParametersDialog.static.name = 'incrementparams';
IncrementParametersDialog.static.title = 'Increment parameters';
IncrementParametersDialog.static.actions = [
{label: 'Close', flags: ['safe', 'close']},
{label: 'Run', flags: ['primary', 'progressive'], action: 'run'}
];
IncrementParametersDialog.prototype.initialize = function() {
IncrementParametersDialog.super.prototype.initialize.apply(this, arguments);
this.content = new OO.ui.PanelLayout({
padded: true,
expanded: false
});
this.content.$element.append(
(new OO.ui.FieldLayout(opts, {align: 'top'})).$element,
(new OO.ui.FieldLayout(increment, {label: 'Increment by', align: 'left'})).$element,
(new OO.ui.FieldLayout(min, {label: 'Min range', align: 'left'})).$element,
(new OO.ui.FieldLayout(max, {label: 'Max range', align: 'left'})).$element,
(new OO.ui.FieldLayout(text, {align: 'top'})).$element
);
this.$body.append(this.content.$element);
};
IncrementParametersDialog.prototype.getActionProcess = function(action) {
return new OO.ui.Process(function() {
if (!action) return this.close().closed;
text.setValue(text.getValue().replace(regex[opts.getValue()], function(match, prefix, num, suffix) {
if (
parseInt(num, 10) < parseInt(min.getNumericValue() || 0, 10) ||
parseInt(num, 10) > parseInt(max.getNumericValue() || Infinity, 10)
) {
return match;
}
return '|' + prefix + (parseInt(num, 10) + parseInt(increment.getNumericValue(), 10)).toString() + suffix + '=';
}));
}, this);
};
IncrementParametersDialog.prototype.getBodyHeight = function() {
this.content.resetScroll();
return this.content.$element.outerHeight(true);
};
var dialog = new IncrementParametersDialog({
size: 'large'
});
OO.ui.getWindowManager().addWindows([dialog]);
OO.ui.getWindowManager().openWindow(dialog);
text.on('change', function() {
dialog.updateSize();
});
});
});