2 * Scripts for action=edit at domready
8 * Fired when the editform is added to the edit page
10 * Similar to the {@link mw.hook#event-wikipage_content wikipage.content hook}
11 * $editForm can still be detached when this hook is fired.
13 * @event wikipage_editform
15 * @param {jQuery} $editForm The most appropriate element containing the
16 * editform, usually #editform.
20 var editBox
, scrollTop
, $editForm
,
21 summaryCodePointLimit
= mw
.config
.get( 'wgCommentCodePointLimit' ),
22 summaryByteLimit
= mw
.config
.get( 'wgCommentByteLimit' ),
23 wpSummary
= OO
.ui
.infuse( $( '#wpSummaryWidget' ) );
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 // (Showing 'chars' is still confusing with the code point limit, since it's not obvious
29 // that e.g. combining diacritics or zero-width punctuation count as characters.)
30 if ( summaryCodePointLimit
) {
31 mw
.widgets
.visibleCodePointLimit( wpSummary
, summaryCodePointLimit
);
32 } else if ( summaryByteLimit
) {
33 mw
.widgets
.visibleByteLimit( wpSummary
, summaryByteLimit
);
36 // Restore the edit box scroll state following a preview operation,
37 // and set up a form submission handler to remember this state.
38 editBox
= document
.getElementById( 'wpTextbox1' );
39 scrollTop
= document
.getElementById( 'wpScrolltop' );
40 $editForm
= $( '#editform' );
41 mw
.hook( 'wikipage.editform' ).fire( $editForm
);
42 if ( $editForm
.length
&& editBox
&& scrollTop
) {
43 if ( scrollTop
.value
) {
44 editBox
.scrollTop
= scrollTop
.value
;
46 $editForm
.submit( function () {
47 scrollTop
.value
= editBox
.scrollTop
;
51 }( mediaWiki
, jQuery
) );