Jump to content

MediaWiki:Common.js: Difference between revisions

From Iskomunidad
No edit summary
No edit summary
Line 1: Line 1:
document.addEventListener("DOMContentLoaded", async () => {
document.addEventListener("DOMContentLoaded", async () => {
    const container = document.getElementById("ilc-announcements");


     console.log("START");
     // Stop if container does not exist
 
    const container =
        document.getElementById("ilc-announcements");
 
    console.log("Container:", container);
 
     if (!container) return;
     if (!container) return;


     try {
     try {
        const url = "https://ilc.upd.edu.ph/wp-json/wp/v2/posts?per_page=5";


         console.log("Before fetch");
         const res = await fetch(url);
 
         const posts = await res.json();
         const response = await fetch(
            "https://ilc.upd.edu.ph/wp-json/wp/v2/posts?per_page=5"
        );


         console.log("Response status:", response.status);
         container.innerHTML = posts.map(post => `
            <div>
                <a href="${post.link}" target="_blank">
                    ${post.title.rendered}
                </a>
            </div>
        `).join("");


        const text = await response.text();
    } catch (err) {
 
         container.innerHTML = "Failed to load announcements.";
        console.log("RAW RESPONSE:", text);
         console.error(err);
 
         container.innerHTML =
            "<pre>" + text + "</pre>";
 
    } catch (error) {
 
         console.error("ERROR:", error);
 
        container.innerHTML =
            "<p>Fetch failed.</p>";
     }
     }
});
});
/*end of new code */
/*end of new code */



Revision as of 05:37, 10 June 2026

document.addEventListener("DOMContentLoaded", async () => {
    const container = document.getElementById("ilc-announcements");

    // Stop if container does not exist
    if (!container) return;

    try {
        const url = "https://ilc.upd.edu.ph/wp-json/wp/v2/posts?per_page=5";

        const res = await fetch(url);
        const posts = await res.json();

        container.innerHTML = posts.map(post => `
            <div>
                <a href="${post.link}" target="_blank">
                    ${post.title.rendered}
                </a>
            </div>
        `).join("");

    } catch (err) {
        container.innerHTML = "Failed to load announcements.";
        console.error(err);
    }
});
/*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>");
});