49e64b5254fa6eabd52364c31ced6587ce6be4ee
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
;
22 if ( $( '#editform' ).hasClass( 'mw-editform-ooui' ) ) {
23 mw
.loader
.using( 'oojs-ui-core' ).then( function () {
24 var wpSummary
= OO
.ui
.infuse( $( '#wpSummaryWidget' ) );
26 // Make sure edit summary does not exceed byte limit
27 wpSummary
.$input
.byteLimit( 255 );
29 // Show a byte-counter to users with how many bytes are left for their edit summary.
30 // TODO: This looks a bit weird, as there is no unit in the UI, just numbers; showing
31 // 'bytes' confused users in testing, and showing 'chars' would be a lie. See T42035.
32 function updateSummaryLabelCount() {
33 wpSummary
.setLabel( String( 255 - $.byteLength( wpSummary
.getValue() ) ) );
35 wpSummary
.on( 'change', updateSummaryLabelCount
);
37 updateSummaryLabelCount();
40 // Make sure edit summary does not exceed byte limit
41 $( '#wpSummary' ).byteLimit( 255 );
44 // Restore the edit box scroll state following a preview operation,
45 // and set up a form submission handler to remember this state.
46 editBox
= document
.getElementById( 'wpTextbox1' );
47 scrollTop
= document
.getElementById( 'wpScrolltop' );
48 $editForm
= $( '#editform' );
49 mw
.hook( 'wikipage.editform' ).fire( $editForm
);
50 if ( $editForm
.length
&& editBox
&& scrollTop
) {
51 if ( scrollTop
.value
) {
52 editBox
.scrollTop
= scrollTop
.value
;
54 $editForm
.submit( function () {
55 scrollTop
.value
= editBox
.scrollTop
;
59 }( mediaWiki
, jQuery
) );