Content deleted Content added
Mike Dillon (talk | contribs) m change check for whether to include in page history from wgIsArticle to wgArticleId > 0 |
m Maintenance: Replacing addOnloadHook with native jQuery (mw:ResourceLoader/Migration_guide_(users)#addOnloadHook - phab:T130879) |
||
(13 intermediate revisions by one other user not shown) | |||
Line 1:
// Requires: [[User:Mike Dillon/Scripts/i18n.js]], [[User:Mike Dillon/Scripts/easydom.js]], [[User:Mike Dillon/Scripts/cookies.js]]
/* <pre><nowiki> */
Line 5:
var pageHistoryCookieName;
var pageHistoryCookieItemCount;
var pageHistoryBeforePorlet;
var pageHistoryExpiresInDays;
/* Messages */
addOnloadHook(function () {▼
// pageHistoryTitle: title of page history portlet
wfAddMsg("en", "pageHistoryTitle", "Page history");
wfAddMsg("es", "pageHistoryTitle", "Historial de páginas");
// clearHistoryLabel: label of the "clear history" link
wfAddMsg("en", "clearHistoryLabel", "clear history");
wfAddMsg("es", "clearHistoryLabel", "borrar historial");
// clearHistoryTitle: tooltip of the "clear history" link
wfAddMsg("en", "clearHistoryTitle", "Clear page history");
wfAddMsg("es", "clearHistoryTitle", "Borrar historial de páginas");
// noPageHistoryText: text to display when there is no page history
wfAddMsg("en", "noPageHistoryText", "No page history");
wfAddMsg("es", "noPageHistoryText", "Ningún historial de páginas");
// Set defaults for variables
if (!pageHistoryCookieName) pageHistoryCookieName = "pageHistory";
if (!pageHistoryCookieItemCount) pageHistoryCookieItemCount = 10;
if (!pageHistoryBeforePorlet) pageHistoryBeforePorlet = null;
if (!pageHistoryExpiresInDays) pageHistoryExpiresInDays = 0;
// Create portlet
with (easyDom) {
var historyPortlet = div({ "class": "portlet", "id": "p-history" },
h5(wfMsg("
var historyList = ul();
var historyPBody = div({ "class": "pBody" }, historyList);
historyPortlet.appendChild(historyPBody);
}
// Insert portlet
var
document.getElementById("column-one").insertBefore(historyPortlet, beforePortlet);
// Extract previous history from cookie
Line 57 ⟶ 77:
}
with (easyDom) {
historyList.appendChild(li(em(wfMsg("
}
deleteCookie(pageHistoryCookieName, { path: "/" });
Line 66 ⟶ 86:
with (easyDom) {
if (historyItems.length == 0) {
historyList.appendChild(li(em(wfMsg("
} else {
for (var n in historyItems) {
Line 75 ⟶ 95:
var itemLabel = historyItems[n].replace(/_/g, " ");
// Add zero-width spaces after other punctuation
itemLabel = itemLabel.replace(/([:;,.)-])/g, "$1\u200B");
historyList.appendChild(li(
a({ "href": itemUrl, "title": historyItems[n] }, itemLabel)));
}
var clearHistoryLink = a({ "href": "#", "title": wfMsg("
em(wfMsg("clearHistoryLabel")));
clearHistoryLink.onclick = clearHistory;
historyPBody.appendChild(div(
{ "style": "padding-top: 1em; text-align: right" }, clearHistoryLink));
}
}
Line 100 ⟶ 123:
historyCookie += encodedItem;
}
writeCookie(pageHistoryCookieName, historyCookie,
{ "path": "/", "expiresInDays": pageHistoryExpiresInDays });
});
|