MediaWiki:Common.js: Difference between revisions
Appearance
added map restriction for UP Diliman Main Map |
No edit summary |
||
| Line 145: | Line 145: | ||
}); | }); | ||
/* Maps */ | /* Maps */ | ||
/* UP Diliman Main Map */ | /* UP Diliman Main Map */ | ||
(function () { | (function () { | ||
'use strict'; | |||
function restrictUpDilimanMap() { | |||
var container = document.querySelector( | |||
'#up-diliman-main-map .leaflet-container' | |||
); | |||
if (!container) { | |||
return false; | |||
} | |||
if (!container._leaflet_id) { | |||
return false; | |||
} | |||
/* | |||
* Leaflet keeps the map instance in its internal object registry. | |||
* Find the object whose _leaflet_id matches the container. | |||
*/ | |||
var map = null; | |||
for (var key in L) { | |||
if (L.hasOwnProperty(key)) { | |||
// Nothing needed here; registry is handled below. | |||
} | |||
} | |||
/* | |||
* Leaflet's global map registry. | |||
* Try the common Leaflet internal storage locations. | |||
*/ | |||
if (L.Map && L.Map._instances) { | |||
map = L.Map._instances[container._leaflet_id]; | |||
} | |||
/* | |||
* If the registry above isn't available, inspect the container's | |||
* Leaflet event data for a map reference. | |||
*/ | |||
if (!map && container._leaflet_events) { | |||
for (var eventName in container._leaflet_events) { | |||
var event = container._leaflet_events[eventName]; | |||
if (event && event._map) { | |||
map = event._map; | |||
break; | |||
} | |||
} | |||
} | |||
if (!map) { | |||
return false; | |||
} | |||
var upDilimanBounds = [ | |||
[14.640, 121.055], | |||
[14.665, 121.085] | |||
]; | |||
map.setMaxBounds(upDilimanBounds); | |||
map.options.maxBoundsViscosity = 1.0; | |||
map.setMinZoom(15); | |||
return true; | |||
} | |||
/* | |||
* Maps may initialize after Common.js loads. | |||
* Try repeatedly for a few seconds. | |||
*/ | |||
var attempts = 0; | |||
var timer = setInterval(function () { | |||
attempts++; | |||
if (typeof window.L !== 'undefined' && | |||
typeof L.Map !== 'undefined' && | |||
}()); | restrictUpDilimanMap()) { | ||
/* End of UP Diliman Main Map */ | clearInterval(timer); | ||
} | |||
if (attempts >= 50) { | |||
clearInterval(timer); | |||
} | |||
}, 100); | |||
}()); | |||
/* End of UP Diliman Main Map */ | |||
Revision as of 05:56, 25 September 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">💬</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 */
$(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">×</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">×</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 restrictUpDilimanMap() {
var container = document.querySelector(
'#up-diliman-main-map .leaflet-container'
);
if (!container) {
return false;
}
if (!container._leaflet_id) {
return false;
}
/*
* Leaflet keeps the map instance in its internal object registry.
* Find the object whose _leaflet_id matches the container.
*/
var map = null;
for (var key in L) {
if (L.hasOwnProperty(key)) {
// Nothing needed here; registry is handled below.
}
}
/*
* Leaflet's global map registry.
* Try the common Leaflet internal storage locations.
*/
if (L.Map && L.Map._instances) {
map = L.Map._instances[container._leaflet_id];
}
/*
* If the registry above isn't available, inspect the container's
* Leaflet event data for a map reference.
*/
if (!map && container._leaflet_events) {
for (var eventName in container._leaflet_events) {
var event = container._leaflet_events[eventName];
if (event && event._map) {
map = event._map;
break;
}
}
}
if (!map) {
return false;
}
var upDilimanBounds = [
[14.640, 121.055],
[14.665, 121.085]
];
map.setMaxBounds(upDilimanBounds);
map.options.maxBoundsViscosity = 1.0;
map.setMinZoom(15);
return true;
}
/*
* Maps may initialize after Common.js loads.
* Try repeatedly for a few seconds.
*/
var attempts = 0;
var timer = setInterval(function () {
attempts++;
if (typeof window.L !== 'undefined' &&
typeof L.Map !== 'undefined' &&
restrictUpDilimanMap()) {
clearInterval(timer);
}
if (attempts >= 50) {
clearInterval(timer);
}
}, 100);
}());
/* End of UP Diliman Main Map */