User:MC10/stubtagtab.js: Difference between revisions

Content deleted Content added
use jQuery
use % to represent jQuery variables, escape template, more compatibility fixes
Line 6:
(function ($) { // Wrap with anonymous function
function stubTagTab() {
var $h, $hb, $newa;
// A list of subpages of WikiProject Stub sorting/Stub types/ that are relevant to this
var a = ['Commerce', 'Culture', 'Education', 'Geography', 'Government, law, and politics', 'History', 'Leisure', 'Military and weaponry', 'Miscellaneous', 'Organizations', 'People', 'Religion, mythology, faiths, and beliefs', 'Science', 'Sports', 'Technology', 'Transport'];
$h = $("<div></div>");
$h.css({
"color": "#000000",
"background-color": "#fff8f8"
});
for (var i = 0; i < a.length; i++) {
$newa = $("<a href=\"#\"></a>");
$newa.click(function (e) {
if (e.preventDefault) e.preventDefault();
if (e.returnValue) e.returnValue = false;
stubTagMenu($(this).text());
});
$newa.text(a[i]);
$h.append($newa);
if ((i + 1) < a.length)
$h.append(" &bull; ");
}
$("#contentSub").append($h);
 
$hb = $("<div></div>");
$hb.css({
"color": "#000000",
"background-color": "#fffff8"
});
$hb.attr("id", "stubtagmenu");
$("#contentSub").append($hb);
}
 
function stubTagMenuRender(data) {
var $parseData = $(data.parse.text["*"]);
$parseData.find("a").each(function () {
var link = $(this).attr("href"),
index = link.indexOf("Template:")
Line 55 ⟶ 56:
}
});
$('#stubtagmenu').html($parseData);
}
 
Line 61 ⟶ 62:
// Fetch the relevant subpage of the WikiProject
$.ajax({
url: mw.config.get("wgServer") + mw.config.get("wgScriptPath") + '/api.php?action=parse&prop=text&text=' + encodeURIComponent('__NOTOC____NOEDITSECTION__\{\{Wikipedia:WikiProject Stub sorting/Stub types/' + stubType + '}}') + '&format=json',
dataType: "json", // "text"
success: stubTagMenuRender