MediaWiki:Common.js: Difference between revisions

From Luminys WIKI
No edit summary
Tag: Reverted
No edit summary
Tag: Manual revert
 
(55 intermediate revisions by 2 users not shown)
Line 1: Line 1:
// http://mediawiki.i.donnie.fun:8085/MediaWiki:Common.js
// http://mediawiki.i.donnie.fun:8085/MediaWiki:Common.js
/* Any JavaScript here will be loaded for all users on every page load. */
/* Any JavaScript here will be loaded for all users on every page load. */
let setBreadcrumbs = function(){
    var pathname = document.location.pathname;
    if(pathname == '/Main_Page') pathname = '/';
    if(pathname == '/index.php') pathname = '/';
    if(pathname != '/'){
      var paths = pathname.replace(/^\//,'').split("/"); var breads = [`<a href="/">Home</a>`];
      for(var pathI = 0; pathI < paths.length; pathI++){
        var p = paths[pathI]; var pName = p.replace(/_/g, ' ').replace(/\%26/g,'&');
        var pUrl = paths.slice(0,pathI+1).join("/");
        if(pathI < paths.length -1 ) breads.push(`<a href="/${pUrl}">${pName}</a>`)
        else if(pName) breads.push(pName)
      }
      $("#mw-content").prepend(`<div style="margin: -36px 20px 0 0; ">${breads.join(" > ")}</div>`);
    }
}


let getCookie = function(name) {
let getCookie = function(name) {
Line 17: Line 33:
     $("#mw-header-container").prepend("<div id='mw-header-lm-title'><div>"+title+"</div></div>")
     $("#mw-header-container").prepend("<div id='mw-header-lm-title'><div>"+title+"</div></div>")
     $("#mw-header-container").prepend(`
     $("#mw-header-container").prepend(`
   <div style="background:white;position: absolute;top: 0;width: 100%;">
   <div style="background:white;position: absolute;top: 0;width: 100%;" class="lm-wiki-header">
   <div style="display:flex; flex-direction:row; align-content: center; align-items:baseline;align-self: center; margin: 0 auto; width: 1280px">
   <div style="display:flex; flex-direction:row; align-content: center; align-items:baseline;align-self: center; margin: 0 auto; width: 1280px">
     <!--<div style="width:14em;"></div>-->
     <!--<div style="width:14em;"></div>-->
     <a href="/" style="height:66px;margin-right:10px"><img src="https://blog.luminyscorp.com/content/images/2024/07/luminys-logo-1.png" style="height:26px;margin:20px 20px 20px 0;"  alt="Luminys Logo">  </a>
     <a href="/" style="height:66px;margin-right:10px"><img src="https://blog.luminyscorp.com/content/images/2024/07/luminys-logo-1.png" style="height:26px;margin:20px 20px 20px 0;"  alt="Luminys Logo">  </a>
     <div class="">
     <div class="">
       <div class="hidden md:block ml-6 font-medium w-full lg:flex lg:w-auto ">
       <!--<div class="hidden md:block ml-6 font-medium w-full lg:flex lg:w-auto ">
         <ul id="lm-header">
         <ul id="lm-header">
           <li><a href='/Main_Page'>Home</a></li>
           <li><a href='/Main_Page'>Home</a></li>
           <li><a href="/Main_Page#How-to_Instructions">Instructions</a></li>
           <li><a href="/Main_Page#How-to_Instructions">Instructions</a></li>
           <li><a href="/Main_Page#Data_Sheets_&_Downloads">Product Support</a></li>
           <li><a href="/Main_Page#Data_Sheets_&_Downloads">Datasheets & Downloads</a></li>
           <li><a href="/Main_Page#How-to_Videos">Videos</a></li>
           <li><a href="/Main_Page#How-to_Videos">Videos</a></li>
         </ul>
         </ul>
       </div>
       </div>-->
     </div>
     </div>
   </div>
   </div>
   </div>
   </div>
     `);
     `);


     if(window.mediaWiki && window.mediaWiki.user && window.mediaWiki.user.getName){
     if(window.mediaWiki && window.mediaWiki.user && window.mediaWiki.user.getName){
Line 46: Line 63:


     if($(".lm-banner img").length > 0){
     if($(".lm-banner img").length > 0){
       $("#mw-header-container").css("background", "url("+ $(".lm-banner img").attr('src') +")").
      var bannerSrc = $(".lm-banner img").attr('src');
      if(!bannerSrc) bannerSrc = "/images/2/27/LuminysMainPageBanner2.png";
       $("#mw-header-container").css("background", "url("+ bannerSrc +")").
         css("background-size", "cover").css('background-repeat', 'no-repeat').  
         css("background-size", "cover").css('background-repeat', 'no-repeat').  
         css('background-position','top 66px right 0')
         css('background-position','top 66px right 0')
Line 54: Line 73:
    
    
$(function () {
$(function () {
    Run();
  Run();
  setBreadcrumbs();
});
});


/* Inserts Back to Top button toward the bottom right of the pages on each page */
$(document).ready(function () {
    // Define the wikitext to render, including "Back to Top" text below the image
    var backToTopWikitext = '[[File:Back_to_Top.png|60px|link=#top|]]<div style="text-align: center; font-size: 12px;">Back to Top</div>';


document.addEventListener('DOMContentLoaded', function () {
     // Use the MediaWiki API to parse the wikitext into HTML
     // Create the modal HTML structure dynamically
     new mw.Api().post({
     var modal = document.createElement('div');
        action: 'parse',
    modal.id = 'image-modal';
        text: backToTopWikitext,
    modal.style.display = 'none';
        contentmodel: 'wikitext',
    modal.style.position = 'fixed';
        format: 'json'
    modal.style.zIndex = '1000';
     }).done(function (data) {
    modal.style.left = '0';
        // Extract the rendered HTML
     modal.style.top = '0';
         var renderedHTML = data.parse.text['*'];
    modal.style.width = '100%';
    modal.style.height = '100%';
    modal.style.backgroundColor = 'rgba(0, 0, 0, 0.8)';
    modal.innerHTML = '<img id="modal-image" style="display: block; margin: auto; max-width: 90%; max-height: 90%; border-radius: 8px;">';
    document.body.appendChild(modal);
 
    // Close modal on clicking outside the image
    modal.addEventListener('click', function () {
         modal.style.display = 'none';
    });


    // Add click event to all images with the class `enlargeable-image`
        // Append the rendered HTML to the end of the content area
    document.querySelectorAll('.enlargeable-image').forEach(function (img) {
        $('#mw-content-text').append('<div style="float: right;">' + renderedHTML + '</div>');
        img.addEventListener('click', function () {
    }).fail(function () {
            var modalImage = document.getElementById('modal-image');
        console.error('Failed to parse wikitext');
            modalImage.src = this.src;
            modal.style.display = 'block';
        });
     });
     });
});
});

Latest revision as of 11:53, 9 December 2024

// http://mediawiki.i.donnie.fun:8085/MediaWiki:Common.js
/* Any JavaScript here will be loaded for all users on every page load. */

let setBreadcrumbs = function(){
    var pathname = document.location.pathname;
    if(pathname == '/Main_Page') pathname = '/';
    if(pathname == '/index.php') pathname = '/';
    if(pathname != '/'){
      var paths = pathname.replace(/^\//,'').split("/"); var breads = [`<a href="/">Home</a>`];
      for(var pathI = 0; pathI < paths.length; pathI++){
        var p = paths[pathI]; var pName = p.replace(/_/g, ' ').replace(/\%26/g,'&');
        var pUrl = paths.slice(0,pathI+1).join("/");
        if(pathI < paths.length -1 ) breads.push(`<a href="/${pUrl}">${pName}</a>`) 
        else if(pName) breads.push(pName)
      }
      $("#mw-content").prepend(`<div style="margin: -36px 20px 0 0; ">${breads.join(" > ")}</div>`);
    }
}

let getCookie = function(name) {
    let cookie = {};
    document.cookie.split(';').forEach(function(el) {
        let split = el.split('=');
        cookie[split[0].trim()] = split.slice(1).join("=");
    })
    return cookie[name];
}
  
let Run = function(){
    let title = $("#firstHeading").text()
    if(title == "Main Page") title = "Luminys Knowledge Base (Wiki)"
    if(title.indexOf('/') >= 0) title = title.replace("/", "<br/>")
    $("#mw-header-container").prepend("<div id='mw-header-lm-title'><div>"+title+"</div></div>")
    $("#mw-header-container").prepend(`
  <div style="background:white;position: absolute;top: 0;width: 100%;" class="lm-wiki-header">
  <div style="display:flex; flex-direction:row; align-content: center; align-items:baseline;align-self: center; margin: 0 auto; width: 1280px">
    <!--<div style="width:14em;"></div>-->
    <a href="/" style="height:66px;margin-right:10px"><img src="https://blog.luminyscorp.com/content/images/2024/07/luminys-logo-1.png" style="height:26px;margin:20px 20px 20px 0;"  alt="Luminys Logo">  </a>
    <div class="">
      <!--<div class="hidden md:block ml-6 font-medium w-full lg:flex lg:w-auto ">
        <ul id="lm-header">
          <li><a href='/Main_Page'>Home</a></li>
          <li><a href="/Main_Page#How-to_Instructions">Instructions</a></li>
          <li><a href="/Main_Page#Data_Sheets_&_Downloads">Datasheets & Downloads</a></li>
          <li><a href="/Main_Page#How-to_Videos">Videos</a></li>
        </ul>
      </div>-->
    </div>
  </div>
  </div>
    `);


    if(window.mediaWiki && window.mediaWiki.user && window.mediaWiki.user.getName){
      //let logined = getCookie('my_wikiUserID');
      let logined = !!window.mediaWiki.user.getName()
      if(logined){ 
        $("#mw-page-header-links ").show(); 
        $("#mw-site-navigation   ").show();
        $("#mw-related-navigation").show();
      }
    }

    if($(".lm-banner img").length > 0){
      var bannerSrc = $(".lm-banner img").attr('src');
      if(!bannerSrc) bannerSrc = "/images/2/27/LuminysMainPageBanner2.png";
      $("#mw-header-container").css("background", "url("+ bannerSrc +")").
        css("background-size", "cover").css('background-repeat', 'no-repeat'). 
        css('background-position','top 66px right 0')
    }
    
}
  
$(function () {
  Run();
  setBreadcrumbs();
});

/* Inserts Back to Top button toward the bottom right of the pages on each page */
$(document).ready(function () {
    // Define the wikitext to render, including "Back to Top" text below the image
    var backToTopWikitext = '[[File:Back_to_Top.png|60px|link=#top|]]<div style="text-align: center; font-size: 12px;">Back to Top</div>';

    // Use the MediaWiki API to parse the wikitext into HTML
    new mw.Api().post({
        action: 'parse',
        text: backToTopWikitext,
        contentmodel: 'wikitext',
        format: 'json'
    }).done(function (data) {
        // Extract the rendered HTML
        var renderedHTML = data.parse.text['*'];

        // Append the rendered HTML to the end of the content area
        $('#mw-content-text').append('<div style="float: right;">' + renderedHTML + '</div>');
    }).fail(function () {
        console.error('Failed to parse wikitext');
    });
});