Completed
Push — master ( 48889d...507809 )
by Stephan
02:32
created

ext.SimpleBatchUpload.js ➔ $   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 49

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 49
rs 9.2258
cc 1
nc 1
nop 0
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: jQuery, mediaWiki */
23
24
;( function ( $, mw, undefined ) {
25
26
	'use strict';
27
28
	$( function () {
29
		$( '#fileupload' ).fileupload( {
30
			dataType: 'json',
31
			dropZone: $( '#fileupload-dropzone' ),
32
33
			add: function ( e, data ) {
34
35
				var status = $( '<li>' ).text( data.files[ 0 ].name );
36
				$( '#fileupload-results' ).append( status );
37
38
				data.formData = {
39
					format: 'json',
40
					action: 'upload',
41
					token: $( this ).fileupload( 'option', 'token' ),
42
					ignorewarnings: 1,
43
					filename: data.files[ 0 ].name
44
				};
45
46
				data.submit()
47
					.success( function ( result /*, textStatus, jqXHR */ ) {
48
49
						if ( result.error != undefined ) {
50
51
							status.text( status.text() + " ERROR: " + result.error.info ).addClass( 'ful-error' );
52
53
						} else {
54
							var link = $( '<a>' );
55
							link
56
								.attr( 'href', mw.Title.makeTitle( mw.config.get( 'wgNamespaceIds' ).file, result.upload.filename ).getUrl() )
57
								.text( result.upload.filename );
58
59
							status
60
								.addClass( 'ful-success' )
61
								.text( ' OK' )
62
								.prepend( link );
63
						}
64
65
					} )
66
					.error( function ( /* jqXHR, textStatus, errorThrown */ ) {
67
						status.text( status.text() + " ERROR" ).addClass( 'ful-error' );
68
					} );
69
70
			}
71
		} );
72
73
		$( document ).bind( 'drop dragover', function ( e ) {
74
			e.preventDefault();
75
		} );
76
	} );
77
78
}( 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...
79