User:Mike Dillon/Scripts/recentpages.js: Difference between revisions

Content deleted Content added
No edit summary
m Maintenance: Replacing addOnloadHook with native jQuery (mw:ResourceLoader/Migration_guide_(users)#addOnloadHook - phab:T130879)
 
(12 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 6:
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");
 
addOnloadHook$(function () {
// 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("Page historypageHistoryTitle")));
var historyList = ul();
var historyPBody = div({ "class": "pBody" }, historyList);
historyPortlet.appendChild(historyPBody);
}
Line 58 ⟶ 77:
}
with (easyDom) {
historyList.appendChild(li(em(wfMsg("No page historynoPageHistoryText"))));
}
deleteCookie(pageHistoryCookieName, { path: "/" });
Line 67 ⟶ 86:
with (easyDom) {
if (historyItems.length == 0) {
historyList.appendChild(li(em(wfMsg("No page historynoPageHistoryText"))));
} else {
for (var n in historyItems) {
Line 76 ⟶ 95:
 
var itemLabel = historyItems[n].replace(/_/g, " ");
var// itemSlashAdd =zero-width itemLabel.lastIndexOf("/");spaces before some punctuation
if (itemSlash != -1) itemLabel = itemLabel.substrreplace(itemSlash +/([\/(])/g, "\u200B$1");
// 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("Clear page historyclearHistoryTitle") }, em("clear history"));
em(wfMsg("clearHistoryLabel")));
clearHistoryLink.onclick = clearHistory;
historyPBody.appendChild(div(
{ "style": "padding-top: 1em; text-align: right" }, clearHistoryLink));
}
}
Line 101 ⟶ 123:
historyCookie += encodedItem;
}
writeCookie(pageHistoryCookieName, historyCookie, { path: "/" });
{ "path": "/", "expiresInDays": pageHistoryExpiresInDays });
});