MediaWiki:Gadget-morebits.js: Difference between revisions

Content deleted Content added
Repo at dafea6cd: Return the promise from the render API
Repo at e99ee60e: lookupCreation: add failure callback; Add number input type to quickform, use in tag
Line 216:
* - Attributes: name, list, event
* - Attributes (within list): name, label, value, checked, disabled, event, subgroup
* - `input`: A text input box.
* - Attributes: name, label, value, size, placeholder, maxlength, disabled, required, readonly, maxlength, event
* - `number`: A number input box.
* - Attributes: Everything the text `input` has, as well as: min, max, step, list
* - `dyninput`: A set of text boxes with "Remove" buttons and an "Add" button.
* - Attributes: name, label, min, max, sublabel, value, size, maxlength, event
Line 518 ⟶ 520:
}
break;
// input is actually a text-type, so number here inherits the same stuff
case 'number':
case 'input':
node = document.createElement('div');
Line 529 ⟶ 533:
 
subnode = node.appendChild(document.createElement('input'));
if (data.value) {
subnode.setAttribute('value', data.value);
}
subnode.setAttribute('name', data.name);
 
subnode.setAttribute('type', 'text');
if (data.sizetype === 'input') {
subnode.setAttribute('sizetype', data.size'text');
} else {
subnode.setAttribute('type', 'textnumber');
if (data.disabled) {
['min', 'max', 'step', 'list'].forEach(function(att) {
subnode.setAttribute('disabled', 'disabled');
if (data[att]) {
}
subnode.setAttribute(att, data[att]);
if (data.required) {
}
subnode.setAttribute('required', 'required');
});
if (data.readonly) {
subnode.setAttribute('readonly', 'readonly');
}
if (data.maxlength) {
subnode.setAttribute('maxlength', data.maxlength);
}
 
['value', 'size', 'placeholder', 'maxlength'].forEach(function(att) {
if (data.value[att]) {
subnode.setAttribute('value'att, data.value[att]);
}
});
['disabled', 'required', 'readonly'].forEach(function(att) {
if (data.disabled[att]) {
subnode.setAttribute('disabled'att, 'disabled'att);
}
});
if (data.event) {
subnode.addEventListener('keyup', data.event, false);
}
 
childContainder = subnode;
break;
Line 2,527 ⟶ 2,535:
onSaveFailure: null,
onLookupCreationSuccess: null,
onLookupCreationFailure: null,
onMoveSuccess: null,
onMoveFailure: null,
Line 3,225 ⟶ 3,234:
* @param {Function} onSuccess - Callback function to be called when
* the username and timestamp are found within the callback.
* @param {Function} [onFailure] - Callback function to be called when
* the lookup fails
*/
this.lookupCreation = function(onSuccess, onFailure) {
ctx.onLookupCreationSuccess = onSuccess;
ctx.onLookupCreationFailure = onFailure || emptyFunction;
if (!onSuccess) {
ctx.statusElement.error('Internal error: no onSuccess callback provided to lookupCreation()!');
ctx.onLookupCreationFailure(this);
return;
}
ctx.onLookupCreationSuccess = onSuccess;
 
var query = {
Line 3,257 ⟶ 3,270:
}
 
ctx.lookupCreationApi = new Morebits.wiki.api('Retrieving page creation information', query, fnLookupCreationSuccess, ctx.statusElement, ctx.onLookupCreationFailure);
ctx.lookupCreationApi.setParent(this);
ctx.lookupCreationApi.post();
Line 3,846 ⟶ 3,859:
var response = ctx.lookupCreationApi.getResponse().query;
 
if (!fnCheckPageName(response, ctx.onLookupCreationFailure)) {
return; // abort
}
Line 3,853 ⟶ 3,866:
if (!rev) {
ctx.statusElement.error('Could not find any revisions of ' + ctx.pageName);
ctx.onLookupCreationFailure(this);
return;
}
Line 3,861 ⟶ 3,875:
if (!ctx.creator) {
ctx.statusElement.error('Could not find name of page creator');
ctx.onLookupCreationFailure(this);
return;
}
Line 3,866 ⟶ 3,881:
if (!ctx.timestamp) {
ctx.statusElement.error('Could not find timestamp of page creation');
ctx.onLookupCreationFailure(this);
return;
}
Line 3,874 ⟶ 3,890:
ctx.lookupCreationApi.query.titles = ctx.pageName; // update pageName if redirect resolution took place in earlier query
 
ctx.lookupCreationApi = new Morebits.wiki.api('Retrieving page creation information', ctx.lookupCreationApi.query, fnLookupNonRedirectCreator, ctx.statusElement, ctx.onLookupCreationFailure);
ctx.lookupCreationApi.setParent(this);
ctx.lookupCreationApi.post();
Line 3,899 ⟶ 3,915:
if (!ctx.creator) {
ctx.statusElement.error('Could not find name of page creator');
ctx.onLookupCreationFailure(this);
return;
}
Line 3,905 ⟶ 3,922:
if (!ctx.timestamp) {
ctx.statusElement.error('Could not find timestamp of page creation');
ctx.onLookupCreationFailure(this);
return;
}