Last active
August 29, 2015 13:56
-
-
Save toniher/9140663 to your computer and use it in GitHub Desktop.
Bit of jQuery code for keeping suitable filename extension in MediaWiki file upload form. Useful when used with default filename parameter in Semantic Forms http://www.mediawiki.org/wiki/Extension:Semantic_Forms/Defining_forms
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Make filename readonly, so filename is either the default one defined in the form or the filename in your drive **/ | |
$("#mw-upload-form #wpDestFile").attr('readonly', true); | |
/** Keep file extension in upload. Default filename is changed according the filename extension uploaded **/ | |
$("input:file").change(function (){ | |
var filename = $('input[type=file]').val().replace(/C:\\fakepath\\/i, ''); | |
var extension = filename.substr( (filename.lastIndexOf('.') +1) ); | |
var subs = "."+extension; | |
var filenamef = $("#wpDestFile").val(); | |
var extensionf = filenamef.substr( (filenamef.lastIndexOf('.') +1) ); | |
var init = "."+extensionf; | |
var filenamev = filenamef.replace(init, subs); | |
$("#wpDestFile").val(filenamev); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment