2014-03-24 06:08:56 +00:00
|
|
|
/**
|
2014-10-19 15:35:43 +00:00
|
|
|
* Disable InputBox submit button when the corresponding text input field is empty.
|
2014-03-24 06:08:56 +00:00
|
|
|
*
|
|
|
|
* @author Tony Thomas
|
2015-07-23 04:44:47 +00:00
|
|
|
* @license http://opensource.org/licenses/MIT MIT License
|
2014-03-24 06:08:56 +00:00
|
|
|
*/
|
|
|
|
( function ( $, mw ) {
|
|
|
|
'use strict';
|
2018-08-28 18:58:49 +00:00
|
|
|
mw.hook( 'wikipage.content' ).add( function ( $content ) {
|
2014-10-19 15:35:43 +00:00
|
|
|
var $input = $content.find( '.createboxInput:not([type=hidden])' ),
|
2018-08-28 18:58:49 +00:00
|
|
|
onChange = function () {
|
|
|
|
var $textbox = $( this ),
|
|
|
|
$submit = $textbox.data( 'form-submit' );
|
2014-03-24 06:08:56 +00:00
|
|
|
|
2018-08-28 18:58:49 +00:00
|
|
|
if ( !$submit ) {
|
|
|
|
$submit = $textbox.nextAll( 'input.createboxButton' ).first();
|
|
|
|
$textbox.data( 'form-submit', $submit );
|
|
|
|
}
|
2014-03-24 06:08:56 +00:00
|
|
|
|
2018-08-28 18:58:49 +00:00
|
|
|
$submit.prop( 'disabled', $textbox.val().length < 1 );
|
|
|
|
}, i;
|
2014-10-05 12:38:39 +00:00
|
|
|
|
|
|
|
for ( i = 0; i < $input.length; i++ ) {
|
|
|
|
onChange.call( $input.get( i ) );
|
|
|
|
}
|
2014-03-24 06:08:56 +00:00
|
|
|
|
2014-10-05 12:38:39 +00:00
|
|
|
$input.on( 'keyup input change', $.debounce( 50, onChange ) );
|
2014-10-19 15:35:43 +00:00
|
|
|
} );
|
2014-10-05 12:38:39 +00:00
|
|
|
}( jQuery, mediaWiki ) );
|