]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - resources/src/mediawiki.action/mediawiki.action.edit.js
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / resources / src / mediawiki.action / mediawiki.action.edit.js
1 /*!
2  * Scripts for action=edit at domready
3  */
4 ( function ( mw, $ ) {
5         'use strict';
6
7         /**
8          * Fired when the editform is added to the edit page
9          *
10          * Similar to the {@link mw.hook#event-wikipage_content wikipage.content hook}
11          * $editForm can still be detached when this hook is fired.
12          *
13          * @event wikipage_editform
14          * @member mw.hook
15          * @param {jQuery} $editForm The most appropriate element containing the
16          *   editform, usually #editform.
17          */
18
19         $( function () {
20                 var editBox, scrollTop, $editForm,
21                         // TODO T6714: Once this can be adjusted, read this from config.
22                         summaryByteLimit = 255,
23                         wpSummary = OO.ui.infuse( $( '#wpSummaryWidget' ) );
24
25                 // Show a byte-counter to users with how many bytes are left for their edit summary.
26                 // TODO: This looks a bit weird, as there is no unit in the UI, just numbers; showing
27                 // 'bytes' confused users in testing, and showing 'chars' would be a lie. See T42035.
28                 mw.widgets.visibleByteLimit( wpSummary, summaryByteLimit );
29
30                 // Restore the edit box scroll state following a preview operation,
31                 // and set up a form submission handler to remember this state.
32                 editBox = document.getElementById( 'wpTextbox1' );
33                 scrollTop = document.getElementById( 'wpScrolltop' );
34                 $editForm = $( '#editform' );
35                 mw.hook( 'wikipage.editform' ).fire( $editForm );
36                 if ( $editForm.length && editBox && scrollTop ) {
37                         if ( scrollTop.value ) {
38                                 editBox.scrollTop = scrollTop.value;
39                         }
40                         $editForm.submit( function () {
41                                 scrollTop.value = editBox.scrollTop;
42                         } );
43                 }
44         } );
45 }( mediaWiki, jQuery ) );