Content deleted Content added
use jQuery |
only add stub menu if not added already |
||
(13 intermediate revisions by the same user not shown) | |||
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
'History', 'Leisure', 'Military and weaponry 'Religion, mythology, faiths, and beliefs', 'Science', 'Sports', 'Technology', 'Transport' $h
"
"background-color": "#fff8f8"
});▼
});
for (var i = 0; i < a.length; i++) {
$newa = $("<a href=\"#\"></a>");
$newa.click(function (e) {
e.preventDefault();
stubTagMenu($(this).text());
});
$newa.text(a[i]);
$h.append($newa);
if ((i + 1) < a.length) {
$h.append(" • ");
}
$("#contentSub").append($h);
$hb = $("<div></div>"
"background-color": "#
}
function stubTagMenuRender(data) {
var $parseData = $(data.parse.text["*"]);
$parseData.find("a").each(function () {
var link = $(this).attr("href"),
index = link.indexOf("Template:");
if (index === -1) {
$(this).attr({
Line 51 ⟶ 54:
});
} else {
$(this).attr("href", mw.config.get("wgServer") + mw.config.get("wgScript")
+ "?title=" + encodeURIComponent(mw.config.get("wgPageName")) + "&action=edit&autoaddstubtag=" + encodeURIComponent(link.slice(index + 9)));
}
});
$(
}
function stubTagMenuFail() {
$("#stubtagmenu").html("Failed to load stub tags.");
}
function stubTagMenu(stubType) {
// Add loading message
$("#stubtagmenu").html("Loading stub tags, please wait...");
// 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",
success: stubTagMenuRender,
error: stubTagMenuFail
});
}
$(function () {
if (mw.config.get("wgNamespaceNumber") === 0 && mw.config.get("wgAction") === "view"
&& $("#ca-edit").length !== 0) {
var portletLink = mw.util.addPortletLink('p-cactions', '#', 'Stub', 'ca-stubtag', 'Add a stub tag to this page', '');
$(portletLink).click(function (e) {
if (
stubTagTab();
}
});
}
if (___location.href.indexOf("&autoaddstubtag=") !== -1 &&
var x = decodeURIComponent(___location.href.split("&autoaddstubtag=")[1]);
if (x.indexOf("-stub") === -1)
x += "-stub";
} $( $(
$(
}
});
} (jQuery)); // End wrap with anonymous function
// [[Category:Wikipedia scripts]]
|