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 10: Line 10:
                 '<div id="popup-box">' +
                 '<div id="popup-box">' +
                 '<h2>Free Legal Consultation</h2>' +
                 '<h2>Free Legal Consultation</h2>' +
                '<h3>Riverview Legal Group (Ontario)</h3>' +
                 '<p>We specialize in helping Landlords and Tenants at the Landlord and Tenant Board.</p>' +
                 '<p>We specialize in helping Landlords and Tenants at the Landlord and Tenant Board.</p>' +
                 '<p>Call us for help at (888) 655-1076</p>' +
                 '<p>Call us for help at (888) 655-1076</p>' +

Revision as of 04:56, 18 February 2025

console.log("Common.js is loading correctly!");

mw.loader.using(['jquery'], function () {
    $(document).ready(function () {
        var popupLastShown = localStorage.getItem("popupLastShown");
        var popupShownThisSession = sessionStorage.getItem("popupShownThisSession");

        function showPopup() {
            var popup = $('<div id="popup-overlay">' +
                '<div id="popup-box">' +
                '<h2>Free Legal Consultation</h2>' +
                '<h3>Riverview Legal Group (Ontario)</h3>' + 
                '<p>We specialize in helping Landlords and Tenants at the Landlord and Tenant Board.</p>' +
                '<p>Call us for help at (888) 655-1076</p>' +
                '<a href="https://riverview.legal/about-us/" target="_blank" class="popup-button">Book a Consultation</a>' +
                '<span id="popup-close">×</span>' +
                '</div>' +
                '</div>');

            $("body").append(popup);
            localStorage.setItem("popupLastShown", Date.now());
            sessionStorage.setItem("popupShownThisSession", "true");

            // Close popup on click
            $("#popup-close").click(function () {
                $("#popup-overlay").fadeOut();
            });

            // Remove scroll listener after triggering
            $(document).off("scroll", showPopup);
        }

        function shouldShowPopup() {
            var now = Date.now();
            var lastShown = popupLastShown ? parseInt(popupLastShown) : 0;
            var twoMinutesPassed = (now - lastShown) > (2 * 60 * 1000); // 2 minutes in milliseconds

            // Show popup if it's a new session (new page load) or 2 minutes have passed
            return !popupShownThisSession || twoMinutesPassed;
        }

        if (shouldShowPopup()) {
            $(document).one("scroll", showPopup);
        }
    });
});

// Add CSS styles
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: relative;" +
    "}" +
    ".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;" +
    "}"
);