Debian Codegraph @

resources/src/mediawiki.action.edit/edit.js

raw symbols SCIP
1 /*!
2 * Scripts for action=edit as rendered by EditPage.php.
3 */
4 'use strict';
5
6 /**
7 * Fired when the editform is added to the edit page.
8 *
9 * Similar to the {@link event:'wikipage.content' wikipage.content hook},
10 * $editForm can still be detached when this hook is fired.
11 *
12 * @event ~'wikipage.editform'
13 * @memberof Hooks
14 * @param {jQuery} $editForm The most appropriate element containing the
15 * editform, usually #editform.
16 */
17
18 $( () => {
19 const $wpSummary = $( '#wpSummaryWidget' );
20
21 // The summary field might not be there, e.g. when extensions replace it
22 if ( $wpSummary.length ) {
23 const wpSummary = OO.ui.infuse( $wpSummary );
24
25 // Show a byte-counter to users with how many bytes are left for their edit summary.
26 mw.widgets.visibleCodePointLimit( wpSummary, mw.config.get( 'wgCommentCodePointLimit' ) );
27 }
28
29 // Restore the edit box scroll state following a preview operation,
30 // and set up a form submission handler to remember this state.
31 const editBox = document.getElementById( 'wpTextbox1' );
32 const scrollTop = document.getElementById( 'wpScrolltop' );
33 const $editForm = $( '#editform' );
34 mw.hook( 'wikipage.editform' ).fire( $editForm );
35 if ( $editForm.length && editBox && scrollTop ) {
36 if ( scrollTop.value ) {
37 editBox.scrollTop = scrollTop.value;
38 }
39 $editForm.on( 'submit', () => {
40 scrollTop.value = editBox.scrollTop;
41 } );
42 }
43
44 mw.hook( 'wikipage.watchlistChange' ).add( ( isWatched, expiry, expirySelected ) => {
45 // Update the "Watch this page" checkbox on action=edit when the
46 // page is watched or unwatched via the tab (T14395).
47 const watchCheckbox = document.getElementById( 'wpWatchthisWidget' );
48 if ( watchCheckbox ) {
49 OO.ui.infuse( watchCheckbox ).setSelected( isWatched );
50
51 // Also reset expiry selection to keep it in sync
52 if ( isWatched ) {
53 const expiryCheckbox = document.getElementById( 'wpWatchlistExpiryWidget' );
54 if ( expiryCheckbox ) {
55 OO.ui.infuse( expiryCheckbox ).setValue( expirySelected );
56 }
57 }
58 }
59 } );
60 } );
61
62 require( './stash.js' );
63
64 require( './watchlistExpiry.js' );