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
enough changed for minor version bump
 
(26 intermediate revisions by the same user not shown)
Line 1:
/* jshint esversion: 6, laxbreak: true, undef: true, eqnull: true, maxerr: 999 */
/* globals console, document, File, FileReader, fetch, window, $, mw, OO */
// <nowiki>
var setupCovery = function setupCovery() {
var SCRIPT = {
name: 'Covery',
version: '1.45.0',
ad: ' (using [[User:Evad37/Covery|Covery]])'
};
Line 123 ⟶ 125:
'Infobox computer game',
'Videogame infobox',
'Video game infobox',
'Infobox video game series',
'Infobox VG series',
'Infobox video game franchise'
];
var infoboxName = toSentanceCase(infobox.name);
Line 161 ⟶ 166:
canvas.width = width;
canvas.height = height;
var ctx = canvas.getContext('2d');
ctx.drawImage(origImg, 0, 0, width, height);
 
Line 433 ⟶ 438:
this.content = new OO.ui.FieldsetLayout();
 
this.fileSelect = new OO.ui.SelectFileWidget();{
droppable: true,
showDropTarget: true,
// thumbnailSizeLimit: 0,
$element: $("<div style='background: #eee;'>")
});
// this.fileSelect.$element
// .find(".oo-ui-selectFileWidget-dropTarget").css({"height":"auto"});
// this.fileSelect.$element
// .find(".oo-ui-selectFileWidget-thumbnail").css({"display":"none"});
// this.fileSelect.$element
// .find(".oo-ui-selectFileInputWidget-info").css({"margin":"0"});
this.urlInput = new OO.ui.TextInputWidget({
type: 'url',
Line 452 ⟶ 469:
this.fileSelectField = new OO.ui.FieldLayout(this.fileSelect, {
label: 'Upload a file...',
align: 'lefttop'
});
this.fileSelect.field = this.fileSelectField;
Line 466 ⟶ 483:
this.titleInputField = new OO.ui.FieldLayout(this.titleInput, {
label: 'File name',
align: 'lefttop'
});
this.titleInputField.setErros(['Invalid file name']);$element
.find(".oo-ui-fieldLayout-messages").css({"margin-top":"2em"}); // prevent errors overlapping input
this.captionInputField = new OO.ui.FieldLayout(this.captionInput, {
label: 'Caption',
Line 491 ⟶ 510:
this.content.addItems([
this.fileSelectField,
// this.urlInputField,
this.titleInputField,
//this.imagePreviewField,
this.captionInputField,
this.altTextInputField,
Line 567 ⟶ 586:
self.updateSize();
widgetUsed.popPending();
if (widgetUsed.setIndicator('required'); {
widgetUsed.setIndicator('required');
});
otherWidget.setDisabled(false);
if (otherWidget.setIndicator(null); {
otherWidget.setIndicator(null);
}
self.titleInput.setValue(fileName);
self.onRequiredInputChange();
Line 579 ⟶ 602:
self.resizedFile = null;
widgetUsed.popPending();
if (widgetUsed.setIndicator('clear'); {
widgetUsed.setIndicator('clear');
}
widgetUsed.field.setErrors([errorMessage]);
otherWidget.setDisabled(false);
if (otherWidget.setIndicator(null); {
otherWidget.setIndicator(null);
}
self.onRequiredInputChange();
}
Line 588 ⟶ 615:
};
 
CoveryDialog.prototype.onFileSelectChange = function(filefiles) {
var file = files && files[0];
if (!file || !file.name) {
return;
}
this.onFileChosen(file, file.name, this.fileSelect, this.urlInput);
};
Line 602 ⟶ 633:
return;
}
var filePromise = fetch(value, {mode: 'no-cors'}).then(function(result) {
return result.blob();
});
Line 611 ⟶ 642:
CoveryDialog.prototype.onTitleInputFlag = function(flag) {
if (flag.invalid === true) {
if (this.titleInput.setValuegetValue().length) {
this.titleInputField.setErros(['Invalid file name']);
this.titleInputField.setErrors(['Invalid file name']);
}
this.actions.setAbilities({
upload: false
Line 639 ⟶ 672:
var impliedTitleMime = mimeLookup[titleExtension] || '';
return fileMime === impliedTitleMime;
};
 
CoveryDialog.prototype.changeTitleExtension = function(newExtension) {
this.titleInput.setValue(
this.titleInput.getValue().replace(/(.*)(\..*?)?/, '$1.' + newExtension)
);
};
 
Line 656 ⟶ 683:
// check file mime matches title mime
var titleHasCorrectExtension = self.checkMimes();
if (!titleHasCorrectExtension && self.resizedFile && self.resizedFile.type) {
self.actionstitleInputField.setAbilitiessetErrors({[
'Invalid file extension (file is a ' +
upload: false
self.resizedFile.type
});
.replace('image/', '')
self.changeTitleExtension(
resizedFile.type.replace('image/', '') .replace(/\+.*$/, '')
.toUpperCase(); +
return; ' image)'
]);
}
 
Line 671 ⟶ 699:
!!self.resizedFile &&
!!self.titleInput.getValue().length &&
titleHasCorrectExtension; &&
!!self.developerInput.getValue().length &&
!!self.publisherInput.getValue().length;
self.actions.setAbilities({
upload: requirementsMet
Line 678 ⟶ 707:
},
function() {
if (self.titleInput.getValue().length) {
self.titleInputField.setErrors(['Invalid file name']);
}
self.actions.setAbilities({
upload: false
Line 967 ⟶ 999:
function(data) {
if (data && data.sucess) {
window.___location.reload();
}
},
Line 1,053 ⟶ 1,085:
) {
$.when(setupForTesting(), $.ready()).then(function() {
mw.loader.load('https://codeen.jquerywikipedia.comorg/qunitw/index.php?title=User:Evad37/qunit-2.68.20.css&action=raw&ctype=text/css', 'text/css');
$.getScript('https://codeen.jquerywikipedia.comorg/qunitw/index.php?title=User:Evad37/qunit-2.68.20.js&action=raw&ctype=text/javascript', function() {
/* globals QUnit */
QUnit.module('Get parameters from a template');
QUnit.test('Single unnamed param', function(assert) {
Line 1,590 ⟶ 1,623:
'{{Videogame infobox}}',
'{{Video game infobox}}',
'{{Infobox video game series}}',
'{{Infobox VG series}}',
'{{Infobox video game franchise}}',
'{{infobox video game}}',
'{{infobox Arcade Game}}',
Line 1,608 ⟶ 1,644:
'{{infobox computer game}}',
'{{videogame infobox}}',
'{{video game infobox}}',
'{{infobox video game series}}',
'{{infobox VG series}}',
'{{infobox video game franchise}}'
];
infoboxesExpectedToPass.forEach(infobox => {
for (let infobox of infoboxesExpectedToPass) {
QUnit.test(infobox, function(assert) {
let infoboxObject = getInfoboxTemplate(infobox);
Line 1,616 ⟶ 1,655:
assert.deepEqual(checkedInfobox, infoboxObject, infobox + ' passes check');
});
});
QUnit.module('Infobox check (expected fail)');
var infoboxesExpectedToFail = [
Line 1,626 ⟶ 1,665:
'{{infobox foo}}'
];
infoboxesExpectedToFail.forEach(infobox => {
for (let infobox of infoboxesExpectedToFail) {
QUnit.test(infobox, function(assert) {
let infoboxObject = getInfoboxTemplate(infobox);
Line 1,633 ⟶ 1,672:
}, infobox + ' throws an error');
});
});
 
QUnit.module('Make infobox wikitext');
Line 1,734 ⟶ 1,773:
'mediawiki.util',
'mediawiki.api',
'mediawiki.RegExp',
'oojs-ui-core',
'oojs-ui-widgets',