-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCopiedOrTranslated.js
More file actions
91 lines (79 loc) · 2.67 KB
/
CopiedOrTranslated.js
File metadata and controls
91 lines (79 loc) · 2.67 KB
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
// <nowiki>
// Requested by Mathglot at https://en.wikipedia.org/wiki/Wikipedia_talk:User_scripts#WAG_estimate_needed_for_attribution_edit_summary_fill-in_script and https://en.wikipedia.org/wiki/Template_talk:Uw-translation#Link_to_content_translation_tool_for_xc_editors?
// See also User:Novem Linguae/Scripts/CWWEditSummary.js
// See also User:Chlod/Scripts/Deputy/AttributionNoticeTemplateEditor
class CopiedOrTranslated {
constructor( $, OO ) {
// eslint-disable-next-line no-jquery/variable-pattern
this.$ = $;
this.OO = OO;
}
execute() {
this.makeUntickedCheckbox();
}
makeUntickedCheckbox() {
// HTML
const checkbox = new this.OO.ui.CheckboxInputWidget( {
value: '1'
} );
const label = new this.OO.ui.LabelWidget( {
label: this.$( '<span>This content is <a href="https://en.wikipedia.org/wiki/Wikipedia:Copying_within_Wikipedia">copied or translated</a>.</span>' )
} );
const field = new this.OO.ui.FieldLayout( checkbox, {
id: 'copied-or-translated-unticked',
label: label.$element,
align: 'inline'
} );
// listeners
checkbox.onChange = ( ticked ) => {
if ( ticked ) {
this.makeTickedCheckbox();
this.$( '#copied-or-translated-unticked' ).remove();
}
};
// glue it all together
checkbox.connect( checkbox, { change: 'onChange' } );
this.$( '#mw-editpage-minoredit' ).after( field.$element );
}
makeTickedCheckbox() {
// HTML
const checkbox = new this.OO.ui.CheckboxInputWidget( {
value: '1',
selected: true
} );
const optionCopied = new this.OO.ui.RadioOptionWidget( {
value: 'copied',
label: this.$( '<span><a href="https://en.wikipedia.org/wiki/Wikipedia:Copying_within_Wikipedia">copied</a>' )
} );
const optionTranslated = new this.OO.ui.RadioOptionWidget( {
value: 'translated',
label: this.$( '<span><a href="https://en.wikipedia.org/w/index.php?title=Wikipedia:TFOLWP">translated</a>' )
} );
const $label = this.$( 'This content is ' )
.append( optionCopied.$element )
.append( ' or ' )
.append( optionTranslated.$element )
.append( '.' );
const field = new this.OO.ui.FieldLayout( checkbox, {
id: 'copied-or-translated-ticked',
label: $label,
align: 'inline'
} );
// listeners
checkbox.onChange = ( ticked ) => {
if ( !ticked ) {
this.makeUntickedCheckbox();
this.$( '#copied-or-translated-ticked' ).remove();
}
};
// glue it all together
checkbox.connect( checkbox, { change: 'onChange' } );
this.$( '#mw-editpage-minoredit' ).after( field.$element );
}
}
$( () => {
mw.loader.using( [ 'oojs-ui-core', 'oojs-ui-widgets', 'oojs-ui.styles.icons-editing-core' ], () => {
( new CopiedOrTranslated( $, OO ) ).execute();
} );
} );
// </nowiki>