MediaWiki:Gadget-refToolbarBase.js: Difference between revisions
Content deleted Content added
localize |
fix for issue reported on talk page |
||
(15 intermediate revisions by 5 users not shown) | |||
Line 1:
/* jshint asi: true */
/* global mw, $, CiteTB, citeTemplate, citeErrorCheck */
if (typeof CiteTB == 'undefined') {▼
var CiteTB = {▼
if ( window.CiteTB === undefined ) {
"Templates" : {}, // All templates
"Options" : {}, // Global options
Line 8 ⟶ 10:
"ErrorChecks" : {} // Error check functions
};
}
mw.usability = {};
mw.usability.getMsg = function(m) { return mw.messages.get(m); }
mw.usability.addMessages = function(msgs) { mw.messages.set(msgs); };
}
// Object for cite templates
window.citeTemplate = function
// Properties
this.templatename = templatename; // The template name - "cite web", "cite book", etc.
Line 18 ⟶ 26:
// Less common - quote, archiveurl - should be everything the template supports minus the basic ones
this.extra = expandedfields;
this.incrementables = {};
// Add it to the list
CiteTB.Templates[this.templatename] = this;
// Methods
this.makeFormInner = function(fields, incrsetup) {
var i=0;
var trs =
var autofills = []
for (i=0; i<fields.length; i++) {
var fieldobj = fields[i];
var field = labelfield = fieldobj.field;
var ad = false;
if (incrsetup && fieldobj.increment_group) {
if ($j.inArray(field, CiteTB.getOption('autodate fields')) != -1 ) {▼
field = fieldobj.field.replace('<N>', '1');
im = $j('<img />').attr('src', 'http://upload.wikimedia.org/wikipedia/commons/thumb/7/7b/Nuvola_apps_date.svg/20px-Nuvola_apps_date.svg.png');▼
labelfield = fieldobj.field.replace('<N>', '');
if (this.incrementables[fieldobj.increment_group] && !this.incrementables[fieldobj.increment_group].setup) {
// The object has been created, but not fully initialized
this.incrementables[fieldobj.increment_group]['fields'].push(fieldobj)
} else if (!this.incrementables[fieldobj.increment_group]) {
// Object not yet created
this.incrementables[fieldobj.increment_group] = {
'fields': [fieldobj],
'val':1,
'setup': false
};
} else if (this.incrementables[fieldobj.increment_group] && this.incrementables[fieldobj.increment_group].setup) {
// Fully initialized from a previous invocation of this function, just resetting the number
this.incrementables[fieldobj.increment_group].val = 1
}
} else if (fieldobj.increment_group) {
// Adding a new row
incrval = this.incrementables[fieldobj.increment_group].val;
field = fieldobj.field.replace('<N>', incrval.toString());
labelfield = fieldobj.field.replace('<N>', '');
}
▲ im = $
im.attr('alt', mw.usability.getMsg('cite-insert-date')).attr('title', mw.usability.getMsg('cite-insert-date'));
var ad = $
ad.append(im);
ad.attr('id', 'cite-date-'+CiteTB.escStr(this.shortform)+'-'+field);
$
}
if (fieldobj.autofillid) {
var autotype = fieldobj.autofillid;
im = $
im.attr('alt', mw.usability.getMsg('cite-autofill-alt')).attr('title', mw.usability.getMsg('cite-autofill-alt'));
var ad = $
ad.append(im);
ad.attr('id', 'cite-auto-'+CiteTB.escStr(this.shortform)+'-'+field+'-'+autotype);
}
if (fieldobj.increment_button) {
var incrtype = fieldobj.increment_group;
im = $('<img />').attr('src', '//upload.wikimedia.org/wikipedia/commons/thumb/b/b9/Nuvola_action_edit_add.svg/20px-Nuvola_action_edit_add.svg.png');
im.attr('alt', mw.usability.getMsg('cite-increment-alt')).attr('title', mw.usability.getMsg('cite-increment-alt'));
var ad = $('<a />').attr('href', '#');
ad.append(im);
ad.attr('id', 'cite-incr-'+CiteTB.escStr(this.shortform)+'-'+incrtype);
}
var display = mw.usability.getMsg('cite-'+
if (typeof display !== 'string') {
var tooltip = fieldobj.tooltip ? $j('<abbr />').attr('title', mw.usability.getMsg(fieldobj.tooltip)).text('*') : false;▼
if (fieldobj.label) {
display = CiteTB.fixStr(fieldobj.label);
} else {
display = CiteTB.fixStr(labelfield)
}
}
▲ var tooltip = fieldobj.tooltip ? $
var input = '';
if (ad) {
input = $
} else {
input = $
}
input.attr('id', 'cite-'+CiteTB.escStr(this.shortform)+'-'+field);
if (fieldobj.autofillprop) {
classname =
if (fieldobj.increment_group) {
input.addClass('cite-'+CiteTB.escStr(this.shortform)+'-incr-'+fieldobj.increment_group);
classname+='-'+this.incrementables[fieldobj.increment_group].val.toString();
}
input.addClass(classname);
}
var label = $
label.attr('for', 'cite-'+CiteTB.escStr(this.shortform)+'-'+field).text(display);
if (tooltip) {
Line 70 ⟶ 125:
style += ' padding-left:1em;';
} else {
var tr = $
}
var td1 = $
td1.append(label);
tr.append(td1);
var td2 = $
td2.append(input);
if (ad) {
Line 84 ⟶ 139:
trs.push(tr);
}
}
var needsetup = false;
for (g in this.incrementables) {
if (!this.incrementables[g].setup) {
needsetup = true;
$( document ).on( 'click', '#cite-incr-'+CiteTB.escStr(this.shortform)+'-'+g, CiteTB.incrementFields );
this.incrementables[g].setup = true;
}
}
if (needsetup || $.isEmptyObject(this.incrementables)) {
for(i=0; i<autofills.length; i++) {
$( document ).on( 'click', autofills[i], CiteTB.initAutofill );
}
}
return trs;
Line 91 ⟶ 159:
// gives a little bit of HTML so the open form can be identified
this.getInitial = function() {
var hidden =
return hidden;
}
Line 98 ⟶ 165:
// makes the form used in the dialog boxes
this.getForm = function() {
var main = $
var form1 = $
var i=0;
var trs = this.makeFormInner(this.basic, true);
for (var i=0; i<trs.length; i++) {
form1.append(trs[i]);
}
var form2 = $
trs = this.makeFormInner(this.extra, true);
for (var i=0; i<trs.length; i++) {
form2.append(trs[i]);
Line 113 ⟶ 180:
main.append(form1).append(form2);
var form3 = $
var tr = $
var td1 = $
var label1 = $
label1.attr('for', "cite-"+CiteTB.escStr(this.shortform)+'-name').text(mw.usability.getMsg('cite-name-label'));
td1.append(label1);
var td2 = $
var input1 = $
input1.attr('id', 'cite-'+CiteTB.escStr(this.shortform)+'-name');
td2.append(input1);
var td3 = $
var label2 = $
label2.attr('for', 'cite-'+CiteTB.escStr(this.shortform)+'-group').text(mw.usability.getMsg('cite-group-label'));
td3.append(label2);
var td4 = $
var input2 = $
input2.attr('id', 'cite-'+CiteTB.escStr(this.shortform)+'-group');
td4.append(input2);
Line 134 ⟶ 201:
form3.append(tr);
main.append(form3);
var extras = $
extras.append('<input type="hidden" class="cite-form-status" value="closed" />');
var hidden = $
hidden.val(this.templatename);
extras.append(hidden);
var span1 = $
span1.text(mw.usability.getMsg('cite-raw-preview'));
extras.append(span1).append('<div class="cite-ref-preview" style="padding:0.5em; font-size:110%" />');
var span2 = $
span2.text(mw.usability.getMsg('cite-parsed-label'));
extras.append(span2).append('<div class="cite-preview-parsed" style="padding-bottom:0.5em; font-size:110%" />');
var link = $
link.text(mw.usability.getMsg('cite-form-parse'));
extras.append(link);
Line 170 ⟶ 237:
*/
window.citeErrorCheck = function
this.obj = obj
CiteTB.ErrorChecks[this.obj.testname] = this;
Line 201 ⟶ 268:
this.getRow = function() {
var row = $
var check = $
check.attr('value', this.obj.testname);
var label = $
label.attr('for', this.obj.testname);
row.append(check).append(' – ').append(label);
Line 210 ⟶ 277:
}
}
$
|