Anonymous user
MediaWiki:Gadget-morebits.js: Difference between revisions
Repo at d404881: Greatly expand style guidelines, enforce linting rules (#657)
imported>Amorymeltzer (Repo at 769b724: Shift lookupCreator to lookupCreation, also include timestamp; Add documentation for Morebits.status (#645); checkboxShiftClickSupport: trigger click event; Remove Morebits.wikipedia (#600); Add untag functionality (#485); batchOperation: allow post processing function; Remove Morebits.bytes) |
(Repo at d404881: Greatly expand style guidelines, enforce linting rules (#657)) |
||
Line 1:
// <nowiki>
/**
* morebits.js
Line 30:
(
var Morebits = {};
Line 43:
* @returns {boolean}
*/
Morebits.userIsInGroup = function (
return mw.config.get(
};
Line 55:
* Converts an IPv6 address to the canonical form stored and used by MediaWiki.
*/
Morebits.sanitizeIPv6 = function (
address = address.trim();
if (
return null;
}
if (
return address; // nothing else to do for IPv4 addresses or invalid ones
}
Line 66:
address = address.toUpperCase();
// Expand zero abbreviations
var abbrevPos = address.indexOf(
if (
// We know this is valid IPv6. Find the last index of the
// address before any CIDR number (e.g. "a:b:c::/24").
var CIDRStart = address.indexOf(
var addressEnd =
// If the '::' is at the beginning...
var repeat, extra, pad;
if (
repeat = '0:';
extra =
pad = 9; // 7+2 (due to '::')
// If the '::' is at the end...
} else if (
repeat = ':0';
extra = '';
Line 90:
}
var replacement = repeat;
pad -= address.split(
for (
replacement += repeat;
}
replacement += extra;
address = address.replace(
}
// Remove leading zeros from each bloc as needed
address = address.replace(
return address;
Line 153:
* @param {*} eventType
*/
Morebits.quickForm = function QuickForm(
this.root = new Morebits.quickForm.element(
};
Line 171:
* @param {Morebits.quickForm.element} data
*/
Morebits.quickForm.prototype.append = function QuickFormAppend(
return this.root.append(
};
Line 179:
* @param {Object}
*/
Morebits.quickForm.element = function QuickFormElement(
this.data = data;
this.childs = [];
Line 193:
* @returns {Morebits.quickForm.element} The same element passed in
*/
Morebits.quickForm.element.prototype.append = function QuickFormElementAppend(
var child;
if (
child = data;
} else {
child = new Morebits.quickForm.element(
}
this.childs.push(
return child;
};
Line 209:
* @returns {HTMLElement}
*/
Morebits.quickForm.element.prototype.render = function QuickFormElementRender(
var currentNode = this.compute(
for
// do not pass internal_subgroup_id to recursive calls
currentNode[1].appendChild(
}
return currentNode[0];
};
Morebits.quickForm.element.prototype.compute = function QuickFormElementCompute(
var node;
var childContainder = null;
var label;
var id = (
if
// hell hack alpha
data.type = 'hidden';
Line 230:
var i, current, subnode;
switch (
node = document.createElement(
node.className =
node.setAttribute(
if (
node.addEventListener(
}
break;
node = document.createDocumentFragment();
// fragments can't have any attributes, so just return it straight away
return [ node, node ];
node = document.createElement(
node.setAttribute(
if (
label = node.appendChild(
label.setAttribute(
label.appendChild(
}
var select = node.appendChild(
if (
select.addEventListener(
}
if (
select.setAttribute(
}
if (
select.setAttribute(
}
select.setAttribute(
if (
for
current = data.list[i];
if (
current.type = 'optgroup';
} else {
current.type = 'option';
}
subnode = this.compute(
select.appendChild(
}
}
childContainder = select;
break;
case 'option':
node.values =
node.
if (data.selected) {
}
if (data.disabled) {
}
node.setAttribute('label', data.label);
node.
break;
case 'optgroup':
node
if (
for
current = data.list[i];
current.type = 'option'; // must be options here
subnode = this.compute(
node.appendChild(
}
}
case 'field':
node = document.createElement('fieldset');
label
if (data.name) {
}
if (data.disabled) {
}
case 'checkbox':
node = document.createElement('div');
if (data.list) {
if (current.type === 'header') {
// inline hack
cur_div = node.appendChild(
cur_div.appendChild(
if (
Morebits.quickForm.element.generateTooltip(
}
continue;
}
cur_div = node.appendChild(document.createElement('div'));
subnode = cur_div.appendChild(document.createElement('input'));
subnode.values = current.value;
subnode
subnode.
subnode.setAttribute(
subnode.setAttribute(
if (
subnode.setAttribute(
}
if (
subnode.setAttribute(
}
label = cur_div.appendChild(
label.appendChild(
label.setAttribute(
if (
Morebits.quickForm.element.generateTooltip(
}
// styles go on the label, doesn't make sense to style a checkbox/radio
if (
label.setAttribute(
}
var event;
if (
var tmpgroup = current.subgroup;
if (
tmpgroup = [ tmpgroup ];
}
var
type: 'div',
id: id + '_' + i + '_subgroup'
$.each(tmpgroup, function(idx, el) {
var newEl = $.extend({}, el);
if (!newEl.type) {
newEl.type = data.type;
}
newEl.name = (current.name || data.name) + '.' + newEl.name;
subgroupRaw.append(newEl);
});
subgroup.className = 'quickformSubgroup';
event = function(e) {
if (e.target.checked) {
e.target.parentNode.appendChild(e.target.subgroup);
if (e.target.type === 'radio') {
var name = e.target.name;
if (e.target.form.names[name] !== undefined) {
e.target.form.names[name].parentNode.removeChild(e.target.form.names[name].subgroup);
}
e.target.form.names[name] = e.target;
}
} else {
e.target.parentNode.removeChild(e.target.subgroup);
}
};
subnode.addEventListener('change', event, true);
if (current.checked) {
subnode.parentNode.appendChild(subgroup);
}
} else if (data.type === 'radio') {
event = function(e) {
if (e.target.checked) {
var name = e.target.name;
if
e.target.form.names[name].parentNode.removeChild(
}
delete e.target.form.names[name]
}
}
subnode.addEventListener('change', event, true);
// add users' event last, so it can interact with the subgroup
subnode.addEventListener('change', data.event, false);
} else if (current.event) {
subnode.addEventListener('change', current.event, true);
}
}
}
case 'input':
node = document.createElement('div');
node
if (
label = node.appendChild(
label.appendChild(
label.setAttribute(
}
subnode = node.appendChild(
if (
subnode.setAttribute(
}
subnode.setAttribute(
subnode.setAttribute(
subnode.setAttribute(
if (
subnode.setAttribute(
}
if (
subnode.setAttribute(
}
if (
subnode.setAttribute(
}
if (
subnode.setAttribute(
}
if (
subnode.addEventListener(
}
break;
var min = data.min || 1;
var max = data.max || Infinity;
node = document.createElement(
label = node.appendChild(
label.appendChild(
var listNode = node.appendChild(
var more = this.compute(
type: 'button',
label: 'more',
disabled: min >= max,
event: function(e) {
var new_node =
e.target.area.appendChild(
if
e.target.setAttribute(
}
e.stopPropagation();
}
}
node.appendChild(
var moreButton = more[1];
var sublist = {
type: '_dyninput_element',
label: data.sublabel || data.label,
name: data.name,
value: data.value,
size: data.size,
remove: false,
maxlength: data.maxlength,
event: data.event
};
for
var elem = new Morebits.quickForm.element(
listNode.appendChild(
}
sublist.remove = true;
sublist.morebutton = moreButton;
sublist.listnode = listNode;
moreButton.sublist = sublist;
moreButton.area = listNode;
moreButton.max = max - min;
moreButton.counter = 0;
break;
node = document.createElement(
if (
label = node.appendChild(
label.appendChild(
label.setAttribute(
}
subnode = node.appendChild(
if (
subnode.setAttribute(
}
subnode.setAttribute(
subnode.setAttribute(
if (
subnode.setAttribute(
}
if (
subnode.setAttribute(
}
if (
subnode.addEventListener(
}
if (
var remove = this.compute(
type: 'button',
label: 'remove',
Line 546:
var more = e.target.morebutton;
list.removeChild(
--more.counter;
more.removeAttribute(
e.stopPropagation();
}
}
node.appendChild(
var removeButton = remove[1];
removeButton.inputnode = node;
removeButton.listnode = data.listnode;
removeButton.morebutton = data.morebutton;
}
break;
case 'hidden':
node = document.createElement('input');
node.setAttribute('type', 'hidden');
node.values = data.value;
node.setAttribute('value', data.value);
break;
case 'header':
node = document.createElement('h5');
node.appendChild(document.createTextNode(data.label));
break;
case 'div':
node = document.createElement('div');
if (data.name) {
node.setAttribute('name', data.name);
}
if (data.label) {
if (!Array.isArray(data.label)) {
data.label = [ data.label ];
}
var result = document.createElement('span');
result.className = 'quickformDescription';
for (i = 0; i < data.label.length; ++i) {
if (typeof data.label[i] === 'string') {
result.appendChild(document.createTextNode(data.label[i]));
} else if (data.label[i] instanceof Element) {
result.appendChild(data.label[i]);
}
}
node.appendChild(result);
}
break;
case 'submit':
node = document.createElement('span');
childContainder = node.appendChild(document.createElement('input'));
childContainder.setAttribute('type', 'submit');
if (data.label) {
childContainder.setAttribute(
}
childContainder.setAttribute(
if (data.disabled) {
childContainder.setAttribute(
}
break;
case 'button':
node = document.createElement('span');
childContainder = node.appendChild(document.createElement('input'));
childContainder.setAttribute('type', 'button');
if (data.label) {
childContainder.setAttribute(
}
childContainder.setAttribute(
if (data.disabled) {
childContainder.setAttribute(
}
if (data.event) {
childContainder.addEventListener('click', data.event, false);
}
break;
case 'textarea':
node = document.createElement('div');
node.setAttribute('id', 'div_' + id);
if (data.label) {
label = node.appendChild(document.createElement('h5'));
// TODO need to nest a <label> tag in here without creating extra vertical space
// label.setAttribute( 'for', id );
}
subnode = node.appendChild(
subnode.setAttribute(
if (
subnode.setAttribute(
}
if (
subnode.setAttribute(
}
if (
subnode.setAttribute(
}
if (
subnode.setAttribute(
}
if (
subnode.value = data.value;
}
break;
throw new Error(
}
if (
childContainder = node;
}
if (
Morebits.quickForm.element.generateTooltip(
}
if (
childContainder.extra = data.extra;
}
if (
childContainder.setAttribute(
}
if (
childContainder.className =
childContainder.className +
data.className
}
childContainder.setAttribute(
return [ node, childContainder ];
Line 673:
Morebits.quickForm.element.autoNWSW = function() {
return $(this).offset().top > ($(document).scrollTop() + ($(window).height() / 2)) ? 'sw' : 'nw';
};
Line 680:
* @param {Object} data
*/
Morebits.quickForm.element.generateTooltip = function QuickFormElementGenerateTooltip(
$('<span/>', {
};
Line 757:
Morebits.quickForm.getElementLabelObject = function QuickFormGetElementLabelObject(element) {
// for buttons, divs and headers, the label is on the element itself
if (element.type ===
element instanceof HTMLDivElement || element instanceof HTMLHeadingElement) {
return element;
// for fieldsets, the label is the child <legend> element
} else if (element instanceof HTMLFieldSetElement) {
return element.getElementsByTagName(
// for textareas, the label is the sibling <h5> element
} else if (element instanceof HTMLTextAreaElement) {
return element.parentNode.getElementsByTagName(
}
// for others, the label is the sibling <label> element
return element.parentNode.getElementsByTagName('label')[0];
};
Line 812 ⟶ 808:
*/
Morebits.quickForm.overrideElementLabel = function QuickFormOverrideElementLabel(element, temporaryLabelText) {
if (!element.hasAttribute(
element.setAttribute(
}
return Morebits.quickForm.setElementLabel(element, temporaryLabelText);
Line 824 ⟶ 820:
*/
Morebits.quickForm.resetElementLabel = function QuickFormResetElementLabel(element) {
if (element.hasAttribute(
return Morebits.quickForm.setElementLabel(element, element.getAttribute(
}
return null;
Line 845 ⟶ 841:
*/
Morebits.quickForm.setElementTooltipVisibility = function QuickFormSetElementTooltipVisibility(element, visibility) {
$(Morebits.quickForm.getElementContainer(element)).find(
};
Line 865 ⟶ 861:
* in twinkleunlink.js, which is better
*/
HTMLFormElement.prototype.getChecked = function(
var elements = this.elements[name];
if (
// if the element doesn't exists, return null.
return null;
Line 873 ⟶ 869:
var return_array = [];
var i;
if (
var options = elements.options;
for
if (
if (
return_array.push(
} else {
return_array.push(
}
}
}
} else if (
if (
return [];
} else if (
return [ elements.value ];
}
} else {
for
if (
if
continue;
}
if (
return_array.push(
} else {
return_array.push(
}
}
Line 913 ⟶ 909:
*/
HTMLFormElement.prototype.getUnchecked = function(
var elements = this.elements[name];
if (
// if the element doesn't exists, return null.
return null;
Line 921 ⟶ 917:
var return_array = [];
var i;
if (
var options = elements.options;
for
if (
if (
return_array.push(
} else {
return_array.push(
}
}
}
} else if (
if (
return [];
} else if (
return [ elements.value ];
}
} else {
for
if (
if
continue;
}
if (
return_array.push(
} else {
return_array.push(
}
}
Line 965 ⟶ 961:
*/
RegExp.escape = function(
text = mw.RegExp.escape(text);
// Special MediaWiki escape - underscore/space are often equivalent
if (
text = text.replace(
}
Line 985 ⟶ 981:
toUpperCaseFirstChar: function(str) {
str = str.toString();
return str.substr(
},
toLowerCaseFirstChar: function(str) {
str = str.toString();
return str.substr(
},
Line 1,001 ⟶ 997:
* @returns {String[]}
*/
splitWeightedByKeys: function(
if (
throw new Error(
}
var level = 0;
var initial = null;
var result = [];
if (
if (
skiplist = [];
} else if (
skiplist = [ skiplist ];
} else {
throw new Error(
}
}
for
for
if
i += skiplist[j].length - 1;
continue;
}
}
if
if (
initial = i;
}
++level;
i += start.length - 1;
} else if
--level;
i += end.length - 1;
}
if (
result.push(
initial = null;
}
Line 1,049 ⟶ 1,045:
* @returns {string}
*/
formatReasonText: function(
var result = str.toString().trim();
var unbinder = new Morebits.unbinder(result);
unbinder.unbind(
unbinder.content = unbinder.content.replace(/\|/g,
return unbinder.rebind();
},
Line 1,063 ⟶ 1,059:
*/
safeReplace: function morebitsStringSafeReplace(string, pattern, replacement) {
return string.replace(pattern, replacement.replace(/\$/g,
}
};
Line 1,077 ⟶ 1,073:
*/
uniq: function(arr) {
if (
throw
}
var result = [];
for
var current = arr[i];
if (
result.push(
}
}
Line 1,095 ⟶ 1,091:
*/
dups: function(arr) {
if (
throw
}
var uniques = [];
var result = [];
for
var current = arr[i];
if (
uniques.push(
} else {
result.push(
}
}
Line 1,119 ⟶ 1,115:
* @returns {Array}
*/
chunk: function(
if (
throw
}
if
return [ arr ]; // we return an array consisting of this array.
}
var result = [];
var current;
for
if (
current = [];
result.push(
}
current.push(
}
return result;
Line 1,163 ⟶ 1,159:
*
* eg. var u = new Morebits.unbinder("Hello world <!-- world --> world");
*
*
*
*
* Text within the 'unbinded' part (in this case, the HTML comment) remains intact
Line 1,177 ⟶ 1,173:
* @param {string} string
*/
Morebits.unbinder = function Unbinder(
if (
throw new Error(
}
this.content = string;
Line 1,193 ⟶ 1,189:
* @param {string} postfix
*/
unbind: function UnbinderUnbind(
var re = new RegExp(
this.content = this.content.replace(
},
Line 1,204 ⟶ 1,200:
var content = this.content;
content.self = this;
for (
if
content = content.replace(
}
}
Line 1,219 ⟶ 1,215:
Morebits.unbinder.getCallback = function UnbinderGetCallback(self) {
return function UnbinderCallback(
var current = self.prefix + self.counter + self.postfix;
self.history[current] = match;
Line 1,238 ⟶ 1,234:
Date.monthNames = ['January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December' ];
Date.monthNamesAbbrev = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
Date.prototype.getMonthName = function() {
return Date.monthNames[
};
Date.prototype.getMonthNameAbbrev = function() {
return Date.monthNamesAbbrev[
};
Date.prototype.getUTCMonthName = function() {
return Date.monthNames[
};
Date.prototype.getUTCMonthNameAbbrev = function() {
return Date.monthNamesAbbrev[
};
Line 1,272 ⟶ 1,268:
*/
Morebits.wiki.isPageRedirect = function wikipediaIsPageRedirect() {
return !!(mw.config.get(
};
Line 1,309 ⟶ 1,305:
Morebits.wiki.nbrOfCheckpointsLeft = 0;
Morebits.wiki.actionCompleted = function(
if
Morebits.wiki.actionCompleted.event(
}
};
Line 1,317 ⟶ 1,313:
// Change per action wanted
Morebits.wiki.actionCompleted.event = function() {
new Morebits.status(
if (
// if it isn't a URL, make it one. TODO: This breaks on the articles 'http://', 'ftp://', and similar ones.
if
Morebits.wiki.actionCompleted.redirect = mw.util.getUrl(
if (
Morebits.wiki.actionCompleted.redirect +=
}
}
window.setTimeout(
window.location = Morebits.wiki.actionCompleted.redirect;
}, Morebits.wiki.actionCompleted.timeOut);
}
};
Morebits.wiki.actionCompleted.timeOut =
Morebits.wiki.actionCompleted.redirect = null;
Morebits.wiki.actionCompleted.notice = 'Action';
Line 1,340 ⟶ 1,338:
Morebits.wiki.removeCheckpoint = function() {
if
Morebits.wiki.actionCompleted.event();
}
Line 1,358 ⟶ 1,356:
* @param {Function} [onError] - The function to call if an error occurs (optional)
*/
Morebits.wiki.api = function(
this.currentAction = currentAction;
this.query = query;
Line 1,365 ⟶ 1,363:
this.onSuccess = onSuccess;
this.onError = onError;
if (
this.statelem = statusElement;
this.statelem.status(
} else {
this.statelem = new Morebits.status(
}
};
Line 1,380 ⟶ 1,378:
query: null,
responseXML: null,
setParent: function(parent) {
this.parent = parent;
}, // keep track of parent object for callbacks
statelem: null, // this non-standard name kept for backwards compatibility
statusText: null, // result received from the API, normally "success" or "error"
Line 1,391:
* really want to give jQuery some extra parameters
*/
post: function(
++Morebits.wiki.numberOfActionsLeft;
var ajaxparams = $.extend(
context: this,
type: 'POST',
Line 1,404:
'Api-User-Agent': morebitsWikiApiUserAgent
}
}, callerAjaxParameters
return $.ajax(
function(xml, statusText) {
this.statusText = statusText;
Line 1,413:
this.errorText = $(xml).find('error').attr('info');
if (typeof this.errorCode ===
// the API didn't like what we told it, e.g., bad edit token or an error creating a page
Line 1,425:
// set the callback context to this.parent for new code and supply the API object
// as the first argument to the callback (for legacy code)
this.onSuccess.call(
} else {
this.statelem.info(
}
Line 1,444:
returnError: function() {
if (
this.statelem.error(
} else {
this.statelem.error(
}
Line 1,455:
// set the callback context to this.parent for new code and supply the API object
// as the first argument to the callback for legacy code
this.onError.call(
}
// don't complete the action so that the error remains displayed
Line 1,485:
* @param {string} ua User agent
*/
Morebits.wiki.api.setApiUserAgent = function(
morebitsWikiApiUserAgent = (
};
Line 1,725:
// Need to be able to do something after the page loads
if (!onSuccess) {
ctx.statusElement.error(
ctx.onLoadFailure(this);
return;
Line 1,756:
}
ctx.loadApi = new Morebits.wiki.api(
ctx.loadApi.setParent(this);
ctx.loadApi.post();
Line 1,782:
if (!ctx.pageLoaded && !canUseMwUserToken) {
ctx.statusElement.error(
ctx.onSaveFailure(this);
return;
}
if (!ctx.editSummary) {
ctx.statusElement.error(
ctx.onSaveFailure(this);
return;
Line 1,795:
if (ctx.fullyProtected && !ctx.suppressProtectWarning &&
!confirm('You are about to make an edit to the fully protected page "' + ctx.pageName +
(ctx.fullyProtected === 'infinity' ? '" (protected indefinitely)' :
'. \n\nClick OK to proceed with the edit, or Cancel to skip this edit.')) {
ctx.statusElement.error(
ctx.onSaveFailure(this);
return;
Line 1,829:
switch (ctx.editMode) {
case 'append':
query.appendtext = ctx.appendText; // use mode to append to current page contents
break;
case 'prepend':
query.prependtext = ctx.prependText; // use mode to prepend to current page contents
break;
case 'revert':
query.undo = ctx.revertCurID;
query.undoafter = ctx.revertOldID;
if (ctx.lastEditTime) {
query.basetimestamp = ctx.lastEditTime; // check that page hasn't been edited since it was loaded
}
query.starttimestamp = ctx.loadTime; // check that page hasn't been deleted since it was loaded (don't recreate bad stuff)
break;
default:
query.text = ctx.pageText; // replace entire contents of the page
if (ctx.lastEditTime) {
query.basetimestamp = ctx.lastEditTime; // check that page hasn't been edited since it was loaded
}
query.starttimestamp = ctx.loadTime; // check that page hasn't been deleted since it was loaded (don't recreate bad stuff)
break;
}
Line 1,860:
}
ctx.saveApi = new Morebits.wiki.api(
ctx.saveApi.setParent(this);
ctx.saveApi.post();
Line 2,050:
this.setFollowRedirect = function(followRedirect) {
if (ctx.pageLoaded) {
ctx.statusElement.error(
return;
}
Line 2,175:
this.lookupCreation = function(onSuccess) {
if (!onSuccess) {
ctx.statusElement.error(
return;
}
Line 2,193:
}
ctx.lookupCreationApi = new Morebits.wiki.api(
ctx.lookupCreationApi.setParent(this);
ctx.lookupCreationApi.post();
Line 2,202:
this.lookupCreator = function(onSuccess) {
console.warn("NOTE: lookupCreator() from Twinkle's Morebits has been deprecated since May/June 2019, please use lookupCreation() instead"); // eslint-disable-line no-console
Morebits.status.warn(
return this.lookupCreation(onSuccess);
};
Line 2,211:
this.patrol = function() {
// There's no patrol link on page, so we can't patrol
if (
return;
}
// Extract the rcid token from the "Mark page as patrolled" link on page
var patrolhref = $(
rcid = mw.util.getParamValue(
if (
var patrolstat = new Morebits.status(
var wikipedia_api = new Morebits.wiki.api(
action: 'patrol',
rcid: rcid,
token: mw.user.tokens.get(
}, null, patrolstat
// We don't really care about the response
Line 2,244:
if (!ctx.revertOldID) {
ctx.statusElement.error(
ctx.onSaveFailure(this);
return;
Line 2,263:
if (!ctx.editSummary) {
ctx.statusElement.error(
ctx.onMoveFailure(this);
return;
}
if (!ctx.moveDestination) {
ctx.statusElement.error(
ctx.onMoveFailure(this);
return;
Line 2,286:
}
ctx.moveApi = new Morebits.wiki.api(
ctx.moveApi.setParent(this);
ctx.moveApi.post();
Line 2,303:
// if a non-admin tries to do this, don't bother
if (!Morebits.userIsInGroup('sysop')) {
ctx.statusElement.error(
ctx.onDeleteFailure(this);
return;
}
if (!ctx.editSummary) {
ctx.statusElement.error(
ctx.onDeleteFailure(this);
return;
Line 2,327:
}
ctx.deleteApi = new Morebits.wiki.api(
ctx.deleteApi.setParent(this);
ctx.deleteApi.post();
Line 2,344:
// if a non-admin tries to do this, don't bother
if (!Morebits.userIsInGroup('sysop')) {
ctx.statusElement.error(
ctx.onUndeleteFailure(this);
return;
}
if (!ctx.editSummary) {
ctx.statusElement.error(
ctx.onUndeleteFailure(this);
return;
Line 2,365:
};
ctx.undeleteApi = new Morebits.wiki.api(
ctx.undeleteApi.setParent(this);
ctx.undeleteApi.post();
Line 2,382:
// if a non-admin tries to do this, don't bother
if (!Morebits.userIsInGroup('sysop')) {
ctx.statusElement.error(
ctx.onProtectFailure(this);
return;
}
if (!ctx.protectEdit && !ctx.protectMove && !ctx.protectCreate) {
ctx.statusElement.error(
ctx.onProtectFailure(this);
return;
}
if (!ctx.editSummary) {
ctx.statusElement.error(
ctx.onProtectFailure(this);
return;
Line 2,411:
}
ctx.protectApi = new Morebits.wiki.api(
ctx.protectApi.setParent(this);
ctx.protectApi.post();
Line 2,425:
// if a non-admin tries to do this, don't bother
if (!Morebits.userIsInGroup('sysop')) {
ctx.statusElement.error(
ctx.onStabilizeFailure(this);
return;
}
if (!ctx.flaggedRevs) {
ctx.statusElement.error(
ctx.onStabilizeFailure(this);
return;
}
if (!ctx.editSummary) {
ctx.statusElement.error(
ctx.onStabilizeFailure(this);
return;
Line 2,450:
}
ctx.stabilizeApi = new Morebits.wiki.api(
ctx.stabilizeApi.setParent(this);
ctx.stabilizeApi.post();
Line 2,504:
var xml = ctx.loadApi.getXML();
if (
return; // abort
}
ctx.pageExists =
if (ctx.pageExists) {
ctx.pageText = $(xml).find('rev').text();
Line 2,527:
ctx.editToken = $(xml).find('page').attr('edittoken');
if (!ctx.editToken) {
ctx.statusElement.error(
ctx.onLoadFailure(this);
return;
Line 2,533:
ctx.loadTime = $(xml).find('page').attr('starttimestamp');
if (!ctx.loadTime) {
ctx.statusElement.error(
ctx.onLoadFailure(this);
return;
Line 2,543:
ctx.revertCurID = $(xml).find('rev').attr('revid');
if (!ctx.revertCurID) {
ctx.statusElement.error(
ctx.onLoadFailure(this);
return;
Line 2,549:
ctx.revertUser = $(xml).find('rev').attr('user');
if (!ctx.revertUser) {
if ($(xml).find('rev').attr('userhidden') ===
ctx.revertUser =
} else {
ctx.statusElement.error(
ctx.onLoadFailure(this);
return;
Line 2,558:
}
// set revert edit summary
ctx.editSummary =
}
Line 2,574:
// check for invalid titles
if (
ctx.statusElement.error(
onFailure(this);
return false; // abort
Line 2,581:
// retrieve actual title of the page after normalization and redirects
if (
var resolvedName = $(xml).find('page').attr('title');
// only notify user for redirects, not normalization
if (
Morebits.status.info(
}
ctx.pageName = resolvedName; // always update in case of normalization
} else {
// could be a circular redirect or other problem
ctx.statusElement.error(
onFailure(this);
Line 2,608 ⟶ 2,607:
// see if the API thinks we were successful
if ($(xml).find('edit').attr('result') ===
// real success
// default on success action - display link for edited page
var link = document.createElement('a');
link.setAttribute('href', mw.util.getUrl(ctx.pageName)
link.appendChild(document.createTextNode(ctx.pageName));
ctx.statusElement.info(['completed (', link, ')']);
Line 2,629 ⟶ 2,628:
if (blacklist) {
var code = document.createElement('code');
code.style.fontFamily =
code.appendChild(document.createTextNode(blacklist));
ctx.statusElement.error(['Could not save the page because the URL ', code, ' is on the spam blacklist.']);
} else if (
ctx.statusElement.error(
} else if (
ctx.statusElement.error('The edit was disallowed by the edit filter rule "' + $editNode.attr('info').substring(17) + '".');
} else if (
var div = document.createElement('div');
div.className =
div.style.fontWeight =
div.style.color =
div.innerHTML = $editNode.attr('warning');
ctx.statusElement.error([ 'The following warning was returned by the edit filter: ', div, 'If you wish to proceed with the edit, please carry it out again. This warning wil not appear a second time.' ]);
Line 2,646 ⟶ 2,645:
// I can't see how to do this without creating a UI dependency on Morebits.wiki.page though -- TTO
} else {
ctx.statusElement.error(
}
Line 2,661 ⟶ 2,660:
// check for edit conflict
if (
// edit conflicts can occur when the page needs to be purged from the server cache
Line 2,669 ⟶ 2,668:
};
var purgeApi = new Morebits.wiki.api(
purgeApi.post(
--Morebits.wiki.numberOfActionsLeft; // allow for normal completion if retry succeeds
ctx.statusElement.info(
if (fnCanUseMwUserToken('edit')) {
ctx.saveApi.post(); // necessarily append or prepend, so this should work as desired
Line 2,683 ⟶ 2,682:
// check for loss of edit token
// it's impractical to request a new token here, so invoke edit conflict logic when this happens
} else if (
ctx.statusElement.info(
--Morebits.wiki.numberOfActionsLeft; // allow for normal completion if retry succeeds
if (fnCanUseMwUserToken('edit')) {
Line 2,694 ⟶ 2,693:
// check for network or server error
} else if (
// the error might be transient, so try again
ctx.statusElement.info(
--Morebits.wiki.numberOfActionsLeft; // allow for normal completion if retry succeeds
ctx.saveApi.post(); // give it another go!
Line 2,705 ⟶ 2,704:
// non-admin attempting to edit a protected page - this gives a friendlier message than the default
if (
ctx.statusElement.error(
} else {
ctx.statusElement.error(
}
ctx.editMode = 'all'; // cancel append/prepend/revert modes
Line 2,720 ⟶ 2,719:
var xml = ctx.lookupCreationApi.getXML();
if (
return; // abort
}
Line 2,726 ⟶ 2,725:
ctx.creator = $(xml).find('rev').attr('user');
if (!ctx.creator) {
ctx.statusElement.error(
return;
}
ctx.timestamp = $(xml).find('rev').attr('timestamp');
if (!ctx.timestamp) {
ctx.statusElement.error(
return;
}
Line 2,741 ⟶ 2,740:
var xml = ctx.moveApi.getXML();
if ($(xml).find('page').attr('missing') ===
ctx.statusElement.error(
ctx.onMoveFailure(this);
return;
Line 2,752 ⟶ 2,751:
if (editprot.length > 0 && editprot.attr('level') === 'sysop' && !ctx.suppressProtectWarning &&
!confirm('You are about to move the fully protected page "' + ctx.pageName +
(editprot.attr('expiry') === 'infinity' ? '" (protected indefinitely)' :
'. \n\nClick OK to proceed with the move, or Cancel to skip this move.')) {
ctx.statusElement.error(
ctx.onMoveFailure(this);
return;
Line 2,762 ⟶ 2,761:
var moveToken = $(xml).find('page').attr('movetoken');
if (!moveToken) {
ctx.statusElement.error(
ctx.onMoveFailure(this);
return;
Line 2,787 ⟶ 2,786:
}
ctx.moveProcessApi = new Morebits.wiki.api(
ctx.moveProcessApi.setParent(this);
ctx.moveProcessApi.post();
Line 2,801 ⟶ 2,800:
var xml = ctx.deleteApi.getXML();
if ($(xml).find('page').attr('missing') ===
ctx.statusElement.error(
ctx.onDeleteFailure(this);
return;
Line 2,811 ⟶ 2,810:
if (editprot.length > 0 && editprot.attr('level') === 'sysop' && !ctx.suppressProtectWarning &&
!confirm('You are about to delete the fully protected page "' + ctx.pageName +
(editprot.attr('expiry') === 'infinity' ? '" (protected indefinitely)' :
'. \n\nClick OK to proceed with the deletion, or Cancel to skip this deletion.')) {
ctx.statusElement.error(
ctx.onDeleteFailure(this);
return;
Line 2,820 ⟶ 2,819:
token = $(xml).find('page').attr('deletetoken');
if (!token) {
ctx.statusElement.error(
ctx.onDeleteFailure(this);
return;
Line 2,838 ⟶ 2,837:
}
ctx.deleteProcessApi = new Morebits.wiki.api(
ctx.deleteProcessApi.setParent(this);
ctx.deleteProcessApi.post();
Line 2,849 ⟶ 2,848:
// check for "Database query error"
if (
ctx.statusElement.info(
--Morebits.wiki.numberOfActionsLeft; // allow for normal completion if retry succeeds
ctx.deleteProcessApi.post(); // give it another go!
} else if (
// this is pathetic, but given the current state of Morebits.wiki.page it would
// be a dog's breakfast to try and fix this
ctx.statusElement.error(
if (ctx.onDeleteFailure) {
ctx.onDeleteFailure.call(this, this, ctx.deleteProcessApi);
}
} else if (
ctx.statusElement.error(
if (ctx.onDeleteFailure) {
ctx.onDeleteFailure.call(this, ctx.deleteProcessApi); // invoke callback
Line 2,867 ⟶ 2,866:
// hard error, give up
} else {
ctx.statusElement.error(
if (ctx.onDeleteFailure) {
ctx.onDeleteFailure.call(this, ctx.deleteProcessApi); // invoke callback
Line 2,890 ⟶ 2,889:
var xml = ctx.undeleteApi.getXML();
if ($(xml).find('page').attr('missing') !==
ctx.statusElement.error(
ctx.onUndeleteFailure(this);
return;
Line 2,900 ⟶ 2,899:
if (editprot.length > 0 && editprot.attr('level') === 'sysop' && !ctx.suppressProtectWarning &&
!confirm('You are about to undelete the fully create protected page "' + ctx.pageName +
(editprot.attr('expiry') === 'infinity' ? '" (protected indefinitely)' :
'. \n\nClick OK to proceed with the undeletion, or Cancel to skip this undeletion.')) {
ctx.statusElement.error(
ctx.onUndeleteFailure(this);
return;
Line 2,922 ⟶ 2,921:
}
ctx.undeleteProcessApi = new Morebits.wiki.api(
ctx.undeleteProcessApi.setParent(this);
ctx.undeleteProcessApi.post();
Line 2,933 ⟶ 2,932:
// check for "Database query error"
if (
ctx.statusElement.info(
--Morebits.wiki.numberOfActionsLeft; // allow for normal completion if retry succeeds
ctx.undeleteProcessApi.post(); // give it another go!
} else if (
// this is pathetic, but given the current state of Morebits.wiki.page it would
// be a dog's breakfast to try and fix this
ctx.statusElement.error(
if (ctx.onUndeleteFailure) {
ctx.onUndeleteFailure.call(this, this, ctx.undeleteProcessApi);
}
} else if (
ctx.statusElement.error(
if (ctx.onUndeleteFailure) {
ctx.onUndeleteFailure.call(this, ctx.undeleteProcessApi); // invoke callback
Line 2,951 ⟶ 2,950:
// hard error, give up
} else {
ctx.statusElement.error(
if (ctx.onUndeleteFailure) {
ctx.onUndeleteFailure.call(this, ctx.undeleteProcessApi); // invoke callback
Line 2,961 ⟶ 2,960:
var xml = ctx.protectApi.getXML();
var missing =
if
ctx.statusElement.error(
ctx.onProtectFailure(this);
return;
}
if (ctx.protectCreate && !missing) {
ctx.statusElement.error(
ctx.onProtectFailure(this);
return;
Line 2,977 ⟶ 2,976:
var protectToken = $(xml).find('page').attr('protecttoken');
if (!protectToken) {
ctx.statusElement.error(
ctx.onProtectFailure(this);
return;
Line 2,995 ⟶ 2,994:
expirys.push(ctx.protectEdit.expiry);
} else if (editprot.length) {
protections.push('edit=' + editprot.attr(
expirys.push(editprot.attr(
}
Line 3,003 ⟶ 3,002:
expirys.push(ctx.protectMove.expiry);
} else if (moveprot.length) {
protections.push('move=' + moveprot.attr(
expirys.push(moveprot.attr(
}
Line 3,011 ⟶ 3,010:
expirys.push(ctx.protectCreate.expiry);
} else if (createprot.length) {
protections.push('create=' + createprot.attr(
expirys.push(createprot.attr(
}
Line 3,030 ⟶ 3,029:
}
ctx.protectProcessApi = new Morebits.wiki.api(
ctx.protectProcessApi.setParent(this);
ctx.protectProcessApi.post();
Line 3,038 ⟶ 3,037:
var xml = ctx.stabilizeApi.getXML();
var missing =
if (missing) {
ctx.statusElement.error(
ctx.onStabilizeFailure(this);
return;
Line 3,047 ⟶ 3,046:
var stabilizeToken = $(xml).find('page').attr('edittoken');
if (!stabilizeToken) {
ctx.statusElement.error(
ctx.onStabilizeFailure(this);
return;
Line 3,064 ⟶ 3,063:
}
ctx.stabilizeProcessApi = new Morebits.wiki.api(
ctx.stabilizeProcessApi.setParent(this);
ctx.stabilizeProcessApi.post();
Line 3,096 ⟶ 3,095:
Morebits.wiki.preview = function(previewbox) {
this.previewbox = previewbox;
$(previewbox).addClass(
/**
Line 3,118 ⟶ 3,117:
title: pageTitle || mw.config.get('wgPageName')
};
var renderApi = new Morebits.wiki.api(
renderApi.post();
};
Line 3,126 ⟶ 3,125:
var html = $(xml).find('text').text();
if (!html) {
apiobj.statelem.error(
return;
}
previewbox.innerHTML = html;
$(previewbox).find(
};
Line 3,151 ⟶ 3,150:
Morebits.wikitext.template = {
parse: function(
var count = -1;
var level = -1;
Line 3,162 ⟶ 3,161:
var key, value;
for
var test3 = text.substr(
if (
current += '{{{';
i += 2;
Line 3,170 ⟶ 3,169:
continue;
}
if (
current += '}}}';
i += 2;
Line 3,176 ⟶ 3,175:
continue;
}
var test2 = text.substr(
if
current += test2;
++i;
Line 3,183 ⟶ 3,182:
continue;
}
if (
current += ']]';
++i;
Line 3,189 ⟶ 3,188:
continue;
}
if (
current += test2;
++i;
--level;
if (
if (
result.name = current.substring(2).trim();
++count;
} else {
if (
key = current.substring(
value = current.substring(
result.parameters[key] = value;
equals = -1;
Line 3,214 ⟶ 3,213:
}
if
if (
result.name = current.substring(2).trim();
++count;
} else {
if (
key = current.substring(
value = current.substring(
result.parameters[key] = value;
equals = -1;
Line 3,230 ⟶ 3,229:
}
current = '';
} else if
equals = current.length;
current += text.charAt(i);
Line 3,246 ⟶ 3,245:
* @param {string} text
*/
Morebits.wikitext.page = function mediawikiPage(
this.text = text;
};
Line 3,257 ⟶ 3,256:
* @param {string} link_target
*/
removeLink: function(
var first_char = link_target.substr(
var link_re_string =
// Files and Categories become links with a leading colon.
// e.g. [[:File:Test.png]]
var special_ns_re = /^(?:[Ff]ile|[Ii]mage|[Cc]ategory):/;
var colon = special_ns_re.test(
var link_simple_re = new RegExp(
var link_named_re = new RegExp(
this.text = this.text.replace(
},
Line 3,277 ⟶ 3,276:
* @param {string} reason - Reason to be included in comment, alongside the commented-out image
*/
commentOutImage: function(
var unbinder = new Morebits.unbinder(
unbinder.unbind(
reason = reason ?
var first_char = image.substr(
var image_re_string =
// Check for normal image links, i.e. [[File:Foobar.png|...]]
// Will eat the whole link
var links_re = new RegExp(
var allLinks = Morebits.array.uniq(Morebits.string.splitWeightedByKeys(
for
if (
var replacement = '<!-- ' + reason + allLinks[i] + ' -->';
unbinder.content = unbinder.content.replace(
}
}
// unbind the newly created comments
unbinder.unbind(
// Check for gallery images, i.e. instances that must start on a new line,
// eventually preceded with some space, and must include File: prefix
// Will eat the whole line.
var gallery_image_re = new RegExp(
unbinder.content = unbinder.content.replace(
// unbind the newly created comments
unbinder.unbind(
// Check free image usages, for example as template arguments, might have the File: prefix excluded, but must be preceeded by an |
// Will only eat the image name and the preceeding bar and an eventual named parameter
var free_image_re = new RegExp(
unbinder.content = unbinder.content.replace(
// Rebind the content now, we are done!
this.text = unbinder.rebind();
Line 3,320 ⟶ 3,319:
* @param {string} data
*/
addToImageComment: function(
var first_char = image.substr(
var first_char_regex = RegExp.escape(
if
first_char_regex = '[' + RegExp.escape(
}
var image_re_string =
var links_re = new RegExp(
var allLinks = Morebits.array.uniq(Morebits.string.splitWeightedByKeys(
for
if (
var replacement = allLinks[i];
// just put it at the end?
replacement = replacement.replace(
this.text = this.text.replace(
}
}
var gallery_re = new RegExp(
var newtext =
this.text = this.text.replace(
},
Line 3,347 ⟶ 3,346:
* include namespace prefix only if not in template namespace
*/
removeTemplate: function(
var first_char = template.substr(
var template_re_string =
var links_re = new RegExp(
var allTemplates = Morebits.array.uniq(Morebits.string.splitWeightedByKeys(
for
if (
this.text = this.text.replace(
}
}
Line 3,388 ⟶ 3,387:
this.params = {};
if (
return;
}
Line 3,395 ⟶ 3,394:
var args = qString.split('&');
for
var pair = args[i].split(
var key = decodeURIComponent(
if (
value = decodeURIComponent(
}
Line 3,410 ⟶ 3,409:
Morebits.queryString.staticInit = function() {
if (
Morebits.queryString.staticstr = new Morebits.queryString(location.search.substring(1));
}
Line 3,435 ⟶ 3,434:
};
Morebits.queryString.create = function(
var resarr = [];
var editToken; // KLUGE: this should always be the last item in the query string (bug TW-B-0013)
for (
if (
continue;
}
var res;
if (
var v = [];
for (var j = 0; j < arr[i].length; ++j
v[j] = encodeURIComponent(
}
res = v.join('|');
} else {
res = encodeURIComponent(
}
if (
editToken = res;
} else {
resarr.push(
}
}
if (
resarr.push(
}
return resarr.join('&');
Line 3,509 ⟶ 3,508:
*/
* @constructor
* Morebits.status.init() must be called before any status object is created, otherwise
Line 3,520 ⟶ 3,519:
*/
Morebits.status = function Status(
this.textRaw = text;
this.text = this.codify(text);
this.type = type || 'status';
this.generate();
if (
this.update(
}
};
Line 3,534 ⟶ 3,533:
* @param {HTMLElement} root - usually a div element
*/
Morebits.status.init = function(
if (
throw new Error(
}
while (
root.removeChild(
}
Morebits.status.root = root;
Line 3,547 ⟶ 3,546:
Morebits.status.root = null;
Morebits.status.onError = function(
if (
Morebits.status.errorEvent = handler;
} else {
throw
}
};
Line 3,568 ⟶ 3,567:
*/
link: function() {
if (
Morebits.status.root.appendChild(
this.linked = true;
}
Line 3,578 ⟶ 3,577:
*/
unlink: function() {
if (
Morebits.status.root.removeChild(
this.linked = false;
}
Line 3,587 ⟶ 3,586:
* Create a document fragment with the status text
*/
codify: function(
if (
obj = [ obj ];
}
var result;
result = document.createDocumentFragment();
for
if (
result.appendChild(
} else if (
result.appendChild(
} // Else cosmic radiation made something shit
}
Line 3,609 ⟶ 3,608:
* @param {String} type - 'status' (blue), 'info' (green), 'warn' (red), or 'error' (bold red)
*/
update: function(
this.stat = this.codify(
if (
this.type = type;
if (type === 'error') {
Line 3,623 ⟶ 3,622:
// also log error messages in the browser console
console.error(this.textRaw +
}
}
Line 3,633 ⟶ 3,632:
*/
generate: function() {
this.node = document.createElement(
this.node.appendChild(
this.node.appendChild(
this.target = this.node.appendChild(
this.target.appendChild(
},
Line 3,645 ⟶ 3,644:
render: function() {
this.node.className = 'tw_status_' + this.type;
while (
this.target.removeChild(
}
this.target.appendChild(
this.link();
},
status: function(
this.update(
},
info: function(
this.update(
},
warn: function(
this.update(
},
error: function(
this.update(
}
};
Morebits.status.info = function(
return new Morebits.status(
};
Morebits.status.warn = function(
return new Morebits.status(
};
Morebits.status.error = function(
return new Morebits.status(
};
Line 3,683 ⟶ 3,682:
* @param {string} message
*/
Morebits.status.printUserText = function(
var p = document.createElement(
p.textContent = message;
var div = document.createElement(
div.className = 'toccolours';
div.style.marginTop = '0';
div.style.whiteSpace = 'pre-wrap';
div.textContent = comments;
p.appendChild(
Morebits.status.root.appendChild(
};
Line 3,702 ⟶ 3,701:
*/
Morebits.htmlNode = function (
var node = document.createElement(
if (
node.style.color = color;
}
node.appendChild(
return node;
};
Line 3,726 ⟶ 3,725:
var thisCb = this;
if (event.shiftKey && lastCheckbox !== null) {
var cbs = $(jQuerySelector, jQueryContext); // can't cache them, obviously, if we want to support resorting
var index = -1, lastIndex = -1, i;
for (i = 0; i < cbs.length; i++) {
if (cbs[i] === thisCb) {
index = i;
if (lastIndex > -1) {
break;
}
}
if (cbs[i] === lastCheckbox) {
lastIndex = i;
if (index > -1) {
break;
}
}
}
if (index > -1 && lastIndex > -1) {
// inspired by wikibits
var endState = thisCb.checked;
var start, finish;
Line 3,816 ⟶ 3,817:
// internal counters, etc.
statusElement: new Morebits.status(currentAction ||
worker: null,
postFinish: null,
countStarted: 0,
countFinished: 0,
Line 3,843 ⟶ 3,844:
* Sets a known option:
* - chunkSize (integer):
*
*
* - preserveIndividualStatusLines (boolean):
*
*/
this.setOption = function(optionName, optionValue) {
Line 3,861 ⟶ 3,862:
this.run = function(worker, postFinish) {
if (ctx.running) {
ctx.statusElement.error(
return;
}
Line 3,876 ⟶ 3,877:
var total = ctx.pageList.length;
if (!total) {
ctx.statusElement.info(
ctx.running = false;
return;
Line 3,886 ⟶ 3,887:
// start the process
Morebits.wiki.addCheckpoint();
ctx.statusElement.status(
fnStartNewChunk();
};
Line 3,898 ⟶ 3,899:
// we know the page title - display a relevant message
var pageName = apiobj.getPageName ? apiobj.getPageName() :
var link = document.createElement('a');
link.setAttribute('href', mw.util.getUrl(pageName));
Line 3,944 ⟶ 3,945:
var total = ctx.pageList.length;
if (ctx.countFinished === total) {
var statusString =
if (ctx.countFinishedSuccess < ctx.countFinished) {
ctx.statusElement.warn(statusString);
Line 3,961 ⟶ 3,962:
// just for giggles! (well, serious debugging, actually)
if (ctx.countFinished > total) {
ctx.statusElement.warn(
Morebits.wiki.removeCheckpoint();
ctx.running = false;
Line 3,967 ⟶ 3,968:
}
ctx.statusElement.status(parseInt(100 * ctx.countFinished / total, 10) +
// start a new chunk if we're close enough to the end of the previous chunk, and
Line 3,991 ⟶ 3,992:
* @param {number} height The maximum allowable height for the content area.
*/
Morebits.simpleWindow = function SimpleWindow(
var content = document.createElement(
this.content = content;
content.className = 'morebits-dialog-content';
Line 4,001 ⟶ 4,002:
$(this.content).dialog({
autoOpen: false,
buttons: {
dialogClass: 'morebits-dialog',
width: Math.min(parseInt(window.innerWidth, 10), parseInt(width ? width : 800, 10)),
Line 4,011 ⟶ 4,012:
close: function(event) {
// dialogs and their content can be destroyed once closed
$(event.target).dialog(
},
resizeStart: function() {
this.scrollbox = $(this).find(
if (this.scrollbox) {
this.scrollbox.style.maxHeight =
}
},
Line 4,023 ⟶ 4,024:
},
resize: function() {
this.style.maxHeight =
if (this.scrollbox) {
this.scrollbox.style.width =
}
}
});
var $widget = $(this.content).dialog(
// add background gradient to titlebar
var $titlebar = $widget.find(
var oldstyle = $titlebar.attr(
$titlebar.attr(
// delete the placeholder button (it's only there so the buttonpane gets created)
$widget.find(
value.parentNode.removeChild(value);
});
// add container for the buttons we add, and the footer links (if any)
var buttonspan = document.createElement(
buttonspan.className =
var linksspan = document.createElement(
linksspan.className =
$widget.find(
// resize the scrollbox with the dialog, if one is present
$widget.resizable(
};
Line 4,064 ⟶ 4,065:
*/
focus: function() {
$(this.content).dialog(
return this;
},
Line 4,077 ⟶ 4,078:
event.preventDefault();
}
$(this.content).dialog(
return this;
},
Line 4,088 ⟶ 4,089:
display: function() {
if (this.scriptName) {
var $widget = $(this.content).dialog(
$widget.find(
var scriptnamespan = document.createElement(
scriptnamespan.className =
scriptnamespan.textContent = this.scriptName +
$widget.find(
}
var dialog = $(this.content).dialog(
if (window.setupTooltips && window.pg && window.pg.re && window.pg.re.diff) { // tie in with NAVPOP
dialog.parent()[0].ranSetupTooltipsAlready = false;
window.setupTooltips(dialog.parent()[0]);
}
this.setHeight(
return this;
},
Line 4,110 ⟶ 4,111:
* @returns {Morebits.simpleWindow}
*/
setTitle: function(
$(this.content).dialog(
return this;
},
Line 4,121 ⟶ 4,122:
* @returns {Morebits.simpleWindow}
*/
setScriptName: function(
this.scriptName = name;
return this;
Line 4,131 ⟶ 4,132:
* @returns {Morebits.simpleWindow}
*/
setWidth: function(
$(this.content).dialog(
return this;
},
Line 4,142 ⟶ 4,143:
* @returns {Morebits.simpleWindow}
*/
setHeight: function(
this.height = height;
Line 4,150 ⟶ 4,151:
// chrome has in height in addition to the height of an equivalent "classic"
// Morebits.simpleWindow
if (parseInt(getComputedStyle($(this.content).dialog(
$(this.content).dialog(
} else {
$(this.content).dialog(
}
$(this.content).dialog(
return this;
},
Line 4,167 ⟶ 4,168:
* @returns {Morebits.simpleWindow}
*/
setContent: function(
this.purgeContent();
this.addContent(
return this;
},
Line 4,178 ⟶ 4,179:
* @returns {Morebits.simpleWindow}
*/
addContent: function(
this.content.appendChild(
// look for submit buttons in the content, hide them, and add a proxy button to the button pane
var thisproxy = this;
$(this.content).find('input[type="submit"], button[type="submit"]').each(function(key, value) {
value.style.display =
var button = document.createElement(
button.textContent =
// here is an instance of cheap coding, probably a memory-usage hit in using a closure here
button.addEventListener(
value.click();
}, false);
thisproxy.buttons.push(button);
});
// remove all buttons from the button pane and re-add them
if (this.buttons.length > 0) {
$(this.content).dialog(
} else {
$(this.content).dialog(
}
return this;
Line 4,207 ⟶ 4,210:
this.buttons = [];
// delete all buttons in the buttonpane
$(this.content).dialog(
while (
this.content.removeChild(
}
return this;
Line 4,220 ⟶ 4,223:
* For example, Twinkle's CSD module adds a link to the CSD policy page,
* as well as a link to Twinkle's documentation.
* @param {string} text
* @param {string} wikiPage Link target
* @returns {Morebits.simpleWindow}
*/
addFooterLink: function(
var $footerlinks = $(this.content).dialog(
if (this.hasFooterLinks) {
var bullet = document.createElement(
bullet.textContent =
$footerlinks.append(bullet);
}
var link = document.createElement(
link.setAttribute(
link.setAttribute(
link.setAttribute(
link.textContent = text;
$footerlinks.append(link);
Line 4,251 ⟶ 4,254:
* @returns {Morebits.simpleWindow}
*/
setModality: function(
$(this.content).dialog(
return this;
}
Line 4,266 ⟶ 4,269:
* @param {boolean} enabled
*/
Morebits.simpleWindow.setButtonsEnabled = function(
$(
};
Line 4,275 ⟶ 4,278:
}
Line 4,287 ⟶ 4,290:
*/
if (
/* global Morebits */
window.SimpleWindow = Morebits.simpleWindow;
Line 4,296 ⟶ 4,299:
}
// </nowiki>
|