Completed
Push — master ( 6d86dc...a39075 )
by Stephan
04:27
created

➔ $(ꞌ#fileuploadꞌ).change   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 1
rs 10
1
/**
2
 * File containing the SimpleBatchUpload class
3
 *
4
 * @copyright (C) 2016, Stephan Gambke
5
 * @license   GNU General Public License, version 2 (or any later version)
6
 *
7
 * This software is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU General Public License
9
 * as published by the Free Software Foundation; either version 2
10
 * of the License, or (at your option) any later version.
11
 * This software is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17
 *
18
 * @file
19
 * @ingroup SimpleBatchUpload
20
 */
21
22
/** global: mediaWiki */
23
/** global: jQuery */
24
25
;( function ( $, mw, undefined ) {
26
27
	'use strict';
28
29
	$( function () {
30
		$( '#fileupload' )
31
32
		.on( 'change', function ( e, data ) { $( '#fileupload-results' ).empty(); } )
0 ignored issues
show
Unused Code introduced by
The parameter e is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter data is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
33
34
		.fileupload( {
35
			dataType: 'json',
36
			dropZone: $( '#fileupload-dropzone' ),
37
			progressInterval: 100,
38
39
			drop: function ( e, data ) {
0 ignored issues
show
Unused Code introduced by
The parameter data is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter e is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
40
				$( '#fileupload-results' ).empty();
41
			},
42
43
			add: function ( e, data ) {
44
45
				data.id = Date.now();
46
47
				var status = $('<li>')
48
					.attr( 'id', data.id )
49
					.text( data.files[0].name );
50
				$( '#fileupload-results' ).append( status );
51
52
				data.formData = {
53
					format: 'json',
54
					action: 'upload',
55
					token: $( this ).fileupload( 'option', 'token' ),
56
					ignorewarnings: 1,
57
					filename: data.files[ 0 ].name
58
				};
59
60
				data.submit()
61
					.success( function ( result /*, textStatus, jqXHR */ ) {
62
63
						if ( result.error != undefined ) {
64
65
							status.text( status.text() + " ERROR: " + result.error.info ).addClass( 'ful-error' );
66
67
						} else {
68
							var link = $( '<a>' );
69
							link
70
								.attr( 'href', mw.Title.makeTitle( mw.config.get( 'wgNamespaceIds' ).file, result.upload.filename ).getUrl() )
71
								.text( result.upload.filename );
72
73
							status
74
								.addClass( 'ful-success' )
75
								.text( ' OK' )
76
								.prepend( link );
77
						}
78
79
					} )
80
					.error( function ( /* jqXHR, textStatus, errorThrown */ ) {
81
						status.text( status.text() + " ERROR" ).addClass( 'ful-error' );
82
					} );
83
84
			},
85
86
			progress: function (e, data) {
87
				if ( data.loaded != data.total ) {
88
					$( '#' + data.id )
89
						.text( data.files[0].name + ' ' + parseInt(data.loaded / data.total * 100, 10) + '%' );
90
				}
91
			}
92
		} );
93
94
		$( document ).bind( 'drop dragover', function ( e ) {
95
			e.preventDefault();
96
		} );
97
	} );
98
99
}( jQuery, mediaWiki ));
0 ignored issues
show
Bug introduced by
The variable mediaWiki seems to be never declared. If this is a global, consider adding a /** global: mediaWiki */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
100