Jump to content

MediaWiki:Common.js: Difference between revisions

From Iskomunidad
added map restriction for UP Diliman Main Map
No edit summary
 
(12 intermediate revisions by the same user not shown)
Line 47: Line 47:
});
});


/*Helpdesk bubble*/
/*
$(function () {
    var bubble = $('<div id="ost-bubble">💬</div>');
    var panel = $('<div id="ost-panel"><iframe src="https://helpdesk.ilc.upd.edu.ph/o.php"></iframe></div>');
    $('body').append(bubble).append(panel);


    bubble.on('click', function () {
        panel.toggle();
    });
});
*/
/* Helpdesk bubble */
/* Helpdesk bubble */
$(function () {
$(function () {
Line 146: Line 134:


/* Maps */
/* Maps */
/* UP Diliman Main Map */
/* UP Diliman Main Map */
(function () {
(function () {
     'use strict';
     'use strict';


     function restrictUpDilimanMap(map) {
     function restrictMap() {
        var container = map.getContainer();


         if (!container) {
         if (typeof window.mapsLeafletList === 'undefined') {
             return;
            return false;
        }
 
        for (var i = 0; i < mapsLeafletList.length; i++) {
 
            var mapWrapper = mapsLeafletList[i];
 
            if (!mapWrapper || !mapWrapper.map) {
                continue;
            }
 
            var map = mapWrapper.map;
            var container = map.getContainer();
 
            if (!container.closest('#up-diliman-main-map')) {
                continue;
            }
 
            map.setMaxBounds([
                [14.645, 121.060],
[14.665, 121.07514208501618]
            ]);
 
            map.options.maxBoundsViscosity = 1.0;
 
             return true;
         }
         }


         if (!container.closest('#up-diliman-main-map')) {
        return false;
             return;
    }
 
    var attempts = 0;
 
    var timer = setInterval(function () {
        attempts++;
 
         if (restrictMap() || attempts >= 50) {
             clearInterval(timer);
         }
         }
    }, 100);


        var upDilimanBounds = [
}());
            [14.640, 121.055], // Southwest
            [14.665, 121.085]  // Northeast
        ];


        // Prevent panning outside the UP Diliman area
/* End of UP Diliman Main Map */
        map.setMaxBounds(upDilimanBounds);
        map.options.maxBoundsViscosity = 1.0;


        // Prevent zooming out too far
        map.setMinZoom(15);
    }


     function installMapHook() {
/* UP Diliman Campus */
         if (typeof window.L === 'undefined' || !L.Map) {
(function () {
    'use strict';
 
     function restrictMap() {
 
         if (typeof window.mapsLeafletList === 'undefined') {
             return false;
             return false;
         }
         }


         if (L.Map.prototype._upDilimanBoundsHookInstalled) {
         for (var i = 0; i < mapsLeafletList.length; i++) {
 
            var mapWrapper = mapsLeafletList[i];
 
            if (!mapWrapper || !mapWrapper.map) {
                continue;
            }
 
            var map = mapWrapper.map;
            var container = map.getContainer();
 
            if (!container.closest('#up-diliman-campus')) {
                continue;
            }
 
            map.setMaxBounds([
                [14.640, 121.055],
                [14.665, 121.085]
            ]);
 
            map.options.maxBoundsViscosity = 1.0;
 
             return true;
             return true;
         }
         }


         L.Map.prototype._upDilimanBoundsHookInstalled = true;
         return false;
    }
 
    var attempts = 0;
 
    var timer = setInterval(function () {
        attempts++;


         L.Map.addInitHook(function () {
         if (restrictMap() || attempts >= 50) {
             restrictUpDilimanMap(this);
             clearInterval(timer);
         });
         }
    }, 100);
 
}());
 
/* End of UP Diliman Campus */


        return true;
/*map recalculation for phones*/
     }
(function () {
     'use strict';


     if (!installMapHook()) {
     function resizeMaps() {
         var attempts = 0;
         if (typeof window.mapsLeafletList === 'undefined') {
            return;
        }


         var timer = setInterval(function () {
         for (var i = 0; i < mapsLeafletList.length; i++) {
             attempts++;
             var mapWrapper = mapsLeafletList[i];


             if (installMapHook() || attempts >= 50) {
             if (mapWrapper && mapWrapper.map) {
                 clearInterval(timer);
                 mapWrapper.map.invalidateSize();
             }
             }
         }, 100);
         }
     }
     }
    window.addEventListener('resize', resizeMaps);
    setTimeout(resizeMaps, 300);
    setTimeout(resizeMaps, 1000);
}());
}());
/* End of UP Diliman Main Map */
 
 
/*map collapse*/
$(function () {
 
    $('.mw-collapsible').on('afterExpand.mw-collapsible', function () {
 
        var collapsible = this;
 
        setTimeout(function () {
 
            $(collapsible).find('.maps-leaflet').each(function () {
 
                var mapElement = this;
 
                /*
                * Find the corresponding Maps extension
                * map object.
                */
                mapsLeafletList.forEach(function (mapObject) {
 
                    if (mapObject[0] === mapElement) {
 
                        /*
                        * mapObject itself is the jQuery object
                        * containing the Leaflet map.
                        */
                        if (typeof mapObject.invalidateSize === 'function') {
 
                            mapObject.invalidateSize();
 
                        }
 
                    }
 
                });
 
            });
 
        }, 300);
 
    });
 
});

Latest revision as of 06:33, 1 October 2026

/* For Main Page Announcement area //this code pulls from the https://ilc.upd.edu.ph/all-posts-and-announcements/ PAGE */
console.log("JS WORKING");

(function () {

    console.log("RUNNING IMMEDIATELY");

    const container =
        document.getElementById("ilc-announcements");

    console.log("Container:", container);

    if (!container) return;

    container.innerHTML = "Loading script...";

    fetch("https://ilc.upd.edu.ph/wp-json/wp/v2/posts?per_page=5")
        .then(res => res.json())
        .then(posts => {

            let html = "";

            posts.forEach(post => {
                html += `
                    <p>
                        <a href="${post.link}" target="_blank">
                            ${post.title.rendered}
                        </a>
                    </p>
                `;
            });

            container.innerHTML = html;

        })
        .catch(err => {
            console.error("FETCH ERROR:", err);
            container.innerHTML = "<p>Failed to load announcements</p>";
        });

})();
/*end of new code */

/* Any JavaScript here will be loaded for all users on every page load. */
$(window).on('load', function(){
	$('#site-tools ul').append("<li><a href='https://iskwiki.upd.edu.ph' target='_blank'>Flipbook</li>");
});


/* Helpdesk bubble */
$(function () {
    var bubble = $('<div id="ost-bubble">' +
    				'<img src="https://helpdesk.ilc.upd.edu.ph/images/ilc-images/Helpdesk-logo-bubble.png" alt="💬">' +
    				'</div>');

    var panel = $(
        '<div id="ost-panel">' +
            '<div id="ost-panel-header">' +
                '<img src="https://helpdesk.ilc.upd.edu.ph/logo.php" alt="Helpdesk" style="height:80px;"> ' +
                '<span id="ost-panel-close">&times;</span>' +
            '</div>' +
            '<div id="ost-panel-body">' +
                '<iframe src="https://helpdesk.ilc.upd.edu.ph/o.php"></iframe>' +
            '</div>' +
            '<div id="ost-panel-footer">' +
                '' +
            '</div>' +
        '</div>'
    );

    $('body').append(bubble).append(panel);

    bubble.on('click', function () {
        panel.toggleClass('ost-open');
    });

    panel.find('#ost-panel-close').on('click', function () {
        panel.removeClass('ost-open');
    });
});

/*Pop-up*/
$(function () {
    // Change this whenever you update the popup
    const popupVersion = "welcome-v1";

    // Only show once on initial visit
    if (localStorage.getItem(popupVersion)) {
        return;
    }
	
	//shows after browse time elapse
	 let elapsed = 0;
    const interval = 100; // 1 msecond

    const timer = setInterval(function () {
        if (!document.hidden) {
            elapsed += interval;
        }

        if (elapsed >= 6000) {
            clearInterval(timer);
            showPopup();
        }
    }, interval);
	
function showPopup() {
    const overlay = $(`
        <div id="welcome-overlay">
            <div id="welcome-popup">
                <button id="welcome-close">&times;</button>

                <a href="https://upsystemdiliman.qualtrics.com/jfe/form/SV_3r4gfKrUHQxo6c6" target="_blank">
                <img src="/images/Survey-link.png"
                alt="Survey Link" id="welcome-image">
				</a>
				
            </div>
        </div>
    `);

    $("body").append(overlay);

    function closePopup() {
        localStorage.setItem(popupVersion, "shown");
        overlay.fadeOut(300, function () {
            overlay.remove();
        });
    }

    $("#welcome-close").on("click", closePopup);
}
});

/* Maps */

/* UP Diliman Main Map */
(function () {
    'use strict';

    function restrictMap() {

        if (typeof window.mapsLeafletList === 'undefined') {
            return false;
        }

        for (var i = 0; i < mapsLeafletList.length; i++) {

            var mapWrapper = mapsLeafletList[i];

            if (!mapWrapper || !mapWrapper.map) {
                continue;
            }

            var map = mapWrapper.map;
            var container = map.getContainer();

            if (!container.closest('#up-diliman-main-map')) {
                continue;
            }

            map.setMaxBounds([
                 [14.645, 121.060],
				 [14.665, 121.07514208501618]
            ]);

            map.options.maxBoundsViscosity = 1.0;

            return true;
        }

        return false;
    }

    var attempts = 0;

    var timer = setInterval(function () {
        attempts++;

        if (restrictMap() || attempts >= 50) {
            clearInterval(timer);
        }
    }, 100);

}());

/* End of UP Diliman Main Map */


/* UP Diliman Campus */
(function () {
    'use strict';

    function restrictMap() {

        if (typeof window.mapsLeafletList === 'undefined') {
            return false;
        }

        for (var i = 0; i < mapsLeafletList.length; i++) {

            var mapWrapper = mapsLeafletList[i];

            if (!mapWrapper || !mapWrapper.map) {
                continue;
            }

            var map = mapWrapper.map;
            var container = map.getContainer();

            if (!container.closest('#up-diliman-campus')) {
                continue;
            }

            map.setMaxBounds([
                [14.640, 121.055],
                [14.665, 121.085]
            ]);

            map.options.maxBoundsViscosity = 1.0;

            return true;
        }

        return false;
    }

    var attempts = 0;

    var timer = setInterval(function () {
        attempts++;

        if (restrictMap() || attempts >= 50) {
            clearInterval(timer);
        }
    }, 100);

}());

/* End of UP Diliman Campus */

/*map recalculation for phones*/
(function () {
    'use strict';

    function resizeMaps() {
        if (typeof window.mapsLeafletList === 'undefined') {
            return;
        }

        for (var i = 0; i < mapsLeafletList.length; i++) {
            var mapWrapper = mapsLeafletList[i];

            if (mapWrapper && mapWrapper.map) {
                mapWrapper.map.invalidateSize();
            }
        }
    }

    window.addEventListener('resize', resizeMaps);

    setTimeout(resizeMaps, 300);
    setTimeout(resizeMaps, 1000);

}());


/*map collapse*/
$(function () {

    $('.mw-collapsible').on('afterExpand.mw-collapsible', function () {

        var collapsible = this;

        setTimeout(function () {

            $(collapsible).find('.maps-leaflet').each(function () {

                var mapElement = this;

                /*
                 * Find the corresponding Maps extension
                 * map object.
                 */
                mapsLeafletList.forEach(function (mapObject) {

                    if (mapObject[0] === mapElement) {

                        /*
                         * mapObject itself is the jQuery object
                         * containing the Leaflet map.
                         */
                        if (typeof mapObject.invalidateSize === 'function') {

                            mapObject.invalidateSize();

                        }

                    }

                });

            });

        }, 300);

    });

});