* @class mw.special.upload
* @singleton
*/
+
+/* eslint-disable no-use-before-define */
+/* global Uint8Array */
+
( function ( mw, $ ) {
- /*jshint latedef:false */
var uploadWarning, uploadLicense,
ajaxUploadDestCheck = mw.config.get( 'wgAjaxUploadDestCheck' ),
$license = $( '#wpLicense' );
// Output result
if ( $( '#wpDestFile' ).length ) {
// Call decodeURIComponent function to remove possible URL-encoded characters
- // from the file name (bug 30390). Especially likely with upload-form-url.
+ // from the file name (T32390). Especially likely with upload-form-url.
// decodeURIComponent can throw an exception if input is invalid utf-8
try {
$( '#wpDestFile' ).val( decodeURIComponent( fname ) );
$( function () {
/**
* Is the FileAPI available with sufficient functionality?
+ *
+ * @return {boolean}
*/
function hasFileAPI() {
return window.FileReader !== undefined;
}, mw.config.get( 'wgFileCanRotate' ) ? function ( data ) {
try {
meta = mw.libs.jpegmeta( data, file.fileName );
- // jscs:disable requireCamelCaseOrUpperCaseIdentifiers, disallowDanglingUnderscores
+ // eslint-disable-next-line no-underscore-dangle, camelcase
meta._binary_data = null;
- // jscs:enable
} catch ( e ) {
meta = null;
}
/**
* Check if the file does not exceed the maximum size
+ *
+ * @param {File} file
+ * @return {boolean}
*/
function checkMaxUploadSize( file ) {
var maxSize, $error;
if ( hasFileAPI() ) {
// Update thumbnail when the file selection control is updated.
$( '#wpUploadFile' ).change( function () {
+ var file;
clearPreview();
if ( this.files && this.files.length ) {
// Note: would need to be updated to handle multiple files.
- var file = this.files[ 0 ];
+ file = this.files[ 0 ];
if ( !checkMaxUploadSize( file ) ) {
return;
allowCloseWindow.release();
} );
} );
+
+ // Add tabindex to mw-editTools
+ $( function () {
+ // Function to change tabindex for all links within mw-editTools
+ function setEditTabindex( $val ) {
+ $( '.mw-editTools' ).find( 'a' ).each( function () {
+ $( this ).attr( 'tabindex', $val );
+ } );
+ }
+
+ // Change tabindex to 0 if user pressed spaced or enter while focused
+ $( '.mw-editTools' ).on( 'keypress', function ( e ) {
+ // Don't continue if pressed key was not enter or spacebar
+ if ( e.which !== 13 && e.which !== 32 ) {
+ return;
+ }
+
+ // Change tabindex only when main div has focus
+ if ( $( this ).is( ':focus' ) ) {
+ $( this ).find( 'a' ).first().focus();
+ setEditTabindex( '0' );
+ }
+ } );
+
+ // Reset tabindex for elements when user focused out mw-editTools
+ $( '.mw-editTools' ).on( 'focusout', function ( e ) {
+ // Don't continue if relatedTarget is within mw-editTools
+ if ( e.relatedTarget !== null && $( e.relatedTarget ).closest( '.mw-editTools' ).length > 0 ) {
+ return;
+ }
+
+ // Reset tabindex back to -1
+ setEditTabindex( '-1' );
+ } );
+
+ // Set initial tabindex for mw-editTools to 0 and to -1 for all links
+ $( '.mw-editTools' ).attr( 'tabindex', '0' );
+ setEditTabindex( '-1' );
+ } );
}( mediaWiki, jQuery ) );