User:Evad37/Covery/sandbox.js: Difference between revisions

Content deleted Content added
.
Version 1.4.0: replace a mismatched file extension with the correct extension
Line 3:
var SCRIPT = {
name: 'Covery',
version: '1.34.0',
ad: ' (using [[User:Evad37/Covery|Covery]])'
};
Line 611:
CoveryDialog.prototype.onTitleInputFlag = function(flag) {
if (flag.invalid === true) {
this.titleInputField.setErros(['Invalid file name']);
this.actions.setAbilities({
upload: false
Line 617 ⟶ 618:
this.onRequiredInputChange();
}
};
 
CoveryDialog.prototype.checkMimes = function() {
var mimeLookup = {
'.bmp': 'image/bmp',
'.gif': 'image/gif',
'.jpeg': 'image/jpeg',
'.jpg': 'image/jpeg',
'.png': 'image/png',
'.svg': 'image/svg+xml',
'.tif': 'image/tiff',
'.tiff': 'image/tiff'
};
var fileMime = (this.resizedFile && this.resizedFile.type) || '';
var titleParts = this.titleInput
.getValue()
.toLowerCase()
.match(/.*(\..*)$/, '$1');
var titleExtension = titleParts && titleParts[1];
var impliedTitleMime = mimeLookup[titleExtension] || '';
return fileMime === impliedTitleMime;
};
 
CoveryDialog.prototype.changeTitleExtension = function(newExtension) {
this.titleInput.setValue(
this.titleInput.getValue().replace(/(.*)(\..*?)?/, '$1.' + newExtension)
);
};
 
Line 624 ⟶ 652:
$.when((change && change.titleIsValid) || this.titleInput.getValidity()).then(
function() {
// remove any old title input errors
self.titleInputField.setErrors([]);
// check file mime matches title mime
var titleHasCorrectExtension = self.checkMimes();
if (!titleHasCorrectExtension && self.resizedFile && self.resizedFile.type) {
self.actions.setAbilities({
upload: false
});
self.changeTitleExtension(
resizedFile.type.replace('image/', '').replace(/\+.*/, '')
);
return;
}
 
var requirementsMet =
!self.fileSelect.isPending() &&
Line 629 ⟶ 671:
!!self.resizedFile &&
!!self.titleInput.getValue().length &&
titleHasCorrectExtension;
!!self.developerInput.getValue().length &&
!!self.developerInput.getValue().length && !!self.publisherInput.getValue().length;
self.actions.setAbilities({
upload: requirementsMet