2 * Scripts for action=edit as rendered by EditPage.php.
7 * Fired when the editform is added to the edit page.
9 * Similar to the {@link event:'wikipage.content' wikipage.content hook},
10 * $editForm can still be detached when this hook is fired.
12 * @event ~'wikipage.editform'
14 * @param {jQuery} $editForm The most appropriate element containing the
15 * editform, usually #editform.
19 const $wpSummary = $( '#wpSummaryWidget' );
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 );
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' ) );
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;
39 $editForm.on( 'submit', () => {
40 scrollTop.value = editBox.scrollTop;
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 );
51 // Also reset expiry selection to keep it in sync
53 const expiryCheckbox = document.getElementById( 'wpWatchlistExpiryWidget' );
54 if ( expiryCheckbox ) {
55 OO.ui.infuse( expiryCheckbox ).setValue( expirySelected );
62 require( './stash.js' );
64 require( './watchlistExpiry.js' );