MediaWiki:Common.js: Difference between revisions
From Riverview Legal Group
Access restrictions were established for this page. If you see this message, you have no access to this page.
mNo edit summary |
mNo edit summary |
||
| Line 4: | Line 4: | ||
$(document).ready(function () { | $(document).ready(function () { | ||
var popupShown = sessionStorage.getItem("popupShown"); | var popupShown = sessionStorage.getItem("popupShown"); | ||
var | var popupTimeout1 = 120000; // 2 minutes for first popup | ||
var popupTimeout2 = 180000; // 3 minutes for second popup | |||
var timeoutTriggered = false; | var timeoutTriggered = false; | ||
| Line 14: | Line 15: | ||
link: "https://riverview.legal/about-us/", | link: "https://riverview.legal/about-us/", | ||
linkText: "Book a Consultation", | linkText: "Book a Consultation", | ||
eventLabel: "Legal Consultation Popup" | eventLabel: "Legal Consultation Popup", | ||
position: "top: 20%; left: 50%; transform: translate(-50%, 0);" | |||
}, | }, | ||
{ | { | ||
| Line 21: | Line 23: | ||
link: "https://patreon.com/CaselawNinja", | link: "https://patreon.com/CaselawNinja", | ||
linkText: "Join Here", | linkText: "Join Here", | ||
eventLabel: "Patreon Popup" | eventLabel: "Patreon Popup", | ||
position: "top: 60%; left: 50%; transform: translate(-50%, 0);" | |||
} | } | ||
]; | ]; | ||
function sendAnalyticsEvent(label) { | function sendAnalyticsEvent(label) { | ||
| Line 40: | Line 40: | ||
} | } | ||
function showPopup() { | function showPopup(popupData) { | ||
var popup = $('<div | var popup = $('<div class="popup-overlay">' + | ||
'<div | '<div class="popup-box" style="' + popupData.position + '">' + | ||
'<h2>' + | '<h2>' + popupData.title + '</h2>' + | ||
'<p>' + | '<p>' + popupData.content + '</p>' + | ||
'<a href="' + | '<a href="' + popupData.link + '" target="_blank" class="popup-button">' + popupData.linkText + '</a>' + | ||
'<span | '<span class="popup-close">×</span>' + | ||
'</div>' + | '</div>' + | ||
'</div>'); | '</div>'); | ||
$("body").append(popup); | $("body").append(popup); | ||
sendAnalyticsEvent(popupData.eventLabel); | |||
sendAnalyticsEvent( | |||
$(" | $(".popup-close").click(function () { | ||
$(" | $(this).closest(".popup-overlay").fadeOut(function() { $(this).remove(); }); | ||
}); | }); | ||
} | } | ||
| Line 73: | Line 64: | ||
if (!loggedInUser) { | if (!loggedInUser) { | ||
setTimeout(function () { | setTimeout(function () { | ||
showPopup(popups[0]); | |||
}, popupTimeout1); | |||
}, | |||
setTimeout(function () { | |||
showPopup(popups[1]); | |||
}, popupTimeout2); | |||
} | } | ||
}); | }); | ||
| Line 84: | Line 77: | ||
// Unified CSS for popups | // Unified CSS for popups | ||
mw.util.addCSS( | mw.util.addCSS( | ||
" | ".popup-overlay {" + | ||
"position: fixed; top: 0; left: 0; width: 100%; height: 100%;" + | "position: fixed; top: 0; left: 0; width: 100%; height: 100%;" + | ||
"background: rgba(0, 0, 0, 0.6); display: flex; justify-content: center; align-items: center; z-index: 9999;" + | "background: rgba(0, 0, 0, 0.6); display: flex; justify-content: center; align-items: center; z-index: 9999;" + | ||
"}" + | "}" + | ||
" | ".popup-box {" + | ||
"background: white; padding: 20px; border-radius: 10px; text-align: center; width: 300px;" + | "background: white; padding: 20px; border-radius: 10px; text-align: center; width: 300px;" + | ||
"box-shadow: 0 0 10px rgba(0, 0, 0, 0.5); position: | "box-shadow: 0 0 10px rgba(0, 0, 0, 0.5); position: absolute;" + | ||
"}" + | "}" + | ||
".popup-button {" + | ".popup-button {" + | ||
| Line 96: | Line 89: | ||
"text-decoration: none; border-radius: 5px; margin-top: 10px;" + | "text-decoration: none; border-radius: 5px; margin-top: 10px;" + | ||
"}" + | "}" + | ||
" | ".popup-close {" + | ||
"position: absolute; top: 10px; right: 15px; cursor: pointer; font-size: 20px;" + | "position: absolute; top: 10px; right: 15px; cursor: pointer; font-size: 20px;" + | ||
"}" | "}" | ||
); | ); | ||
Revision as of 05:10, 25 February 2025
console.log("Common.js is loading correctly!");
mw.loader.using(['jquery', 'mediawiki.user'], function () {
$(document).ready(function () {
var popupShown = sessionStorage.getItem("popupShown");
var popupTimeout1 = 120000; // 2 minutes for first popup
var popupTimeout2 = 180000; // 3 minutes for second popup
var timeoutTriggered = false;
// Define the two popups
var popups = [
{
title: "Free Legal Consultation <br> Riverview Legal Group (Ontario)",
content: "Our primary focus is the Ontario Landlord and Tenant Board.<br>Call us for help at (888) 655-1076",
link: "https://riverview.legal/about-us/",
linkText: "Book a Consultation",
eventLabel: "Legal Consultation Popup",
position: "top: 20%; left: 50%; transform: translate(-50%, 0);"
},
{
title: "Are you a Legal Professional?",
content: "Support our work with the Caselaw Ninja on Patreon.<br>Become a member today",
link: "https://patreon.com/CaselawNinja",
linkText: "Join Here",
eventLabel: "Patreon Popup",
position: "top: 60%; left: 50%; transform: translate(-50%, 0);"
}
];
function sendAnalyticsEvent(label) {
if (typeof gtag === "function") {
gtag('event', 'popup_shown', {
'event_category': 'Engagement',
'event_label': label,
'value': 1
});
} else {
console.warn("Google Analytics not detected.");
}
}
function showPopup(popupData) {
var popup = $('<div class="popup-overlay">' +
'<div class="popup-box" style="' + popupData.position + '">' +
'<h2>' + popupData.title + '</h2>' +
'<p>' + popupData.content + '</p>' +
'<a href="' + popupData.link + '" target="_blank" class="popup-button">' + popupData.linkText + '</a>' +
'<span class="popup-close">×</span>' +
'</div>' +
'</div>');
$("body").append(popup);
sendAnalyticsEvent(popupData.eventLabel);
$(".popup-close").click(function () {
$(this).closest(".popup-overlay").fadeOut(function() { $(this).remove(); });
});
}
var loggedInUser = mw.config.get('wgUserName');
console.log("Logged-in User:", loggedInUser);
sessionStorage.removeItem("popupShown");
if (!loggedInUser) {
setTimeout(function () {
showPopup(popups[0]);
}, popupTimeout1);
setTimeout(function () {
showPopup(popups[1]);
}, popupTimeout2);
}
});
});
// Unified CSS for popups
mw.util.addCSS(
".popup-overlay {" +
"position: fixed; top: 0; left: 0; width: 100%; height: 100%;" +
"background: rgba(0, 0, 0, 0.6); display: flex; justify-content: center; align-items: center; z-index: 9999;" +
"}" +
".popup-box {" +
"background: white; padding: 20px; border-radius: 10px; text-align: center; width: 300px;" +
"box-shadow: 0 0 10px rgba(0, 0, 0, 0.5); position: absolute;" +
"}" +
".popup-button {" +
"display: inline-block; background: #007bff; color: white; padding: 10px;" +
"text-decoration: none; border-radius: 5px; margin-top: 10px;" +
"}" +
".popup-close {" +
"position: absolute; top: 10px; right: 15px; cursor: pointer; font-size: 20px;" +
"}"
);