Merge "jsduck: Explcitly name library files so we don't pull in CSS files"
[lhc/web/wiklou.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
24 if ( $( '#editform' ).hasClass( 'mw-editform-ooui' ) ) {
25 mw.loader.using( 'oojs-ui-core' ).then( function () {
26 var wpSummary = OO.ui.infuse( $( '#wpSummaryWidget' ) );
27
28 // Restore appropriate modifier keys for the accesskey in the 'title' attribute
29 // TODO: This should be an OOjs UI feature, or somehow happen automatically after infusing.
30 wpSummary.$input.updateTooltipAccessKeys();
31
32 // Show a byte-counter to users with how many bytes are left for their edit summary.
33 // TODO: This looks a bit weird, as there is no unit in the UI, just numbers; showing
34 // 'bytes' confused users in testing, and showing 'chars' would be a lie. See T42035.
35 mw.widgets.visibleByteLimit( wpSummary, summaryByteLimit );
36 } );
37 } else {
38 // Make sure edit summary does not exceed byte limit
39 $( '#wpSummary' ).byteLimit( summaryByteLimit );
40 }
41
42 // Restore the edit box scroll state following a preview operation,
43 // and set up a form submission handler to remember this state.
44 editBox = document.getElementById( 'wpTextbox1' );
45 scrollTop = document.getElementById( 'wpScrolltop' );
46 $editForm = $( '#editform' );
47 mw.hook( 'wikipage.editform' ).fire( $editForm );
48 if ( $editForm.length && editBox && scrollTop ) {
49 if ( scrollTop.value ) {
50 editBox.scrollTop = scrollTop.value;
51 }
52 $editForm.submit( function () {
53 scrollTop.value = editBox.scrollTop;
54 } );
55 }
56 } );
57 }( mediaWiki, jQuery ) );