Difference between revisions of "MediaWiki:Mobile.js"

 
Line 1: Line 1:
/* All JavaScript here will be loaded for users of the mobile site */
/* Il codice JavaScript inserito qui viene caricato da ciascuna pagina, per tutti gli utenti. */
window.onscroll = function() {scrollFunction()};
 
function scrollFunction() {
if(document.getElementById("myBtn")!=null){
    if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
      if(document.getElementById("myBtn").style!=null){
        document.getElementById("myBtn").style.display = "block";
        document.getElementById("myBtn").onclick =  function() {topFunction();};
      }
    } else {
      if(document.getElementById("myBtn").style!=null){
        document.getElementById("myBtn").style.display = "none";
      }
    }
    }
}
 
function topFunction() {
console.log("topFunction");
    document.body.scrollTop = 0; // For Safari
    document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
}
/* All JavaScript here will be loaded for users of the mobile site */
/* All JavaScript here will be loaded for users of the mobile site */



Revision as of 09:54, 23 December 2022

/* Il codice JavaScript inserito qui viene caricato da ciascuna pagina, per tutti gli utenti. */
window.onscroll = function() {scrollFunction()};

function scrollFunction() {
	if(document.getElementById("myBtn")!=null){
    if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
      if(document.getElementById("myBtn").style!=null){
        document.getElementById("myBtn").style.display = "block";
        document.getElementById("myBtn").onclick =  function() {topFunction();};
      }
    } else {
      if(document.getElementById("myBtn").style!=null){
        document.getElementById("myBtn").style.display = "none";
      }
    }
    }
}

function topFunction() {
	console.log("topFunction");
    document.body.scrollTop = 0; // For Safari
    document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
}
/* All JavaScript here will be loaded for users of the mobile site */

/* https://www.mediawiki.org/wiki/Topic:Vqy1kx6q4e0bzvyb */

/* Add to MediaWiki:Mobile.js for custom Mobile Menu links 
  for MW-1.34.2 with MobileFrontend and MinervaNeue 
  Just replace span text and href to add links */
  
var timer = setInterval(function() {
       if ($('.menu ul:first').length) {
           console.log("mobile menu exists");
           clearInterval(timer);
           $('.menu ul:first').after(
                 '<ul class="level1"> \
                      <li> \
                      <a href="#" \
                            class="mw-ui-icon mw-ui-icon-before mw-ui-icon-minerva-watchlist"> \
                      <span>Masticationpedia ▼</span> \
                      </a> \
                      </li> \
                      <ul class ="level2"> \
                           <li> \
                           <a href="https://www.masticationpedia.org/" \
                                 class="mw-ui-icon mw-ui-icon-before"> \
                           <span>Main website</span> \
                           </a> \
                           </li> \
                           <li> \
                           <a href="https://www.masticationpedia.org/about.php" \
                                 class="mw-ui-icon mw-ui-icon-before"> \
                           <span>About us</span> \
                           </a> \
                           </li> \
                           <li> \
                           <a href="https://www.masticationpedia.org/scientific_community.php" \
                                 class="mw-ui-icon mw-ui-icon-before"> \
                           <span>Scientific Community</span> \
                           </a> \
                           </li> \
                      </ul> \
                 </ul> \
                 <ul> \
                      <li> \
                      <a href="/wiki/Introduction" \
                            class="mw-ui-icon mw-ui-icon-before mw-ui-icon-minerva-watchlist"> \
                      <span>➜ Introduction</span> \
                      </a> \
                      </li> \
                 </ul> \
                 <ul> \
                      <li> \
                      <a href="/wiki/Masticationpedia:Donate" \
                            class="mw-ui-icon mw-ui-icon-before mw-ui-icon-minerva-watchlist"> \
                      <span>Donate <span style="color: red">♥</span> now</span> \
                      </a> \
                      </li> \
                 </ul>'
            );
            $(".menu").find(".level2").hide(); // hide level2 until level1 is clicked
            $(".level1").click(function(event){ 
                 $(this).find(".level2").slideToggle(500);
            }); // if level1 is clicked, dropdown level2
       }
  }, 100); // check every 100ms