Jump to content

MediaWiki:Common.js: Difference between revisions

From Iskomunidad
No edit summary
No edit summary
Line 1: Line 1:
/* For Main Page Announcement area //this code pulls from the https://ilc.upd.edu.ph/all-posts-and-announcements/ PAGE */
/* For Main Page Announcement area //this code pulls from the https://ilc.upd.edu.ph/all-posts-and-announcements/ PAGE */
document.addEventListener("DOMContentLoaded", async () => {
console.log("JS WORKING");
 
(function () {
 
    console.log("RUNNING IMMEDIATELY");


     const container =
     const container =
         document.getElementById("ilc-announcements");
         document.getElementById("ilc-announcements");
    console.log("Container:", container);


     if (!container) return;
     if (!container) return;


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


        const response = await fetch(
    fetch("https://ilc.upd.edu.ph/wp-json/wp/v2/posts?per_page=5")
            "https://ilc.upd.edu.ph/wp-json/wp/v2/posts?per_page=5",
        .then(res => res.json())
            {
         .then(posts => {
                method: "GET",
                mode: "cors"
            }
         );


        const posts = await response.json();
            let html = "<h2>Announcements</h2>";


        let html = `
             posts.forEach(post => {
             <div class="ilc-announcement-list">
                html += `
                <h2>Announcements</h2>
                     <p>
        `;
 
        posts.forEach(post => {
 
            html += `
                <div class="ilc-announcement-item">
                     <h3>
                         <a href="${post.link}" target="_blank">
                         <a href="${post.link}" target="_blank">
                             ${post.title.rendered}
                             ${post.title.rendered}
                         </a>
                         </a>
                     </h3>
                     </p>
                 </div>
                 `;
            `;
            });
        });


        html += `</div>`;
            container.innerHTML = html;


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


        container.innerHTML =
})();
            "<p>Failed to load announcements.</p>";
    }
});
/*end of new code */
/*end of new code */



Revision as of 05:42, 10 June 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 = "<h2>Announcements</h2>";

            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>");
});