MediaWiki:Common.js: Difference between revisions

From XMethod Wiki
Jump to navigation Jump to search
No edit summary
Admin (talk | contribs)
Add YouTube video embed handler for youtube-video-embed divs
 
Line 21: Line 21:
     mw.loader.load("/index.php?title=MediaWiki:Gadget-SocialFeed.js&action=raw&ctype=text/javascript&v=11");
     mw.loader.load("/index.php?title=MediaWiki:Gadget-SocialFeed.js&action=raw&ctype=text/javascript&v=11");
}
}
/* YouTube video embed handler */
$(function() {
    var embeds = document.querySelectorAll(".youtube-video-embed");
    embeds.forEach(function(el) {
        var videoId = el.getAttribute("data-video-id");
        if (videoId) {
            var iframe = document.createElement("iframe");
            iframe.src = "https://www.youtube.com/embed/" + videoId;
            iframe.style.position = "absolute";
            iframe.style.top = "0";
            iframe.style.left = "0";
            iframe.style.width = "100%";
            iframe.style.height = "100%";
            iframe.setAttribute("frameborder", "0");
            iframe.setAttribute("allowfullscreen", "");
            iframe.setAttribute("allow", "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture");
            el.innerHTML = "";
            el.appendChild(iframe);
        }
    });
});

Latest revision as of 05:55, 12 February 2026

/* Make Admin Tools sidebar header clickable - links to Newsletter Dashboard */
$(function() {
    var sections = document.querySelectorAll(".vector-menu-heading-label");
    sections.forEach(function(header) {
        if (header.textContent.trim() === "Admin Tools") {
            var link = document.createElement("a");
            link.href = "/Special:NewsletterDashboard";
            link.style.color = "inherit";
            link.style.textDecoration = "none";
            link.style.cursor = "pointer";
            link.textContent = header.textContent;
            header.textContent = "";
            header.appendChild(link);
        }
    });
});

/* Load SocialFeed on the Social page - v11 */
if (mw.config.get("wgPageName").indexOf("User:Docmoates/Social") !== -1) {
    mw.loader.load("/index.php?title=MediaWiki:Gadget-SocialFeed.css&action=raw&ctype=text/css&v=11", "text/css");
    mw.loader.load("/index.php?title=MediaWiki:Gadget-SocialFeed.js&action=raw&ctype=text/javascript&v=11");
}

/* YouTube video embed handler */
$(function() {
    var embeds = document.querySelectorAll(".youtube-video-embed");
    embeds.forEach(function(el) {
        var videoId = el.getAttribute("data-video-id");
        if (videoId) {
            var iframe = document.createElement("iframe");
            iframe.src = "https://www.youtube.com/embed/" + videoId;
            iframe.style.position = "absolute";
            iframe.style.top = "0";
            iframe.style.left = "0";
            iframe.style.width = "100%";
            iframe.style.height = "100%";
            iframe.setAttribute("frameborder", "0");
            iframe.setAttribute("allowfullscreen", "");
            iframe.setAttribute("allow", "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture");
            el.innerHTML = "";
            el.appendChild(iframe);
        }
    });
});